Skip to content

A programming framework for agentic AI

refactor!: Migrate python code executor tool to autogen-ext (#4824)

Leonardo Pinheiroc078b252fb7e
diff --git a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/tool-use-with-intervention.ipynb b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/tool-use-with-intervention.ipynb
index 27f9bfc6a..46b759509 100644
--- a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/tool-use-with-intervention.ipynb
+++ b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/cookbook/tool-use-with-intervention.ipynb
@@ -36,9 +36,10 @@
" UserMessage,\n",
")\n",
"from autogen_core.tool_agent import ToolAgent, ToolException, tool_agent_caller_loop\n",
- "from autogen_core.tools import PythonCodeExecutionTool, ToolSchema\n",
+ "from autogen_core.tools import ToolSchema\n",
"from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor\n",
- "from autogen_ext.models.openai import OpenAIChatCompletionClient"
+ "from autogen_ext.models.openai import OpenAIChatCompletionClient\n",
+ "from autogen_ext.tools.code_execution import PythonCodeExecutionTool"
]
},
{
diff --git a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/tools.ipynb b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/tools.ipynb
index 7e7ea0ef9..f2bf29425 100644
--- a/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/tools.ipynb
+++ b/python/packages/autogen-core/docs/src/user-guide/core-user-guide/framework/tools.ipynb
@@ -22,7 +22,7 @@
"source": [
"## Built-in Tools\n",
"\n",
- "One of the built-in tools is the {py:class}`~autogen_core.tools.PythonCodeExecutionTool`,\n",
+ "One of the built-in tools is the {py:class}`~autogen_ext.tools.code_execution.PythonCodeExecutionTool`,\n",
"which allows agents to execute Python code snippets.\n",
"\n",
"Here is how you create the tool and use it."
@@ -44,8 +44,8 @@
],
"source": [
"from autogen_core import CancellationToken\n",
- "from autogen_core.tools import PythonCodeExecutionTool\n",
"from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor\n",
+ "from autogen_ext.tools.code_execution import PythonCodeExecutionTool\n",
"\n",
"# Create the tool.\n",
"code_executor = DockerCommandLineCodeExecutor()\n",
diff --git a/python/packages/autogen-core/src/autogen_core/components/tools/__init__.py b/python/packages/autogen-core/src/autogen_core/components/tools/__init__.py
index e3c480fee..f9b590694 100644
--- a/python/packages/autogen-core/src/autogen_core/components/tools/__init__.py
+++ b/python/packages/autogen-core/src/autogen_core/components/tools/__init__.py
@@ -9,19 +9,10 @@ from ...tools import (
from ...tools import (
BaseToolWithState as BaseToolWithStateAlias,
)
-from ...tools import (
- CodeExecutionInput as CodeExecutionInputAlias,
-)
-from ...tools import (
- CodeExecutionResult as CodeExecutionResultAlias,
-)
from ...tools import FunctionTool as FunctionToolAlias
from ...tools import (
ParametersSchema as ParametersSchemaAlias,
)
-from ...tools import (
- PythonCodeExecutionTool as PythonCodeExecutionToolAlias,
-)
from ...tools import (
Tool as ToolAlias,
)
@@ -35,9 +26,6 @@ __all__ = [
"ParametersSchema",
"BaseTool",
"BaseToolWithState",
- "PythonCodeExecutionTool",
- "CodeExecutionInput",
- "CodeExecutionResult",
"FunctionTool",
]
@@ -80,27 +68,6 @@ class BaseToolWithState(BaseToolWithStateAlias[ArgsT, ReturnT, StateT]):
pass
-@deprecated(
- "autogen_core.tools.PythonCodeExecutionToolAlias moved to autogen_core.tools.PythonCodeExecutionToolAlias. This alias will be removed in 0.4.0."
-)
-class PythonCodeExecutionTool(PythonCodeExecutionToolAlias):
- pass
-
-
-@deprecated(
- "autogen_core.tools.CodeExecutionInputAlias moved to autogen_core.tools.CodeExecutionInputAlias. This alias will be removed in 0.4.0."
-)
-class CodeExecutionInput(CodeExecutionInputAlias):
- pass
-
-
-@deprecated(
- "autogen_core.tools.CodeExecutionResultAlias moved to autogen_core.tools.CodeExecutionResultAlias. This alias will be removed in 0.4.0."
-)
-class CodeExecutionResult(CodeExecutionResultAlias):
- pass
-
-
@deprecated(
"autogen_core.tools.FunctionToolAlias moved to autogen_core.tools.FunctionToolAlias. This alias will be removed in 0.4.0."
)
diff --git a/python/packages/autogen-core/src/autogen_core/tools/__init__.py b/python/packages/autogen-core/src/autogen_core/tools/__init__.py
index dcfb1759a..52a9d725f 100644
--- a/python/packages/autogen-core/src/autogen_core/tools/__init__.py
+++ b/python/packages/autogen-core/src/autogen_core/tools/__init__.py
@@ -1,5 +1,4 @@
from ._base import BaseTool, BaseToolWithState, ParametersSchema, Tool, ToolSchema
-from ._code_execution import CodeExecutionInput, CodeExecutionResult, PythonCodeExecutionTool
from ._function_tool import FunctionTool
__all__ = [
@@ -8,8 +7,5 @@ __all__ = [
"ParametersSchema",
"BaseTool",
"BaseToolWithState",
- "PythonCodeExecutionTool",
- "CodeExecutionInput",
- "CodeExecutionResult",
"FunctionTool",
]
diff --git a/python/packages/autogen-ext/src/autogen_ext/tools/code_execution/__init__.py b/python/packages/autogen-ext/src/autogen_ext/tools/code_execution/__init__.py
new file mode 100644
index 000000000..f58ea00df
--- /dev/null
+++ b/python/packages/autogen-ext/src/autogen_ext/tools/code_execution/__init__.py
@@ -0,0 +1,3 @@
+from ._code_execution import CodeExecutionInput, CodeExecutionResult, PythonCodeExecutionTool
+
+__all__ = ["CodeExecutionInput", "CodeExecutionResult", "PythonCodeExecutionTool"]
diff --git a/python/packages/autogen-core/src/autogen_core/tools/_code_execution.py b/python/packages/autogen-ext/src/autogen_ext/tools/code_execution/_code_execution.py
similarity index 87%
rename from python/packages/autogen-core/src/autogen_core/tools/_code_execution.py
rename to python/packages/autogen-ext/src/autogen_ext/tools/code_execution/_code_execution.py
index f3f2b072e..95e8fa34a 100644
--- a/python/packages/autogen-core/src/autogen_core/tools/_code_execution.py
+++ b/python/packages/autogen-ext/src/autogen_ext/tools/code_execution/_code_execution.py
@@ -1,9 +1,8 @@
+from autogen_core import CancellationToken
+from autogen_core.code_executor import CodeBlock, CodeExecutor
+from autogen_core.tools import BaseTool
from pydantic import BaseModel, Field, model_serializer
-from .. import CancellationToken
-from ..code_executor import CodeBlock, CodeExecutor
-from ._base import BaseTool
-
class CodeExecutionInput(BaseModel):
code: str = Field(description="The contents of the Python code block that should be executed")