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
Dynamic Tool preview

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 desktop

Related patterns