Overview
Tools allow agents to execute functions and interact with external systems. TheAgentTool interface extends the base Tool interface from @mariozechner/pi-ai with execution capabilities and UI metadata.
AgentTool Interface
Properties
A human-readable label for the tool to be displayed in UI.
The function name used by the LLM to invoke the tool. Must be unique within the agent’s tool set.
Description of what the tool does. Used by the LLM to decide when to call the tool.
TypeBox schema defining the tool’s input parameters. Must be a TypeBox object schema.
execute
(toolCallId: string, params: Static<TParameters>, signal?: AbortSignal, onUpdate?: AgentToolUpdateCallback<TDetails>) => Promise<AgentToolResult<TDetails>>
required
Function that executes the tool logic.Parameters:
toolCallId: Unique identifier for this tool callparams: Validated parameters matching the schemasignal: Optional AbortSignal for cancellationonUpdate: Optional callback for streaming partial results
AgentToolResult containing content blocks and details.AgentToolResult
Content blocks that will be sent back to the LLM. Supports text and images.
Arbitrary data to be displayed in UI or logged. Not sent to the LLM.
Creating Tools
Simple Tool
Tool with Detailed Output
Tool with Streaming Updates
Tool with Cancellation Support
Error Handling
Tools can throw errors which will be caught by the agent loop and sent back to the LLM:- The agent loop catches it
- Creates a tool result message with
isError: true - Sends the error message back to the LLM
- The LLM can decide how to handle it (retry, give up, etc.)
Registering Tools
Tools are registered with the agent via thetools property: