makeAssistantTool
makeAssistantTool
creates a React component that provides a tool to the assistant. This is useful for defining reusable tools that can be composed into your application.
Usage
API Reference
Parameters
tool
: A tool definition created using thetool()
helper functionparameters
: Zod schema defining the tool's parametersexecute
: Function that implements the tool's behavior
Returns
Returns a React component that:
- Provides the tool to the assistant when mounted
- Automatically removes the tool when unmounted
- Renders nothing in the DOM (returns null)
Example with Multiple Tools
Best Practices
-
Parameter Validation
- Always use Zod schemas to define parameters
- Be specific about parameter types and constraints
- Add helpful error messages to schema validations
-
Error Handling
- Return meaningful error messages
- Consider returning partial results when possible
- Handle async errors appropriately
-
Composition
- Break complex tools into smaller, focused ones
- Consider tool dependencies and interactions
- Use multiple tools together for complex functionality