Quick Start
1
Optional Parameter
Create a tool where parameters can be omitted by the agent:
2
Literal for Fixed Choices
Restrict parameter values to specific literal options:
3
Enum for Choices
Use Enum classes for reusable choice sets across tools:
How It Works
The agent converts your Python type annotations into JSON Schema before the LLM sees the tool definition.Common Patterns
Mode Flags with Defaults
Shared Choice Sets
Structured Collections
Best Practices
Prefer Optional types over bare parameters
Prefer Optional types over bare parameters
Use
Optional[int] with a default of None instead of leaving parameters untyped. This tells the agent the parameter can be omitted and what type to use when provided.Use Literal for small fixed sets, Enum for reusable choices
Use Literal for small fixed sets, Enum for reusable choices
Choose
Literal[...] when values are unique to one tool. Use Enum when the same choices appear across multiple tools.Parameterize your collections
Parameterize your collections
Write
List[str] instead of bare list so the agent knows what elements to include.Related
Tool Schema Validation
Validate tool schemas and catch type errors
Custom Tools Guide
Complete guide to creating custom tools
Dynamic Tool Schemas
Generate schemas dynamically at runtime
Different Ways to Create Tools
Explore all methods for tool creation

