tool( )





Pattern
Dynamic Tool
Create dynamic tools with runtime-generated schemas using dynamicTool. Demonstrates unit conversion tools where schema adapts based on conversion type (temperature, length, weight, currency) and supports dynamic model selection.
IntermediateNov 2025View the full pattern on desktop


Problems solved
- Create tools at runtime with dynamicTool
- Adapt tool name, description, and Zod schema from user selection
- Support unit conversion schemas that change by conversion type
- Handle tools whose schemas are unknown at compile time
Use cases
- Unit conversion assistants
- MCP-style tools loaded at runtime
- User-defined function calling demos
- Dynamic tool configuration UIs
AI SDK APIs
streamTextconvertToModelMessagesdynamicTooluseChatprepareSendMessagesRequest
Tags
aitoolsdynamic-toolruntime-toolsunit-converterschema-generationdynamic-schemaai-sdktool-apimodel-selection
Requirements
- Node.js
- 24+
- Memory
- 512MB
- Other
- AI API key (OpenAI, Anthropic, or Google)
Environment variables
External services
openaianthropicgoogle
Ready to use?
View the full interactive pattern with live preview and copy the source code.
View the pattern on desktopRelated patterns


Tool Input Lifecycle Hooks
Explore tool input lifecycle hooks: onInputStart, onInputDelta, and onInputAvailable. See how to track tool input generation in real-time during streaming.
aitools+7
View pattern β


Preliminary Tool Results
Return preliminary tool results using async iterables. Stream status updates during tool execution before the final result is available.
aitools+6
View pattern β



