Source: https://docs.cumuluslabs.io/reference/agents.clone
Content version: dad135d2

# agents.clone

Clone an agent's head, chosen version or never-published draft into a new agent's first draft (201; replay 200)

## Request {#request}

`POST /api/v1/agents/{agent_id}/clone`

- MCP: `agents_clone`
- SDK: `client.agents.clone` (SDK path arguments use `path`; MCP uses `params`).
- Minimum API key role: **member**.
- Idempotency: **required_header**. Send an `Idempotency-Key` header; MCP uses `idempotency_key`. Reuse it after an unknown outcome.

Use the request schema below. Read IDs from earlier operation results.

## Input schema {#input-schema}

```json
{
  "parameters": [
    {
      "name": "agent_id",
      "in": "path",
      "required": true,
      "schema": {
        "type": "string",
        "minLength": 1,
        "maxLength": 256,
        "pattern": "^[A-Za-z0-9][A-Za-z0-9_.:-]*$"
      }
    },
    {
      "name": "Idempotency-Key",
      "in": "header",
      "required": true,
      "schema": {
        "type": "string",
        "minLength": 1,
        "maxLength": 256
      }
    }
  ],
  "requestBody": {
    "required": true,
    "content": {
      "application/json": {
        "schema": {
          "$ref": "#/components/schemas/AgentsCloneRequest"
        }
      }
    }
  }
}
```

## Responses {#responses}

```json
{
  "200": {
    "description": "Clone an agent's head, chosen version or never-published draft into a new agent's first draft (201; replay 200)",
    "content": {
      "application/json": {
        "schema": {
          "$ref": "#/components/schemas/AgentSummary"
        }
      }
    }
  },
  "201": {
    "description": "Clone an agent's head, chosen version or never-published draft into a new agent's first draft (201; replay 200)",
    "content": {
      "application/json": {
        "schema": {
          "$ref": "#/components/schemas/AgentSummary"
        }
      }
    }
  },
  "4XX": {
    "description": "Typed error (ApiError)",
    "content": {
      "application/json": {
        "schema": {
          "$ref": "#/components/schemas/ApiError"
        }
      }
    }
  },
  "5XX": {
    "description": "Typed error (ApiError)",
    "content": {
      "application/json": {
        "schema": {
          "$ref": "#/components/schemas/ApiError"
        }
      }
    }
  }
}
```

## Referenced schemas {#schemas}

```json
{
  "components": {
    "schemas": {
      "AgentsCloneRequest": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256
          },
          "version": {
            "allOf": [
              {
                "type": "integer",
                "minimum": 0,
                "maximum": 2147483647
              }
            ],
            "nullable": true
          }
        },
        "required": [
          "name"
        ],
        "additionalProperties": false
      },
      "AgentSummary": {
        "type": "object",
        "properties": {
          "ref": {
            "type": "object",
            "properties": {
              "tenant_id": {
                "type": "string",
                "format": "uuid"
              },
              "kind": {
                "type": "string",
                "enum": [
                  "agent"
                ]
              },
              "id": {
                "type": "string",
                "minLength": 1,
                "maxLength": 256,
                "pattern": "^[A-Za-z0-9][A-Za-z0-9_.:-]*$"
              }
            },
            "required": [
              "tenant_id",
              "kind",
              "id"
            ],
            "additionalProperties": false
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256
          },
          "head": {
            "type": "object",
            "properties": {
              "version": {
                "type": "integer",
                "minimum": 0,
                "maximum": 2147483647
              },
              "digest": {
                "type": "string",
                "pattern": "^sha256:[a-f0-9]{64}$"
              },
              "channels": {
                "type": "array",
                "items": {
                  "type": "string",
                  "enum": [
                    "cloud",
                    "phone"
                  ]
                },
                "minItems": 1
              },
              "languages": {
                "type": "array",
                "items": {
                  "type": "string",
                  "enum": [
                    "en",
                    "es"
                  ]
                },
                "minItems": 1
              },
              "published_at": {
                "type": "string",
                "format": "date-time"
              }
            },
            "required": [
              "version",
              "digest",
              "channels",
              "languages",
              "published_at"
            ],
            "additionalProperties": false,
            "nullable": true
          },
          "draft": {
            "type": "object",
            "properties": {
              "draft_id": {
                "type": "string",
                "format": "uuid"
              },
              "revision": {
                "type": "integer",
                "exclusiveMinimum": true,
                "minimum": 0
              },
              "base_version": {
                "allOf": [
                  {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 2147483647
                  }
                ],
                "nullable": true
              },
              "published_revision": {
                "type": "integer",
                "exclusiveMinimum": true,
                "minimum": 0,
                "nullable": true
              }
            },
            "required": [
              "draft_id",
              "revision",
              "base_version",
              "published_revision"
            ],
            "additionalProperties": false,
            "nullable": true
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "description": "The head's publish time, else created_at: the key of the updated_desc agents.list order"
          },
          "last_run": {
            "type": "object",
            "properties": {
              "run_id": {
                "type": "string",
                "format": "uuid"
              },
              "created_at": {
                "type": "string",
                "format": "date-time"
              },
              "state": {
                "type": "string",
                "enum": [
                  "admitted",
                  "running",
                  "ending",
                  "completed",
                  "failed",
                  "cancelled",
                  "rejected",
                  "expired"
                ]
              },
              "disposition": {
                "type": "string",
                "nullable": true
              }
            },
            "required": [
              "run_id",
              "created_at",
              "state",
              "disposition"
            ],
            "additionalProperties": false,
            "nullable": true,
            "description": "The most recent non-test run of any version; null when the agent never ran outside Studio tests"
          }
        },
        "required": [
          "ref",
          "name",
          "head",
          "draft",
          "created_at",
          "updated_at",
          "last_run"
        ],
        "additionalProperties": false
      },
      "ApiError": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string",
                "enum": [
                  "unauthenticated",
                  "forbidden",
                  "not_found",
                  "conflict",
                  "invalid_request",
                  "idempotency_conflict",
                  "policy_denied",
                  "capability_unavailable",
                  "provider_unavailable",
                  "knowledge_unavailable",
                  "publication_invalid",
                  "run_not_active",
                  "rate_limited",
                  "outcome_unknown",
                  "internal"
                ]
              },
              "message": {
                "type": "string"
              },
              "retryable": {
                "type": "boolean"
              },
              "outcome": {
                "type": "string",
                "enum": [
                  "none",
                  "unknown"
                ]
              },
              "details": {
                "type": "object",
                "additionalProperties": {}
              }
            },
            "required": [
              "code",
              "message",
              "retryable",
              "outcome"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "error"
        ],
        "additionalProperties": false
      }
    }
  }
}
```

## Errors and recovery {#errors}

See [API error handling](https://docs.cumuluslabs.io/api#errors) and [Troubleshooting](https://docs.cumuluslabs.io/troubleshooting).

## Related guides {#related-guides}

- [Using the API](https://docs.cumuluslabs.io/api)
- [Agents](https://docs.cumuluslabs.io/agents)
- [Build and test recipes](https://docs.cumuluslabs.io/recipes)
