Skip to content

fix(agent): 种子部署下基线系统提示从未到达模型 + 提示词去重#165

Merged
sweetcornna merged 1 commit into
mainfrom
fix/baseline-prompt-reachability
Jul 26, 2026
Merged

fix(agent): 种子部署下基线系统提示从未到达模型 + 提示词去重#165
sweetcornna merged 1 commit into
mainfrom
fix/baseline-prompt-reachability

Conversation

@sweetcornna

Copy link
Copy Markdown
Owner

背景

Claude 5 上下文工程规范整改的第二个 PR(第一个是 #164)。审计时发现一个真实 bug,顺带按规则 4 做系统提示去重。

Bug

_ensure_system_prompt 只在"无 system 消息"时注入 _CODING_SYSTEM_PROMPT(12 条行为基线),但它在 _assemble_context 之后运行——而 always-on skill 注入(context_assembler.py:461)和 skill 目录(:521)在请求不带 system 消息时必然合成一条。所以任何种子部署(_DEFAULT_ALWAYS_SKILLS 非空 + 目录非空)走到这里时 system 消息永远存在 → 基线提示从未发给模型,只追加了 env block。:795 的 docstring 声称的行为与实际相反,现有测试只测 helper 孤立行为,没有穿透 Chat

修复

  • Chat 在装配快照 authored_system(调用方自带 system 消息,或命中 agent card——复用已算好的 bound_card)。
  • _ensure_system_prompt(start, authored_system=...):authored → 维持现状只追加 env;非 authored 且存在(skill 合成的)system 消息 → 前置基线提示,最终形态 基线 → skills → catalog → env
  • 修正过期 docstring。

去重(规则 4:工具说明单一来源 = 工具描述)

  • # Todo discipline 整节(todo_write 描述已覆盖 3+ 步/单一 in_progress/即时 completed 全部内容,近逐字重复)。
  • # Ask only when blocked 去掉 ask_user 停轮机制句(工具描述已有),保留判断原则。
  • # Tool hierarchy 压缩为一句(7 个工具名枚举 + workspace 限制在各工具 param 描述里已有)。

验证

  • 新增穿透 Chat 的 e2e 回归测试(gRPC in-process + skill 合成 assembler stub):旧代码红、新代码绿(红绿已实测)。
  • 新增 authored_system=False 前置路径与 _has_system_message 单测。
  • test_ask_user_system_prompt_clause_present 原本在强制这份重复,改为 pin 工具描述为单一来源。
  • test_agent_servicer.py 全文件 84 passed;ruff / mypy 对改动文件干净。

与在途未提交的 memory-scoping 工作在 agent_servicer.py 上可能有琐碎格式冲突(该工作包含全文件 reflow),语义不相交。

_ensure_system_prompt injected _CODING_SYSTEM_PROMPT only when no system
message existed — but it runs AFTER _assemble_context, and always-on
skill injection / the skill catalog synthesize a system message whenever
the request carries none. On any seeded deployment (non-empty
_DEFAULT_ALWAYS_SKILLS + catalog) a system message therefore always
existed by that point, so the 12-rule behavioral baseline never reached
the model; only the env block was appended.

Fix: snapshot BEFORE assembly whether the request brings its own system
prompt (caller-supplied message, or a matched agent card via the
already-computed bound_card). _ensure_system_prompt now takes
authored_system: when False and a (skill-synthesized) system message
exists, the baseline is PREPENDED (final shape: baseline -> skills ->
catalog -> env). Authored prompts keep today's append-env-only behavior.

Also de-duplicate tool instructions out of the baseline prompt per the
Claude-5 context-engineering rules (tool descriptions are the single
source of truth):
- drop '# Todo discipline' (todo_write's description carries the cadence)
- drop the ask_user turn-ending mechanics from '# Ask only when blocked'
  (the tool description carries them); keep the judgment rule
- compress '# Tool hierarchy' (per-tool path semantics live on each
  tool's parameter descriptions)

Tests: e2e regression through Chat with a skill-synthesizing assembler
stub (red on the old code, green now), unit coverage for the prepend
path and _has_system_message, and the ask_user protocol test now pins
the tool description as the single source instead of enforcing the
duplication.
@github-actions github-actions Bot added codex:needs-review A Codex review is needed for the current PR head. codex:review-requested A Codex review was requested or should be running automatically. status: 🔁 re-review loop A fresh Codex review was requested after the latest change or comment. labels Jul 26, 2026
@sweetcornna
sweetcornna merged commit ff9af9d into main Jul 26, 2026
10 checks passed
@github-actions github-actions Bot added status: ✅ merge-ready Evidence and review are clear; normal merge gates may proceed. and removed codex:review-requested A Codex review was requested or should be running automatically. codex:needs-review A Codex review is needed for the current PR head. status: 🔁 re-review loop A fresh Codex review was requested after the latest change or comment. labels Jul 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: ✅ merge-ready Evidence and review are clear; normal merge gates may proceed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant