Skip to main content

ag_kit.tools

The ag_kit.tools package provides a comprehensive toolkit system that enables AI agents to interact with the external world through a unified, type-safe interface.

Available Tools

Installation

pip install ag-kit

Core Architecture

All tools implement a standardized BaseTool interface for consistency and type safety:
from typing import Any, Dict
from pydantic import BaseModel

class BaseTool:
    """Base class for all tools"""
    
    name: str
    description: str
    
    async def execute(self, input_data: Dict[str, Any]) -> ToolResult:
        """Execute the tool with given input"""
        pass
Every tool execution returns a structured result with comprehensive error handling:
from typing import Any, Optional, Literal

class ToolResult(BaseModel):
    """Standardized tool execution result"""
    
    success: bool
    data: Optional[Any] = None
    error: Optional[str] = None
    error_type: Optional[Literal["validation", "execution", "permission", "network"]] = None
    execution_time: Optional[float] = None

Quick Start

from ag_kit.tools import CodeExecutor, FileSystemTool

# Code execution
executor = CodeExecutor()
result = await executor.execute({
    "code": "print('Hello, World!')"
})

print(result.data["output"])  # Hello, World!

# File operations
fs_tool = FileSystemTool(base_path="/project")
content = await fs_tool.execute({
    "operation": "read",
    "path": "config.json"
})

Key Features

  • Type Safety: Full Pydantic support with schema validation
  • Security: Path validation, input sanitization, and sandboxed execution
  • Extensibility: Easy custom tool creation with the base tool class
  • Performance: Async operations with timeout control and resource management
  • Error Handling: Structured error types with detailed context

Tool Categories

File System Tools

Complete file and directory operations including read, write, edit, search, and pattern matching. Learn more →

Code Execution Tools

Secure Python code execution with both sandboxed and local options. Learn more →

Command Line Tools

Shell command execution with proper isolation and environment control. Learn more →

Framework Adapters

Seamless bidirectional conversion between AG-Kit tools and popular AI frameworks like LangChain and LlamaIndex. Learn more →

MCP Integration

Bidirectional integration with Model Context Protocol for connecting to external MCP servers and exposing AG-Kit tools. Learn more →

Custom Tools

Framework for building specialized tools tailored to your specific use cases. Learn more →

Next Steps

Integration Resources