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)
class ToolFactoryTool(BaseTool):
- memory_agent: MemoryAgent - For workspace management
- tools_registry_path: Path - Tools registry file path
- config: Config - Configuration
create_toolCreates a new tool with code generation and registry registration.
Parameters:
tool_id (str, required): Unique tool identifiertool_config (Dict, optional): Tool configurationTool 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
}
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']}")
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:
test: Test operation for validationstatus: Get tool status_custom_operation: Custom operation handlerTools 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
}
All generated tools:
Tools are automatically:
Generates complete tool code:
Registers tools in:
data/config/official_tools_registry.json
Uses memory agent for:
Created tools are:
# 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 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}")
agents.memory_agent.MemoryAgent: Workspace managementcore.bdi_agent.BaseTool: Base tool class (for generated tools)utils.config.Config: Configurationutils.logging_config.get_logger: LoggingGenerated tools saved to:
tools/{tool_id}.py
Tools registry located at:
data/config/official_tools_registry.json
Basic tool template includes: