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

# Call other agents

> Let a sub-agent ask another sub-agent for an answer, or hand a task to a different agent and carry on

There are two ways for one agent to use another, and they do different jobs. This guide sets up both.

| You want | Use | What comes back |
| - | - | - |
| One sub-agent to ask another sub-agent **in the same agent**, and use its answer | **Call sub-agent** | The other sub-agent's reply |
| To hand a job to **a different agent** and carry on without waiting | **Agent Task Tool** | Nothing. The other agent works on its own |

## Before you begin

* For **Call sub-agent**: an agent with two sub-agents, each with a provider. See [Create an agent](https://docs.servflow.io/guides/create-an-agent.md).
* For **Agent Task Tool**: a second agent that is enabled and whose entry is a trigger. See [Entries and entry handlers](https://docs.servflow.io/concepts/entries.md).
* Both checks run the agents. Your model company bills you for those runs.

## Let a sub-agent ask another sub-agent

The example is an agent named Support desk. Its `Support` sub-agent answers customers, and asks a `Researcher` sub-agent for the facts first.

![The canvas with a Support sub-agent and a Researcher sub-agent](https://mintcdn.com/servflow/545ICsSSJFr63lId/images/guides/call-other-agents/03-canvas.png?fit=max\&auto=format\&n=545ICsSSJFr63lId\&q=85\&s=9c54f900128cfb9e2dce598b333c5497)

**1. Open the calling sub-agent**

Click `Support` on the canvas. Its panel opens.

**2. Add the tool**

Under **Tools**, open **Add a tool…** and choose **Call sub-agent…**. The **Configure Call sub-agent** dialog opens.

**3. Name the tool**

In **Display name**, enter `ask_researcher`. Use letters, numbers, and underscores, with no spaces. Some model companies reject a tool whose name contains a space.

**4. Say when to use it**

In **When to use**, enter `Ask the researcher to look up the facts needed to answer the customer.` The model reads this to decide when to call the tool.

**5. Choose the sub-agent to call**

Under **Sub-agent**, choose `Researcher`.

![The Configure Call sub-agent dialog with a display name, a description, and Researcher chosen](https://mintcdn.com/servflow/Tigm2DtWfuvgudby/images/guides/call-other-agents/01-call-subagent-dialog.png?fit=max\&auto=format\&n=Tigm2DtWfuvgudby\&q=85\&s=a050981983b42a382f8cbc31f654cb94)

**6. Save the tool**

Click **Save tool**. The tool appears under **Tools**.

**7. Tell the calling sub-agent to use it**

In the **System prompt** of `Support`, say when to use the tool:

```
You answer customer questions. Always ask the researcher for the facts first, then reply to the customer in a friendly sentence or two.
```

Without this, the model may answer on its own and never call the tool.

**8. Set what the called sub-agent asks**

Click `Researcher`. The caller does not pass its question along. The called sub-agent asks whatever its own **User prompt** says, so point that prompt at the message that started the run:

```
{{ body "question" }}
```

Give it a **System prompt** for its own job, such as `You look up facts and answer in one or two sentences.`

![The Researcher panel with a User prompt that reads the question from the request](https://mintcdn.com/servflow/545ICsSSJFr63lId/images/guides/call-other-agents/02-called-user-prompt.png?fit=max\&auto=format\&n=545ICsSSJFr63lId\&q=85\&s=8d3fbee41efdf3196feb4f9495be0eb8)

**9. Save and run**

Click **Save**, then **Run**, and enter a request:

```json theme={null}
{ "question": "Which planet has the most moons?" }
```

The **Log** shows `Support` starting a tool, `Researcher` answering, the tool finishing, and then the reply from `Support`.

![The Run panel showing the tool call, the Researcher's answer, and the final response from Support](https://mintcdn.com/servflow/Tigm2DtWfuvgudby/images/guides/call-other-agents/04-run-call.png?fit=max\&auto=format\&n=Tigm2DtWfuvgudby\&q=85\&s=c1d40548d1a8d37cd62e6412e265d64a)

The called sub-agent uses its own provider, tools, and workspace, and does not see the caller's conversation. Add one tool for each sub-agent you want reachable.

### Pass a question of the caller's own

If you create agents from config files, the calling model can write its own question for the called sub-agent. Declare a parameter on the tool with `params`, and read it in the called sub-agent's prompt with `tool_param`:

```yaml theme={null}
tools:
  - type: agent
    name: ask_researcher
    description: Ask the researcher to look up a fact. Pass the question.
    params: [question]
    agentConfig:
      id: researcher
```

The called sub-agent's `userPrompt` then reads `{{ tool_param "question" }}`. The dashboard's **Configure Call sub-agent** dialog has no setting for parameters. For the whole shape of an agent, see the [CLI reference](https://docs.servflow.io/references/cli.md#the-shape-of-an-agent).

## Hand a task to another agent

The example is a Helpdesk agent that hands report writing to a separate agent named Weekly report.

**1. Check the other agent**

Open the Weekly report agent. Its entry has to be a trigger, and the agent has to be enabled.

**2. Make the other agent read the task**

In its sub-agent's **User prompt**, enter:

```
{{ input "instruction" }}
```

Click **Save**. The task arrives under the name `instruction`.

**3. Add the tool to the first agent**

Open the Helpdesk agent and click its sub-agent. Under **Tools**, open **Add a tool…** and choose **Agent Task Tool…**. The **Configure Agent Task Tool** dialog opens.

**4. Name the tool and say when to use it**

In **Display name**, enter `start_weekly_report`. In **When to use**, enter `Hand over writing the weekly report. Say what it should cover.`

**5. Choose the agent**

Under **Agent**, choose Weekly report. The list shows enabled agents whose entry is a trigger.

![The Configure Agent Task Tool dialog with the Weekly report agent chosen](https://mintcdn.com/servflow/Tigm2DtWfuvgudby/images/guides/call-other-agents/05-agent-task-dialog.png?fit=max\&auto=format\&n=Tigm2DtWfuvgudby\&q=85\&s=876b6d788cc18b36604ece27d6211c76)

**6. Save the tool and tell the agent to use it**

Click **Save tool**. In the sub-agent's **System prompt**, say when to use the tool and what to say afterwards:

```
When someone asks for the weekly report, you must use the start_weekly_report tool to hand the job over. Only say it has been started after the tool has been used.
```

Without the second sentence, the model may say the report has started without starting it.

**7. Save and run**

Click **Save**, then **Run**, and ask for the report. The **Log** shows "attempting to execute tool" and "successfully executed tool", and the agent replies that the report has been started.

![The Run panel showing the tool step and the agent confirming the report was started](https://mintcdn.com/servflow/Tigm2DtWfuvgudby/images/guides/call-other-agents/06-run-task-sent.png?fit=max\&auto=format\&n=Tigm2DtWfuvgudby\&q=85\&s=1ea3d355384f94bd05c5c5dab1712975)

The other agent's answer never comes back to the first one. If the agent you want is missing from the **Agent** list, it is disabled or its entry is not a trigger.

## Limit who can set this off

Both tools take guards. A guard checks who sent the message before the tool runs, so you can let everyone talk to an agent while only some people can make it call another one. See [Guard rails](https://docs.servflow.io/concepts/guard-rails.md).

## Related

> [card] [Add a tool to an agent](https://docs.servflow.io/guides/add-a-tool.md)
>
> The other kinds of tool a sub-agent can have.

> [card] [Guard rails](https://docs.servflow.io/concepts/guard-rails.md)
>
> Limit what people can make your agent do.

> [card] [Entries and entry handlers](https://docs.servflow.io/concepts/entries.md)
>
> Triggers and the other ways an agent is started.

> [card] [Tools](https://docs.servflow.io/concepts/tools.md)
>
> Every tool type and its fields.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.