Tool
A collapsible component for displaying tool invocation details in AI chatbot interfaces.
The Tool component displays a collapsible interface for showing/hiding tool details. It is designed to take the ToolUIPart type from the AI SDK and display it in a collapsible interface.
Install using CLI
Install Manually
Copy and paste the following code in the same folder.
Usage with AI SDK
Build a simple stateful weather app that renders the last message in a tool using useChat.
Add the following component to your frontend:
Add the following route to your backend:
Features
- Collapsible interface for showing/hiding tool details
- Visual status indicators with icons and badges
- Support for multiple tool execution states (pending, running, completed, error)
- Formatted parameter display with JSON syntax highlighting
- Result and error handling with appropriate styling
- Composable structure for flexible layouts
- Accessible keyboard navigation and screen reader support
- Consistent styling that matches your design system
- Auto-opens completed tools by default for better UX
Examples
Input Streaming (Pending)
Shows a tool in its initial state while parameters are being processed.
Input Available (Running)
Shows a tool that's actively executing with its parameters.
Input Streaming (Completed)
Shows a completed tool with successful results. Opens by default to show the results. In this instance, the output is a JSON object, so we can use the CodeBlock component to display it.
Output Error
Shows a tool that encountered an error during execution. Opens by default to display the error.