From 78ff883d24b936ca3055df56ed2590e165fb44d2 Mon Sep 17 00:00:00 2001 From: Jay Prakash Thakur Date: Sun, 2 Mar 2025 17:00:08 -0800 Subject: [PATCH] =?UTF-8?q?docs:=20add=20note=20about=20markdown=20code=20?= =?UTF-8?q?block=20requirement=20in=20CodeExecutorA=E2=80=A6=20(#5785)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Why are these changes needed? The CodeExecutorAgent documentation needs to be updated to explicitly mention that it only processes code properly formatted in markdown code blocks with triple backticks. This change adds a clear note with examples to help users understand the required format for code execution. ## Related issue number Closes #5771 Co-authored-by: Eric Zhu --- .../agents/_code_executor_agent.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py index 162217d35..6c78ddc01 100644 --- a/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py +++ b/python/packages/autogen-agentchat/src/autogen_agentchat/agents/_code_executor_agent.py @@ -37,6 +37,23 @@ class CodeExecutorAgent(BaseChatAgent, Component[CodeExecutorAgentConfig]): It is recommended that the `CodeExecutorAgent` agent uses a Docker container to execute code. This ensures that model-generated code is executed in an isolated environment. To use Docker, your environment must have Docker installed and running. Follow the installation instructions for `Docker `_. + .. note:: + + The code executor only processes code that is properly formatted in markdown code blocks using triple backticks. + For example: + + .. code-block:: text + + ```python + print("Hello World") + ``` + + # or + + ```sh + echo "Hello World" + ``` + In this example, we show how to set up a `CodeExecutorAgent` agent that uses the :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.