The system prompt is surface node 0
系统提示词是表面节点 0
Keeping the system prompt in a log-only request header gives model-visible messages two durable homes. Serializers, compaction, token accounting and request inspection must prepend header text to conversation history independently. Comparing that text alongside configuration and tools also makes instruction changes indistinguishable from request-setting changes. A header cannot represent instructions introduced later
English
Problem
Keeping the system prompt in a log-only request header gives model-visible messages two durable homes. Serializers, compaction, token accounting and request inspection must prepend header text to conversation history independently. Comparing that text alongside configuration and tools also makes instruction changes indistinguishable from request-setting changes. A header cannot represent instructions introduced later in the conversation.
Decision
System instructions are ordinary system/message surface events. The first accepted request reserves a protected system head, including when its content is empty. Empty system content remains addressable in the log and surface but projects to no model message. Later updates can occupy their own conversation positions. Section admission owns current attribution and incremental updates; deferred compaction rebuilding owns consolidation. The earlier whole-prompt replacement rule is superseded, while this single durable representation remains.
The surface fold supplies logged system messages to adapters alongside the rest of the conversation. Adapters choose native messages or their protocol representation without changing durable roles. EpochHeader holds configuration, adapter defaults and tools, not system text; prompt changes therefore have their own event identity rather than a header change reason. Header reasons still describe initial, resumed, changed or new-series requests.
assertSystemHeadRewrite rejects a replacement covering node 0 when it is a system message unless another system message replaces exactly that node. Later system nodes remain replaceable by compaction. Protecting even an empty head gives rebuilding a stable target without inserting a node ahead of existing history. Per-node replacements preserve intervening conversation and use the existing replacement-generation accounting.
The loop commits prepared instructions inside an open step, after request middleware and route preparation, before new user input and the model call. Rejection or cancellation before commitment admits neither instructions nor users. System-prompt assembly prepares candidates; the loop owns their durable append or replacement. Runtime context remains an independent user-role contribution. Both become model-visible through logged messages rather than adapter-local state.
Token usage anchors to the priced surface immediately before the successful assistant event. Step start is too early: system and user admission, or retry recovery, can still change the request afterward. Embedded provider output is priced separately so assistant rewrites retain their signed delta; the open step retains lifecycle coordinates rather than another node snapshot.
Released conversion
The V2-to-V3 specification owns structural conversion, message identities, reference preservation and refusal of unsupported sources. Migrated requests are semantically equivalent, not byte-identical to native recordings. When conversion cannot preserve historical order under the step invariant, refusal is preferable to moving messages or relaxing ownership. Historical acceptance coordinates do not acknowledge transformed logs. Released-format rules preserve each conversion's semantics; an existing target generation does not rerun its incoming edge, and projection-cache versions are independent. Canonical envelopes retain their separate strict-acceptance rationale.
Alternatives considered
Keep header.system for the initial prompt and use events only for updates. Every consumer would still need two sources, and header comparison would need a special exception while a system node exists.
A log-only change event that rewrites the header. This distinguishes changes but still cannot place a system message inside history; later updates would need another mechanism.
Synthesize instructions from consecutive headers in an adapter. Adapters are stateless per request and do not see the log. Adapter-local reconstruction cannot make the durable message fold authoritative.
Use a user-role snapshot like runtime context. This sends a different role and loses native system authority on models that support it.
Consequences
Request inspection, compaction, accounting, SDK events and recorded-session prompt sidecars read the same logged system messages. Human transcript projections omit them because they are model instructions rather than conversational speech. Replacing a system node changes the request prefix and replacement generation; appending a section can preserve its preceding prefix. No header-to-message join is required.
The initial head cannot be compacted by any provider, even when empty; later system additions can be removed. Initial emptiness does not require later instructions to move to the head during ordinary admission. Current section and compaction decisions determine their placement.
Verification
Session surface tests cover protected-head rewrites, empty projection, ordinary later-node replacement and persisted system-message validation. Adapter tests cover system-block rendering on text and image paths. Compaction tests retain the leading derived prompt and reject ranges covering the protected head. Request reconstruction and both SDK expected outputs verify that model-visible instructions are logged. Token-meter tests cover admission and retry changes before usage anchoring; recorded-session snapshots cover shipped profile requests and prompt sidecars.
中文
问题
将系统提示词放在仅日志可见的请求头中,会为模型可见消息建立两个持久来源。序列化、压缩、token 计量和请求检查都必须独立地把请求头文本加到对话历史之前。将该文本与配置和工具一起比较,还会让指令变化与请求设置变化无法区分。请求头不能表示在对话后续才引入的指令。
决策
系统指令是普通的 system/message 表面事件。首次接受的请求保留一个受保护的系统头节点,包括内容为空的情况。空系统内容在日志和表面中保持可寻址,但不投影为模型消息。后续更新可占据自己的对话位置。分段准入负责当前归属和增量更新;压缩后的延迟重建负责合并。此前的整份提示词替换规则已被取代,但这份统一的持久表示保持不变。
表面折叠将日志中的系统消息与其余对话一起提供给适配器。适配器选择原生消息或对应协议表示,不改变持久角色。EpochHeader 保存配置、适配器默认值和工具,不保存系统文本;因此提示词变化具有独立的事件标识,而非请求头的 change 原因。请求头原因仍描述初始、恢复、变化或新序列请求。
当节点 0 是系统消息时,assertSystemHeadRewrite 拒绝覆盖它的替换,除非另一条系统消息恰好替换该节点。后续系统节点仍可由压缩替换。连空头节点也受保护,为重建提供了稳定目标,无需在既有历史前插入节点。逐节点替换保留中间对话,并沿用现有替换代次计量。
循环在开放步骤内提交准备好的指令,时机在请求中间件和路由准备之后、新用户输入和模型调用之前。提交前的拒绝或取消不会准入指令或用户消息。系统提示词组装准备候选;循环负责其持久追加或替换。运行时上下文仍是独立的用户角色贡献。两者都通过日志消息对模型可见,而非适配器本地状态。
Token 用量锚定成功 assistant 事件前的已计价表面。步骤开始过早:系统与用户准入或重试恢复随后仍可改变请求。内嵌的提供方输出单独计价,因此 assistant 重写保留带符号增量;开放步骤只保留生命周期坐标,不再保存另一份节点快照。
已发布转换
V2 到 V3 规范负责结构转换、消息标识、引用保留及不支持来源的拒绝。迁移请求与原生记录语义等价,但并非字节相同。转换若无法在步骤约束下保留历史顺序,拒绝优于移动消息或放宽所有权。历史接受坐标不构成对转换后日志的确认。已发布格式规则保留每次转换的语义;已有目标代次不会重跑其传入转换边,投影缓存版本也独立于格式版本。规范信封保留其独立的严格接受依据。
考虑过的替代方案
保留 header.system 表示初始提示词,仅用事件表示更新。 每个消费者仍需读取两个来源,而系统节点存在时,请求头比较需要特殊例外。
仅日志可见的变化事件重写请求头。 这能区分变化,却仍不能将系统消息置于历史中;后续更新还需要另一套机制。
在适配器中从连续请求头合成指令。 适配器对每次请求无状态,也不读取日志。适配器本地重建无法让持久消息折叠成为权威来源。
像运行时上下文一样使用用户角色快照。 这发送了不同角色,并在支持系统角色的模型上丢失原生系统权限。
影响
请求检查、压缩、计量、SDK 事件和已记录 Session 的提示词侧文件读取同一批日志系统消息。面向人的 transcript(文本记录)投影省略它们,因为它们是模型指令而非对话发言。替换系统节点改变请求前缀和替换代次;追加段则可能保留此前前缀。无需将请求头与消息列表合并。
任何提供方都不能压缩初始头节点,即使它为空;后续系统新增内容可以移除。初始为空并不要求普通准入将后来的指令移至头部。当前分段与压缩决策负责确定其位置。
验证
Session 表面测试覆盖受保护头节点重写、空投影、普通后续节点替换及持久化系统消息校验。适配器测试覆盖文本和图像路径的系统块渲染。压缩测试保留开头的派生提示词,并拒绝覆盖受保护头节点的范围。请求重建和两种 SDK 的预期输出验证模型可见指令写入日志。Token 计量测试覆盖用量锚定前的准入及重试变化;已记录 Session 快照覆盖发行配置的请求和提示词侧文件。