A Simple and Universal Swarm Intelligence Engine, Predicting Anything. 简洁通用的群体智能引擎,预测万物
Python agent-memoryfinancial-forecastingfuture-predictionknowledge-graphllmsmulti-agent-simulationpublic-opinion-analysispython3social-predictionswarm-intelligence
fix(report_agent): increase minimum tool call requirement from 2 to 3 per chapter and enhance user prompts to encourage diverse tool usage
666ghj0a59bace9289
diff --git a/backend/app/services/report_agent.py b/backend/app/services/report_agent.pyindex 536f9ab0..a9b61540 100644--- a/backend/app/services/report_agent.py+++ b/backend/app/services/report_agent.py@@ -556,8 +556,7 @@ class ReportAgent:"parameters": {"query": "你想深入分析的问题或话题","report_context": "当前报告章节的上下文(可选,有助于生成更精准的子问题)"- },- "priority": "high"+ }},"panorama_search": {"name": "panorama_search",@@ -579,8 +578,7 @@ class ReportAgent:"parameters": {"query": "搜索查询,用于相关性排序","include_expired": "是否包含过期/历史内容(默认True)"- },- "priority": "medium"+ }},"quick_search": {"name": "quick_search",@@ -597,8 +595,7 @@ class ReportAgent:"parameters": {"query": "搜索查询字符串","limit": "返回结果数量(可选,默认10)"- },- "priority": "low"+ }},"interview_agents": {"name": "interview_agents",@@ -630,8 +627,7 @@ class ReportAgent:"parameters": {"interview_topic": "采访主题或需求描述(如:'了解学生对宿舍甲醛事件的看法')","max_agents": "最多采访的Agent数量(可选,默认5)"- },- "priority": "high"+ }}}@@ -1001,7 +997,7 @@ class ReportAgent:- 你正在以「上帝视角」观察未来的预演- 所有内容必须来自模拟世界中发生的事件和Agent言行- 禁止使用你自己的知识来编写报告内容- - 每个章节至少调用2次工具(最多5次)来观察模拟的世界,它代表了未来+ - 每个章节至少调用3次工具(最多5次)来观察模拟的世界,它代表了未来2. 【必须引用Agent的原始言行】- Agent的发言和行为是对未来人群行为的预测@@ -1053,16 +1049,16 @@ class ReportAgent:```═══════════════════════════════════════════════════════════════-【可用检索工具】(每章节调用2-5次)+【可用检索工具】(每章节调用3-5次)═══════════════════════════════════════════════════════════════{self._get_tools_description()}-【工具使用建议】-- insight_forge: 用于深度分析,会自动分解问题并多维度检索-- panorama_search: 用于了解全貌和演变过程-- quick_search: 用于快速验证某个具体信息-- interview_agents: 用于采访模拟Agent,获取不同角色的真实观点和看法+【工具使用建议 - 请混合使用不同工具,不要只用一种】+- insight_forge: 深度洞察分析,自动分解问题并多维度检索事实和关系+- panorama_search: 广角全景搜索,了解事件全貌、时间线和演变过程+- quick_search: 快速验证某个具体信息点+- interview_agents: 采访模拟Agent,获取不同角色的第一人称观点和真实反应═══════════════════════════════════════════════════════════════【ReACT工作流程】@@ -1133,7 +1129,7 @@ class ReportAgent:【重要提醒】1. 仔细阅读上方已完成的章节,避免重复相同的内容!2. 开始前必须先调用工具获取模拟数据-3. 推荐先使用 insight_forge 进行深度检索+3. 请混合使用不同工具,不要只用一种4. 报告内容必须来自检索结果,不要使用自己的知识【⚠️ 格式警告 - 必须遵守】@@ -1155,8 +1151,10 @@ class ReportAgent:# ReACT循环tool_calls_count = 0max_iterations = 5 # 最大迭代轮数- min_tool_calls = 2 # 最少工具调用次数-+ min_tool_calls = 3 # 最少工具调用次数+ used_tools = set() # 记录已调用过的工具名+ all_tools = {"insight_forge", "panorama_search", "quick_search", "interview_agents"}+# 报告上下文,用于InsightForge的子问题生成report_context = f"章节标题: {section.title}\n模拟需求: {self.simulation_requirement}"@@ -1209,9 +1207,11 @@ class ReportAgent:# 工具调用次数不足,拒绝并要求继续调工具if tool_calls_count < min_tool_calls:messages.append({"role": "assistant", "content": response})+ unused_tools = all_tools - used_tools+ unused_hint = f"(这些工具还未使用,推荐用一下他们: {', '.join(unused_tools)})" if unused_tools else ""messages.append({"role": "user",- "content": f"【注意】你只调用了{tool_calls_count}次工具,信息可能不够充分。请再调用工具获取更多模拟数据,然后再输出 Final Answer。"+ "content": f"【注意】你只调用了{tool_calls_count}次工具,至少需要{min_tool_calls}次。请再调用工具获取更多模拟数据,然后再输出 Final Answer。{unused_hint}"})continue@@ -1269,6 +1269,14 @@ class ReportAgent:)tool_calls_count += 1+ used_tools.add(call['name'])++ # 构建未使用工具提示+ unused_tools = all_tools - used_tools+ unused_hint = ""+ if unused_tools and tool_calls_count < self.MAX_TOOL_CALLS_PER_SECTION:+ unused_list = "、".join(unused_tools)+ unused_hint = f"\n💡 你还没有使用过: {unused_list},建议尝试不同工具获取多角度信息"messages.append({"role": "assistant", "content": response})messages.append({@@ -1279,7 +1287,7 @@ class ReportAgent:{result}═══════════════════════════════════════════════════════════════-已调用工具 {tool_calls_count}/{self.MAX_TOOL_CALLS_PER_SECTION} 次+已调用工具 {tool_calls_count}/{self.MAX_TOOL_CALLS_PER_SECTION} 次(已用: {', '.join(used_tools)}){unused_hint}- 如果信息充分:以 "Final Answer:" 开头输出章节内容(必须引用上述原文)- 如果需要更多信息:调用一个工具继续检索═══════════════════════════════════════════════════════════════"""@@ -1290,13 +1298,13 @@ class ReportAgent:messages.append({"role": "assistant", "content": response})if tool_calls_count < min_tool_calls:- # 工具调用次数不足,催促调工具+ # 工具调用次数不足,推荐未用过的工具+ unused_tools = all_tools - used_tools+ unused_hint = f"(这些工具还未使用,推荐用一下他们: {', '.join(unused_tools)})" if unused_tools else ""+messages.append({"role": "user",- "content": f"""当前只调用了 {tool_calls_count} 次工具,至少需要 {min_tool_calls} 次。请调用工具获取模拟数据:-<tool_call>-{{"name": "insight_forge", "parameters": {{"query": "{section.title}相关的模拟结果和分析"}}}}-</tool_call>"""+ "content": f"当前只调用了 {tool_calls_count} 次工具,至少需要 {min_tool_calls} 次。请调用工具获取模拟数据。{unused_hint}"})continue