mirror of
https://github.com/microsoft/autogen.git
synced 2025-12-28 07:29:54 +00:00
Refactor code executor namespace (#4538)
* refactor code exec namespaces * delete code exec init * update conflicts --------- Co-authored-by: Leonardo Pinheiro <lpinheiro@microsoft.com>
This commit is contained in:
parent
c02d87e9cf
commit
4018a129f8
@ -31,7 +31,7 @@ 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
|
||||
@ -39,7 +39,7 @@ class CodeExecutorAgent(BaseChatAgent):
|
||||
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
|
||||
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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"
|
||||
]
|
||||
},
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -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",
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
from ._azure_container_code_executor import ACADynamicSessionsCodeExecutor, TokenProvider
|
||||
from ._docker_code_executor import DockerCommandLineCodeExecutor
|
||||
|
||||
__all__ = ["DockerCommandLineCodeExecutor", "TokenProvider", "ACADynamicSessionsCodeExecutor"]
|
||||
@ -0,0 +1,3 @@
|
||||
from ._azure_container_code_executor import ACADynamicSessionsCodeExecutor, TokenProvider
|
||||
|
||||
__all__ = ["TokenProvider", "ACADynamicSessionsCodeExecutor"]
|
||||
@ -23,7 +23,7 @@ from autogen_core.code_executor import (
|
||||
)
|
||||
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
|
||||
@ -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.**
|
||||
@ -0,0 +1,3 @@
|
||||
from ._docker_code_executor import DockerCommandLineCodeExecutor
|
||||
|
||||
__all__ = ["DockerCommandLineCodeExecutor"]
|
||||
@ -22,7 +22,7 @@ from autogen_core.code_executor import (
|
||||
FunctionWithRequirementsStr,
|
||||
)
|
||||
|
||||
from ._common import (
|
||||
from .._common import (
|
||||
CommandLineCodeResult,
|
||||
build_python_functions_file,
|
||||
get_file_name_from_content,
|
||||
@ -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
|
||||
@ -323,6 +327,7 @@ $functions"""
|
||||
async def start(self) -> None:
|
||||
try:
|
||||
import asyncio_atexit
|
||||
|
||||
import docker
|
||||
from docker.errors import ImageNotFound
|
||||
except ImportError as e:
|
||||
@ -10,7 +10,7 @@ import pytest
|
||||
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"]
|
||||
|
||||
@ -11,7 +11,7 @@ from autogen_core.code_executor import (
|
||||
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"
|
||||
|
||||
@ -10,7 +10,7 @@ import pytest_asyncio
|
||||
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:
|
||||
|
||||
@ -8,7 +8,7 @@ import os
|
||||
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
|
||||
|
||||
@ -10,7 +10,7 @@ import logging
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user