> ## 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](/guides/create-an-agent).
* For **Agent Task Tool**: a second agent that is enabled and whose entry is a trigger. See [Entries and entry handlers](/concepts/entries).
* 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.

<Frame>
  <img src="https://mintcdn.com/servflow/Tigm2DtWfuvgudby/images/guides/call-other-agents/03-canvas.png?fit=max&auto=format&n=Tigm2DtWfuvgudby&q=85&s=3a946486b853efa5de4f7184b9bcbf1f" alt="The canvas with a Support sub-agent and a Researcher sub-agent" width="2880" height="1800" data-path="images/guides/call-other-agents/03-canvas.png" />
</Frame>

<Steps>
  <Step title="Open the calling sub-agent">
    Click `Support` on the canvas. Its panel opens.
  </Step>

  <Step title="Add the tool">
    Under **Tools**, open **Add a tool…** and choose **Call sub-agent…**. The **Configure Call sub-agent** dialog opens.
  </Step>

  <Step title="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.
  </Step>

  <Step title="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.
  </Step>

  <Step title="Choose the sub-agent to call">
    Under **Sub-agent**, choose `Researcher`.

    <Frame>
      <img src="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" alt="The Configure Call sub-agent dialog with a display name, a description, and Researcher chosen" width="2880" height="1800" data-path="images/guides/call-other-agents/01-call-subagent-dialog.png" />
    </Frame>
  </Step>

  <Step title="Save the tool">
    Click **Save tool**. The tool appears under **Tools**.
  </Step>

  <Step title="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.
  </Step>

  <Step title="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.`

    <Frame>
      <img src="https://mintcdn.com/servflow/Tigm2DtWfuvgudby/images/guides/call-other-agents/02-called-user-prompt.png?fit=max&auto=format&n=Tigm2DtWfuvgudby&q=85&s=81fdcafaa4df4dd70dfa8ad14c39e2dd" alt="The Researcher panel with a User prompt that reads the question from the request" width="2880" height="1800" data-path="images/guides/call-other-agents/02-called-user-prompt.png" />
    </Frame>
  </Step>

  <Step title="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`.

    <Frame>
      <img src="https://mintcdn.com/servflow/Tigm2DtWfuvgudby/images/guides/call-other-agents/04-run-call.png?fit=max&auto=format&n=Tigm2DtWfuvgudby&q=85&s=c1d40548d1a8d37cd62e6412e265d64a" alt="The Run panel showing the tool call, the Researcher's answer, and the final response from Support" width="2880" height="1800" data-path="images/guides/call-other-agents/04-run-call.png" />
    </Frame>
  </Step>
</Steps>

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](/references/cli#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.

<Steps>
  <Step title="Check the other agent">
    Open the Weekly report agent. Its entry has to be a trigger, and the agent has to be enabled.
  </Step>

  <Step title="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`.
  </Step>

  <Step title="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.
  </Step>

  <Step title="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.`
  </Step>

  <Step title="Choose the agent">
    Under **Agent**, choose Weekly report. The list shows enabled agents whose entry is a trigger.

    <Frame>
      <img src="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" alt="The Configure Agent Task Tool dialog with the Weekly report agent chosen" width="2880" height="1800" data-path="images/guides/call-other-agents/05-agent-task-dialog.png" />
    </Frame>
  </Step>

  <Step title="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.
  </Step>

  <Step title="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.

    <Frame>
      <img src="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" alt="The Run panel showing the tool step and the agent confirming the report was started" width="2880" height="1800" data-path="images/guides/call-other-agents/06-run-task-sent.png" />
    </Frame>
  </Step>
</Steps>

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](/concepts/guard-rails).

## Related

<CardGroup cols={2}>
  <Card title="Add a tool to an agent" icon="wrench" href="/guides/add-a-tool">
    The other kinds of tool a sub-agent can have.
  </Card>

  <Card title="Guard rails" icon="shield-halved" href="/concepts/guard-rails">
    Limit what people can make your agent do.
  </Card>

  <Card title="Entries and entry handlers" icon="right-to-bracket" href="/concepts/entries">
    Triggers and the other ways an agent is started.
  </Card>

  <Card title="Tools" icon="wrench" href="/concepts/tools">
    Every tool type and its fields.
  </Card>
</CardGroup>
