# Delegate to agents

Let one agent hand a question to another agent, called as a tool, and use its answer. Each call runs as a [child run](/docs/concepts/runs.md#child-runs).

## Before you start

You need a project with an agent. See [Create an agent](/docs/agents/create-agent.md).

## Let an agent call another

**Code**

1. Add the specialist. Here it holds the answer to refund questions:

```ts title="agents/billing.ts"
import { agent } from "veryfront/agent";

export default agent({
  id: "billing",
  name: "Billing",
  system: "Answer billing questions in one sentence. Refunds take 5 business days.",
});
```

2. Name it in the front agent's `delegates`. Each one becomes an `agent_<id>` tool:

```ts title="agents/support.ts" {7}
import { agent } from "veryfront/agent";

export default agent({
  id: "support",
  name: "Support assistant",
  system: "Send billing and refund questions to the billing agent and pass its answer on.",
  delegates: ["billing"],
});
```

3. Start the project with `npm run dev`.
4. Open **Chat** in Studio.
5. Pick Support assistant.
6. Ask "How long does a refund take?". You should now see it call `agent_billing` and reply 5 business days.

## With MCP

1. Call `veryfront__create_file` for the specialist:

```json
{
  "project_reference": "my-project",
  "path": "agents/billing.ts",
  "content": "import { agent } from \"veryfront/agent\";\n\nexport default agent({\n  id: \"billing\",\n  name: \"Billing\",\n  system: \"Answer billing questions in one sentence. Refunds take 5 business days.\",\n});\n"
}
```

2. Call `veryfront__update_file` to name it in the front agent's `delegates`:

```json
{
  "project_reference": "my-project",
  "path": "agents/support.ts",
  "content": "import { agent } from \"veryfront/agent\";\n\nexport default agent({\n  id: \"support\",\n  name: \"Support assistant\",\n  system: \"Send billing and refund questions to the billing agent and pass its answer on.\",\n  delegates: [\"billing\"],\n});\n"
}
```

3. Ask `support` "How long does a refund take?" with the calls in [Chat with an agent](/docs/agents/chat.md), and keep the run's `id` (a UUID, not its `run_…` `run_id`).
4. Call `veryfront__list_run_child_runs` with the run's `id` as `run_id`. It worked when the list holds a child run for the `billing` agent.

## Next steps

* [Build a workflow](/docs/orchestration/workflows.md)
* [Debug a run](/docs/observability/debug.md)
