> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pragmatiks.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Update Instance

> Update an existing agent instance.

Only provided fields are updated. Returns the updated instance.

Returns:
    Updated agent instance.

Raises:
    NotFoundError: If instance not found or belongs to another organization.



## OpenAPI

````yaml https://api.pragmatiks.io/openapi.json patch /agents/instances/{instance_id}
openapi: 3.1.0
info:
  title: Pragma API
  version: 0.1.0
servers: []
security: []
paths:
  /agents/instances/{instance_id}:
    patch:
      tags:
        - agent-instances
      summary: Update Instance
      description: |-
        Update an existing agent instance.

        Only provided fields are updated. Returns the updated instance.

        Returns:
            Updated agent instance.

        Raises:
            NotFoundError: If instance not found or belongs to another organization.
      operationId: agent-instances-update_instance
      parameters:
        - name: instance_id
          in: path
          required: true
          schema:
            type: string
            title: Instance Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AgentInstanceUpdate'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AgentInstance'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    AgentInstanceUpdate:
      properties:
        task_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Task Id
        turn_count:
          anyOf:
            - type: integer
            - type: 'null'
          title: Turn Count
        tokens_total:
          anyOf:
            - type: integer
            - type: 'null'
          title: Tokens Total
        needs_input:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Needs Input
        current_step:
          anyOf:
            - type: string
            - type: 'null'
          title: Current Step
        last_action_at:
          anyOf:
            - type: string
            - type: 'null'
          title: Last Action At
        session_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Session Id
      type: object
      title: AgentInstanceUpdate
      description: >-
        Request body for updating an agent instance. All fields optional.


        Status changes are not allowed here — use the transition endpoint
        instead.


        Attributes:
            task_id: Task this instance is working on.
            turn_count: Number of LLM turns completed.
            tokens_total: Total tokens consumed.
            needs_input: Whether the instance is blocked waiting for human input.
            current_step: Description of what the instance is currently doing.
            last_action_at: Timestamp of the most recent action.
            session_id: External session identifier.
    AgentInstance:
      properties:
        created_at:
          type: string
          format: date-time
          title: Created At
        updated_at:
          type: string
          format: date-time
          title: Updated At
        id:
          anyOf:
            - type: string
            - type: 'null'
          title: Id
        agent_type_id:
          type: string
          title: Agent Type Id
        task_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Task Id
        status:
          $ref: '#/components/schemas/InstanceStatus'
          default: starting
        started_at:
          anyOf:
            - type: string
            - type: 'null'
          title: Started At
        ended_at:
          anyOf:
            - type: string
            - type: 'null'
          title: Ended At
        turn_count:
          type: integer
          title: Turn Count
          default: 0
        tokens_total:
          type: integer
          title: Tokens Total
          default: 0
        needs_input:
          type: boolean
          title: Needs Input
          default: false
        current_step:
          anyOf:
            - type: string
            - type: 'null'
          title: Current Step
        last_action_at:
          anyOf:
            - type: string
            - type: 'null'
          title: Last Action At
        session_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Session Id
      type: object
      required:
        - agent_type_id
      title: AgentInstance
      description: |-
        A running or completed agent session.

        Agent instances live inside the tenant SurrealDB namespace — the
        namespace is the organization boundary, so the record itself
        carries no ``organization_id`` field.

        Attributes:
            id: SurrealDB record ID (populated by database).
            agent_type_id: Agent type this instance runs.
            task_id: Task this instance is working on.
            status: Current lifecycle status.
            started_at: When the instance began execution.
            ended_at: When the instance reached a terminal status.
            turn_count: Number of LLM turns completed.
            tokens_total: Total tokens consumed.
            needs_input: Whether the instance is blocked waiting for human input.
            current_step: Description of what the instance is currently doing.
            last_action_at: Timestamp of the most recent action.
            session_id: External session identifier for conversation continuity.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    InstanceStatus:
      type: string
      enum:
        - starting
        - running
        - waiting
        - paused
        - completed
        - error
        - stopped
      title: InstanceStatus
      description: Lifecycle status of an agent instance.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````