From 1a6d3ee1fd64905cd048c5c9eb2c22fcba72fa60 Mon Sep 17 00:00:00 2001 From: Tom McGinn Date: Tue, 16 Jun 2026 10:19:13 -0500 Subject: [PATCH] fix(delegation): forward background flag to delegate task --- run_agent.py | 1 + tests/run_agent/test_run_agent.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/run_agent.py b/run_agent.py index 2bf27d575101d..a97f6c9c0aaca 100644 --- a/run_agent.py +++ b/run_agent.py @@ -5140,6 +5140,7 @@ def _dispatch_delegate_task(self, function_args: dict) -> str: acp_command=function_args.get("acp_command"), acp_args=function_args.get("acp_args"), role=function_args.get("role"), + background=function_args.get("background"), parent_agent=self, ) diff --git a/tests/run_agent/test_run_agent.py b/tests/run_agent/test_run_agent.py index 827bc0ef690af..313276da55e7c 100644 --- a/tests/run_agent/test_run_agent.py +++ b/tests/run_agent/test_run_agent.py @@ -97,6 +97,22 @@ def agent_with_memory_tool(): return a +def test_dispatch_delegate_task_forwards_background_flag(agent): + """AIAgent's delegate_task dispatch must preserve async background requests.""" + with patch("tools.delegate_tool.delegate_task", return_value="ok") as mock_delegate: + assert agent._dispatch_delegate_task( + { + "goal": "slow background task", + "context": "context", + "toolsets": ["web"], + "role": "leaf", + "background": True, + } + ) == "ok" + + assert mock_delegate.call_args.kwargs["background"] is True + + def test_aiagent_reuses_existing_errors_log_handler(): """Repeated AIAgent init should not accumulate duplicate errors.log handlers.""" root_logger = logging.getLogger()