fix(agent): 种子部署下基线系统提示从未到达模型 + 提示词去重#165
Merged
Merged
Conversation
_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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
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。去重(规则 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),语义不相交。