# Agents and tools

Build agents that choose tools at run time, within explicit limits. Function calling, ReAct and plan-and-execute architectures, every built-in tool, Tool Router and Tool Chain.

Source: https://glamorous-boar.cloudvent.net/agents/

---

An **agent** is a model in a loop: it reads the task, decides whether to call a tool, sees the result, and repeats until it can answer. In AgenticMind the **Agent** node runs that loop, and **tool nodes** wired into its `tools` input define exactly what it may do. The theory is in [Agents](/learn/agents/); this page is the how-to.

## Build an agent

Template *Agent with tools*:

1. **Manual Input** `question` → Agent `task`.
2. Tool nodes → Agent `tools` (a multiple input): **Knowledge Search Tool** (connected to the same Embedding Model and Vector Store as indexing), **Calculator Tool**, **Date & Time Tool**.
3. Agent `answer` → **Output** `answer`.
4. Index a document (**Run → Index report**), then ask in Chat: *How many leave days do 3 employees get in total?*
5. Expand *Used N tool calls*: the agent searched the handbook, found 25 days per employee, and called the calculator for 25 × 3.

Inputs: `task` (required), `tools`, `context` (extra background), `history` (earlier messages, e.g. from Conversation History). Outputs: `answer`, `result` (`{answer, steps, report}` for Chat and APIs) and `transcript`.

## Limits and budgets

Agents are **bounded**. Every Agent has:

| Setting | Default | Meaning |
|---|---|---|
| `max_turns` | 6 | Maximum model calls. |
| `max_tool_calls` | 12 | Maximum tool executions in total. |
| `token_budget` | 60,000 | Stop when input + output tokens exceed it. |
| `cost_budget_usd` | 0.25 | Stop when reported cost exceeds it (0 = no limit; needs a provider that reports cost, such as OpenRouter). |
| `tool_timeout_seconds` | 30 | Per tool call. |
| `on_limit` | `fail` | `fail` (`AGENT_LIMIT_REACHED`) or `return_partial` (a wrap-up turn answers with what it has). |

The Agent node is never retried automatically, because tools may have side effects.

## Architectures

Choose with `architecture`:

| Architecture | How it works | Use when |
|---|---|---|
| `function_calling` (default) | The model calls tools natively; several calls in one turn run **in parallel** (`parallel_tool_calls`), results return in call order. | Almost always. Fastest and most reliable with modern models. |
| `react` | The model writes `Thought:` / `Action:` / `Action Input:` (JSON) or `Final Answer:`; the runtime runs the action and replies `Observation: …`. Tools are described in the prompt, so it works without native tool calling. Every thought is traced (`agent_thought`). A malformed reply gets one corrective observation. | Models without tool calling, or when you want visible reasoning. |
| `plan_and_execute` | One call writes up to `max_plan_steps` steps; each step runs as a function-calling loop that sees earlier results and the remaining budget; a final call composes the answer. | Multi-step tasks that benefit from an explicit plan. |

All three share the same tool checks, limits and `on_limit`. Chat shows ReAct thoughts and plan steps with nested tool calls.

## Built-in tools

| Tool node | Gives the agent | Notes |
|---|---|---|
| **Knowledge Search Tool** | `search_documents` over your index | Returns numbered passages with file, page and section. |
| **Calculator Tool** | `calculator` | Safe AST evaluator: `+ - * / // % **`, parentheses, `sqrt`, `log`, `exp`, trig, `abs`, `round`, `min`, `max`, `pi`, `e`. No code execution. |
| **Date & Time Tool** | `current_datetime` | Optional IANA time zone. Stops agents guessing today's date. |
| **Web Fetch Tool** | `fetch_web_page` | Only `allowed_domains` (required; subdomains included). Blocks private and metadata addresses, re-checks every redirect, size and time limits. |
| **Memory Tool** | `recall_memory` or `save_memory` | Save only with `consent` true. See [Memory](/memory/). |
| **Code Interpreter Tool** | `run_code` | Python/JavaScript in the sandbox. See [Code execution](/code-execution/). |
| **SQL Tool** | `query_database` | Read-only SQL with the schema in its description. See [Databases](/databases/). |
| **Auto Ontology Tool** | `business_data` | `search_terms` / `ask_question`. |
| **MCP Server** | every tool of an MCP server | See [MCP](/mcp/). |
| **Subagent** | a delegate agent | See [Multi-agent](/multi-agent/). |

Every tool node lets you rename the tool (`name`) and rewrite its `description`. The description is what the model reads to decide when to use the tool, so make it specific.

### How tool calls are checked

1. The model asks for a tool by name with JSON arguments.
2. Unknown tools, and arguments that violate the tool's JSON Schema (Draft 2020-12), are returned to the model as errors so it can correct itself. They are not node failures.
3. The tool's required permissions must be a subset of the Agent's.
4. The tool runs with its own timeout. Errors (`ToolError`) go back to the model.
5. A tool that fails **permanently** (for example a site refusing bots) is marked failed for the rest of the run: later calls, including from sub-agents, return the reason instantly instead of retrying.
6. Every call is a `tool_call` trace event and a span in OpenTelemetry exports.

## Tool Router and Tool Chain

Not every task needs a full agent loop.

- **Tool Router**: one request → the single best tool, chosen by `keywords` (e.g. `{"calculator": ["sum", "%"]}`), by the `model`, or `hybrid` (keywords first). The model then fills that tool's arguments. Outputs `result`, `tool` and `text`. Falls back to `default_tool`.
- **Tool Chain**: a fixed sequence of tool calls, no model. Arguments are templates:

<CodeBlock language="json" filename="Tool Chain steps" showCopy={true}>

```
[
  {"tool": "calculator", "arguments": {"expression": "{{input}}"}},
  {"tool": "calculator", "arguments": {"expression": "{{previous}} * 2"}},
  {"tool": "fetch_web_page", "arguments": {"url": "https://example.org/{{steps.0.result}}"}}
]
```

</CodeBlock>

A string that is exactly one template keeps the value's type. The chain stops at the first failure unless `stop_on_error` is off.

## Writing your own tool

A tool is a node that outputs a `ToolHandle` plus an implementation. See [Node SDK: writing a tool](/architecture/node-sdk/#writing-a-tool-for-agents).

## Making agents faster

- Agent latency is dominated by **model turns**. Fewer, better-described tools mean fewer turns.
- Set `reasoning_effort` per node: `low` on simple workers, default or higher on planners. Low effort can skip tools and answer from stale knowledge.
- Keep `parallel_tool_calls` on.
- Use a Tool Router or Tool Chain when the path is predictable.

## Versions

Agent **1.2.0** adds the `subprocess` permission needed for stdio MCP tools and the Code Interpreter. Projects saved with 1.0.0 or 1.1.0 keep their exact permissions and refuse those tools with `TOOL_PERMISSION_DENIED` (with a hint to upgrade).
