Tool Architecture
The tools system has three main components:- Tool Definitions: Metadata and schemas for all available tools
- Tool Registry: Runtime registry that maps tool names to implementations
- Meta-Tools: Dynamic tool discovery and invocation
Tool Definitions
Every tool is defined using theToolDefinition dataclass:
Category Index
Tools are automatically indexed by category and action at import time:- “Give me all calendar tools” →
BY_CATEGORY["calendar"] - “What tools can delete?” →
BY_ACTION["delete"]
Tool Registry
TheAgentTools class implements the tool registry:
Tool Execution
The registry provides a standardized execution interface:Pydantic validation happens before execution, ensuring type safety and catching errors early.
Pydantic Schemas
Each tool has a Pydantic model defining its parameters:- Type safety: Parameters are validated at runtime
- Auto-documentation: Field descriptions become tool documentation
- IDE support: Type hints enable autocomplete
- Error messages: Pydantic provides clear validation errors
Meta-Tools Pattern
Meta-tools enable lazy tool loading - the agent discovers and loads tool schemas only when needed.Why Meta-Tools?
Traditional approach (loading all tools):The Three Meta-Tools
discover_tools
discover_tools
Find available tools by category, action, or keyword.Parameters:
categories: Filter by category (calendar, gmail, tasks)actions: Filter by action (search, create, update, delete, list, read)query: Keyword search in tool names and summaries
get_tool_schema
get_tool_schema
Get the complete parameter schema for a specific tool.Parameters:
tool_name: The exact tool name from discover_tools results
invoke_tool
invoke_tool
Execute a tool with the given parameters.Parameters:For destructive operations:
tool_name: The tool to executeparameters: Parameters matching the tool’s schema
Meta-Tools Implementation
LLM Workflow with Meta-Tools
Here’s how the LLM uses meta-tools to fulfill a request:Tool Wrapper Pattern
Tool methods inAgentTools wrap service methods and add:
- Date/time parsing: Convert natural language to ISO format
- Default values: Fill in common parameters
- Error handling: Standardized error responses
Adding New Tools
To add a new tool, follow these steps:
That’s it! The tool is now automatically:
- Discoverable via
discover_tools(categories=["gmail"], actions=["create"]) - Validated using the Pydantic schema
- Executable via
invoke_tool("send_email", {...})
Next Steps
Agent Flow
See complete examples of how tools are used in agent execution
Architecture
Understand how tools fit into the overall system architecture