🛠️ 工具集接口¶
evoagentx.tools ¶
Tool ¶
Bases: BaseModule
Base interface for all tools. All tools must implement:
- get_tool_schemas
: Returns the OpenAI-compatible function schema
- get_tools
: Returns a list of callable functions for all tools
- get_tool_descriptions
: Returns a list of descriptions for all tools
Source code in evoagentx/core/module.py
get_tool_schemas ¶
Returns the OpenAI-compatible function schema for this tool. The schema follows the format used by MCP servers and OpenAI function calling.
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
Dict[str, Any]: The function schema in OpenAI format |
Source code in evoagentx/tools/tool.py
BaseInterpreter ¶
Bases: Tool
Base class for interpreter tools that execute code securely. Implements the standard tool interface with get_tool_schemas and execute methods.
Source code in evoagentx/tools/interpreter_base.py
DockerInterpreter ¶
DockerInterpreter(name: str = 'DockerInterpreter', image_tag: str = None, dockerfile_path: str = None, require_confirm: bool = False, print_stdout: bool = True, print_stderr: bool = True, host_directory: str = '', container_directory: str = '/home/app/', container_command: str = 'tail -f /dev/null', tmp_directory: str = '/tmp', **data)
Bases: BaseInterpreter
A Docker-based interpreter for executing Python, Bash, and R scripts in an isolated environment.
Initialize a Docker-based interpreter for executing code in an isolated environment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the interpreter |
'DockerInterpreter'
|
image_tag
|
str
|
The Docker image tag to use. Must be provided if dockerfile_path is not. |
None
|
dockerfile_path
|
str
|
Path to the Dockerfile to build. Must be provided if image_tag is not. |
None
|
require_confirm
|
bool
|
Whether to require confirmation before executing code |
False
|
print_stdout
|
bool
|
Whether to print stdout from code execution |
True
|
print_stderr
|
bool
|
Whether to print stderr from code execution |
True
|
host_directory
|
str
|
The path to the host directory to mount in the container |
''
|
container_directory
|
str
|
The target directory inside the container |
'/home/app/'
|
container_command
|
str
|
The command to run in the container |
'tail -f /dev/null'
|
tmp_directory
|
str
|
The temporary directory to use for file creation in the container |
'/tmp'
|
**data
|
Additional data to pass to the parent class |
{}
|
Source code in evoagentx/tools/interpreter_docker.py
execute ¶
Executes code in a Docker container.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code
|
str
|
The code to execute |
required |
language
|
str
|
The programming language to use |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The execution output |
Raises:
Type | Description |
---|---|
RuntimeError
|
If container is not properly initialized or execution fails |
ValueError
|
If code content is invalid or exceeds limits |
Source code in evoagentx/tools/interpreter_docker.py
execute_script ¶
Reads code from a file and executes it in a Docker container.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
The path to the script file to execute |
required |
language
|
str
|
The programming language of the code. If None, will be determined from the file extension. |
None
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The execution output |
Raises:
Type | Description |
---|---|
FileNotFoundError
|
If the script file does not exist |
RuntimeError
|
If container is not properly initialized or execution fails |
ValueError
|
If file content is invalid or exceeds limits |
Source code in evoagentx/tools/interpreter_docker.py
get_tool_schemas ¶
Returns the OpenAI-compatible function schema for the Docker interpreter.
Returns:
Type | Description |
---|---|
list[Dict[str, Any]]
|
list[Dict[str, Any]]: Function schema in OpenAI format |
Source code in evoagentx/tools/interpreter_docker.py
get_tool_descriptions ¶
Returns a brief description of the Docker interpreter tool.
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: Tool description |
Source code in evoagentx/tools/interpreter_docker.py
PythonInterpreter ¶
PythonInterpreter(name: str = 'PythonInterpreter', project_path: Optional[str] = '.', directory_names: Optional[List[str]] = [], allowed_imports: Optional[Set[str]] = None, **kwargs)
Bases: BaseInterpreter
Initialize a Python interpreter for executing code in a controlled environment.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the interpreter |
'PythonInterpreter'
|
project_path
|
Optional[str]
|
Path to the project directory for module resolution |
'.'
|
directory_names
|
Optional[List[str]]
|
List of directory names to check for imports |
[]
|
allowed_imports
|
Optional[Set[str]]
|
Set of allowed module imports to enforce security |
None
|
**kwargs
|
Additional data to pass to the parent class |
{}
|
Source code in evoagentx/tools/interpreter_python.py
execute ¶
Analyzes and executes the provided Python code in a controlled environment.
NOTE: This method only returns content printed to stdout during execution. It does not return any values from the code itself. To see results, use print statements in your code.
WARNING: This method uses Python's exec() function internally, which executes code with full privileges. While safety checks are performed, there is still a security risk. Do not use with untrusted code.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
code
|
str
|
The Python code to execute. |
required |
language
|
str
|
The programming language of the code. Defaults to "python". |
'python'
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The output of the executed code (printed content only), or a list of violations if found. |
Source code in evoagentx/tools/interpreter_python.py
execute_script ¶
Reads Python code from a file and executes it using the execute
method.
NOTE: This method only returns content printed to stdout during execution. It does not return any values from the code itself. To see results, use print statements in your code.
WARNING: This method uses Python's exec() function internally, which executes code with full privileges. While safety checks are performed, there is still a security risk. Do not use with untrusted code.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file_path
|
str
|
The path to the Python file to be executed. |
required |
language
|
str
|
The programming language of the code. Defaults to "python". |
'python'
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The output of the executed code (printed content only), or an error message if the execution fails. |
Source code in evoagentx/tools/interpreter_python.py
get_tool_schemas ¶
Returns the OpenAI-compatible function schema for the Python interpreter.
Returns:
Type | Description |
---|---|
list[Dict[str, Any]]
|
list[Dict[str, Any]]: Function schema in OpenAI format |
Source code in evoagentx/tools/interpreter_python.py
get_tool_descriptions ¶
Returns a brief description of the Python interpreter tool.
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: Tool descriptions |
Source code in evoagentx/tools/interpreter_python.py
SearchBase ¶
SearchBase(name: str = 'SearchBase', num_search_pages: Optional[int] = 5, max_content_words: Optional[int] = None, **kwargs)
Bases: Tool
Base class for search tools that retrieve information from various sources. Implements the standard tool interface with get_tool_schemas and execute methods.
Initialize the base search tool.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the tool |
'SearchBase'
|
num_search_pages
|
int
|
Number of search results to retrieve |
5
|
max_content_words
|
int
|
Maximum number of words to include in content, default None means no limit. |
None
|
**kwargs
|
Additional keyword arguments for parent class initialization |
{}
|
Source code in evoagentx/tools/search_base.py
SearchGoogleFree ¶
SearchGoogleFree(name: str = 'GoogleFreeSearch', num_search_pages: Optional[int] = 5, max_content_words: Optional[int] = None, **kwargs)
Bases: SearchBase
Free Google Search tool that doesn't require API keys.
Initialize the Free Google Search tool.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
Name of the tool |
'GoogleFreeSearch'
|
num_search_pages
|
int
|
Number of search results to retrieve |
5
|
max_content_words
|
int
|
Maximum number of words to include in content |
None
|
**kwargs
|
Additional keyword arguments for parent class initialization |
{}
|
Source code in evoagentx/tools/search_google_f.py
search ¶
Searches Google for the given query and retrieves content from multiple pages.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
The search query. |
required |
num_search_pages
|
int
|
Number of search results to retrieve |
None
|
max_content_words
|
int
|
Maximum number of words to include in content, None means no limit |
None
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: Contains a list of search results and optional error message. |
Source code in evoagentx/tools/search_google_f.py
get_tool_schemas ¶
Returns the OpenAI-compatible function schema for the free Google search tool.
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
list[Dict[str, Any]]: Function schema in OpenAI format |
Source code in evoagentx/tools/search_google_f.py
SearchWiki ¶
SearchWiki(name: str = 'SearchWiki', num_search_pages: Optional[int] = 5, max_content_words: Optional[int] = None, max_summary_sentences: Optional[int] = None, **kwargs)
Bases: SearchBase
Initialize the Wikipedia Search tool.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the search tool |
'SearchWiki'
|
num_search_pages
|
int
|
Number of search results to retrieve |
5
|
max_content_words
|
int
|
Maximum number of words to include in content, None means no limit |
None
|
max_summary_sentences
|
int
|
Maximum number of sentences in the summary, None means no limit |
None
|
**kwargs
|
Additional data to pass to the parent class |
{}
|
Source code in evoagentx/tools/search_wiki.py
search ¶
search(query: str, num_search_pages: int = None, max_content_words: int = None, max_summary_sentences: int = None) -> Dict[str, Any]
Searches Wikipedia for the given query and returns the summary and truncated full content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
The search query. |
required |
num_search_pages
|
int
|
Number of search results to retrieve |
None
|
max_content_words
|
int
|
Maximum number of words to include in content, None means no limit |
None
|
max_summary_sentences
|
int
|
Maximum number of sentences in the summary, None means no limit |
None
|
Returns:
Name | Type | Description |
---|---|---|
dict |
Dict[str, Any]
|
A dictionary with the title, summary, truncated content, and Wikipedia page link. |
Source code in evoagentx/tools/search_wiki.py
get_tool_schemas ¶
Returns the OpenAI-compatible function schema for the Wikipedia search tool.
Returns:
Type | Description |
---|---|
list[Dict[str, Any]]
|
list[Dict[str, Any]]: Function schema in OpenAI format |
Source code in evoagentx/tools/search_wiki.py
get_tool_descriptions ¶
Returns a brief description of the Wikipedia search tool.
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: Tool descriptions |
SearchGoogle ¶
SearchGoogle(name: str = 'SearchGoogle', num_search_pages: Optional[int] = 5, max_content_words: Optional[int] = None, **kwargs)
Bases: SearchBase
Initialize the Google Search tool.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
The name of the search tool |
'SearchGoogle'
|
num_search_pages
|
int
|
Number of search results to retrieve |
5
|
max_content_words
|
int
|
Maximum number of words to include in content, None means no limit |
None
|
**kwargs
|
Additional data to pass to the parent class |
{}
|
Source code in evoagentx/tools/search_google.py
search ¶
Search Google using the Custom Search API and retrieve detailed search results with content snippets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query
|
str
|
The search query to execute on Google |
required |
num_search_pages
|
int
|
Number of search results to retrieve |
None
|
max_content_words
|
int
|
Maximum number of words to include in content, None means no limit |
None
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: Contains search results and optional error message |
Source code in evoagentx/tools/search_google.py
get_tool_schemas ¶
Returns the OpenAI-compatible function schema for the Google search tool.
Returns:
Type | Description |
---|---|
list[Dict[str, Any]]
|
list[Dict[str, Any]]: Function schema in OpenAI format |
Source code in evoagentx/tools/search_google.py
get_tool_descriptions ¶
Returns a brief description of the Google search tool.
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: Tool descriptions |
MCPClient ¶
MCPClient(server_configs: StdioServerParameters | dict[str, Any] | list[StdioServerParameters | dict[str, Any]], connect_timeout: float = 120.0)
Source code in evoagentx/tools/mcp.py
MCPToolkit ¶
MCPToolkit(servers: Optional[list[MCPClient]] = None, config_path: Optional[str] = None, config: Optional[dict[str, Any]] = None)
Source code in evoagentx/tools/mcp.py
get_tools ¶
Return a flattened list of all tools across all servers