Skip to main content
Use expressive Python type annotations in tool signatures and agents understand exactly what parameters they can pass.
The user asks the agent to call a typed tool; annotations become JSON Schema so the model passes valid parameters.

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

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.
Choose Literal[...] when values are unique to one tool. Use Enum when the same choices appear across multiple tools.
Don’t use Union[str, dict] for “either a string or a dict” - the LLM struggles with such choices. Create separate tools instead.
Write List[str] instead of bare list so the agent knows what elements to include.

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