diff --git a/nanobot/agent/subagent.py b/nanobot/agent/subagent.py index 6e815af03..06fd3fdb2 100644 --- a/nanobot/agent/subagent.py +++ b/nanobot/agent/subagent.py @@ -631,7 +631,8 @@ class SubagentManager: except SubagentControlError as exc: return ToolResult.error(f"Error: {exc}") status = record.status - return f"Subagent [{status.label}] started (id: {status.task_id}). I'll notify you when it completes." + return (f"Subagent [{status.label}] started (id: {status.task_id}). " + "I'll notify you when it completes. Don't duplicate its work.") async def run_inline( self, diff --git a/tests/agent/test_subagent_control.py b/tests/agent/test_subagent_control.py index 6bfc15fa9..788b7d7a2 100644 --- a/tests/agent/test_subagent_control.py +++ b/tests/agent/test_subagent_control.py @@ -190,6 +190,7 @@ async def test_default_loop_keeps_slack_thread_for_late_subagent_result( # Keep bounded waits without treating a loaded Windows runner as a routing failure. timeout = 30 child_started, release_child, parent_idle = (asyncio.Event() for _ in range(3)) + parent_tool_results = [] class Provider(LLMProvider): def __init__(self): @@ -207,6 +208,8 @@ async def test_default_loop_keeps_slack_thread_for_late_subagent_result( id="delegate", name="subagent", arguments={"action": "create", "task": "Inspect config", "wait": False}, )]) + if self.parent_calls == 2: + parent_tool_results.extend(m["content"] for m in messages if m.get("role") == "tool") return LLMResponse(content="Parent reply" if self.parent_calls == 2 else "Late follow-up") def get_default_model(self): @@ -246,6 +249,7 @@ async def test_default_loop_keeps_slack_thread_for_late_subagent_result( metadata={"slack": slack_route}, session_key_override=session_key, )) initial_reply = await next_reply("Parent reply") + assert any("Don't duplicate its work." in result for result in parent_tool_results) await asyncio.wait_for(child_started.wait(), timeout=timeout) await asyncio.wait_for(parent_idle.wait(), timeout=timeout) saved = SessionManager(workspace, sessions_root=sessions_root).get_existing(session_key) diff --git a/tests/agent/tools/test_subagent_tools.py b/tests/agent/tools/test_subagent_tools.py index 0dfcf7d32..af72853e4 100644 --- a/tests/agent/tools/test_subagent_tools.py +++ b/tests/agent/tools/test_subagent_tools.py @@ -304,10 +304,12 @@ async def test_background_spawn_waits_for_concurrency_capacity(tmp_path): )): first_result = await tool.execute(action="create", task="first task") assert "started" in first_result + assert first_result.endswith("Don't duplicate its work.") await asyncio.wait_for(first_entered.wait(), timeout=1.0) second_result = await tool.execute(action="create", task="second task") assert "started" in second_result + assert second_result.endswith("Don't duplicate its work.") tasks = list(mgr._running_tasks.values()) await asyncio.sleep(0) assert not second_entered.is_set()