> ## 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.

# Add a tool to an agent

> Give a sub-agent something to call during a run: attach an action as a tool, choose what the model fills in, test it from the editor, and guard it

This guide attaches a tool to a sub-agent, so the model can call it during a run. It covers choosing which inputs the model supplies, testing the tool from the editor, and adding a guard that decides when the tool may run. Use it when an agent has to look something up or act on something, and its prompt alone is not enough.

The example is a tool named `github_repo` that looks a repository up on the GitHub API. The model supplies the repository name and nothing else.

## Before you begin

* An agent that answers a webhook and has a provider. See [Create an agent](https://docs.servflow.io/guides/create-an-agent.md). The screenshots show an agent named Repo lookup that answers on `/repo`.
* For the example, an instance that can reach `api.github.com`. The request needs no credentials.

## Attach an action tool

**1. Open the sub-agent's Tools section**

Open the agent in the editor and click the sub-agent that needs the tool. In its panel, scroll to the **Tools** section. With nothing attached, it reads "No tools — it answers from the prompt alone."

![A sub-agent panel with an empty Tools section and the Add a tool select](https://mintcdn.com/servflow/545ICsSSJFr63lId/images/guides/add-a-tool/01-tools-section.png?fit=max\&auto=format\&n=545ICsSSJFr63lId\&q=85\&s=d55c55ee8fc02c9859a53764ac980d6a)

**2. Choose Run action and pick the action**

Under **Add a tool…**, choose **Run action…**. The **Choose action** dialog opens. It lists the built-in actions and the actions of every app ServFlow connects to, grouped by app, so search for what the tool should do. Type `http request` and click **HTTP Request**.

![The Choose action dialog with a search box, an app filter, and a grid of action cards](https://mintcdn.com/servflow/545ICsSSJFr63lId/images/guides/add-a-tool/02-choose-action.png?fit=max\&auto=format\&n=545ICsSSJFr63lId\&q=85\&s=945367253dee20ed0daedb10f106d7b0)

A row appears in the **Tools** section, and the **Configure Run action** dialog opens. The dialog has three sections, listed on its left edge: **Tool**, **Action**, and **Guards**.

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

In the **Tool** section, enter a **Display name**, for example `github_repo`. The model calls the tool by this name, so use letters, digits, and underscores.

Under **When to use**, describe the situation the tool is for. The model reads this to decide whether to call it:

```
When the user asks about a GitHub repository, such as its description, stars, or default branch.
```

![The Configure Run action dialog with the Display name and When to use fields filled in, and HTTP Request shown under Action](https://mintcdn.com/servflow/545ICsSSJFr63lId/images/guides/add-a-tool/02-dialog-tool.png?fit=max\&auto=format\&n=545ICsSSJFr63lId\&q=85\&s=cd6ff1941a48121adbd7848c6d47878c)

**4. Open the action's fields**

In the **Action** section, the action you picked is shown under **Action**, with a **Change** link to pick another. Its fields are listed below it. Each field holds a value you set, and most have a **Let the model set this** link under them.

**5. Set the fields and the model's input**

Leave **HTTP Method** at `GET`. Under **URL**, enter the address with the model's input in the place it belongs:

```
https://api.github.com/repos/{{ tool_param "repo" }}
```

The `tool_param` function reads an input the model sends when it calls the tool. With the rest of the URL fixed, the model chooses a repository and cannot point the request at another host. If you open the field with **Open editor**, the tool's inputs are offered under **Tags**, and clicking one writes the call for you.

![The Action section with HTTP Request chosen and a URL that contains a tool\_param call](https://mintcdn.com/servflow/545ICsSSJFr63lId/images/guides/add-a-tool/03-dialog-action.png?fit=max\&auto=format\&n=545ICsSSJFr63lId\&q=85\&s=e4c19e13f7e05ba7e7fd05f970df8124)

Every `tool_param` call in a field becomes an input the model is asked for, so `repo` is now everything the model sends when it calls this tool.

To hand a whole field to the model instead, click **Let the model set this** under it. The field then holds the name of the input, and **Set a fixed value instead** switches it back.

**6. Save the tool**

Click **Save tool**. The row in the **Tools** section reads `github_repo`, and the tool appears on the canvas beside the sub-agent, marked **Action**. The gear on the row opens the dialog again, and the trash icon removes the tool.

![The Tools section listing github\_repo, and the tool shown on the canvas next to the sub-agent](https://mintcdn.com/servflow/545ICsSSJFr63lId/images/guides/add-a-tool/05-tools-row.png?fit=max\&auto=format\&n=545ICsSSJFr63lId\&q=85\&s=ee31b331d2e12b6519e32732c7ad5c84)

**7. Tell the model about the tool**

In the same panel, set the sub-agent's **System prompt** so the model knows to use the tool:

```
Answer questions about GitHub repositories. Use the github_repo tool to look a repository up, and answer from what it returns.
```

Click **Save** in the top bar. The button reads **Saved**.

## Verify

**1. Run the agent from the editor**

Click **Run** in the top bar. Enter a **Request body** that needs the tool, and click **Run**:

```json theme={null}
{ "question": "What is the Servflow/servflow repository about?" }
```

![The Run dialog with a question about a GitHub repository as the request body](https://mintcdn.com/servflow/xWuDwV6ivYm_bf7G/images/guides/add-a-tool/06-run-dialog.png?fit=max\&auto=format\&n=xWuDwV6ivYm_bf7G\&q=85\&s=81219c5dc625deb0021b540fbab2515e)

**2. Read the log**

The **Run** panel shows **Completed**. Its **Log** lists "attempting to execute tool", then "finished request" from the HTTP action, then "successfully executed tool". The **Final response** answers from what GitHub returned.

![The Run panel with log lines for the tool call and a final response describing the repository](https://mintcdn.com/servflow/xWuDwV6ivYm_bf7G/images/guides/add-a-tool/07-run-result.png?fit=max\&auto=format\&n=xWuDwV6ivYm_bf7G\&q=85\&s=5229f8b49bcbc99ed2acdc9776305004)

If the log has no tool lines, the model answered without the tool. See [If the tool is not called](#if-the-tool-is-not-called).

**3. Call the agent from outside**

Send the same question to the agent's path:

```bash theme={null}
curl -X POST http://localhost:8080/repo \
  -H 'Content-Type: application/json' \
  -d '{"question": "What is the Servflow/servflow repository about?"}'
```

The response body is the agent's reply.

## Add a guard

A guard is a condition on the request that started the run. When it does not pass, the tool call is refused, whatever the model sent. This example allows the lookup only for requests that carry `"plan": "pro"`.

**1. Open the Guards section**

In the **Tools** section, click the gear on the `github_repo` row. In the dialog, click **Guards** on the left edge, then click **Add guard**.

**2. Name the guard and write its condition**

Enter a **Guard name**, for example `pro_plan_only`. The name appears in traces, and in what the model is told when a call is refused.

Under **Allow the call when**, enter a template that renders `true` when the call is allowed:

```
{{ eq (body "plan") "pro" }}
```

The section's summary reads "1 condition must pass", and **Guards** on the left edge shows a count of 1.

![The Guards section with a guard named pro\_plan\_only and its condition](https://mintcdn.com/servflow/545ICsSSJFr63lId/images/guides/add-a-tool/08-dialog-guards.png?fit=max\&auto=format\&n=545ICsSSJFr63lId\&q=85\&s=b91a1ee04c60e44a150e29f43f3283bb)

**3. Save and test the refusal**

Click **Save tool**, then **Save**. Click **Run** and send the earlier request body, which has no `plan` field. The log reads "condition evaluated to false", then "tool call denied by guard", and the model answers without the repository data.

![The Run panel with log lines showing the tool call denied by the guard](https://mintcdn.com/servflow/xWuDwV6ivYm_bf7G/images/guides/add-a-tool/09-run-denied.png?fit=max\&auto=format\&n=xWuDwV6ivYm_bf7G\&q=85\&s=7c32d8c33598865dbba95368fdfc602e)

Click **New payload** and add `"plan": "pro"` to the body. The tool runs as before.

## Attach another type of tool

**Add a tool…** lists three more types. Each opens the same dialog with a different middle section. For every field, see the [Tools reference](https://docs.servflow.io/concepts/tools.md).

### MCP server

To offer the tools of a Model Context Protocol server, choose **MCP server…**. In the **Server** section, enter the **Server endpoint**. If the server needs a token, choose where it comes from under **Access token**: an **Integration** connected through OAuth, a **Secret**, or a pasted **Token**. Click **Load tools** and select the **Allowed tools**. **Save tool** stays disabled until at least one tool is selected.

![The Configure MCP server dialog with the Server endpoint, Access token, and Allowed tools fields](https://mintcdn.com/servflow/xWuDwV6ivYm_bf7G/images/guides/add-a-tool/10-dialog-mcp.png?fit=max\&auto=format\&n=xWuDwV6ivYm_bf7G\&q=85\&s=1360fc95ab072f365fab9acc733996ad)

### Call sub-agent

To let one sub-agent call another in the same agent, choose **Call sub-agent…**. Under **Sub-agent**, choose the sub-agent to call. The **Display name** takes that sub-agent's name. The called sub-agent's reply is what comes back. For the full steps, including what the called sub-agent's prompt has to say, see [Call other agents](https://docs.servflow.io/guides/call-other-agents.md#let-a-sub-agent-ask-another-sub-agent).

![The Configure Call sub-agent dialog with a sub-agent chosen](https://mintcdn.com/servflow/xWuDwV6ivYm_bf7G/images/guides/add-a-tool/11-dialog-subagent.png?fit=max\&auto=format\&n=xWuDwV6ivYm_bf7G\&q=85\&s=2f8e27117bd8d9b285e877e803003aa6)

### Agent Task Tool

To hand a task to another stored agent, choose **Agent Task Tool…**. Under **Agent**, choose an enabled agent that is entered by a trigger. When the model calls the tool it writes one instruction, which the other agent reads as `{{ input "instruction" }}`. The tool returns as soon as the task has started, and nothing the other agent says comes back. See [Call other agents](https://docs.servflow.io/guides/call-other-agents.md#hand-a-task-to-another-agent).

![The Configure Agent Task Tool dialog with an agent chosen](https://mintcdn.com/servflow/xWuDwV6ivYm_bf7G/images/guides/add-a-tool/12-dialog-agent-task.png?fit=max\&auto=format\&n=xWuDwV6ivYm_bf7G\&q=85\&s=e9451ba17b2dae04854157581444f5ef)

### Built-in file tools

Every sub-agent already has `read_memory`, `write_memory`, and `list_memory`, with nothing to attach. They work in the folder chosen under **Workspace** in the panel's **Memory** section. See [Built-in tools](https://docs.servflow.io/references/cli.md#built-in-file-tools). To set a workspace up, see [Set up memory and file access](https://docs.servflow.io/guides/set-up-memory-and-file-access.md).

## If the tool is not called

* **The model did not choose it.** Make **When to use** specific, and name the tool in the sub-agent's **System prompt**.
* **A guard refused it.** The log reads "tool call denied by guard". Check the request against the guard's condition.
* **The model sent a value the field does not accept.** A select field that the model fills must receive one of its listed values.
* **An MCP server lists no tools.** The server is asked with the access token you entered, so it lists nothing until the token is right. Correct the token and click **Refresh**.

## Related

> [card] [Tools](https://docs.servflow.io/concepts/tools.md)
>
> The four kinds of tool, and what the agent fills in.

> [card] [Dynamic content](https://docs.servflow.io/concepts/dynamic-content.md)
>
> Template functions such as `tool_param`, `body`, and `header`.

> [card] [Available actions](https://docs.servflow.io/references/actions.md)
>
> Every action a tool can run.

> [card] [Create an agent](https://docs.servflow.io/guides/create-an-agent.md)
>
> Build the agent this guide adds a tool to.


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