Skip to main content

Tool System

The Tool system defines the capabilities available to the agent during execution. Each tool is a discrete function with a JSON schema, security validation, and structured result format.

Architecture Overview

Tool Trait

All tools implement the Tool trait from src/tools/traits.rs:

Tool Result

Tool Spec

Shell Tool Implementation

Real implementation from src/tools/shell.rs:

File Tools

File Read Tool

File Write Tool

Memory Tools

Tools that interact with the memory system:

Tool Registry

Tools are assembled into registries in src/tools/mod.rs:

Security Integration

Tools interact with SecurityPolicy for validation:

Command Validation

Path Validation

Rate Limiting

Tool Execution Flow

Adding a New Tool

From AGENTS.md §7.3:
  1. Create tool file: src/tools/new_tool.rs
  1. Register in mod.rs:
  1. Add tests: Validate parameter schema and execution

Best Practices

Parameter Validation

  • Use JSON Schema for type safety
  • Provide clear descriptions for LLM
  • Set sensible defaults
  • Handle missing/invalid parameters gracefully

Security

  • Always validate against SecurityPolicy
  • Check autonomy level for side-effecting operations
  • Sanitize all inputs
  • Never panic in execute() - return ToolResult with error

Error Handling

  • Return success=false with error message
  • Don’t expose sensitive information in errors
  • Provide actionable error messages
  • Log debug info separately

Output Format

  • Keep output concise but informative
  • Truncate large outputs (1MB limit)
  • Use structured formats when helpful
  • Include relevant context in error messages

Next Steps

  • Memory - Memory system and persistence
  • Security - Security architecture deep dive