Commit a454fcfe by sunqi02 Committed by 胡悦

feat(agent_hub): inject THINKING_GUIDE into main and sub-agent prompts

Adds a new THINKING_GUIDE module-level constant in agent_hub.py and
appends it to both the main (steward) and sub-agent system prompts. The
guide constrains the LLM's reasoning style: ≤20 chars thinking, direct
tool_call output without explanation, and detailed reasoning summarized
in tool results. The main prompt still gets REVIEW_GUIDE; sub-agents do
not (they are leaf executors, not coordinators).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent cce02270
...@@ -31,6 +31,13 @@ REVIEW_GUIDE = """ ...@@ -31,6 +31,13 @@ REVIEW_GUIDE = """
3. 不要再调用同一个子Agent重复处理 3. 不要再调用同一个子Agent重复处理
""" """
THINKING_GUIDE = """
## 思考风格
- reasoning 阶段的思考文字 ≤20 字
- 行动时直接输出 tool_call,不要附加解释
- 需要详细推理时在 tool result 里总结
"""
async def _im_post_reasoning_hook( async def _im_post_reasoning_hook(
self, kwargs, output, self, kwargs, output,
...@@ -297,7 +304,7 @@ class AgentHub: ...@@ -297,7 +304,7 @@ class AgentHub:
if sub_lines: if sub_lines:
prompt += "\n\n## 可调用的子Agent\n" + "\n".join(sub_lines) prompt += "\n\n## 可调用的子Agent\n" + "\n".join(sub_lines)
return prompt + REVIEW_GUIDE return prompt + REVIEW_GUIDE + THINKING_GUIDE
def _build_sub_agent_prompt(self, agent_code: str, context: Dict[str, Any]) -> str: def _build_sub_agent_prompt(self, agent_code: str, context: Dict[str, Any]) -> str:
"""Build prompt for a sub-agent when handling a routed query.""" """Build prompt for a sub-agent when handling a routed query."""
...@@ -305,7 +312,7 @@ class AgentHub: ...@@ -305,7 +312,7 @@ class AgentHub:
if not agent: if not agent:
raise AgentHubError(f"Agent {agent_code} 配置未找到") raise AgentHubError(f"Agent {agent_code} 配置未找到")
return agent.prompt # 直接使用,无需拼接 return agent.prompt + THINKING_GUIDE # sub 加思考风格约束
def _dict_to_msg(self, m: dict) -> Msg: def _dict_to_msg(self, m: dict) -> Msg:
"""SessionStore dict → AgentScope Msg。只处理 user/assistant 文本消息。""" """SessionStore dict → AgentScope Msg。只处理 user/assistant 文本消息。"""
......
...@@ -782,3 +782,27 @@ async def test_call_sub_agent_uses_sub_model(): ...@@ -782,3 +782,27 @@ async def test_call_sub_agent_uses_sub_model():
assert captured_model is hub.sub_model assert captured_model is hub.sub_model
# 不应是 main model # 不应是 main model
assert captured_model is not hub.model assert captured_model is not hub.model
# ── Tests for THINKING_GUIDE injection ──
def test_main_prompt_includes_thinking_guide():
"""_build_main_prompt 输出应包含 THINKING_GUIDE。"""
hub = _make_test_hub()
context = {"user_query": "test", "messages": [], "room_id": "r1", "user_id": "u1"}
prompt = hub._build_main_prompt(context)
assert "思考" in prompt
assert "20" in prompt
# main 独有:REVIEW_GUIDE 应在
assert "收到子Agent返回后" in prompt
def test_sub_agent_prompt_includes_thinking_guide_only():
"""_build_sub_agent_prompt 应只拼 THINKING_GUIDE,不含 REVIEW_GUIDE。"""
hub = _make_test_hub()
prompt = hub._build_sub_agent_prompt(MEETING_KEY, {})
assert "思考" in prompt
assert "20" in prompt
# sub 不应有 REVIEW_GUIDE
assert "收到子Agent返回后" not in prompt
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!