A tool is a function the model may call. Gwenflow describes it to the model with a JSON schema (name, description, parameters) built from the function itself, runs it when the model asks, and sends the result back as a tool message.

Functions as tools

Wrap any function with Tool, or register it on an agent with @agent.tool. The name comes from the function, the description from the first paragraph of its docstring, the parameters from its signature and type annotations:
  • Types. str, int, float, bool, list and dict map to their JSON types; anything else is sent as a string.
  • Required parameters. Parameters without a default are required.
  • Descriptions. Each parameter’s description comes from the docstring, in Google style (Args:) or reStructuredText (:param city:), or from a Pydantic Field(description=...) used as the default.
Tool accepts overrides: Tool(fn, name="weather", description="...", parameters={...}).

Return values

A tool returns anything: a string is sent as is, a Pydantic model as its JSON, other values through json.dumps (or str as a last resort). An exception is reported to the model as the tool’s result, so it can correct its call; the run goes on.

Tool classes

For a tool with configuration or state, subclass BaseTool and implement _run. The schema is built from _run’s signature:

Retries

A tool that raises is retried up to max_retries times (3 by default), with an exponential backoff of 1 to 10 seconds, before its error goes back to the model. Set max_retries=1 for a tool that must not run twice:
A tool declared with requires_approval=True always runs once: a retry would repeat a change the user approved a single time. See Tool approvals.

Parallel calls

When the model asks for several tools in one turn, they run one after the other, in order, and their results keep the order of the calls. Calls to delegated agents (team members and sub-agents) run in parallel threads. With arun, every tool call of a turn runs concurrently.

Large outputs

One file read or a broad search can fill the context window on its own. max_tool_output_tokens caps a single result: a longer one is set aside, the model gets its beginning and a reference, and a read_tool_output tool to page through the rest.
See Context management.

Tools by name

Built-in tools can be named by a short key, as flows and the command line do:
See Built-in tools for the list, and MCP for tools served by an MCP server.