01 Define a tool
Before you start
Complete 02 Anatomy of an agent and 01 Linear pipelines. You should have a single-step workflow running with the stub provider.
Concept
A tool is a named capability an agent can invoke during a step. You declare it in Python; the runtime validates inputs against a JSON Schema and calls your execute function when the agent selects the tool.
The constructor signature is:
| Argument | Purpose |
|---|---|
name | Stable identifier (lowercase, no spaces); must be unique per agent |
description | Human-readable summary shown to the model during tool selection |
input_schema | JSON Schema object describing allowed arguments |
execute | Callable accepting one dict and returning a str result |
timeout_seconds | Per-invocation limit (must be positive) |
Validation happens at construction time:
- Empty
nameordescriptionraisesToolConfigurationError. - Non-dict or non-serializable
input_schemaraisesToolConfigurationError. - Non-callable
executeraisesToolConfigurationError.
The execute function receives parsed arguments as a dict (keys match schema properties). Return a string; the runtime feeds that back into the agent loop.
Tools are definitions, like agents. They do not run until a workflow step executes and the agent loop selects them.
Example
An echo tool that returns a message field:
Save as define_tool.py:
Run:
Stub runs may not always invoke the tool the way a live model would, but the workflow still completes and proves tool registration.
Verify
| Check | Expected |
|---|---|
| Valid tool construction | No exception |
| Invalid schema type | Tool(..., input_schema="bad",...) raises ToolConfigurationError |
| Empty name | Tool(name="",...) raises ToolConfigurationError |
Invalid schema check:
Next
02 Attach tools to agents covers multiple tools, duplicate name validation, and workflow wiring.