Dynamic Tools
Not every tool should be available in every situation. Filter tools at runtime based on auth state, permissions, feature flags, or conversation stage using @wrap_model_call middleware.
Quick Reference
- →Dynamic tools = modify request.tools inside @wrap_model_call before the model sees them
- →Filter by State: check request.state['authenticated'] or message count
- →Filter by Store: read per-user feature flags from request.runtime.store
- →Filter by Runtime Context: pass user_role at invoke time via context_schema
- →Runtime registration: use DynamicToolMiddleware (wrap_model_call + wrap_tool_call) for tools unknown at startup
Why Static Tools Break Under Load
Static tools are registered once and always visible to the model. That works for simple agents, but breaks down in production: an unauthenticated user should not see admin tools, a beginner conversation should not be overwhelmed with 20 advanced options, and a model with too many tools in context makes more errors and costs more tokens. Dynamic tools let you control exactly which tools the model sees at each call — without changing the agent definition.
Research shows models perform better with 5-10 relevant tools than with 20+ tools where only a few are applicable. Filtering tools dynamically is a cheap way to improve accuracy and reduce cost.