Module tools

Module tools 

Source
Expand description

§Tool System Architecture

This module provides a modular, composable architecture for VTCode agent tools, implementing a registry-based system for tool discovery, execution, and management.

§Architecture Overview

The tool system is designed around several key principles:

  • Modularity: Each tool is a focused, reusable component
  • Registry Pattern: Centralized tool registration and discovery
  • Policy-Based Execution: Configurable execution policies and safety checks
  • Type Safety: Strong typing for tool parameters and results
  • Async Support: Full async/await support for all tool operations

§Core Components

§Tool Registry

use vtcode_core::tools::{ToolRegistry, ToolRegistration};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let workspace = std::env::current_dir()?;
    let mut registry = ToolRegistry::new(workspace);

    // Register a custom tool
    let tool = ToolRegistration {
        name: "my_tool".to_string(),
        description: "A custom tool".to_string(),
        parameters: serde_json::json!({"type": "object"}),
        handler: |args| async move {
            Ok(serde_json::json!({"result": "success"}))
        },
    };

    registry.register_tool(tool).await?;
    Ok(())
}

§Tool Categories

§File Operations
  • File Operations: Read, write, create, delete files
  • Search Tools: Grep, AST-based search, advanced search
  • Cache Management: File caching and performance optimization
§Terminal Integration
  • Bash Tools: Shell command execution
  • PTY Support: Full terminal emulation
  • Command Policies: Safety and execution controls
§Code Analysis
  • Tree-Sitter: Syntax-aware code analysis
  • AST Grep: Structural code search and transformation
  • Srgn: Syntax-aware code modification

§Tool Execution

use vtcode_core::tools::ToolRegistry;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let mut registry = ToolRegistry::new(std::env::current_dir()?);

    // Execute a tool
    let args = serde_json::json!({"path": "."});
    let result = registry.execute_tool("list_files", args).await?;

    println!("Result: {}", result);
    Ok(())
}

§Safety & Policies

The tool system includes comprehensive safety features:

  • Path Validation: All file operations check workspace boundaries
  • Command Policies: Configurable allow/deny lists for terminal commands
  • Execution Limits: Timeout and resource usage controls
  • Audit Logging: Complete trail of tool executions

§Custom Tool Development

use vtcode_core::tools::traits::Tool;
use serde_json::Value;

struct MyCustomTool;

#[async_trait::async_trait]
impl Tool for MyCustomTool {
    async fn execute(&self, args: Value) -> Result<Value, Box<dyn std::error::Error + Send + Sync>> {
        // Tool implementation
        Ok(serde_json::json!({"status": "completed"}))
    }

    fn name(&self) -> &str {
        "my_custom_tool"
    }

    fn description(&self) -> &str {
        "A custom tool for specific tasks"
    }

    fn parameters(&self) -> Value {
        serde_json::json!({
            "type": "object",
            "properties": {
                "input": {"type": "string"}
            }
        })
    }
}

Modular tool system for VTCode

This module provides a composable architecture for agent tools, breaking down the monolithic implementation into focused, reusable components.

Re-exports§

pub use ast_grep_tool::AstGrepTool;
pub use bash_tool::BashTool;
pub use cache::FileCache;
pub use curl_tool::CurlTool;
pub use grep_search::GrepSearchManager;
pub use registry::ToolRegistration;
pub use registry::ToolRegistry;
pub use simple_search::SimpleSearchTool;
pub use srgn::SrgnTool;
pub use traits::Tool;
pub use traits::ToolExecutor;
pub use registry::build_function_declarations;
pub use registry::build_function_declarations_for_level;
pub use types::*;

Modules§

advanced_search
Advanced search tools with enhanced case-insensitive capabilities
apply_patch
Patch application module implementing the OpenAI Codex patch format
ast_grep
AST-grep integration for VTCode
ast_grep_tool
AST-grep tool implementation for VTCode
bash_tool
Bash-like tool for command execution
cache
Caching system for tool results
command
Command execution tool
curl_tool
Sandboxed curl-like tool with strict safety guarantees
file_ops
File operation tools with composable functionality
file_search
Recursive file search functionality for VTCode
grep_search
Helper that owns the debounce/cancellation logic for rp_search operations.
registry
Tool registry and function declarations
search
Search tool implementation with multiple modes
simple_search
Simple bash-like search tool
srgn
Srgn (code surgeon) tool integration for VTCode
traits
Core traits for the composable tool system
tree_sitter
Tree-sitter integration for Research-preview code parsing and analysis
types
Common types used across the tool system