---
docId: doc_a3b8c152043b4412aa9c13fdaaab179c
title: Link a subagent
description: "Adds or replaces a subagent link in the parent’s draft."
api:
  group: agentes/subagentes
  auth: bearer
  operations:
    - operationId: setSubagentLink
      method: PUT
      path: '/v1/agents/{agentId}/draft/subagents/{childId}'
      postmanName: Link or change a subagent
---

<script>
  import { Ways } from '$lib/components';
</script>

# Link a subagent

Link an existing agent as a subagent or replace the rules for its link. Send the complete `link` object for that `childId`. The change is saved in the parent’s draft; [publish it](/api-reference/agents/publications/publish) to use it. You do not need to send the whole `subagents` list.

## Example

<Ways tabs="api,sdk">
<Ways.Way name="api">

```bash
curl -X PUT https://api.platic.ai/v1/agents/$AGENT_ID/draft/subagents/$CHILD_ID \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "link": {
      "alias": "billing",
      "mode": "assist",
      "enabled": true,
      "description": "Questions about invoices",
      "delegationCriteria": "The customer asks about an invoice",
      "completionCriteria": "The invoice question is answered",
      "oneWayDelegation": false
    }
  }'
```

</Ways.Way>
<Ways.Way name="sdk">

```ts
await platic.agents.subagents.link("agent_123", "agent_456", {
  link: {
    alias: "billing",
    mode: "assist",
    enabled: true,
    description: "Questions about invoices",
    delegationCriteria: "The customer asks about an invoice",
    completionCriteria: "The invoice question is answered",
    oneWayDelegation: false,
  },
});
```

</Ways.Way>
</Ways>

## Path parameters

| Parameter | Type | Description | Required |
|-----------|------|-------------|----------|
| `agentId` | string | Parent agent id | ✓ |
| `childId` | string | Subagent id | ✓ |

## Request body

| Field | Type | Description | Required |
|-------|------|-------------|----------|
| `link` | object | The complete link, with the same fields as in [Create a subagent](/api-reference/agents/subagents/create#request-body), all required | ✓ |
| `note` | string | Note for the parent's new version, up to 500 characters | - |

The subagent's id comes from the path, not from the body. If the link already existed, `link` replaces it as a whole.

```json
{
  "link": {
    "alias": "Technical support",
    "mode": "assist",
    "enabled": true,
    "description": "Technical questions about the product",
    "delegationCriteria": "",
    "completionCriteria": "",
    "oneWayDelegation": false
  },
  "note": "Add technical support"
}
```

## Response

The fields are those from [Update the draft](/api-reference/agents/drafts/update#response):

```json
{
  "status": "success",
  "data": {
    "changed": true,
    "draft": { "versionId": "v6", "number": 6 },
    "version": {
      "versionId": "v6",
      "number": 6,
      "basedOnVersionId": "v5",
      "restoredFromVersionId": null,
      "copiedFrom": null,
      "createdAt": "2026-10-28T12:12:00.000Z",
      "createdBy": { "kind": "api_key", "keyId": "k3yId" },
      "source": "api",
      "via": null,
      "note": "Add technical support"
    }
  }
}
```

## Errors

| Status | `details.code` | When |
|--------|----------------|------|
| `400` | `INVALID_REQUEST` | The body doesn't have the expected shape, for example `link` is missing |
| `403` | `FORBIDDEN` | The credential can't edit the parent agent |
| `404` | `AGENT_NOT_FOUND` | The parent agent doesn't exist in the workspace or was deleted |
| `409` | `CONFLICT` | Someone else changed this at the same time. Try again |
| `422` | `INVALID_CONFIG` | `link` contains an invalid value or is missing a field. `details.issues` lists the field path of each problem |
| `422` | `INVALID_SUBAGENT_LINK` | `childId` doesn't exist in the workspace, was deleted or is the parent agent itself |

When the subagent doesn't exist:

```json
{
  "code": 422,
  "error": "Unprocessable Entity - Unable to process the request",
  "details": {
    "code": "INVALID_SUBAGENT_LINK",
    "message": "Some subagent links are not valid",
    "issues": [
      {
        "path": ["subagents", 0, "agentId"],
        "message": "Agent Zz9nope2LwP4kZ1aB9cD does not exist in this workspace"
      }
    ]
  }
}
```

## Notes

- Changing the link creates a version of the parent and **doesn't publish**. It reaches production when you [publish](/api-reference/agents/publications/publish) that version.
- Publishing checks that the links do not form a cycle, where an agent becomes its own subagent. A cycle returns `422` with `details.code: "INVALID_SUBAGENT_LINK"`. Use [Validate changes](/api-reference/agents/drafts/validate) to check before publishing.
- A link always uses the subagent's **published version**.
