Basic Tool Integration
Add tools to an agent using thetools configuration:
Tool Parameters
Define tool parameters using Zod schemas:Accessing Context in Tools
Tools can access context variables usingtoState():
Multiple Tools
Agents can have multiple tools:Tool Choice
Control when tools are used:'auto'- Model decides when to use tools'none'- Never use tools'required'- Always use at least one tool
Tool Execution Examples
File System Operations
API Calls
Database Operations
Real-World Example: Research Agent
From the source code examples:research_bot.ts:56:76
Best Practices
Clear Tool Descriptions
Clear Tool Descriptions
Write descriptive tool descriptions so the agent knows when to use each tool:
Parameter Descriptions
Parameter Descriptions
Add descriptions to Zod schema fields:
Error Handling
Error Handling
Handle errors gracefully in tool execution:
Tool Response Format
Tool Response Format
Return structured data that’s easy for the agent to interpret:
Next Steps
Multi-Agent Systems
Coordinate agents with handoffs
Context Variables
Share state between agents and tools
Structured Output
Get type-safe responses