Skip to content

Commit

Permalink
Refactor code executor namespace (microsoft#4538)
Browse files Browse the repository at this point in the history
* refactor code exec namespaces

* delete code exec init

* update conflicts

---------

Co-authored-by: Leonardo Pinheiro <[email protected]>
  • Loading branch information
lspinheiro and lpinheiroms authored Dec 5, 2024
1 parent c02d87e commit 4018a12
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ class CodeExecutorAgent(BaseChatAgent):
Follow the installation instructions for `Docker <https://docs.docker.com/get-docker/>`_.
In this example, we show how to set up a `CodeExecutorAgent` agent that uses the
:py:class:`~autogen_ext.code_executors.DockerCommandLineCodeExecutor`
:py:class:`~autogen_ext.code_executors.docker.DockerCommandLineCodeExecutor`
to execute code snippets in a Docker container. The `work_dir` parameter indicates where all executed files are first saved locally before being executed in the Docker container.
.. code-block:: python
import asyncio
from autogen_agentchat.agents import CodeExecutorAgent
from autogen_agentchat.messages import TextMessage
from autogen_ext.code_executors import DockerCommandLineCodeExecutor
from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor
from autogen_core import CancellationToken
Expand Down
4 changes: 2 additions & 2 deletions python/packages/autogen-core/docs/src/packages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ pip install 'autogen-ext==0.4.0.dev8'
Extras:

- `langchain` needed for {py:class}`~autogen_ext.tools.LangChainToolAdapter`
- `azure` needed for {py:class}`~autogen_ext.code_executors.ACADynamicSessionsCodeExecutor`
- `docker` needed for {py:class}`~autogen_ext.code_executors.DockerCommandLineCodeExecutor`
- `azure` needed for {py:class}`~autogen_ext.code_executors.azure.ACADynamicSessionsCodeExecutor`
- `docker` needed for {py:class}`~autogen_ext.code_executors.docker.DockerCommandLineCodeExecutor`
- `openai` needed for {py:class}`~autogen_ext.models.OpenAIChatCompletionClient`

[{fas}`circle-info;pst-color-primary` User Guide](/user-guide/extensions-user-guide/index.md) | [{fas}`file-code;pst-color-primary` API Reference](/reference/python/autogen_ext.agents.web_surfer.rst) | [{fab}`python;pst-color-primary` PyPI](https://pypi.org/project/autogen-ext/0.4.0.dev8/) | [{fab}`github;pst-color-primary` Source](https://github.com/microsoft/autogen/tree/main/python/packages/autogen-ext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
")\n",
"from autogen_core.components.tools import PythonCodeExecutionTool, ToolSchema\n",
"from autogen_core.tool_agent import ToolAgent, ToolException, tool_agent_caller_loop\n",
"from autogen_ext.code_executors import DockerCommandLineCodeExecutor\n",
"from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor\n",
"from autogen_ext.models import OpenAIChatCompletionClient"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"\n",
"from autogen_core import CancellationToken\n",
"from autogen_core.code_executor import CodeBlock\n",
"from autogen_ext.code_executors import DockerCommandLineCodeExecutor\n",
"from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor\n",
"\n",
"work_dir = Path(\"coding\")\n",
"work_dir.mkdir(exist_ok=True)\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"source": [
"from autogen_core import CancellationToken\n",
"from autogen_core.components.tools import PythonCodeExecutionTool\n",
"from autogen_ext.code_executors import DockerCommandLineCodeExecutor\n",
"from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor\n",
"\n",
"# Create the tool.\n",
"code_executor = DockerCommandLineCodeExecutor()\n",
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from ._azure_container_code_executor import ACADynamicSessionsCodeExecutor, TokenProvider

__all__ = ["TokenProvider", "ACADynamicSessionsCodeExecutor"]
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
)
from typing_extensions import ParamSpec

from ._common import build_python_functions_file, get_required_packages, to_stub
from .._common import build_python_functions_file, get_required_packages, to_stub

if TYPE_CHECKING:
from azure.core.credentials import AccessToken
Expand All @@ -47,7 +47,11 @@ class ACADynamicSessionsCodeExecutor(CodeExecutor):
.. note::
This class requires the :code:`azure` extra for the :code:`autogen-ext` package.
This class requires the :code:`azure` extra for the :code:`autogen-ext` package:
.. code-block:: bash
pip install 'autogen-ext[azure]==0.4.0.dev7'
**This will execute LLM generated code on an Azure dynamic code container.**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from ._docker_code_executor import DockerCommandLineCodeExecutor

__all__ = ["DockerCommandLineCodeExecutor"]
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
FunctionWithRequirementsStr,
)

from ._common import (
from .._common import (
CommandLineCodeResult,
build_python_functions_file,
get_file_name_from_content,
Expand Down Expand Up @@ -55,7 +55,11 @@ class DockerCommandLineCodeExecutor(CodeExecutor):
.. note::
This class requires the :code:`docker` extra for the :code:`autogen-ext` package.
This class requires the :code:`docker` extra for the :code:`autogen-ext` package:
.. code-block:: bash
pip install 'autogen-ext[docker]==0.4.0.dev7'
The executor first saves each code block in a file in the working
Expand Down Expand Up @@ -323,6 +327,7 @@ async def stop(self) -> None:
async def start(self) -> None:
try:
import asyncio_atexit

import docker
from docker.errors import ImageNotFound
except ImportError as e:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from anyio import open_file
from autogen_core import CancellationToken
from autogen_core.code_executor import CodeBlock
from autogen_ext.code_executors import ACADynamicSessionsCodeExecutor
from autogen_ext.code_executors.azure import ACADynamicSessionsCodeExecutor
from azure.identity import DefaultAzureCredential

UNIX_SHELLS = ["bash", "sh", "shell"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
FunctionWithRequirements,
with_requirements,
)
from autogen_ext.code_executors import ACADynamicSessionsCodeExecutor
from autogen_ext.code_executors.azure import ACADynamicSessionsCodeExecutor
from azure.identity import DefaultAzureCredential

ENVIRON_KEY_AZURE_POOL_ENDPOINT = "AZURE_POOL_ENDPOINT"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from aiofiles import open
from autogen_core import CancellationToken
from autogen_core.code_executor import CodeBlock
from autogen_ext.code_executors import DockerCommandLineCodeExecutor
from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor


def docker_tests_enabled() -> bool:
Expand Down
2 changes: 1 addition & 1 deletion python/packages/autogen-magentic-one/examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from autogen_core import AgentId, AgentProxy, SingleThreadedAgentRuntime
from autogen_core.application.logging import EVENT_LOGGER_NAME
from autogen_core.code_executor import CodeBlock
from autogen_ext.code_executors import DockerCommandLineCodeExecutor
from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor
from autogen_magentic_one.agents.coder import Coder, Executor
from autogen_magentic_one.agents.file_surfer import FileSurfer
from autogen_magentic_one.agents.multimodal_web_surfer import MultimodalWebSurfer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from autogen_core import AgentId, AgentProxy, SingleThreadedAgentRuntime
from autogen_core.application.logging import EVENT_LOGGER_NAME
from autogen_core.code_executor import CodeBlock
from autogen_ext.code_executors import DockerCommandLineCodeExecutor
from autogen_ext.code_executors.docker import DockerCommandLineCodeExecutor
from autogen_magentic_one.agents.coder import Coder, Executor
from autogen_magentic_one.agents.orchestrator import RoundRobinOrchestrator
from autogen_magentic_one.agents.user_proxy import UserProxy
Expand Down

0 comments on commit 4018a12

Please sign in to comment.