Commit 3d4823f6 by sunqi02 Committed by 胡悦

feat: main agent stays silent when exactly one sub_agent was called

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 0332ea14
...@@ -465,18 +465,24 @@ class AgentHub: ...@@ -465,18 +465,24 @@ class AgentHub:
self.session_service.save_to_db(session_id) self.session_service.save_to_db(session_id)
# Send via hook — failure non-fatal, only log # Send via hook — failure non-fatal, only log
try: # 1 次 call_sub_agent 时跳过:子 Agent 已用自己的 bot 发送回复
await self.post_reply_hook.execute({ if self._current_route_ctx.get("call_count", 0) != 1:
"agent_name": target_agent, try:
"response_content": response_content, await self.post_reply_hook.execute({
"room_id": room_id, "agent_name": target_agent,
"mentioned_list": [user_id], "response_content": response_content,
"bot_id_mapping": bot_id_mapping or {}, "room_id": room_id,
}) "mentioned_list": [user_id],
except Exception: "bot_id_mapping": bot_id_mapping or {},
logger.warning( })
"[最终回复 IM 发送失败] agent=%s session=%s room=%s", except Exception:
target_agent, session_id, room_id, exc_info=True, logger.warning(
"[最终回复 IM 发送失败] agent=%s session=%s room=%s",
target_agent, session_id, room_id, exc_info=True,
)
else:
logger.info(
"[主Agent 静默] call_count=1,子 Agent 已发送回复,跳过主 Agent post_reply"
) )
processing_time_ms = (time.time() - start_time) * 1000 processing_time_ms = (time.time() - start_time) * 1000
......
...@@ -1060,3 +1060,44 @@ class TestSubAgentPostReply: ...@@ -1060,3 +1060,44 @@ class TestSubAgentPostReply:
# 结果正常返回 # 结果正常返回
assert "会议纪要已生成" in result assert "会议纪要已生成" in result
def test_main_agent_silent_when_call_count_is_1(self):
"""1 次 call_sub_agent 时,主 Agent 不发 post_reply。"""
hub = _make_test_hub()
hub._current_route_ctx = dict(
room_id="r1", user_id="u1", bot_id_mapping={},
call_count=1,
)
# 模拟 process_message 结尾的判断逻辑
call_count = hub._current_route_ctx.get("call_count", 0)
assert call_count == 1
# count == 1 时跳过发送
should_send = call_count != 1
assert should_send is False
def test_main_agent_sends_when_call_count_is_0(self):
"""0 次 call_sub_agent 时,主 Agent 正常发送。"""
hub = _make_test_hub()
hub._current_route_ctx = dict(
room_id="r1", user_id="u1", bot_id_mapping={},
call_count=0,
)
call_count = hub._current_route_ctx.get("call_count", 0)
assert call_count == 0
should_send = call_count != 1
assert should_send is True
def test_main_agent_sends_when_call_count_is_2(self):
"""2+ 次 call_sub_agent 时,主 Agent 正常发综合回复。"""
hub = _make_test_hub()
hub._current_route_ctx = dict(
room_id="r1", user_id="u1", bot_id_mapping={},
call_count=2,
)
call_count = hub._current_route_ctx.get("call_count", 0)
assert call_count == 2
should_send = call_count != 1
assert should_send is True
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!