PythonExecutorToolkit
- [ ] polish _execute_python_code_sync
PythonExecutorToolkit
Bases: AsyncBaseToolkit
A tool for executing Python code in a sandboxed environment.
Source code in utu/tools/python_executor_toolkit.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
tools_map
property
tools_map: dict[str, Callable]
Lazy loading of tools map. - collect tools registered by @register_tool
execute_python_code
async
execute_python_code(code: str, timeout: int = 30) -> dict
Executes Python code and returns the output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
The Python code to execute. |
required |
timeout
|
int
|
The execution timeout in seconds. Defaults to 30. |
30
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
A dictionary containing the execution results. |
Source code in utu/tools/python_executor_toolkit.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
get_tools_map_func
get_tools_map_func() -> dict[str, Callable]
Get tools map. It will filter tools by config.activated_tools if it is not None.
Source code in utu/tools/base.py
36 37 38 39 40 41 42 43 44 45 | |
get_tools_in_agents
get_tools_in_agents() -> list[FunctionTool]
Get tools in openai-agents format.
Source code in utu/tools/base.py
47 48 49 50 51 52 53 54 55 56 57 58 | |
get_tools_in_openai
get_tools_in_openai() -> list[dict]
Get tools in OpenAI format.
Source code in utu/tools/base.py
60 61 62 63 | |
get_tools_in_mcp
get_tools_in_mcp() -> list[Tool]
Get tools in MCP format.
Source code in utu/tools/base.py
65 66 67 68 | |
call_tool
async
call_tool(name: str, arguments: dict) -> str
Call a tool by its name.
Source code in utu/tools/base.py
70 71 72 73 74 75 76 | |