Overview
Concrete tool abstraction for defining callable tools with JSON schemas that agents invoke during tool-calling loops.
Description
The Tool and Toolkit classes provide the foundation for tool-augmented agents in EvoAgentX. A Tool subclass defines a `name`, `description`, `inputs` schema (type, description per argument), and implements `__call__`. Subclass validation in `__init_subclass__` enforces that every declared input has a matching parameter in `__call__`. A Toolkit groups multiple `Tool` instances and generates OpenAI-compatible function schemas via `get_tool_schemas()`. When attached to a `CustomizeAgent`, tools participate in the tool-calling loop managed by `CustomizeAction`.
Usage
- Tool-augmented agents: Pass `tools=[FileToolkit()]` to `CustomizeAgent` to enable file I/O operations.
- MCP integration: Use `MCPToolkit(config_path=...)` to expose external MCP server tools.
- Custom tools: Subclass `Tool` with `name`, `description`, `inputs`, and implement `__call__`.
- Workflow generation: Pass toolkits to `WorkFlowGenerator` so generated agents can use them.
Code Reference
Source Location
- Repository: EvoAgentX
- Base File: evoagentx/tools/tool.py (L24-127)
- FileToolkit: evoagentx/tools/file_tool.py (L409)
- MCPToolkit: evoagentx/tools/mcp.py (L297-329)
- ArxivToolkit: evoagentx/tools/request_arxiv.py (L361)
Signature
class Tool(BaseModule):
name: str
description: str
inputs: Dict[str, Dict[str, Any]] # {"input_name": {"type": "string", "description": "..."}}
required: Optional[List[str]] = None
def __call__(self, **kwargs) -> Any
def get_tool_schema(self) -> Dict
@classmethod
def validate_attributes(cls) -> None
class Toolkit(BaseModule):
name: str
tools: List[Tool]
def get_tool_names(self) -> List[str]
def get_tool_schemas(self) -> List[Dict]
def add_tool(self, tool: Tool) -> None
def remove_tool(self, tool_name: str) -> None
def get_tool(self, tool_name: str) -> Tool
Import
from evoagentx.tools.tool import Tool, Toolkit
from evoagentx.tools.file_tool import FileToolkit
from evoagentx.tools.mcp import MCPToolkit
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| name |
str |
Yes |
Tool or toolkit name
|
| description |
str |
Yes |
What the tool does
|
| inputs |
Dict[str, dict] |
Yes |
Argument schemas: `{"arg_name": {"type": "string", "description": "..."}}`
|
| required |
List[str] |
No |
List of required input names
|
Outputs
| Name |
Type |
Description
|
| get_tool_schema returns |
dict |
OpenAI function-calling JSON schema
|
| __call__ returns |
Any |
Tool execution result
|
Usage Examples
Custom Tool
from evoagentx.tools.tool import Tool, Toolkit
class WeatherTool(Tool):
name = "get_weather"
description = "Get current weather for a city"
inputs = {"city": {"type": "string", "description": "City name"}}
required = ["city"]
def __call__(self, city: str) -> str:
# Simulate weather API call
return f"Sunny, 22C in {city}"
# Wrap in a toolkit
weather_toolkit = Toolkit(name="weather", tools=[WeatherTool()])
Agent with FileToolkit
from evoagentx.agents.customize_agent import CustomizeAgent
from evoagentx.tools.file_tool import FileToolkit
from evoagentx.models.model_configs import OpenAILLMConfig
agent = CustomizeAgent(
name="FileAssistant",
description="Reads and analyzes files",
prompt="Read the file at {file_path} and provide a summary.",
llm_config=OpenAILLMConfig(model="gpt-4o-mini", openai_key="sk-..."),
inputs=[{"name": "file_path", "type": "str", "description": "Path to file"}],
outputs=[{"name": "summary", "type": "str", "description": "File summary"}],
parse_mode="title",
tools=[FileToolkit()],
)
Related Pages
Implements Principle
Requires Environment
Uses Heuristic