Sheng Yan commited on
Commit
2e02e3c
·
1 Parent(s): 0108510

feat: Add Hybrid B mode (debate + nested agent) with sub-agent status display and improved rebuttal mechanism

Browse files
README.md CHANGED
@@ -11,6 +11,7 @@
11
  - **Debate Mode**(对抗辩论):支持方与反对方针对代码设计进行多轮博弈,最后由裁判 Agent 给出终极裁决
12
  - **Nested Agent**(任务拆解):主 Agent 根据需求动态规划,按需召唤子 Agent 完成代码、测试或文档,实现树状任务分发
13
  - **Hybrid A**(三阶段混合流水线):并行生成(代码 + 测试 + 文档)→ 循环质检(最多3轮)→ 条件分支(复杂代码进行安全审查),复用已有模式的 Agent,组合为全自动交付链路
 
14
  - **模型自动降级**:依次尝试 6 个模型,成功即返回并在 UI 中标注实际使用的模型名
15
  - **多模式切换**:侧边栏一键切换编排模式,界面实时动态刷新
16
  - **实时状态展示**:执行中动态更新 Agent 状态徽章,折叠面板展示各 Agent 输出
@@ -65,6 +66,54 @@ graph TD
65
  Finalizer --> End((交付完成))
66
  ```
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
68
  ## 技术栈
69
 
70
  | 组件 | 技术 |
@@ -157,6 +206,20 @@ multi-agent/
157
  │ │ ├── complexity.py # 复杂度判断 Agent(新)
158
  │ │ └── finalizer.py # 最终交付整合 Agent(新)
159
  │ └── prompts.py # complexity + finalizer Prompt 模板
 
 
 
 
 
 
 
 
 
 
 
 
 
 
160
  ├── requirements.txt
161
  ├── .env.example
162
  └── .env # 本地密钥(不提交)
@@ -223,6 +286,7 @@ streamlit run app.py
223
  | Debate | 多 Agent 对抗辩论 | ✅ 已上线 |
224
  | Nested Agent | 嵌套子 Agent 调用 | ✅ 已上线 |
225
  | Hybrid A | 并行 + 循环质检 + 条件分支混合流水线 | ✅ 已上线 |
 
226
 
227
  ## License
228
 
 
11
  - **Debate Mode**(对抗辩论):支持方与反对方针对代码设计进行多轮博弈,最后由裁判 Agent 给出终极裁决
12
  - **Nested Agent**(任务拆解):主 Agent 根据需求动态规划,按需召唤子 Agent 完成代码、测试或文档,实现树状任务分发
13
  - **Hybrid A**(三阶段混合流水线):并行生成(代码 + 测试 + 文档)→ 循环质检(最多3轮)→ 条件分支(复杂代码进行安全审查),复用已有模式的 Agent,组合为全自动交付链路
14
+ - **Hybrid B**(辩论+嵌套混合):支持方/反对方在辩论前先召唤专项子Agent(性能/成本/安全/可维护性)收集数据,再基于数据发言。UI实时显示子Agent召唤状态(⚡性能/💰成本/🔒安全/🔧可维护性),论点更有依据。第2轮自动获取对方所有历史论点进行针对性反驳
15
  - **模型自动降级**:依次尝试 6 个模型,成功即返回并在 UI 中标注实际使用的模型名
16
  - **多模式切换**:侧边栏一键切换编排模式,界面实时动态刷新
17
  - **实时状态展示**:执行中动态更新 Agent 状态徽章,折叠面板展示各 Agent 输出
 
66
  Finalizer --> End((交付完成))
67
  ```
68
 
69
+ ### 4. Hybrid B (辩论+嵌套混合)
70
+
71
+ 辩论模式与嵌套 Agent 的结合。每一方辩论时不是直接生成观点,而是先召唤专项子 Agent 收集数据,再基于数据发言。论点有依据,辩论更有深度。
72
+
73
+ **场景**:架构方案评审。用户输入一个技术架构方案(比如"用 Redis 做主数据库"),两方基于数据辩论。
74
+
75
+ **角色设计**:
76
+ - 支持方 Orchestrator:召唤 → 性能子 Agent + 成本子 Agent → 汇总论点
77
+ - 反对方 Orchestrator:召唤 → 安全子 Agent + 维护性子 Agent → 汇总论点
78
+ - 裁判 Agent:综合所有轮次数据,给出最终采纳/否决建议
79
+
80
+ **UI 特性**:
81
+ - 实时显示子Agent召唤状态(⚡ 性能Agent ✅ / 💰 成本Agent ✅)
82
+ - 支持方/反对方论点旁显示使用的模型名称
83
+ - 折叠面板展示子Agent分析数据(性能/成本/安全/可维护性)
84
+
85
+ **反驳机制**:
86
+ - 第2轮自动获取对方所有历史论点(不仅是上一轮)
87
+ - Prompt 强制要求"必须针对对方的所有论点逐一反驳,不得重复第1轮观点"
88
+
89
+ ```mermaid
90
+ graph TD
91
+ Input[架构方案输入] --> Round1[第1轮]
92
+ Round1 --> ProOrch1[支持方 Orchestrator]
93
+ ProOrch1 -->|Send| Perf1[性能 Agent]
94
+ ProOrch1 -->|Send| Cost1[成本 Agent]
95
+ Perf1 --> ProSum1[支持方汇总]
96
+ Cost1 --> ProSum1
97
+ ProSum1 --> ConOrch1[反对方 Orchestrator]
98
+ ConOrch1 -->|Send| Sec1[安全 Agent]
99
+ ConOrch1 -->|Send| Maint1[维护性 Agent]
100
+ Sec1 --> ConSum1[反对方汇总]
101
+ Maint1 --> ConSum1
102
+ ConSum1 --> Round2[第2轮-反驳]
103
+ Round2 --> ProOrch2[支持方 Orchestrator]
104
+ ProOrch2 -->|Send| Perf2[性能 Agent]
105
+ ProOrch2 -->|Send| Cost2[成本 Agent]
106
+ Perf2 --> ProSum2[支持方反驳-针对所有反方论点]
107
+ Cost2 --> ProSum2
108
+ ProSum2 --> ConOrch2[反对方 Orchestrator]
109
+ ConOrch2 -->|Send| Sec2[安全 Agent]
110
+ ConOrch2 -->|Send| Maint2[维护性 Agent]
111
+ Sec2 --> ConSum2[反对方反驳-针对所有支持方论点]
112
+ Maint2 --> ConSum2
113
+ ConSum2 --> Judge[裁判 Agent]
114
+ Judge --> Verdict[最终建议]
115
+ ```
116
+
117
  ## 技术栈
118
 
119
  | 组件 | 技术 |
 
206
  │ │ ├── complexity.py # 复杂度判断 Agent(新)
207
  │ │ └── finalizer.py # 最终交付整合 Agent(新)
208
  │ └── prompts.py # complexity + finalizer Prompt 模板
209
+ ├── hybrid_b/ # ✅ Hybrid B 辩论+嵌套混合模式
210
+ │ ├── __init__.py
211
+ │ ├── graph.py # 辩论循环 + 嵌套子Agent 图定义
212
+ │ ├── agents/
213
+ │ │ ├── pro_orchestrator.py # 支持方 Orchestrator
214
+ │ │ ├── con_orchestrator.py # 反对方 Orchestrator
215
+ │ │ ├── performance.py # 性能分析子 Agent
216
+ │ │ ├── cost.py # 成本分析子 Agent
217
+ │ │ ├── security.py # 安全分析子 Agent(复用)
218
+ │ │ ├── maintainability.py # 可维护性分析子 Agent(复用)
219
+ │ │ ├── pro_summarizer.py # 支持方论点汇总
220
+ │ │ ├── con_summarizer.py # 反对方论点汇总
221
+ │ │ └── judge.py # 裁判 Agent
222
+ │ └── prompts.py # 所有 Prompt 模板
223
  ├── requirements.txt
224
  ├── .env.example
225
  └── .env # 本地密钥(不提交)
 
286
  | Debate | 多 Agent 对抗辩论 | ✅ 已上线 |
287
  | Nested Agent | 嵌套子 Agent 调用 | ✅ 已上线 |
288
  | Hybrid A | 并行 + 循环质检 + 条件分支混合流水线 | ✅ 已上线 |
289
+ | Hybrid B | 辩论+嵌套混合,支持方/反对方召唤子Agent收集数据后辩论 | ✅ 已上线 |
290
 
291
  ## License
292
 
app.py CHANGED
The diff for this file is too large to render. See raw diff
 
hybrid_b/__init__.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Hybrid B - 辩论 + 嵌套 Agent
3
+ 支持方/反对方召唤子Agent收集数据后辩论
4
+ """
5
+
6
+ from hybrid_b.graph import stream_hybrid_b
7
+
8
+ __all__ = ["stream_hybrid_b"]
hybrid_b/agents/con_orchestrator.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ 反对方 Orchestrator Agent
3
+ 负责召唤安全分析子Agent和可维护性分析子Agent,然后汇总生成反对论点。
4
+ """
5
+ import json
6
+ from langchain_core.messages import SystemMessage, HumanMessage
7
+ from llm import call_with_fallback
8
+ from hybrid_b.prompts import (
9
+ CON_ORCHESTRATOR_SYSTEM_PROMPT,
10
+ CON_ORCHESTRATOR_HUMAN_PROMPT
11
+ )
12
+
13
+
14
+ def format_history(history):
15
+ """格式化辩论历史"""
16
+ if not history:
17
+ return "辩论刚刚开始。"
18
+ formatted = []
19
+ for item in history:
20
+ role = "支持方" if item["role"] == "pro" else "反对方"
21
+ formatted.append(f"【{role} 第{item['round']}轮】\n{item['content'][:500]}...")
22
+ return "\n\n".join(formatted)
23
+
24
+
25
+ def con_orchestrator_node(state: dict) -> dict:
26
+ """
27
+ 反对方 Orchestrator 节点。
28
+ 1. 分析架构方案,制定子Agent分析计划
29
+ 2. 返回分析计划,由 graph 负责召唤子Agent
30
+ """
31
+ scheme = state["scheme"]
32
+ current_round = state["current_round"] # 保持当前轮次,与支持方相同
33
+ debate_history = state.get("debate_history", [])
34
+
35
+ # 获取对方所有论点(用于反驳)
36
+ opponent_info = ""
37
+ pro_arguments = [item for item in debate_history if item["role"] == "pro"]
38
+ if pro_arguments:
39
+ opponent_info = "\n对方所有论点:\n"
40
+ for arg in pro_arguments:
41
+ opponent_info += f"【第{arg['round']}轮】{arg['content'][:500]}...\n"
42
+
43
+ messages = [
44
+ SystemMessage(content=CON_ORCHESTRATOR_SYSTEM_PROMPT.format(
45
+ current_round=current_round,
46
+ opponent_info=opponent_info
47
+ )),
48
+ HumanMessage(content=CON_ORCHESTRATOR_HUMAN_PROMPT.format(
49
+ scheme=scheme,
50
+ debate_history=format_history(debate_history)
51
+ )),
52
+ ]
53
+
54
+ result = call_with_fallback(messages)
55
+
56
+ # 解析 JSON 计划
57
+ try:
58
+ plan = json.loads(result.content)
59
+ security_focus = "\n".join(plan.get("security_focus", []))
60
+ maintainability_issues = "\n".join(plan.get("maintainability_issues", []))
61
+ strategy = plan.get("strategy", "")
62
+ except:
63
+ # 如果解析失败,使用默认内容
64
+ security_focus = "安全分析"
65
+ maintainability_issues = "可维护性分析"
66
+ strategy = result.content[:200]
67
+
68
+ return {
69
+ "security_focus": security_focus,
70
+ "maintainability_focus": maintainability_issues,
71
+ "con_strategy": strategy,
72
+ "model_used_by": {"con_orchestrator": result.model_used},
73
+ }
hybrid_b/agents/con_summarizer.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ 反对方汇总 Agent
3
+ 基于安全分析和可维护性分析的数据,生成反对论点。
4
+ """
5
+ from langchain_core.messages import SystemMessage, HumanMessage
6
+ from llm import call_with_fallback
7
+ from hybrid_b.prompts import CON_SUMMARIZER_SYSTEM_PROMPT, CON_SUMMARIZER_HUMAN_PROMPT
8
+
9
+
10
+ def format_history(history):
11
+ """格式化辩论历史"""
12
+ if not history:
13
+ return "辩论刚刚开始。"
14
+ formatted = []
15
+ for item in history:
16
+ role = "支持方" if item["role"] == "pro" else "反对方"
17
+ formatted.append(f"【{role} 第{item['round']}轮】\n{item['content']}")
18
+ return "\n\n" + "=" * 50 + "\n\n".join(formatted)
19
+
20
+
21
+ def con_summarizer_node(state: dict) -> dict:
22
+ """
23
+ 反对方汇总节点。
24
+ 读取 state 中的安全分析和可维护性分析结果,生成反对论点。
25
+ """
26
+ scheme = state["scheme"]
27
+ current_round = state["current_round"]
28
+ security_result = state.get("security_result", "未获得安全分析数据")
29
+ maintainability_result = state.get("maintainability_result", "未获得可维护性分析数据")
30
+ debate_history = state.get("debate_history", [])
31
+
32
+ # 获取对方上一轮论点
33
+ opponent_info = ""
34
+ if debate_history:
35
+ last_entry = debate_history[-1]
36
+ if last_entry["role"] == "pro":
37
+ opponent_info = f"\n对方上一轮论点:\n{last_entry['content']}"
38
+
39
+ messages = [
40
+ SystemMessage(content=CON_SUMMARIZER_SYSTEM_PROMPT.format(
41
+ current_round=current_round,
42
+ opponent_info=opponent_info
43
+ )),
44
+ HumanMessage(content=CON_SUMMARIZER_HUMAN_PROMPT.format(
45
+ scheme=scheme,
46
+ security_result=security_result,
47
+ maintainability_result=maintainability_result,
48
+ debate_history=format_history(debate_history)
49
+ )),
50
+ ]
51
+
52
+ result = call_with_fallback(messages)
53
+
54
+ return {
55
+ "debate_history": [{
56
+ "role": "con",
57
+ "round": current_round,
58
+ "content": result.content,
59
+ "security_result": security_result,
60
+ "maintainability_result": maintainability_result,
61
+ }],
62
+ "model_used_by": {"con_summarizer": result.model_used},
63
+ }
hybrid_b/agents/cost.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ 成本分析子 Agent
3
+ 分析架构方案的成本方面:基础设施成本、许可费用、运维成本、扩展成本等。
4
+ """
5
+ from langchain_core.messages import SystemMessage, HumanMessage
6
+ from llm import call_with_fallback
7
+ from hybrid_b.prompts import COST_SYSTEM_PROMPT, COST_HUMAN_PROMPT
8
+
9
+
10
+ def cost_node(state: dict) -> dict:
11
+ """
12
+ 成本分析子 Agent 节点。
13
+ 读取 state["scheme"],输出成本分析报告到 state["cost_result"]。
14
+ """
15
+ scheme = state["scheme"]
16
+ cost_concerns = state.get("cost_focus", "成本分析")
17
+
18
+ messages = [
19
+ SystemMessage(content=COST_SYSTEM_PROMPT),
20
+ HumanMessage(content=COST_HUMAN_PROMPT.format(
21
+ scheme=scheme,
22
+ cost_concerns=cost_concerns
23
+ )),
24
+ ]
25
+
26
+ result = call_with_fallback(messages)
27
+
28
+ return {
29
+ "cost_result": result.content,
30
+ "model_used_by": {"cost": result.model_used},
31
+ }
hybrid_b/agents/judge.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ 裁判 Agent (Judge)
3
+ 综合所有轮次的辩论数据,给出最终采纳/否决建议。
4
+ """
5
+ from langchain_core.messages import SystemMessage, HumanMessage
6
+ from llm import call_with_fallback
7
+ from hybrid_b.prompts import JUDGE_SYSTEM_PROMPT, JUDGE_HUMAN_PROMPT
8
+
9
+
10
+ def format_history(history):
11
+ """格式化完整辩论历史,包含子Agent数据"""
12
+ if not history:
13
+ return "无辩论过程。"
14
+
15
+ formatted = []
16
+ for item in history:
17
+ role = "支持方" if item["role"] == "pro" else "反对方"
18
+ entry = f"【{role} 第{item['round']}轮】\n"
19
+ entry += f"论点:\n{item['content']}\n"
20
+
21
+ # 添加子Agent数据
22
+ if item.get("performance_result"):
23
+ entry += f"\n性能分析数据:\n{item['performance_result'][:500]}...\n"
24
+ if item.get("cost_result"):
25
+ entry += f"\n成本分析数据:\n{item['cost_result'][:500]}...\n"
26
+ if item.get("security_result"):
27
+ entry += f"\n安全分析数据:\n{item['security_result'][:500]}...\n"
28
+ if item.get("maintainability_result"):
29
+ entry += f"\n可维护性分析数据:\n{item['maintainability_result'][:500]}...\n"
30
+
31
+ formatted.append(entry)
32
+
33
+ return "\n\n" + "="*50 + "\n\n".join(formatted)
34
+
35
+
36
+ def judge_node(state: dict) -> dict:
37
+ """
38
+ 裁判节点。
39
+ 读取完整辩论历史,输出最终裁决。
40
+ """
41
+ scheme = state["scheme"]
42
+ debate_history = state.get("debate_history", [])
43
+
44
+ messages = [
45
+ SystemMessage(content=JUDGE_SYSTEM_PROMPT),
46
+ HumanMessage(content=JUDGE_HUMAN_PROMPT.format(
47
+ scheme=scheme,
48
+ debate_history=format_history(debate_history)
49
+ )),
50
+ ]
51
+
52
+ result = call_with_fallback(messages)
53
+
54
+ return {
55
+ "final_conclusion": result.content,
56
+ "model_used_by": {"judge": result.model_used},
57
+ }
hybrid_b/agents/maintainability.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ 可维护性分析子 Agent
3
+ 分析架构方案的可维护性方面:复杂度、文档完整性、监控和调试、团队技能要求等。
4
+ """
5
+ from langchain_core.messages import SystemMessage, HumanMessage
6
+ from llm import call_with_fallback
7
+ from hybrid_b.prompts import MAINTAINABILITY_SYSTEM_PROMPT, MAINTAINABILITY_HUMAN_PROMPT
8
+
9
+
10
+ def maintainability_node(state: dict) -> dict:
11
+ """
12
+ 可维护性分析子 Agent 节点。
13
+ 读取 state["scheme"],输出可维护性分析报告到 state["maintainability_result"]。
14
+ """
15
+ scheme = state["scheme"]
16
+ maintainability_issues = state.get("maintainability_focus", "可维护性分析")
17
+
18
+ messages = [
19
+ SystemMessage(content=MAINTAINABILITY_SYSTEM_PROMPT),
20
+ HumanMessage(content=MAINTAINABILITY_HUMAN_PROMPT.format(
21
+ scheme=scheme,
22
+ maintainability_issues=maintainability_issues
23
+ )),
24
+ ]
25
+
26
+ result = call_with_fallback(messages)
27
+
28
+ return {
29
+ "maintainability_result": result.content,
30
+ "model_used_by": {"maintainability": result.model_used},
31
+ }
hybrid_b/agents/performance.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ 性能分析子 Agent
3
+ 分析架构方案的性能方面:响应时间、资源消耗、可扩展性、缓存策略等。
4
+ """
5
+ from langchain_core.messages import SystemMessage, HumanMessage
6
+ from llm import call_with_fallback
7
+ from hybrid_b.prompts import PERFORMANCE_SYSTEM_PROMPT, PERFORMANCE_HUMAN_PROMPT
8
+
9
+
10
+ def performance_node(state: dict) -> dict:
11
+ """
12
+ 性能分析子 Agent 节点。
13
+ 读取 state["scheme"],输出性能分析报告到 state["performance_result"]。
14
+ """
15
+ scheme = state["scheme"]
16
+ focus_areas = state.get("performance_focus", "性能分析")
17
+
18
+ messages = [
19
+ SystemMessage(content=PERFORMANCE_SYSTEM_PROMPT),
20
+ HumanMessage(content=PERFORMANCE_HUMAN_PROMPT.format(
21
+ scheme=scheme,
22
+ focus_areas=focus_areas
23
+ )),
24
+ ]
25
+
26
+ result = call_with_fallback(messages)
27
+
28
+ return {
29
+ "performance_result": result.content,
30
+ "model_used_by": {"performance": result.model_used},
31
+ }
hybrid_b/agents/pro_orchestrator.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ 支持方 Orchestrator Agent
3
+ 负责召唤性能分析子Agent和成本分析子Agent,然后汇总生成支持论点。
4
+ """
5
+ import json
6
+ from langchain_core.messages import SystemMessage, HumanMessage
7
+ from llm import call_with_fallback
8
+ from hybrid_b.prompts import (
9
+ PRO_ORCHESTRATOR_SYSTEM_PROMPT,
10
+ PRO_ORCHESTRATOR_HUMAN_PROMPT
11
+ )
12
+
13
+
14
+ def format_history(history):
15
+ """格式化辩论历史"""
16
+ if not history:
17
+ return "辩论刚刚开始。"
18
+ formatted = []
19
+ for item in history:
20
+ role = "支持方" if item["role"] == "pro" else "反对方"
21
+ formatted.append(f"【{role} 第{item['round']}轮】\n{item['content'][:500]}...")
22
+ return "\n\n".join(formatted)
23
+
24
+
25
+ def pro_orchestrator_node(state: dict) -> dict:
26
+ """
27
+ 支持方 Orchestrator 节点。
28
+ 1. 分析架构方案,制定子Agent分析计划
29
+ 2. 返回分析计划,由 graph 负责召唤子Agent
30
+ """
31
+ scheme = state["scheme"]
32
+ current_round = state.get("current_round", 0) + 1
33
+ debate_history = state.get("debate_history", [])
34
+
35
+ # 获取对方所有论点(用于反驳)
36
+ opponent_info = ""
37
+ con_arguments = [item for item in debate_history if item["role"] == "con"]
38
+ if con_arguments:
39
+ opponent_info = "\n对方所有论点:\n"
40
+ for arg in con_arguments:
41
+ opponent_info += f"【第{arg['round']}轮】{arg['content'][:500]}...\n"
42
+
43
+ messages = [
44
+ SystemMessage(content=PRO_ORCHESTRATOR_SYSTEM_PROMPT.format(
45
+ current_round=current_round,
46
+ opponent_info=opponent_info
47
+ )),
48
+ HumanMessage(content=PRO_ORCHESTRATOR_HUMAN_PROMPT.format(
49
+ scheme=scheme,
50
+ debate_history=format_history(debate_history)
51
+ )),
52
+ ]
53
+
54
+ result = call_with_fallback(messages)
55
+
56
+ # 解析 JSON 计划
57
+ try:
58
+ plan = json.loads(result.content)
59
+ focus_areas = "\n".join(plan.get("focus_areas", []))
60
+ cost_concerns = "\n".join(plan.get("cost_concerns", []))
61
+ strategy = plan.get("strategy", "")
62
+ except:
63
+ # 如果解析失败,使用默认内容
64
+ focus_areas = "性能分析"
65
+ cost_concerns = "成本分析"
66
+ strategy = result.content[:200]
67
+
68
+ return {
69
+ "current_round": current_round,
70
+ "performance_focus": focus_areas,
71
+ "cost_focus": cost_concerns,
72
+ "pro_strategy": strategy,
73
+ "model_used_by": {"pro_orchestrator": result.model_used},
74
+ }
hybrid_b/agents/pro_summarizer.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ 支持方汇总 Agent
3
+ 基于性能分析和成本分析的数据,生成支持论点。
4
+ """
5
+ from langchain_core.messages import SystemMessage, HumanMessage
6
+ from llm import call_with_fallback
7
+ from hybrid_b.prompts import PRO_SUMMARIZER_SYSTEM_PROMPT, PRO_SUMMARIZER_HUMAN_PROMPT
8
+
9
+
10
+ def format_history(history):
11
+ """格式化辩论历史"""
12
+ if not history:
13
+ return "辩论刚刚开始。"
14
+ formatted = []
15
+ for item in history:
16
+ role = "支持方" if item["role"] == "pro" else "反对方"
17
+ formatted.append(f"【{role} 第{item['round']}轮】\n{item['content']}")
18
+ return "\n\n" + "=" * 50 + "\n\n".join(formatted)
19
+
20
+
21
+ def pro_summarizer_node(state: dict) -> dict:
22
+ """
23
+ 支持方汇总节点。
24
+ 读取 state 中的性能分析和成本分析结果,生成支持论点。
25
+ """
26
+ scheme = state["scheme"]
27
+ current_round = state["current_round"]
28
+ performance_result = state.get("performance_result", "未获得性能分析数据")
29
+ cost_result = state.get("cost_result", "未获得成本分析数据")
30
+ debate_history = state.get("debate_history", [])
31
+
32
+ # 获取对方上一轮论点
33
+ opponent_info = ""
34
+ if debate_history:
35
+ last_entry = debate_history[-1]
36
+ if last_entry["role"] == "con":
37
+ opponent_info = f"\n对方上一轮论点:\n{last_entry['content']}"
38
+
39
+ messages = [
40
+ SystemMessage(content=PRO_SUMMARIZER_SYSTEM_PROMPT.format(
41
+ current_round=current_round,
42
+ opponent_info=opponent_info
43
+ )),
44
+ HumanMessage(content=PRO_SUMMARIZER_HUMAN_PROMPT.format(
45
+ scheme=scheme,
46
+ performance_result=performance_result,
47
+ cost_result=cost_result,
48
+ debate_history=format_history(debate_history)
49
+ )),
50
+ ]
51
+
52
+ result = call_with_fallback(messages)
53
+
54
+ return {
55
+ "debate_history": [{
56
+ "role": "pro",
57
+ "round": current_round,
58
+ "content": result.content,
59
+ "performance_result": performance_result,
60
+ "cost_result": cost_result,
61
+ }],
62
+ "model_used_by": {"pro_summarizer": result.model_used},
63
+ }
hybrid_b/agents/security.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ 安全分析子 Agent
3
+ 分析架构方案的安全方面:数据泄露风险、访问控制、注入攻击等。
4
+ """
5
+ from langchain_core.messages import SystemMessage, HumanMessage
6
+ from llm import call_with_fallback
7
+ from hybrid_b.prompts import SECURITY_SYSTEM_PROMPT, SECURITY_HUMAN_PROMPT
8
+
9
+
10
+ def security_node(state: dict) -> dict:
11
+ """
12
+ 安全分析子 Agent 节点。
13
+ 读取 state["scheme"],输出安全分析报告到 state["security_result"]。
14
+ """
15
+ scheme = state["scheme"]
16
+ security_focus = state.get("security_focus", "安全分析")
17
+
18
+ messages = [
19
+ SystemMessage(content=SECURITY_SYSTEM_PROMPT),
20
+ HumanMessage(content=SECURITY_HUMAN_PROMPT.format(
21
+ scheme=scheme,
22
+ security_focus=security_focus
23
+ )),
24
+ ]
25
+
26
+ result = call_with_fallback(messages)
27
+
28
+ return {
29
+ "security_result": result.content,
30
+ "model_used_by": {"security": result.model_used},
31
+ }
hybrid_b/graph.py ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Hybrid B - LangGraph 图定义
3
+ 辩论模式 + 嵌套 Agent 的结合。
4
+ 每一方辩论时召唤专项子 Agent 收集数据,再基于数据发言。
5
+
6
+ 流程:
7
+ 第1轮:支持方(召唤性能+成本) → 反对方(召唤安全+维护性)
8
+ 第2轮:支持方(反驳+召唤子Agent) → 反对方(反驳+召唤子Agent)
9
+ 裁判:综合所有数据给出最终建议
10
+ """
11
+ from typing import TypedDict, Optional, List, Dict, Annotated
12
+ import operator
13
+ from langgraph.graph import StateGraph, END, START
14
+ from langgraph.types import Send
15
+
16
+ from hybrid_b.agents.pro_orchestrator import pro_orchestrator_node
17
+ from hybrid_b.agents.con_orchestrator import con_orchestrator_node
18
+ from hybrid_b.agents.performance import performance_node
19
+ from hybrid_b.agents.cost import cost_node
20
+ from hybrid_b.agents.security import security_node
21
+ from hybrid_b.agents.maintainability import maintainability_node
22
+ from hybrid_b.agents.pro_summarizer import pro_summarizer_node
23
+ from hybrid_b.agents.con_summarizer import con_summarizer_node
24
+ from hybrid_b.agents.judge import judge_node
25
+
26
+
27
+ # ── Reducer 定义 ──────────────────────────────────────────
28
+ def merge_dicts(left: Optional[dict], right: Optional[dict]) -> dict:
29
+ """合并字典,用于追踪模型使用情况"""
30
+ if left is None: left = {}
31
+ if right is None: right = {}
32
+ return {**left, **right}
33
+
34
+
35
+ def append_history(left: List[dict], right: List[dict]) -> List[dict]:
36
+ """累加辩论历史"""
37
+ return left + right
38
+
39
+
40
+ # ── State 定义 ────────────────────────────────────────────
41
+ class HybridBState(TypedDict):
42
+ """Hybrid B 的共享状态"""
43
+ scheme: str # 用户输入的架构方案
44
+ current_round: int # 当前轮次
45
+ max_rounds: int # 最大轮次(默认2)
46
+
47
+ # 支持方数据
48
+ performance_focus: Optional[str] # 性能分析重点
49
+ cost_focus: Optional[str] # 成本分析重点
50
+ performance_result: Optional[str] # 性能分析结果
51
+ cost_result: Optional[str] # 成本分析结果
52
+ pro_strategy: Optional[str] # 支持方策略
53
+
54
+ # 反对方数据
55
+ security_focus: Optional[str] # 安全分析重点
56
+ maintainability_focus: Optional[str] # 可维护性分析重点
57
+ security_result: Optional[str] # 安全分析结果
58
+ maintainability_result: Optional[str] # 可维护性分析结果
59
+ con_strategy: Optional[str] # 反对方策略
60
+
61
+ # 辩论历史(使用 Annotated + reducer 累加)
62
+ debate_history: Annotated[List[dict], append_history]
63
+
64
+ # 最终裁决
65
+ final_conclusion: Optional[str]
66
+
67
+ # 模型使用记录(使用 Annotated + reducer 合并)
68
+ model_used_by: Annotated[Dict[str, str], merge_dicts]
69
+
70
+
71
+ # ── Dispatcher 路由函数(用于 Send API)────────────────────
72
+ def pro_dispatcher(state: HybridBState) -> List[Send]:
73
+ """
74
+ 支持方调度器:使用 Send API 将状态分发给性能Agent和成本Agent。
75
+ """
76
+ return [
77
+ Send("performance_agent", state),
78
+ Send("cost_agent", state),
79
+ ]
80
+
81
+
82
+ def con_dispatcher(state: HybridBState) -> List[Send]:
83
+ """
84
+ 反对方调度器:使用 Send API 将状态分发给安全Agent和可维护性Agent。
85
+ """
86
+ return [
87
+ Send("security_agent", state),
88
+ Send("maintainability_agent", state),
89
+ ]
90
+
91
+
92
+ # ── 循环条件判断 ──────────────────────────────────────────
93
+ def should_continue(state: HybridBState) -> str:
94
+ """判断是继续下一轮辩论还是进入裁判环节"""
95
+ if state["current_round"] < state["max_rounds"]:
96
+ return "pro_orchestrator"
97
+ return "judge_agent"
98
+
99
+
100
+ # ── 构建 StateGraph ───────────────────────────────────────
101
+ def build_graph() -> StateGraph:
102
+ """
103
+ 构建 Hybrid B 工作流图。
104
+
105
+ 流程:
106
+ START → pro_orchestrator → pro_dispatcher → [performance, cost] → pro_summarizer
107
+ → con_orchestrator → con_dispatcher → [security, maintainability] → con_summarizer
108
+ → (循环或进入裁判)
109
+ → judge_agent → END
110
+ """
111
+ workflow = StateGraph(HybridBState)
112
+
113
+ # 添加所有节点
114
+ workflow.add_node("pro_orchestrator", pro_orchestrator_node)
115
+ workflow.add_node("con_orchestrator", con_orchestrator_node)
116
+ workflow.add_node("performance_agent", performance_node)
117
+ workflow.add_node("cost_agent", cost_node)
118
+ workflow.add_node("security_agent", security_node)
119
+ workflow.add_node("maintainability_agent", maintainability_node)
120
+ workflow.add_node("pro_summarizer", pro_summarizer_node)
121
+ workflow.add_node("con_summarizer", con_summarizer_node)
122
+ workflow.add_node("judge_agent", judge_node)
123
+
124
+ # 设置入口
125
+ workflow.set_entry_point("pro_orchestrator")
126
+
127
+ # 1. 支持方 Orchestrator 之后,调度子Agent(并行)
128
+ workflow.add_conditional_edges(
129
+ "pro_orchestrator",
130
+ pro_dispatcher,
131
+ ["performance_agent", "cost_agent"]
132
+ )
133
+
134
+ # 2. 子Agent 完成后,进入汇总器(LangGraph 会等待所有并行任务完成)
135
+ workflow.add_edge("performance_agent", "pro_summarizer")
136
+ workflow.add_edge("cost_agent", "pro_summarizer")
137
+
138
+ # 3. 支持方汇总后,进入反对方 Orchestrator
139
+ workflow.add_edge("pro_summarizer", "con_orchestrator")
140
+
141
+ # 4. 反对方 Orchestrator 之后,调度子Agent(并行)
142
+ workflow.add_conditional_edges(
143
+ "con_orchestrator",
144
+ con_dispatcher,
145
+ ["security_agent", "maintainability_agent"]
146
+ )
147
+
148
+ # 5. 子Agent 完成后,进入汇总器
149
+ workflow.add_edge("security_agent", "con_summarizer")
150
+ workflow.add_edge("maintainability_agent", "con_summarizer")
151
+
152
+ # 6. 反对方汇总后,判断是否继续循环
153
+ workflow.add_conditional_edges(
154
+ "con_summarizer",
155
+ should_continue,
156
+ {
157
+ "pro_orchestrator": "pro_orchestrator",
158
+ "judge_agent": "judge_agent",
159
+ }
160
+ )
161
+
162
+ # 7. 裁判完后结束
163
+ workflow.add_edge("judge_agent", END)
164
+
165
+ return workflow.compile()
166
+
167
+
168
+ # ── 流式执行函数 ──────────────────────────────────────────
169
+ def stream_hybrid_b(scheme: str, max_rounds: int = 2):
170
+ """
171
+ 流式执行 Hybrid B 工作流。
172
+
173
+ Args:
174
+ scheme: 架构方案
175
+ max_rounds: 最大辩论轮次(默认2轮)
176
+
177
+ Yields:
178
+ (node_name, state_update) 元组
179
+ """
180
+ graph = build_graph()
181
+ initial_state: HybridBState = {
182
+ "scheme": scheme,
183
+ "current_round": 0, # 开始第1轮前是0,pro_orchestrator会+1
184
+ "max_rounds": max_rounds,
185
+ "performance_focus": None,
186
+ "cost_focus": None,
187
+ "performance_result": None,
188
+ "cost_result": None,
189
+ "pro_strategy": None,
190
+ "security_focus": None,
191
+ "maintainability_focus": None,
192
+ "security_result": None,
193
+ "maintainability_result": None,
194
+ "con_strategy": None,
195
+ "debate_history": [],
196
+ "final_conclusion": None,
197
+ "model_used_by": {},
198
+ }
199
+
200
+ for event in graph.stream(initial_state, stream_mode="updates"):
201
+ for node_name, state_update in event.items():
202
+ yield node_name, state_update
hybrid_b/prompts.py ADDED
@@ -0,0 +1,296 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Hybrid B - Prompt 模板
3
+ 包含 Orchestrator、子 Agent、汇总器、裁判的提示词。
4
+ """
5
+
6
+ # ── 支持方 Orchestrator Prompt ─────────────────────────────────
7
+ PRO_ORCHESTRATOR_SYSTEM_PROMPT = """你是一个支持方协调者。你的任务是分析架构方案,并召唤性能分析子Agent和成本分析子Agent来收集支持论据。
8
+
9
+ 当前轮次:{current_round}
10
+ {opponent_info}
11
+
12
+ 你的工作流程:
13
+ 1. 分析用户提供的架构方案
14
+ 2. 确定需要性能分析和成本分析的重点关注点
15
+ 3. 召唤子Agent并等待它们返回数据
16
+ 4. 你将在后续步骤中基于子Agent的数据生成支持论点
17
+
18
+ 请以JSON格式输出你的分析计划:
19
+ {{
20
+ "focus_areas": ["性能关注点1", "性能关注点2", ...],
21
+ "cost_concerns": ["成本关注点1", "成本关注点2", ...],
22
+ "strategy": "本轮辩论策略说明"
23
+ }}
24
+ """
25
+
26
+ PRO_ORCHESTRATOR_HUMAN_PROMPT = """请分析以下架构方案,并制定子Agent分析计划:
27
+
28
+ 架构方案:
29
+ ```
30
+ {scheme}
31
+ ```
32
+
33
+ 辩论历史:
34
+ {debate_history}
35
+
36
+ 请输出你的分析计划。"""
37
+
38
+ # ── 反对方 Orchestrator Prompt ─────────────────────────────────
39
+ CON_ORCHESTRATOR_SYSTEM_PROMPT = """你是一个反对方协调者。你的任务是分析架构方案,并召唤安全分析子Agent和可维护性分析子Agent来收集反对论据。
40
+
41
+ 当前轮次:{current_round}
42
+ {opponent_info}
43
+
44
+ 你的工作流程:
45
+ 1. 分析用户提供的架构方案
46
+ 2. 确定需要安全分析和可维护性分析的重点关注点
47
+ 3. 召唤子Agent并等待它们返回数据
48
+ 4. 你将在后续步骤中基于子Agent的数据生成反对论点
49
+
50
+ 请以JSON格式输出你的分析计划:
51
+ {{
52
+ "security_focus": ["安全关注点1", "安全关注点2", ...],
53
+ "maintainability_issues": ["可维护性关注点1", "可维护性关注点2", ...],
54
+ "strategy": "本轮辩论策略说明"
55
+ }}
56
+ """
57
+
58
+ CON_ORCHESTRATOR_HUMAN_PROMPT = """请分析以下架构方案,并制定子Agent分析计划:
59
+
60
+ 架构方案:
61
+ ```
62
+ {scheme}
63
+ ```
64
+
65
+ 辩论历史:
66
+ {debate_history}
67
+
68
+ 请输出你的分析计划。"""
69
+
70
+ # ── 性能分析子 Agent Prompt ─────────────────────────────────
71
+ PERFORMANCE_SYSTEM_PROMPT = """你是一个架构性能分析专家。请仔细分析用户提供的架构方案,重点关注以下性能方面:
72
+
73
+ 1. 响应时间和延迟(预期吞吐量、峰值处理能力)
74
+ 2. 资源消耗(CPU、内存、网络带宽)
75
+ 3. 可扩展性(水平扩展能力、瓶颈识别)
76
+ 4. 缓存策略(是否合理、命中率预期)
77
+ 5. 数据库性能(查询效率、连接池配置)
78
+ 6. 并发处理能力(线程模型、异步处理)
79
+
80
+ 请以结构化格式输出分析报告,包含:
81
+ - 性能优势(支持使用该方案的原因)
82
+ - 潜在风险(需要注意的性能问题)
83
+ - 量化指标(如果可以估算)
84
+ """
85
+
86
+ PERFORMANCE_HUMAN_PROMPT = """请分析以下架构方案的性能:
87
+
88
+ 架构方案:
89
+ ```
90
+ {scheme}
91
+ ```
92
+
93
+ 分析重点:
94
+ {focus_areas}
95
+
96
+ 请输出详细的性能分析报告。"""
97
+
98
+ # ── 成本分析子 Agent Prompt ─────────────────────────────────
99
+ COST_SYSTEM_PROMPT = """你是一个IT成本分析专家。请仔细分析用户提供的架构方案,重点关注以下成本方面:
100
+
101
+ 1. 基础设施成本(服务器、存储、网络)
102
+ 2. 许可费用(软件授权、商业组件)
103
+ 3. 运维成本(人力、监控、备份)
104
+ 4. 扩展成本(增加用户或数据量的边际成本)
105
+ 5. 隐性成本(培训、迁移、停机损失)
106
+ 6. 成本效益比(ROI预期)
107
+
108
+ 请以结构化格式输出分析报告,包含:
109
+ - 成本优势(使用该方案节省的成本)
110
+ - 成本风险(可能超支的项目)
111
+ - 量化估算(如果可以估算金额或百分比)
112
+ """
113
+
114
+ COST_HUMAN_PROMPT = """请分析以下架构方案的成本:
115
+
116
+ 架构方案:
117
+ ```
118
+ {scheme}
119
+ ```
120
+
121
+ 成本关注点:
122
+ {cost_concerns}
123
+
124
+ 请输出详细的成本分析报告。"""
125
+
126
+ # ── 安全分析子 Agent Prompt (复用 parallel/ 逻辑,调整上下文) ─
127
+ SECURITY_SYSTEM_PROMPT = """你是一个架构安全审查专家。请仔细分析用户提供的架构方案,重点关注以下安全问题:
128
+
129
+ 1. 数据泄露风险(存储安全、传输加密)
130
+ 2. 访问控制(认证、授权、权限管理)
131
+ 3. 注入攻击(SQL注入、NoSQL注入、命令注入)
132
+ 4. 不安全的依赖(第三方库漏洞)
133
+ 5. 配置安全(默认密码、开放端口、敏感信息泄露)
134
+ 6. 合规性(数据保护法规、审计要求)
135
+
136
+ 请以结构化格式输出分析报告,包含:
137
+ - 安全风险(使用该方案可能面临的安全威胁)
138
+ - 风险等级(高/中/低)
139
+ - 建议措施(如何缓解安全风险)
140
+ """
141
+
142
+ SECURITY_HUMAN_PROMPT = """请分析以下架构方案的安全性:
143
+
144
+ 架构方案:
145
+ ```
146
+ {scheme}
147
+ ```
148
+
149
+ 安全关注点:
150
+ {security_focus}
151
+
152
+ 请输出详细的安全分析报告。"""
153
+
154
+ # ── 可维护性分析子 Agent Prompt (复用 parallel/ 逻辑,调整上下文) ─
155
+ MAINTAINABILITY_SYSTEM_PROMPT = """你是一个架构可维护性分析专家。请仔细分析用户提供的架构方案,重点关注以下可维护性问题:
156
+
157
+ 1. 复杂度(组件数量、依赖关系、学习曲线)
158
+ 2. 文档完整性(是否有足够的设计文档、API文档)
159
+ 3. 监控和调试(日志、监控、故障排查难度)
160
+ 4. 团队技能要求(是否需要特殊技能、招聘难度)
161
+ 5. 技术债务(是否使用过时技术、定制化程度)
162
+ 6. 升级和迁移(版本升级、数据迁移的难易程度)
163
+
164
+ 请以结构化格式输出分析报告,包含:
165
+ - 可维护性问题(使用该方案可能面临的维护挑战)
166
+ - 问题影响(高/中/低)
167
+ - 改进建议(如何提高可维护性)
168
+ """
169
+
170
+ MAINTAINABILITY_HUMAN_PROMPT = """请分析以下架构方案的可维护性:
171
+
172
+ 架构方案:
173
+ ```
174
+ {scheme}
175
+ ```
176
+
177
+ 可维护性关注点:
178
+ {maintainability_issues}
179
+
180
+ 请输出详细的可维护性分析报告。"""
181
+
182
+ # ── 支持方汇总 Prompt ──────────────────────────────────────
183
+ PRO_SUMMARIZER_SYSTEM_PROMPT = """你是一个支持方辩论手。你已获得性能分析子Agent和成本分析子Agent的数据,请基于这些数据生成有力的支持论点。
184
+
185
+ 当前轮次:{current_round}
186
+ {opponent_info}
187
+
188
+ 你的任务:
189
+ 1. 综合性能分析和成本分析的数据
190
+ 2. **必须针对反对方的以下所有论点逐一反驳,不得重复第1轮自己的观点**
191
+ 3. 提出清晰、有数据支撑的支持论据
192
+ 4. 强调该架构方案的优势和价值
193
+
194
+ **重要:如果你在第2轮,你必须:**
195
+ - 仔细阅读辩论历史中反对方的所有论点(第1轮和第2轮)
196
+ - 对每个反对方论点进行针对性反驳
197
+ - 不得简单重复第1轮你已经说过的观点
198
+ - 必须提出新的、有数据支撑的支持意见
199
+
200
+ 请以清晰的结构输出支持论点,包含:
201
+ - 核心优势总结
202
+ - 数据支撑的论据(引用子Agent的分析结果)
203
+ - **对反对方所有论点的逐一反驳**(必须具体回应每个论点)
204
+ - 结论和建议
205
+ """
206
+
207
+ PRO_SUMMARIZER_HUMAN_PROMPT = """请基于以下子Agent分析数据,生成支持方论点:
208
+
209
+ 架构方案:
210
+ ```
211
+ {scheme}
212
+ ```
213
+
214
+ 性能分析报告:
215
+ {performance_result}
216
+
217
+ 成本分析报告:
218
+ {cost_result}
219
+
220
+ 辩论历史:
221
+ {debate_history}
222
+
223
+ 请生成有力的支持论点。"""
224
+
225
+ # ── 反对方汇总 Prompt ──────────────────────────────────────
226
+ CON_SUMMARIZER_SYSTEM_PROMPT = """你是一个反对方辩论手。你已获得安全分析子Agent和可维护性分析子Agent的数据,请基于这些数据生成有力的反对论点。
227
+
228
+ 当前轮次:{current_round}
229
+ {opponent_info}
230
+
231
+ 你的任务:
232
+ 1. 综合安全分析和可维护性分析的数据
233
+ 2. **必须针对支持方的以下所有论点逐一反驳,不得重复第1轮自己的观点**
234
+ 3. 提出清晰、有数据支撑的反对论据
235
+ 4. 强调该架构方案的风险和隐患
236
+
237
+ **重要:如果你在第2轮,你必须:**
238
+ - 仔细阅读辩论历史中支持方的所有论点(第1轮和第2轮)
239
+ - 对每个支持方论点进行针对性反驳
240
+ - 不得简单重复第1轮你已经说过的观点
241
+ - 必须提出新的、有数据支撑的反对意见
242
+
243
+ 请以清晰的结构输出反对论点,包含:
244
+ - 核心风险总结
245
+ - 数据支撑的论据(引用子Agent的分析结果)
246
+ - **对支持方所有论点的逐一反驳**(必须具体回应每个论点)
247
+ - 结论和建议(不采纳或需要改进的方向)
248
+ """
249
+
250
+ CON_SUMMARIZER_HUMAN_PROMPT = """请基于以下子Agent分析数据,生成反对方论点:
251
+
252
+ 架构方案:
253
+ ```
254
+ {scheme}
255
+ ```
256
+
257
+ 安全分析报告:
258
+ {security_result}
259
+
260
+ 可维护性分析报告:
261
+ {maintainability_result}
262
+
263
+ 辩论历史:
264
+ {debate_history}
265
+
266
+ 请生成有力的反对论点。"""
267
+
268
+ # ── 裁判 Prompt ──────────────────────────────────────────
269
+ JUDGE_SYSTEM_PROMPT = """你是一个中立的架构评审裁判。你已经看到了多轮辩论中支持方和反对方基于子Agent数据分析的论点。
270
+
271
+ 你的任务:
272
+ 1. 客观评估双方论点的质量和数据支撑
273
+ 2. 识别论点中的逻辑漏洞或数据偏差
274
+ 3. 权衡方案的利弊
275
+ 4. 给出最终的采纳/否决建议,并提供理由
276
+
277
+ 请以结构化格式输出最终裁决,包含:
278
+ - 方案概述(简要说明被评审的方案)
279
+ - 支持方论点评估( strengths 和 weaknesses)
280
+ - 反对方论点评估(strengths 和 weaknesses)
281
+ - 综合评估(权衡所有因素)
282
+ - 最终建议(采纳/否决/有条件采纳)
283
+ - 实施建议(如果采纳,需要注意的关键点)
284
+ """
285
+
286
+ JUDGE_HUMAN_PROMPT = """请根据以下辩论过程,给出最终裁决:
287
+
288
+ 架构方案:
289
+ ```
290
+ {scheme}
291
+ ```
292
+
293
+ 完整辩论历史:
294
+ {debate_history}
295
+
296
+ 请输出你的最终裁决。"""