A programming framework for agentic AI
Add suppress_result_output to ACADynamicSessionsCodeExecutor initializer (#6130)
Stuart Leeksc24eba6ae1c1
diff --git a/python/packages/autogen-ext/src/autogen_ext/code_executors/azure/_azure_container_code_executor.py b/python/packages/autogen-ext/src/autogen_ext/code_executors/azure/_azure_container_code_executor.pyindex 2a6f6c8ee..5691d21ba 100644--- a/python/packages/autogen-ext/src/autogen_ext/code_executors/azure/_azure_container_code_executor.py+++ b/python/packages/autogen-ext/src/autogen_ext/code_executors/azure/_azure_container_code_executor.py@@ -70,6 +70,7 @@ class ACADynamicSessionsCodeExecutor(CodeExecutor):a default working directory will be used. The default workingdirectory is the current directory ".".functions (List[Union[FunctionWithRequirements[Any, A], Callable[..., Any]]]): A list of functions that are available to the code executor. Default is an empty list.+ suppress_result_output bool: By default the executor will attach any result info in the execution response to the result outpu. Set this to True to prevent this."""SUPPORTED_LANGUAGES: ClassVar[List[str]] = [@@ -95,6 +96,7 @@ $functions"""]] = [],functions_module: str = "functions",+ suppress_result_output: bool = False,):if timeout < 1:raise ValueError("Timeout must be greater than or equal to 1.")@@ -120,6 +122,8 @@ $functions"""else:self._setup_functions_complete = True+ self._suppress_result_output = suppress_result_output+self._pool_management_endpoint = pool_management_endpointself._access_token: str | None = Noneself._session_id: str = str(uuid4())@@ -433,7 +437,8 @@ import pkg_resources\n[d.project_name for d in pkg_resources.working_set]data = data["properties"]logs_all += data.get("stderr", "") + data.get("stdout", "")if "Success" in data["status"]:- logs_all += str(data["result"])+ if not self._suppress_result_output:+ logs_all += str(data["result"])elif "Failure" in data["status"]:exitcode = 1diff --git a/python/packages/autogen-ext/tests/code_executors/test_aca_dynamic_sessions.py b/python/packages/autogen-ext/tests/code_executors/test_aca_dynamic_sessions.pyindex 7a69a1879..51f677f34 100644--- a/python/packages/autogen-ext/tests/code_executors/test_aca_dynamic_sessions.py+++ b/python/packages/autogen-ext/tests/code_executors/test_aca_dynamic_sessions.py@@ -61,6 +61,55 @@ async def test_execute_code() -> None:assert code_result.exit_code == 0 and "hello world!" in code_result.output and "200" in code_result.output+ not POOL_ENDPOINT,+ reason="do not run if pool endpoint is not defined",+)+async def test_execute_code_create_image() -> None:+ assert POOL_ENDPOINT is not None+ cancellation_token = CancellationToken()+ executor = ACADynamicSessionsCodeExecutor(+ pool_management_endpoint=POOL_ENDPOINT,+ credential=DefaultAzureCredential(),+ suppress_result_output=True,+ )++ # Test code block that creates an image.+ # This code cuases the session call to return a result with the base64 encoded output+ # By default, this is appended to the output+ # This test verifies that suppress_result_output prevents this from happening+ code_blocks = [+ CodeBlock(+ code="""+import matplotlib.pyplot as plt+import matplotlib.patches as patches++# Create a figure and axis+fig, ax = plt.subplots(figsize=(6, 6))++# Add a circle+circle = patches.Circle((0.5, 0.5), 0.3, color='blue', fill=True)+ax.add_patch(circle)+++# Set the axis limits and aspect ratio+ax.set_xlim(0, 1)+ax.set_ylim(0, 1)+ax.set_aspect('equal')+ax.axis('off') # Turn off the axis++# Save the image to a file+plt.savefig("circle.png", bbox_inches='tight')+print("Saved to circle.png")+""",+ language="python",+ ),+ ]+ code_result = await executor.execute_code_blocks(code_blocks, cancellation_token)+ assert code_result.exit_code == 0 and "base64_data" not in code_result.output++@pytest.mark.skipif(not POOL_ENDPOINT,reason="do not run if pool endpoint is not defined",