Architecture Overview
The tool system has three layers:- Tool Definitions (
tool_definitions.py) - Declares tools with metadata and schemas - Tool Registry (
registry.py) - Wraps service methods and handles execution - Pydantic Schemas (
schemas.py) - Validates parameters and provides type safety
Adding a New Tool
Define the Pydantic Schema
Create a parameter schema in The schema provides:
agent/schemas.py:agent/schemas.py
- Type validation via Pydantic
- Field descriptions for LLM tool calling
- Optional parameters with defaults
Register the Tool Definition
Add your tool to Key fields:
TOOL_DEFINITIONS in agent/tools/tool_definitions.py:agent/tools/tool_definitions.py
name- Tool identifier (must match method name)summary- Short description (~15 tokens) for discoverydescription- Full description for LLM tool bindingcategory- Groups tools (“calendar”, “gmail”, “tasks”)actions- Action types (“create”, “read”, “update”, “delete”, etc.)is_write- SetTruefor destructive operationsschema- The Pydantic model from step 1
Implement the Tool Method
Add the implementation to Return format:
AgentTools class in agent/tools/registry.py:agent/tools/registry.py
- Always return a dict with
success: bool - Include a human-readable
message - On error, include
errorwith details - On success, include relevant data (IDs, objects, etc.)
Implement the Service Method
If you need to add a new service integration, implement it in
services/:services/gmail.py
Add to System Prompt (Optional)
If your tool requires special instructions or examples, update the system prompt in
agent/prompts/.The meta-tools approach means the LLM discovers tools dynamically, but you can add guidance:Tool Definition Reference
Here’s a complete example from the codebase:agent/tools/tool_definitions.py
agent/schemas.py
agent/tools/registry.py
Best Practices
Clear Descriptions
Write descriptions that help the LLM understand when to use the tool, not just what it does.
Validation
Use Pydantic Field constraints (ge, le, min_length, etc.) to validate parameters at the schema level.
Error Handling
Always return structured error responses with helpful messages for the user.
Idempotency
Design tools to be safely retryable when possible.
Testing Your Tool
Once implemented, test your tool:-
Direct invocation:
-
Through the agent:
-
Verify discovery:
See Also
Service Integration
Learn how to integrate new external services
Graph Nodes
Understand the agent execution graph