diff --git a/mateclaw-server/src/main/java/vip/mate/agent/graph/plan/node/StepExecutionNode.java b/mateclaw-server/src/main/java/vip/mate/agent/graph/plan/node/StepExecutionNode.java index fa055a95..4831787d 100644 --- a/mateclaw-server/src/main/java/vip/mate/agent/graph/plan/node/StepExecutionNode.java +++ b/mateclaw-server/src/main/java/vip/mate/agent/graph/plan/node/StepExecutionNode.java @@ -36,7 +36,12 @@ import java.util.Map; * 步骤执行节点 *

* 执行当前步骤,使用显式工具执行循环(internalToolExecutionEnabled=false)。 - * 单步最大工具调用次数限制为 5 次,防止无限循环。 + * 单步最大工具调用次数限制为 {@link #MAX_TOOL_CALLS_PER_STEP} 次,与 + * {@code BaseAgent.MAX_ITERATIONS_HARD_CEILING} 对齐——因此实际生效的上限 + * 永远是 agent 的 {@code max_iterations}(DB 列),单步本身不会先于 agent + * 的整体预算被打掉。早期 5 次的硬限制对"查新闻 + 整理 Word"这种合理多 + * 工具任务过紧,被 LimitExceededNode 提前拦截后用户看到的是冷冰冰的 + * "工具调用次数超出最大限制"。 *

* 支持 NEEDS_APPROVAL 审批流程:对需要审批的工具调用创建 pending, * 发出 SSE 事件后立即返回审批提示(非阻塞)。审批通过后通过 replay 重新执行。 @@ -55,7 +60,15 @@ public class StepExecutionNode implements NodeAction { private final String reasoningEffort; private final NodeStreamingChatHelper streamingHelper; - private static final int MAX_TOOL_CALLS_PER_STEP = 5; + /** + * Per-step tool-call ceiling, aligned with {@code BaseAgent.MAX_ITERATIONS_HARD_CEILING}. + * Matching the agent-level cap means this constant is never the bottleneck — + * the agent's own {@code max_iterations} (DB column) will fire first if a + * task is genuinely runaway, and a well-budgeted multi-tool step (e.g. + * web_search + browser_navigate + browser_read*N + file_write) is no longer + * cut short by an arbitrary 5-call ceiling. + */ + private static final int MAX_TOOL_CALLS_PER_STEP = 100; private static final ObjectMapper MAPPER = new ObjectMapper(); public StepExecutionNode(ChatModel chatModel, AgentToolSet toolSet, diff --git a/mateclaw-server/src/main/resources/prompts/graph/limit-exceeded-system.txt b/mateclaw-server/src/main/resources/prompts/graph/limit-exceeded-system.txt index 070dcbd1..1c774282 100644 --- a/mateclaw-server/src/main/resources/prompts/graph/limit-exceeded-system.txt +++ b/mateclaw-server/src/main/resources/prompts/graph/limit-exceeded-system.txt @@ -1,10 +1,10 @@ [系统指令 — 最高优先级] -你已达到本轮最大推理步数({maxIterations} 步),请立即停止任何工具调用意图。 +请基于以下已收集的信息直接给出最终回答。**不要再调用任何工具。** -请基于以下已收集的信息直接给出最终回答: +回答要求: 1. 给出简洁、诚实、可执行的回答 -2. 若信息不足以完全回答,明确说明哪些部分是不确定的 -3. 如果有未完成的调查方向,简要列出建议的后续步骤 -4. 不要为未完成道歉,直接给结论 +2. 若信息不足以完全回答,明确说明哪些部分还不确定 +3. 如果还有未完成的方向,简要列出建议的下一步 +4. **不要为「未完成」道歉,不要提及「推理步数」「迭代次数」「工具调用上限」这类技术细节** —— 直接给结论 5. 保持输出简洁,避免重复已知内容 -6. 在回答末尾用**与用户问题相同的语言**告知:本轮已达到最大推理步数;如需继续请发送 "继续" / "continue" 或补充新指令,我会接着完成剩余工作。 \ No newline at end of file +6. 在回答末尾用**与用户问题相同的语言**自然地告诉用户:如果还想深入某个方向,发送 "继续" 或者具体说一下,我会接着帮忙。