# Spawning agents

> Agents with can_spawn can create other agents at runtime, within limits on tools, models and depth. Spawning is declared in the file, not left to a prompt.

A swarm can grow while it runs. The overseer and any agent with `can_spawn = true` can call `create_agent(hcl)` with one `agent` block. The server parses it, validates it against the swarm, and creates it in Pending with the caller as its **parent**.

## Declared, not prompted

Whether a team may grow is an attribute in the file:

```hcl
agent "lead" {
  provider  = provider.anthropic
  model     = "claude-opus-5"
  prompt    = file("prompts/lead.md")
  can_spawn = true
}
```

`can_spawn` defaults to `false`. A prompt that says "create helpers" does nothing without it: the server rejects `create_agent` from an agent whose spec lacks it (`spawn_not_allowed`), and the tool is not registered for it. Putting the permission in the language means you can read from the file alone who can add agents, and a prompt injection cannot grant it. The overseer's `can_spawn` is set on the `swarm` block and defaults to `true`.

## Limits

| Rule | Error |
| --- | --- |
| The caller must have `can_spawn` | `spawn_not_allowed` |
| Spawn depth: declared agents and the overseer are depth 0; a chain may go to depth 3 | `depth_limit` |
| The child's `tools` must be a subset of the parent's | `tools_not_allowed` |
| The child's provider and model must be the parent's, or be used by a declared agent | `model_not_allowed` |
| The block must be valid: no `count` or `for_each`, a free name, `inputs` and `depends_on` that resolve | `invalid_agent` |

For the overseer, which has no tools of its own, the subset rule is replaced by the swarm-wide union: the child's tools, provider and model must each appear on some declared agent. A child may itself set `can_spawn = true`, subject to the same rules and the depth limit.

There is no limit on the number of agents. `--max-processes` protects the machine, and `max_cost_usd` bounds the cost of spawning too many. See [budgets](/docs/concepts/budgets/).

## Parents and children

- A parent may stop only agents it created, with `stop_agent(name, reason)`. The overseer may also stop a Stuck agent. `convoy stop` may stop any.
- Stopping a parent stops its children first, depth-first.
- A parent that Fails also stops its children.
- Created agents exist only in the server. They do not appear in your `.cvy` files.

## Why bounds matter

A web page read by one agent can carry instructions. Because a child can use at most what its parent has, and the overseer cannot change the goal, an injected instruction cannot widen the swarm's reach. See also [the overseer](/docs/concepts/overseer/) and [agents](/docs/concepts/agents/).
