tool_factory_tool.md · 7.0 KB

Tool Factory Tool Documentation

Overview

The ToolFactoryTool enables BDI agents to dynamically create new tools. It handles code generation, registry registration, and tool lifecycle management, allowing mindX to extend its capabilities autonomously.

File: tools/tool_factory_tool.py Class: ToolFactoryTool Version: 1.0.0 Status: ✅ Active (High Priority)

Architecture

Design Principles

  1. Dynamic Creation: Create tools at runtime
  2. Registry Integration: Automatic registry registration
  3. Code Generation: Generate tool code from templates
  4. BaseTool Compliance: All tools inherit from BaseTool
  5. Standard Interface: Consistent tool interface

Core Components

class ToolFactoryTool(BaseTool):
    - memory_agent: MemoryAgent - For workspace management
    - tools_registry_path: Path - Tools registry file path
    - config: Config - Configuration

Available Actions

1. create_tool

Creates a new tool with code generation and registry registration.

Parameters:

Tool Config:

{
    "name": str,              # Tool display name
    "description": str,        # Tool description
    "version": str,           # Tool version (default: "1.0.0")
    "enabled": bool,         # Enable status (default: True)
    "operations": List[str]   # Custom operations (optional)
}

Returns:

Tuple[bool, Dict[str, Any]]  # (success, tool_metadata)

Tool Metadata:

{
    "tool_id": str,
    "name": str,
    "description": str,
    "code_path": str,
    "created_at": float,
    "created_by": str,
    "status": str
}

Usage

Create New Tool

from tools.tool_factory_tool import ToolFactoryTool
from agents.memory_agent import MemoryAgent

tool = ToolFactoryTool(memory_agent=memory_agent)

Create tool

success, metadata = await tool.execute( action="create_tool", tool_id="custom_analyzer", tool_config={ "name": "Custom Analyzer", "description": "Specialized analysis tool for custom data", "version": "1.0.0", "enabled": True } )

if success: print(f"Tool created: {metadata['tool_id']}") print(f"Code path: {metadata['code_path']}")

Tool Creation Process

Step 1: Code Generation

Step 2: Registry Registration

Step 3: Metadata Creation

Generated Tool Code Structure

The tool generates BaseTool-compliant tools with:

Standard Structure:

class CustomAnalyzerTool(BaseTool):
    """Dynamically created tool"""
    
    def __init__(self, memory_agent, config, kwargs):
        super().__init__(config=config, kwargs)
        # Initialization
    
    async def execute(self, operation: str, parameters: Dict = None, kwargs):
        # Operation execution

Standard Operations:

Registry Entry Structure

Tools are registered with:

{
    "id": "tool_id",
    "name": "Tool Name",
    "description": "Tool description",
    "module_path": "tools.tool_id",
    "class_name": "ToolIdTool",
    "version": "1.0.0",
    "enabled": true,
    "commands": [...],
    "access_control": {"allowed_agents": ["*"]},
    "created_by": "tool_factory_tool",
    "created_at": 1234567890
}

Features

1. BaseTool Compliance

All generated tools:

2. Automatic Registration

Tools are automatically:

3. Code Generation

Generates complete tool code:

Limitations

Current Limitations

  1. Basic Templates: Simple tool templates only
  2. No Custom Templates: Cannot use custom templates
  3. No Tool Updates: Cannot update existing tools
  4. No Tool Deletion: No tool removal capability
  5. Limited Operations: Basic operations only

Recommended Improvements

  1. Custom Templates: Support for custom tool templates
  2. Tool Updates: Update existing tools
  3. Tool Deletion: Safe tool removal
  4. Operation Library: Library of common operations
  5. Template Library: Library of tool templates
  6. Tool Versioning: Version control for tools
  7. Testing Framework: Auto-generate tests

Integration

With Tools Registry

Registers tools in:

data/config/official_tools_registry.json

With Memory Agent

Uses memory agent for:

With BDI Agents

Created tools are:

Examples

Create Specialized Tool

# Create specialized analysis tool
success, metadata = await tool.execute(
    action="create_tool",
    tool_id="advanced_analyzer",
    tool_config={
        "name": "Advanced Analyzer",
        "description": "Advanced data analysis with ML capabilities",
        "version": "1.0.0",
        "enabled": True
    }
)

Create Multiple Tools

# Create multiple tools for different purposes
tools = [
    ("data_collector", "Data Collection Tool"),
    ("data_processor", "Data Processing Tool"),
    ("data_visualizer", "Data Visualization Tool")
]

for tool_id, name in tools: success, metadata = await tool.execute( action="create_tool", tool_id=tool_id, tool_config={"name": name} ) if success: print(f"Created {tool_id}")

Technical Details

Dependencies

Generated Code Location

Generated tools saved to:

tools/{tool_id}.py

Registry File

Tools registry located at:

data/config/official_tools_registry.json

Tool Template

Basic tool template includes:

Future Enhancements

  1. Template System: Rich template library
  2. Tool Updates: Update existing tools
  3. Tool Deletion: Safe removal
  4. Version Control: Tool versioning
  5. Operation Library: Common operations
  6. Testing Framework: Auto-generate tests
  7. Documentation Generation: Auto-generate docs
  8. Tool Marketplace: Share tool templates

All DocumentsDocument IndexThe Book of mindXImprovement JournalAPI Reference