295 lines
16 KiB
Markdown
295 lines
16 KiB
Markdown
# 多智能体主智能体(Team Leader)提示词优化调研报告
|
||
|
||
> 调研时间:2026-07-14
|
||
> 目的:为 Astrion 项目的多智能体模式 Team Leader 提示词优化提供素材参考
|
||
|
||
---
|
||
|
||
## 一、当前现状
|
||
|
||
### 当前 Team Leader 提示词(`prompts/multi_agent/master.txt`)结构
|
||
|
||
1. 角色定义(一句话:协调多个子智能体分工协作)
|
||
2. 工作原则(6 条:主动分工、明确指令、及时回答、监督进度、运行时引导、明确问答)
|
||
3. 工具清单(9 个多智能体工具表格)
|
||
4. 会收到的消息格式(输出/提问 XML 示例)
|
||
5. 关于显示名
|
||
6. 通信协议三条硬性原则
|
||
7. 关于团队全局可见
|
||
|
||
### 当前子智能体提示词(`prompts/multi_agent/sub_agent.txt`)结构
|
||
|
||
1. 多智能体身份(团队成员,Team Leader 督导全局)
|
||
2. 在任务中(4 条:不频繁输出、只汇报关键步骤、完成后给详细结论、自然结束即本轮结束)
|
||
3. 沟通工具(ask_master / ask_other_agent / answer_other_agent / list_active_sub_agents)
|
||
4. 汇报强制要求(向其他子智能体提问必须同时向 Team Leader 汇报)
|
||
5. 输出格式
|
||
6. 显示名
|
||
7. 专属设定(role_body 占位符)
|
||
|
||
---
|
||
|
||
## 二、外部调研发现
|
||
|
||
### 来源 1:Anthropic 多智能体研究系统(最重要)
|
||
|
||
**来源**:https://www.anthropic.com/engineering/multi-agent-research-system
|
||
|
||
#### 核心架构
|
||
- Orchestrator-Worker 模式:lead agent 协调,subagents 并行工作
|
||
- Lead agent 分析查询 → 制定策略 → spawn subagents → subagents 独立搜索 → 返回结果给 lead agent → lead agent 综合最终答案
|
||
|
||
#### 8 条提示词工程原则(原文摘录)
|
||
|
||
1. **Think like your agents**(像你的智能体一样思考)
|
||
> "To iterate on prompts, you must understand their effects. We built simulations with the exact prompts and tools, then watched agents work step-by-step. This immediately revealed failure modes: agents continuing when they already had sufficient results, using overly verbose search queries, or selecting incorrect tools."
|
||
|
||
2. **Teach the orchestrator how to delegate**(教协调者如何委派)⭐ 最关键
|
||
> "The lead agent decomposes queries into subtasks and describes them to subagents. Each subagent needs an objective, an output format, guidance on the tools and sources to use, and clear task boundaries. Without detailed task descriptions, agents duplicate work, leave gaps, or fail to find necessary information."
|
||
> 教训:简单的 "research the semiconductor shortage" 指令太模糊,导致子智能体重复工作或误解任务。
|
||
|
||
3. **Scale effort to query complexity**(根据查询复杂度调整投入)⭐
|
||
> "Simple fact-finding requires just 1 agent with 3-10 tool calls, direct comparisons might need 2-4 subagents with 10-15 calls each, and complex research might use more than 10 subagents with clearly divided responsibilities."
|
||
|
||
4. **Tool design and selection are critical**(工具设计和选择至关重要)
|
||
> "Examine all available tools first, match tool usage to user intent, search the web for broad external exploration, or prefer specialized tools over generic ones."
|
||
|
||
5. **Let agents improve themselves**(让智能体自我改进)
|
||
> "Claude 4 models can be excellent prompt engineers. When given a prompt and a failure mode, they are able to diagnose why the agent is failing and suggest improvements."
|
||
|
||
6. **Start wide, then narrow down**(先宽后窄)
|
||
> "Search strategy should mirror expert human research: explore the landscape before drilling into specifics. Agents often default to overly long, specific queries. We counteracted this by prompting agents to start with short, broad queries, evaluate what's available, then progressively narrow focus."
|
||
|
||
7. **Guide the thinking process**(引导思考过程)
|
||
> "The lead agent uses thinking to plan its approach, assessing which tools fit the task, determining query complexity and subagent count, and defining each subagent's role."
|
||
|
||
8. **Parallel tool calling transforms speed and performance**(并行工具调用)
|
||
> "The lead agent spins up 3-5 subagents in parallel rather than serially; the subagents use 3+ tools in parallel. These changes cut research time by up to 90%."
|
||
|
||
#### 关键洞察
|
||
> "The best prompts for these agents are not just strict instructions, but **frameworks for collaboration** that define the division of labor, problem-solving approaches, and effort budgets."
|
||
|
||
#### 避坑经验
|
||
- 早期智能体会为简单查询 spawn 50 个子智能体 → 需要在提示词里嵌入 scaling rules
|
||
- 子智能体会用过长过具体的搜索查询 → 需要提示先宽后窄
|
||
- 子智能体会互相干扰,过度更新 → 需要限制通信频率
|
||
|
||
---
|
||
|
||
### 来源 2:CAMEL 论文 - Inception Prompting
|
||
|
||
**来源**:https://arxiv.org/abs/2303.17760 (NeurIPS 2023)
|
||
|
||
#### 四大失败模式(CAMEL 系统识别的)
|
||
|
||
1. **Role-Flipping(角色反转)**:子智能体停止干活,开始像父智能体一样提问、要求澄清、或反向委派
|
||
2. **Instruction Echoing(指令回声)**:子智能体用不同的话复述任务但不实际执行
|
||
3. **Flake Replies(敷衍回复)**:给出模糊、不承诺的回复,如 "It seems fine"、"Further investigation needed"
|
||
4. **Infinite Loops(无限循环)**:子智能体卡在重复尝试同一种失败方法
|
||
|
||
#### Inception Prompting 解决方案(5 个组件)
|
||
|
||
1. **Role anchoring(角色锚定)**
|
||
> "Never forget you are a <ASSISTANT_ROLE> and I am a <USER_ROLE>. Never flip roles! Never instruct me!"
|
||
|
||
2. **Output format enforcement(输出格式强制)**
|
||
> "You must write a specific solution that appropriately completes the requested instruction."
|
||
> "Always end <YOUR_SOLUTION> with: Next request."
|
||
|
||
3. **Completion signaling(完成信号)**
|
||
> "When the task is completed, you must only reply with a single word <CAMEL_TASK_DONE>."
|
||
|
||
4. **Anti-echo directives(反回声指令)**
|
||
> "Do not restate the task. Perform it."
|
||
|
||
5. **Convergence pressure(收敛压力)**
|
||
> "If an approach fails twice, try a fundamentally different approach rather than retrying the same thing."
|
||
|
||
#### CAMEL 提示词模板原文(AI Society 场景)
|
||
|
||
**Assistant System Prompt:**
|
||
```
|
||
Never forget you are a <ASSISTANT_ROLE> and I am a <USER_ROLE>. Never flip roles!
|
||
Never instruct me!
|
||
We share a common interest in collaborating to successfully complete a task.
|
||
You must help me to complete the task.
|
||
Here is the task: <TASK>. Never forget our task!
|
||
I must instruct you based on your expertise and my needs to complete the task.
|
||
I must give you one instruction at a time.
|
||
You must write a specific solution that appropriately completes the requested instruction.
|
||
You must decline my instruction honestly if you cannot perform the instruction due to physical, moral, legal reasons or your capability and explain the reasons.
|
||
Unless I say the task is completed, you should always start with: Solution: <YOUR_SOLUTION>
|
||
<YOUR_SOLUTION> should be specific, and provide preferable implementations and examples for task-solving.
|
||
Always end <YOUR_SOLUTION> with: Next request.
|
||
```
|
||
|
||
**User System Prompt:**
|
||
```
|
||
Never forget you are a <USER_ROLE> and I am a <ASSISTANT_ROLE>.
|
||
Never flip roles! You will always instruct me.
|
||
We share a common interest in collaborating to successfully complete a task.
|
||
I must help you to complete the task.
|
||
Here is the task: <TASK>. Never forget our task!
|
||
You must instruct me based on my expertise and your needs to complete the task ONLY in the following two ways:
|
||
1. Instruct with a necessary input:
|
||
Instruction: <YOUR_INSTRUCTION>
|
||
Input: <YOUR_INPUT>
|
||
2. Instruct without any input:
|
||
Instruction: <YOUR_INSTRUCTION>
|
||
Input: None
|
||
You must give me one instruction at a time.
|
||
I must write a response that appropriately completes the requested instruction.
|
||
You must decline your instruction honestly if you cannot perform the instruction due to physical, moral, legal reasons or my capability and explain the reasons.
|
||
You should instruct me not ask me questions.
|
||
Now you must start to instruct me using the two ways described above.
|
||
Do not add anything else other than your instruction and the optional corresponding input!
|
||
Keep giving me instructions and necessary inputs until you think the task is completed.
|
||
When the task is completed, you must only reply with a single word <CAMEL_TASK_DONE>.
|
||
Never say <CAMEL_TASK_DONE> unless my responses have solved your task.
|
||
```
|
||
|
||
---
|
||
|
||
### 来源 3:MetaGPT 论文 - SOP 驱动的多智能体协作
|
||
|
||
**来源**:https://arxiv.org/abs/2308.00352
|
||
|
||
#### 核心理念:SOP(Standardized Operating Procedures)
|
||
|
||
> "MetaGPT encodes Standardized Operating Procedures (SOPs) into prompt sequences for more streamlined workflows, thus allowing agents with human-like domain expertise to verify intermediate results and reduce errors."
|
||
|
||
#### 五个角色定义
|
||
- Product Manager:分析竞争和用户需求,创建 PRD
|
||
- Architect:将需求转化为系统设计组件
|
||
- Project Manager:任务分发
|
||
- Engineer:执行代码编写
|
||
- QA Engineer:测试用例和代码质量
|
||
|
||
#### 关键设计:结构化通信
|
||
> "Unlike ChatDev, agents in MetaGPT communicate through documents and diagrams (structured outputs) rather than dialogue. These documents contain all necessary information, preventing irrelevant or missing content."
|
||
|
||
#### 发布-订阅机制
|
||
> "Any agent can directly retrieve required information from the shared pool, eliminating the need to inquire about other agents and await their responses."
|
||
> "An agent activates its action only after receiving all its prerequisite dependencies."
|
||
|
||
#### 对闲聊的抑制
|
||
> "This reduces the risk of hallucinations caused by idle chatter between LLMs, particularly in role-playing frameworks, like: 'Hi, hello and how are you?' – Alice (Product Manager); 'Great! Have you had lunch?' – Bob (Architect)."
|
||
|
||
---
|
||
|
||
### 来源 4:LangGraph/CrewAI/AutoGen 框架对比
|
||
|
||
**来源**:https://dev.to/pockit_tools/langgraph-vs-crewai-vs-autogen-the-complete-multi-agent-ai-orchestration-guide-for-2026-2d63
|
||
|
||
#### LangGraph Supervisor Pattern 提示词示例
|
||
```python
|
||
def supervisor_node(state: AgentState) -> AgentState:
|
||
"""Central coordinator that routes to specialists."""
|
||
llm = ChatOpenAI(model="gpt-4o")
|
||
decision = llm.invoke([
|
||
{"role": "system", "content": """You are a supervisor.
|
||
Based on the current state, decide the next action:
|
||
- 'research': Need more information
|
||
- 'respond': Ready to generate response
|
||
- 'escalate': Needs human intervention
|
||
- 'complete': Task is done"""},
|
||
{"role": "user", "content": f"Current state: {state}"}
|
||
])
|
||
return {"next_action": decision.content}
|
||
```
|
||
|
||
#### CrewAI 角色定义模式
|
||
```python
|
||
classifier_agent = Agent(
|
||
role="Customer Intent Classifier",
|
||
goal="Accurately categorize customer inquiries to route them appropriately",
|
||
backstory="""You are an expert at understanding customer needs.
|
||
With years of experience in customer service, you can quickly
|
||
identify whether a customer needs billing help, technical support,
|
||
or has a complaint that needs escalation.""",
|
||
verbose=True,
|
||
allow_delegation=False # 关键:防止无限委派
|
||
)
|
||
```
|
||
|
||
#### 常见陷阱及解决方案
|
||
1. **Over-Engineering**:20 个智能体做 3 个就能做的事 → 从 2-3 个开始
|
||
2. **Infinite Loops**:智能体互相无限委派 → 设置终止条件 `max_iter=10`
|
||
3. **Context Window Explosion**:传递完整历史 → 实现摘要或滑动窗口
|
||
4. **No Error Boundaries**:一个智能体失败崩溃全系统 → 包裹错误处理
|
||
|
||
---
|
||
|
||
### 来源 5:GitHub Issue - Inception Prompting 实战
|
||
|
||
**来源**:https://github.com/NousResearch/hermes-agent/issues/375
|
||
|
||
#### Hermes Agent 的 Inception Prompting 实现方案
|
||
|
||
**Phase 1: Prompt Hardening(提示词加固)**
|
||
|
||
修改 `_build_child_system_prompt()` 包含:
|
||
- **Role-anchoring**: "You are executing a delegated task. Do the work directly — do not ask questions, request clarification, or suggest the requester do it instead."
|
||
- **Anti-echo**: "Do not restate or paraphrase the task. Perform it using your tools and report concrete results."
|
||
- **Output format guidance**: "Your response must include specific findings, file paths, code snippets, or other concrete artifacts. Vague summaries like 'it seems fine' or 'further investigation needed' are not acceptable."
|
||
- **Convergence pressure**: "If an approach fails twice, try a fundamentally different approach rather than retrying the same thing."
|
||
|
||
**Phase 2: Enhanced Guard Rails(增强护栏)**
|
||
- 角色特定提示词(coordinator, worker, synthesizer)
|
||
- 反循环检测:如果智能体最近 N 条消息语义相似,注入 "you appear stuck" 干预
|
||
|
||
---
|
||
|
||
## 三、综合分析:当前提示词的不足
|
||
|
||
对照外部最佳实践,当前 Team Leader 提示词存在以下可改善点:
|
||
|
||
### 3.1 Team Leader 提示词
|
||
|
||
| # | 不足 | 外部参考 |
|
||
|---|------|----------|
|
||
| 1 | **缺少任务复杂度评估指引** | Anthropic:应在提示词中嵌入 scaling rules,教 Team Leader 评估何时用 1 个子智能体、何时用多个 |
|
||
| 2 | **缺少委派质量标准** | Anthropic:每个子智能体需要 objective + output format + tools guidance + task boundaries,当前只说"写清楚任务目标、范围、产出要求"太笼统 |
|
||
| 3 | **缺少"先宽后窄"策略指引** | Anthropic:应引导 Team Leader 在分解任务时先探索全局再深入 |
|
||
| 4 | **缺少防过度工程指引** | LangGraph/CrewAI:应明确"从 2-3 个子智能体开始,遇到明确瓶颈再加" |
|
||
| 5 | **缺少收敛和终止判断指引** | CAMEL/MetaGPT:应教 Team Leader 如何判断任务完成、如何防止子智能体无限循环 |
|
||
| 6 | **缺少对子智能体失败模式的预判** | CAMEL:应告知 Team Leader 子智能体可能出现 role-flipping、echoing、flake replies,并给出应对策略 |
|
||
| 7 | **角色定义太单薄** | CrewAI/MetaGPT:当前只有一句话"协调多个子智能体分工协作",缺少 goal、constraints、思维方式指引 |
|
||
| 8 | **缺少综合与决策角色强调** | Anthropic:Team Leader 不仅是"协调者",更是"综合者"和"决策者" |
|
||
| 9 | **缺少上下文管理意识** | Anthropic:应提醒 Team Leader 子智能体输出会消耗主上下文,需要引导子智能体精简输出 |
|
||
|
||
### 3.2 子智能体提示词
|
||
|
||
| # | 不足 | 外部参考 |
|
||
|---|------|----------|
|
||
| 1 | **缺少 role anchoring** | CAMEL:应明确"你是执行者,不要反转角色,不要反向提问或委派" |
|
||
| 2 | **缺少 anti-echo 指令** | CAMEL/Hermes:应明确"不要复述任务,直接执行" |
|
||
| 3 | **缺少输出具体性要求** | Hermes:应要求"输出必须包含具体发现、文件路径、代码片段等具体产物,模糊总结不可接受" |
|
||
| 4 | **缺少收敛压力** | CAMEL/Hermes:应加入"如果一个方法失败两次,换一种根本不同的方法" |
|
||
| 5 | **缺少 stuck 自检指引** | Hermes Phase 2:应引导子智能体自我检测是否陷入循环 |
|
||
| 6 | **"不频繁输出"太模糊** | 应给出更具体的输出节奏指引 |
|
||
|
||
---
|
||
|
||
## 四、优化方向建议
|
||
|
||
### 4.1 Team Leader 提示词优化方向
|
||
|
||
1. **丰富角色定义**:从"协调者"升级为"战略规划者 + 任务分解者 + 综合决策者"
|
||
2. **加入任务复杂度评估框架**:简单/中等/复杂三档,对应不同的子智能体数量和工具调用预算
|
||
3. **加入委派质量检查清单**:每次委派前自检 objective/output format/tools/boundaries 是否齐全
|
||
4. **加入失败模式预判和应对**:告知子智能体可能的问题行为及干预手段
|
||
5. **加入收敛和终止指引**:如何判断整体任务完成、如何处理卡住的子智能体
|
||
6. **加入上下文管理意识**:引导子智能体精简输出,避免主上下文膨胀
|
||
|
||
### 4.2 子智能体提示词优化方向
|
||
|
||
1. **加入 role anchoring**:明确角色边界,禁止角色反转
|
||
2. **加入 anti-echo 和输出具体性要求**:不复述任务,输出必须具体
|
||
3. **加入收敛压力和 stuck 自检**:失败换方法,自我检测循环
|
||
4. **优化输出节奏指引**:从"不频繁输出"改为更具体的节奏建议
|
||
|
||
---
|
||
|
||
*报告完毕,接下来可与用户讨论具体优化方案。*
|