Skip to content

Commit

Permalink
Add missing API doc for Python code execution tool (#4901)
Browse files Browse the repository at this point in the history
* Add missing API doc for Python code execution tool

* wip

* Add API doc for the executor tool

---------

Co-authored-by: Jack Gerrits <[email protected]>
  • Loading branch information
ekzhu and jackgerrits authored Jan 6, 2025
1 parent 4486c67 commit 2ff543e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions python/packages/autogen-core/docs/src/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ python/autogen_ext.teams.magentic_one
python/autogen_ext.models.openai
python/autogen_ext.models.replay
python/autogen_ext.tools.langchain
python/autogen_ext.tools.code_execution
python/autogen_ext.code_executors.local
python/autogen_ext.code_executors.docker
python/autogen_ext.code_executors.azure
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
autogen\_ext.tools.code\_execution
==================================


.. automodule:: autogen_ext.tools.code_execution
:members:
:undoc-members:
:show-inheritance:
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,49 @@ def ser_model(self) -> str:


class PythonCodeExecutionTool(BaseTool[CodeExecutionInput, CodeExecutionResult]):
"""A tool that executes Python code in a code executor and returns output.
Example executors:
* :class:`autogen_ext.code_executors.local.LocalCommandLineCodeExecutor`
* :class:`autogen_ext.code_executors.docker.DockerCommandLineCodeExecutor`
* :class:`autogen_ext.code_executors.azure.ACADynamicSessionsCodeExecutor`
Example usage:
.. code-block:: bash
pip install "autogen-agentchat==0.4.0.dev13" "autogen-ext[openai]==0.4.0.dev13" "yfinance" "matplotlib"
.. code-block:: python
import asyncio
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.ui import Console
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_ext.code_executors.local import LocalCommandLineCodeExecutor
from autogen_ext.tools.code_execution import PythonCodeExecutionTool
async def main() -> None:
tool = PythonCodeExecutionTool(LocalCommandLineCodeExecutor(work_dir="coding"))
agent = AssistantAgent(
"assistant", OpenAIChatCompletionClient(model="gpt-4o"), tools=[tool], reflect_on_tool_use=True
)
await Console(
agent.run_stream(
task="Create a plot of MSFT stock prices in 2024 and save it to a file. Use yfinance and matplotlib."
)
)
asyncio.run(main())
Args:
executor (CodeExecutor): The code executor that will be used to execute the code blocks.
"""

def __init__(self, executor: CodeExecutor):
super().__init__(CodeExecutionInput, CodeExecutionResult, "CodeExecutor", "Execute Python code blocks.")
self._executor = executor
Expand Down

0 comments on commit 2ff543e

Please sign in to comment.