Pi-ai system reminder fallback
Pi-ai 系统提醒回退
Pi-ai concatenates later system messages into the initial prompt for models without native mid-conversation system support. Later system messages supplied to the adapter therefore invalidate the preceding conversation cache prefix.
English
Problem
Pi-ai concatenates later system messages into the initial prompt for models without native mid-conversation system support. Later system messages supplied to the adapter therefore invalidate the preceding conversation cache prefix.
Decision
Section-based updates admit instruction deltas independently of native system-message support. This note owns their adapter representation on pi-ai routes.
The pi-ai adapter uses the prepared model's existing supportsMidConvoSystemMessages capability mapping. It preserves native system messages on capable models and converts each non-empty later system message into a user message wrapped in <system-reminder> otherwise, before pi-ai receives the context. Leading system messages remain in the initial prompt. System text blocks are trimmed and separated by blank lines. Message order and repeated updates remain intact, and durable messages retain their original roles.
The fallback belongs to the adapter because it depends on the selected protocol capability. The system service captures source deltas and the loop commits them; neither consolidates instructions solely because the route lacks native support.
Alternatives considered
Let pi-ai concatenate updates. Retains system-role priority but changes the initial prompt whenever later system text changes, defeating prefix reuse.
Advertise native support or send developer messages. Misstates model capability or relies on another unsupported instruction role. The fallback uses ordinary user messages and does not change capability metadata.
Consequences
The wrapper does not confer system-role authority, so reminders have user-role priority. Cache hits remain provider-dependent; tool changes and compaction can still invalidate prefixes. Both text-only and attachment-aware conversion apply the same fallback, and wire tests inspect the real pi-ai serializer output.
中文
问题
对于不原生支持对话中系统消息的模型,pi-ai 会把后续系统消息拼接进初始提示词。因此,传给适配器的后续系统消息会使此前的对话缓存前缀失效。
决策
按段更新独立于原生系统消息支持来准入指令增量。本记录负责它们在 pi-ai 路由上的适配器表示。
pi-ai 适配器使用已准备模型的现有 supportsMidConvoSystemMessages 能力映射。对于具备该能力的模型,适配器保留原生系统消息;否则,在 pi-ai 接收上下文之前,将每条非空的后续系统消息转换为以 <system-reminder> 包裹的用户消息。开头的系统消息仍位于初始提示词中。系统文本块去除首尾空白,并以空行分隔。消息顺序和重复更新保持不变,持久消息保留原始角色。
回退由适配器负责,因为它取决于所选协议能力。系统服务捕获来源增量,循环提交它们;两者都不会仅因路由缺乏原生支持而合并指令。
考虑过的替代方案
让 pi-ai 拼接更新。 保留系统角色优先级,但后续系统文本每次变化都会改变初始提示词,破坏前缀复用。
宣称原生支持或发送 developer 消息。 错报模型能力,或依赖另一种不受支持的指令角色。回退使用普通用户消息,不改变能力元数据。
后果
包裹文本不会赋予系统角色权限,因此提醒具有用户角色优先级。缓存命中仍取决于提供方;工具变化和压缩仍可能使前缀失效。纯文本与附件感知转换使用相同的回退,线协议测试检查真实 pi-ai 序列化器的输出。