Skip to main content
Dynamic tool schemas let your tool’s parameter limits and descriptions reflect live configuration, so the agent always sees the truth. The user invokes the agent; dynamic schema overrides refresh parameter limits before the LLM sees the tool definition.

Quick Start

1

Simple Agent with Dynamic Tool

Use the @tool decorator with dynamic_schema_overrides to create a tool whose schema changes based on runtime state.
The user delegates research; dynamic tool schemas expose only the fields each sub-task needs.
2

Using BaseTool Subclass

For more control, subclass BaseTool and provide the override in the constructor.

How It Works

The override function is called every time the agent needs tool definitions, ensuring schemas always reflect current runtime state.

Filtering the advertised schema

get_tool_definitions() accepts an optional permission_resolver= — a (tool_name) -> bool callable that drops a tool from the advertised schema when it returns False (deny = hide). Passing None (the default) advertises every available tool, so existing calls stay fully backward-compatible.

Common Patterns

Pattern A: Concurrency Limits

Reflect runtime concurrency settings in parameter constraints.

Pattern B: API Key Filtering

Show only services with valid API keys in enum options.

Pattern C: Live Status Updates

Include current quotas or status information in tool descriptions.

Best Practices

Override functions run on every schema read, so avoid expensive operations like network calls or file I/O. Cache expensive computations and update them periodically rather than computing on each schema request.
Always return a new dictionary rather than mutating the input schema. The base schema is already a deep copy, but your modifications should create new objects to avoid side effects.
If your override function raises an exception, the tool falls back to its base schema with a warning logged. Don’t rely on the override for critical functionality—it should enhance the schema, not make it functional.
Prefer the @tool(dynamic_schema_overrides=...) decorator for plain functions. Only subclass BaseTool when you need richer lifecycle methods or complex state management.

Tool Schema Validation

Validate tool schemas for OpenAI compatibility

Tool Parameter Types

Optional, Union, Literal, and Enum in tool parameters