Skip to content

默认职责提示词教的终止方式与 CodeAct 守卫判定相矛盾,问答场景高频陷入重试循环直至 max_steps #3986

Description

@2862282695gjh-afk

版本:v2.6.0 main(v2.5.1 私有化部署同样复现)

问题描述

三处组件对"如何终止会话"的约定互相矛盾:

  1. 默认职责提示词 backend/prompts/utils/prompt_generate_zh.yaml:64 明确教模型:
    「在思考结束后,当Agent认为可以回答用户问题,那么可以不生成代码,直接生成最终回答给到用户并停止循环」,
    且示例(任务1)的终止措辞是「思考:……现在我将生成最终回答」——这正是守卫判定的"动作前奏"句式;
  2. core_agent.py 的 _looks_like_incomplete_action_output:输出提及任一工具名 + 含动作意图句式
    即判为 action preamble,抛 InvalidActionFormatError 重试;finish_reason == "length" 时无条件判 preamble;
  3. verification.py:958:代码块中无 final_answer( 会触发 tool_relevance_signal 检查——
    但默认提示词从未教过 final_answer() 的存在与用法(它仅在 max_steps 兜底模板中出现)。

实际现象

知识问答智能体(思考型模型)高频触发:
The previous response described an action but ended before producing an executable tool call...
模型遵循默认提示词的示例输出「……我将生成最终回答」,被守卫判为 preamble → 重试 → 模型按同样示例再输出 →
循环直至 max_steps(默认15),以兜底总结收场。每次重试还将守卫消息与失败输出追加进上下文,进一步加剧截断。
另:引导模型改用 final_answer() 后,长 markdown 答案被塞进单引号字符串导致
unterminated string literal(默认提示词无三引号用法教学)。

建议

  1. 统一终止约定:默认提示词明确教学 final_answer() 用法(含三引号包裹多行答案的示例),
    并修改示例中「我将生成最终回答」这类前奏式措辞;
  2. 守卫加熔断:同一会话连续 2 次 InvalidActionFormatError 后停止重试,输出兜底答案,避免烧满 max_steps;
  3. 文档补充思考型模型的输出 token 配置建议(reasoning 占用导致 content 被 length 截断的场景)。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions