Skip to content

Commit 7adfc57

Browse files
committed
Pass checks
1 parent 180bae8 commit 7adfc57

File tree

4 files changed

+28
-20
lines changed

4 files changed

+28
-20
lines changed

python/docs/src/user-guide/core-user-guide/components/tools.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"source": [
2323
"## Built-in Tools\n",
2424
"\n",
25-
"One of the built-in tools is the {py:class}`~autogen_ext.tools.code_execution.PythonCodeExecutionTool`,\n",
25+
"One of the built-in tools is the {py:class}`~autogen_ext.tools.code_execution.CodeExecutionTool`,\n",
2626
"which allows agents to execute Python code snippets.\n",
2727
"\n",
2828
"Here is how you create the tool and use it."
@@ -45,17 +45,17 @@
4545
"source": [
4646
"from autogen_core import CancellationToken\n",
4747
"from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor\n",
48-
"from autogen_ext.tools.code_execution import PythonCodeExecutionTool\n",
48+
"from autogen_ext.tools.code_execution import CodeExecutionTool\n",
4949
"\n",
5050
"# Create the tool.\n",
5151
"code_executor = DockerCommandLineCodeExecutor()\n",
5252
"await code_executor.start()\n",
53-
"code_execution_tool = PythonCodeExecutionTool(code_executor)\n",
53+
"code_execution_tool = CodeExecutionTool(code_executor)\n",
5454
"cancellation_token = CancellationToken()\n",
5555
"\n",
5656
"# Use the tool directly without an agent.\n",
5757
"code = \"print('Hello, world!')\"\n",
58-
"result = await code_execution_tool.run_json({\"code\": code}, cancellation_token)\n",
58+
"result = await code_execution_tool.run_json({\"language\":\"python\", \"code\": code}, cancellation_token)\n",
5959
"print(code_execution_tool.return_value_as_string(result))"
6060
]
6161
},
@@ -66,7 +66,7 @@
6666
"The {py:class}`~autogen_ext.code_executors.docker.DockerCommandLineCodeExecutor`\n",
6767
"class is a built-in code executor that runs Python code snippets in a subprocess\n",
6868
"in the command line environment of a docker container.\n",
69-
"The {py:class}`~autogen_ext.tools.code_execution.PythonCodeExecutionTool` class wraps the code executor\n",
69+
"The {py:class}`~autogen_ext.tools.code_execution.CodeExecutionTool` class wraps the code executor\n",
7070
"and provides a simple interface to execute Python code snippets.\n",
7171
"\n",
7272
"Examples of other built-in tools\n",

python/docs/src/user-guide/core-user-guide/cookbook/tool-use-with-intervention.ipynb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"from autogen_core.tools import ToolSchema\n",
4141
"from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor\n",
4242
"from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
43-
"from autogen_ext.tools.code_execution import PythonCodeExecutionTool"
43+
"from autogen_ext.tools.code_execution import CodeExecutionTool"
4444
]
4545
},
4646
{
@@ -169,7 +169,7 @@
169169
"First, we create a Docker-based command-line code executor\n",
170170
"using {py:class}`~autogen_ext.code_executors.docker.DockerCommandLineCodeExecutor`,\n",
171171
"and then use it to instantiate a built-in Python code execution tool\n",
172-
"{py:class}`~autogen_core.tools.PythonCodeExecutionTool`\n",
172+
"{py:class}`~autogen_core.tools.CodeExecutionTool`\n",
173173
"that runs code in a Docker container."
174174
]
175175
},
@@ -182,8 +182,8 @@
182182
"# Create the docker executor for the Python code execution tool.\n",
183183
"docker_executor = DockerCommandLineCodeExecutor()\n",
184184
"\n",
185-
"# Create the Python code execution tool.\n",
186-
"python_tool = PythonCodeExecutionTool(executor=docker_executor)"
185+
"# Create the code execution tool.\n",
186+
"execution_tool = CodeExecutionTool(executor=docker_executor)"
187187
]
188188
},
189189
{
@@ -216,7 +216,7 @@
216216
" \"tool_executor_agent\",\n",
217217
" lambda: ToolAgent(\n",
218218
" description=\"Tool Executor Agent\",\n",
219-
" tools=[python_tool],\n",
219+
" tools=[execution_tool],\n",
220220
" ),\n",
221221
")\n",
222222
"model_client = OpenAIChatCompletionClient(model=\"gpt-4o-mini\")\n",
@@ -227,7 +227,7 @@
227227
" description=\"Tool Use Agent\",\n",
228228
" system_messages=[SystemMessage(content=\"You are a helpful AI Assistant. Use your tools to solve problems.\")],\n",
229229
" model_client=model_client,\n",
230-
" tool_schema=[python_tool.schema],\n",
230+
" tool_schema=[execution_tool.schema],\n",
231231
" tool_agent_type=tool_agent_type,\n",
232232
" ),\n",
233233
")"

python/packages/autogen-ext/src/autogen_ext/tools/code_execution/_code_execution.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ class CodeExecutionToolConfig(BaseModel):
2626
description: str = "Execute code blocks."
2727

2828

29-
class CodeExecutionTool(
30-
BaseTool[CodeExecutionInput, CodeExecutionResult], Component[CodeExecutionToolConfig]
31-
):
29+
class CodeExecutionTool(BaseTool[CodeExecutionInput, CodeExecutionResult], Component[CodeExecutionToolConfig]):
3230
"""A tool that executes code in a code executor and returns output.
3331
3432
Example executors:

python/packages/autogen-ext/tests/tools/test_code_executor_tool.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ async def test_code_execution_tool(caplog: pytest.LogCaptureFixture) -> None:
1919
with caplog.at_level(logging.INFO):
2020
# Test simple code execution
2121
code = "print('hello world!')"
22-
result = await tool.run_json(args={"code": code, "language": "python"}, cancellation_token=CancellationToken())
22+
result = await tool.run_json(
23+
args={"code": code, "language": "python"}, cancellation_token=CancellationToken()
24+
)
2325
# Check log output
2426
assert "hello world!" in caplog.text
2527

@@ -30,32 +32,40 @@ async def test_code_execution_tool(caplog: pytest.LogCaptureFixture) -> None:
3032
# Test code with computation
3133
code = """a = 100 + 200 \nprint(f'Result: {a}')
3234
"""
33-
result = await tool.run(args=CodeExecutionInput(language="python", code=code), cancellation_token=CancellationToken())
35+
result = await tool.run(
36+
args=CodeExecutionInput(language="python", code=code), cancellation_token=CancellationToken()
37+
)
3438

3539
# Verify computation result
3640
assert result.success is True
3741
assert "Result: 300" in result.output
3842

3943
# Test error handling
4044
code = "print(undefined_variable)"
41-
result = await tool.run(args=CodeExecutionInput(language="python", code=code), cancellation_token=CancellationToken())
45+
result = await tool.run(
46+
args=CodeExecutionInput(language="python", code=code), cancellation_token=CancellationToken()
47+
)
4248

4349
# Verify error handling
4450
assert result.success is False
4551
assert "NameError" in result.output
4652

4753
# Test shell command execution
4854
code = "echo 'hello world!'"
49-
result = await tool.run(args=CodeExecutionInput(language="sh", code=code), cancellation_token=CancellationToken())
55+
result = await tool.run(
56+
args=CodeExecutionInput(language="sh", code=code), cancellation_token=CancellationToken()
57+
)
5058

5159
assert result.success is True
5260
assert "hello world!" in result.output
5361

5462
code = "fake_command"
55-
result = await tool.run(args=CodeExecutionInput(language="sh", code=code), cancellation_token=CancellationToken())
63+
result = await tool.run(
64+
args=CodeExecutionInput(language="sh", code=code), cancellation_token=CancellationToken()
65+
)
5666

5767
assert result.success is False
58-
assert "fake_command: command not found" in result.output
68+
assert "fake_command: not found" in result.output
5969

6070

6171
def test_code_execution_tool_serialization() -> None:

0 commit comments

Comments
 (0)