fix(subagent): discourage duplicate delegated work

This commit is contained in:
chengyongru authored and chengyongru committed 2026-11-12 11:47:53 +08:00
1 parent 8607b6445c
commit 9f7ae6fb7b
3 files changed
+8 -1

No files matched your search

+2 -1
View File
@@ -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,
+4
View File
@@ -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)
+2
View File
@@ -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()