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

> ## Agent Instructions
> For AgentScope Python, use https://docs.agentscope.io/stable/en/index for new projects. For existing projects, check the installed agentscope version and use matching versioned documentation.
> The /latest/ alias points to development documentation. Use it only with the matching development source. Do not mix AgentScope 1.x and 2.x APIs.
> State the AgentScope version when providing installation commands or code examples. ReMe uses its own continuously updated /reme/latest/ documentation.

# Replace a procedure's contents

> Rewrite a procedure; runs keep the copy they started with.

Args:
    sop_id (`str`):
        The procedure to update.
    body (`UpdateSOPRequest`):
        The procedure as it should now read.
    user_id (`str`):
        Injected authenticated user id.
    storage (`StorageBase`):
        Injected storage backend.

Returns:
    `SOPRecord`:
        The procedure as stored.

Raises:
    `HTTPException`:
        422 if a run of it could not open its sessions.



## OpenAPI

````yaml /en/versions/2.0.9/deploy/openapi.json patch /sop/{sop_id}
openapi: 3.1.0
info:
  title: AgentScope
  version: 2.0.9
servers: []
security: []
paths:
  /sop/{sop_id}:
    patch:
      tags:
        - sop
      summary: Replace a procedure's contents
      description: |-
        Rewrite a procedure; runs keep the copy they started with.

        Args:
            sop_id (`str`):
                The procedure to update.
            body (`UpdateSOPRequest`):
                The procedure as it should now read.
            user_id (`str`):
                Injected authenticated user id.
            storage (`StorageBase`):
                Injected storage backend.

        Returns:
            `SOPRecord`:
                The procedure as stored.

        Raises:
            `HTTPException`:
                422 if a run of it could not open its sessions.
      operationId: update_sop_sop__sop_id__patch
      parameters:
        - name: sop_id
          in: path
          required: true
          schema:
            type: string
            title: Sop Id
        - name: x-user-id
          in: header
          required: true
          schema:
            type: string
            description: >-
              Caller's user ID. Temporary header-based identity; will be
              replaced by JWT auth.
            title: X-User-Id
          description: >-
            Caller's user ID. Temporary header-based identity; will be replaced
            by JWT auth.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/UpdateSOPRequest'
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SOPRecord'
        '404':
          description: Not found
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    UpdateSOPRequest:
      properties:
        data:
          $ref: '#/components/schemas/SOPData'
          description: The procedure as it should now read.
      type: object
      required:
        - data
      title: UpdateSOPRequest
      description: Request body for replacing a procedure's contents.
    SOPRecord:
      properties:
        id:
          type: string
          title: Id
          description: Unique identifier for the credential.
        updated_at:
          type: string
          format: date-time
          title: Updated At
        created_at:
          type: string
          format: date-time
          title: Created At
        user_id:
          type: string
          title: User Id
        data:
          $ref: '#/components/schemas/SOPData'
      type: object
      required:
        - user_id
        - data
      title: SOPRecord
      description: A stored procedure.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    SOPData:
      properties:
        name:
          type: string
          title: Name
          description: The name of the procedure.
        description:
          type: string
          title: Description
          description: What the procedure is for.
          default: ''
        steps:
          items:
            $ref: '#/components/schemas/SOPStepDataV1'
          type: array
          minItems: 1
          title: Steps
          description: Its milestones, in the order they must happen.
        workspace_grain:
          $ref: '#/components/schemas/SOPWorkspaceGrain'
          description: How many workspaces a run of this gets.
          default: run
        session_settings:
          additionalProperties:
            $ref: '#/components/schemas/SessionSettings'
          type: object
          title: Session Settings
          description: What each conversation is opened with, keyed by session key.
      type: object
      required:
        - name
        - steps
      title: SOPData
      description: 'A procedure: its milestones, in order.'
    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
    SOPStepDataV1:
      properties:
        version:
          type: string
          const: v1
          title: Version
          default: v1
        subject:
          type: string
          title: Subject
          description: A brief, actionable name.
        description:
          type: string
          title: Description
          description: What this step must achieve — the destination.
        executor:
          $ref: '#/components/schemas/SOPAgentRef'
          description: Who does the work.
        verifier:
          anyOf:
            - oneOf:
                - $ref: '#/components/schemas/AgentVerifier'
                - $ref: '#/components/schemas/HumanVerifier'
              discriminator:
                propertyName: type
                mapping:
                  agent:
                    $ref: '#/components/schemas/AgentVerifier'
                  human:
                    $ref: '#/components/schemas/HumanVerifier'
            - type: 'null'
          title: Verifier
          description: Who judges it. ``None`` accepts whatever comes back.
        max_attempts:
          type: integer
          exclusiveMinimum: 0
          title: Max Attempts
          description: How many refusals before the run gives up on it.
          default: 3
      type: object
      required:
        - subject
        - description
        - executor
      title: SOPStepDataV1
      description: |-
        One milestone, as :class:`~agentscope.sop.SOPStep` runs it.
        An incompatible change becomes a new model discriminated on
        :attr:`version`.
    SOPWorkspaceGrain:
      type: string
      enum:
        - run
        - per_session_key
      title: SOPWorkspaceGrain
      description: |-
        How many workspaces a run gets. Always minted for the run, never
        shared with another run.
    SessionSettings:
      properties:
        chat_model_config:
          additionalProperties: true
          type: object
          title: Chat Model Config
        fallback_chat_model_config:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Fallback Chat Model Config
        permission_mode:
          type: string
          title: Permission Mode
          default: default
      type: object
      required:
        - chat_model_config
      title: SessionSettings
      description: Settings for a session a channel or SOP run opens for a user.
    SOPAgentRef:
      properties:
        agent_id:
          type: string
          title: Agent Id
          description: The agent that does the work.
        session_key:
          type: string
          title: Session Key
          description: >-
            Which conversation it does it in; references sharing a key share one
            session.
      type: object
      required:
        - agent_id
        - session_key
      title: SOPAgentRef
      description: Which agent does something, and in which conversation.
    AgentVerifier:
      properties:
        type:
          type: string
          const: agent
          title: Type
          default: agent
        agent:
          $ref: '#/components/schemas/SOPAgentRef'
          description: Who judges the work.
        criteria:
          type: string
          format: textarea
          title: Criteria
          description: What to hold the work to, beyond the step's own description.
          default: ''
      type: object
      required:
        - agent
      title: AgentVerifier
      description: A verifier that is itself an agent.
    HumanVerifier:
      properties:
        type:
          type: string
          const: human
          title: Type
          default: human
        question:
          type: string
          format: textarea
          title: Question
          description: What the person is asked.
          default: Does this meet what the step had to prove?
      type: object
      title: HumanVerifier
      description: A verifier that asks a person and waits for the answer.

````