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

# Attach a subagent

> Let the agent delegate to another agent. Idempotent: attaching an agent that is already allowed returns `changed: false`.

The subagent must be in the same workspace as the agent, or shared with that workspace. Whether the agent may also clone itself is `metadata.subagent.allow_self_clone` on `PATCH /agents/{agent_id}`.




## OpenAPI

````yaml put /agents/{agent_id}/subagents/{subagent_id}
openapi: 3.0.0
info:
  title: Public API
  version: 1.0.0
servers:
  - url: https://api.gumloop.com/api/v1
security: []
paths:
  /agents/{agent_id}/subagents/{subagent_id}:
    put:
      tags:
        - Agents
      summary: Attach a subagent
      description: >
        Let the agent delegate to another agent. Idempotent: attaching an agent
        that is already allowed returns `changed: false`.


        The subagent must be in the same workspace as the agent, or shared with
        that workspace. Whether the agent may also clone itself is
        `metadata.subagent.allow_self_clone` on `PATCH /agents/{agent_id}`.
      operationId: attachAgentSubagent
      parameters:
        - in: path
          name: agent_id
          required: true
          schema:
            type: string
          description: ID of a custom agent.
        - in: path
          name: subagent_id
          required: true
          schema:
            type: string
          description: ID of the agent to allow as a subagent.
      responses:
        '200':
          description: The allowed subagents after the change.
          content:
            application/json:
              schema:
                type: object
                properties:
                  agent_id:
                    type: string
                  subagent_ids:
                    type: array
                    items:
                      type: string
                  changed:
                    type: boolean
        '400':
          description: >-
            `subagent_not_in_workspace` — the subagent is not reachable from the
            agent's workspace; or `agent_not_customizable`.
        '401':
          description: Unauthorized — missing or invalid API key.
        '403':
          description: Forbidden — the caller does not have update access to this agent.
        '404':
          description: Agent not found.
      security:
        - bearerAuth: []
      x-codeSamples:
        - lang: bash
          label: cURL
          source: >
            curl -X PUT
            'https://api.gumloop.com/api/v1/agents/abc123DEFghiJKL/subagents/xyz789MNOpqrSTU'
            \
              -H 'Authorization: Bearer YOUR_ACCESS_TOKEN'
        - lang: python
          label: Python
          source: >
            from gumloop import Gumloop


            client = Gumloop(access_token="YOUR_ACCESS_TOKEN")


            response = client.agents.attach_subagent("abc123DEFghiJKL",
            "xyz789MNOpqrSTU")

            print(response.subagent_ids)
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        A personal API key or an [OAuth 2.0](/api-reference/oauth) access token.
        Personal API keys also require the `x-auth-key` header with your user
        ID.

````