tool() function from the ai package with Zod schemas for input validation.
Creating a Custom Tool
Combining Built-in and Custom Tools
Mix and match built-in tools with your own:Tool Best Practices
- Clear descriptions help the model understand when and how to use each tool
- Zod schemas provide both validation and type safety
- Return structured data so the model can reason about results
- Handle errors gracefully — thrown errors are surfaced to the model as tool errors, allowing it to adjust its approach