Skip to content

feat: split the system prompt into a stable part and a per-turn block - #114

Merged
wxkingstar merged 2 commits into
mainfrom
claude/unruffled-cori-8a95ad
Oct 8, 2026
Merged

wxkingstar merged 2 commits into
mainfrom
claude/unruffled-cori-8a95ad

Conversation

@wxkingstar

Copy link
Copy Markdown
Owner

背景

  • Codex 续聊看不到新的系统提示。 relay-codex 每轮用 -c developer_instructions= 传整份提示,但 Codex 只在新建 thread 时读取它,exec resume 时忽略。多轮会话的 rollout 里只有第一轮的身份标签,「当前时间」也停在第一轮。于是发言者、换人提醒、时间、本人飞书授权状态、一次性密钥、协作/同事答复/定时续接的阶段说明,在续聊轮次都到不了模型。
  • Claude 每轮破缓存。 每轮随机身份标签 + 精确到分钟的时间让 system prompt 每轮都不同,续聊时整段历史都要重新写缓存。

改动

  • 两层结构:system prompt(Claude --append-system-prompt / Codex developer_instructions)只取决于机器人配置、平台、聊天类型、后端,同一会话逐字不变。发言者、换人提醒和各能力的本轮状态写进用户消息开头由平台生成的 [SYS_TURN:<tag>] 块;规则仍在 system prompt。
  • 换人提醒点名前后两个人:「发言者从 A 换成了 B……不要沿用 A 的账号、参数或查询范围」。
  • 身份标签按会话固定:由 relay 会话 id 与主密钥派生(Cipher.mac),无需迁移;用户消息里带标签的 [SYS_USER:…]、[SYS_TURN:…] 行一律过滤。
  • 删除「当前时间」段:改为固定规则——用户说的时间按北京时间理解,需要当前时间时执行 TZ=Asia/Singapore date。
  • 稳定段与发言者无关:群里身份未知的人说话,个人凭证、协作、业务系统的规则照挂,本轮块说明这一轮用不了。业务系统清单去掉随目录拉取变化的模块数/操作数,改标「可查操作目录」。
  • 不为新的稳定段丢历史:会话只在用户重置或超时过期时换新。Codex 已有会话沿用建会话时的稳定段,管理台改动要等重置或过期;每轮块始终是最新的。
  • 运行时节点不用改、不用升级;无数据库迁移。

设计见 docs/superpowers/specs/2026-10-07-turn-context-prompt.md。

测试

  • uv run pytest -n 4:2989 passed
  • uv run ruff check .、uv run mypy coreman 通过
  • 新增/改写:稳定段不含发言者与时间、会话标签派生、每轮块格式与换人点名、消毒去掉带标签的行、本轮块在用户消息最前(含多模态)、群里 A/B 交替两轮 system prompt 逐字相同、凭证/一次性密钥/协作与定时续接说明出现在本轮块

🤖 Generated with Claude Code

Codex reads developer_instructions only when it creates a thread, so every
later turn of a Codex conversation kept the first turn's speaker line, time,
speaker-change notice and per-turn capability status. Claude got a fresh
system prompt every turn, but a per-turn random tag and a minute-precise time
made the system prompt differ on every turn, so the conversation history never
came from the prompt cache.

The system prompt now depends only on the employee's configuration, platform,
chat type and backend. Who is speaking, a speaker change naming both people,
and per-turn status (personal Feishu/WeCom authorization, saved and one-time
credential names, business systems without a token this turn, collaboration
and continuation phases) go into a [SYS_TURN:<tag>] block in front of the
user's message. The identity tag is fixed per conversation, derived from the
relay session id with the master key; tagged identity lines are stripped from
message text. The current-time section is replaced by a rule to run
`TZ=Asia/Singapore date`. Business system listings drop catalog counts so a
catalog fetch does not change the prompt. Conversations are never restarted
to apply a changed prompt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-8a95ad

# Conflicts:
#	CHANGELOG.md
#	coreman/core/auth/system_access.py
#	tests/api/test_systems_catalog.py
@wxkingstar
wxkingstar merged commit 42749aa into main Oct 8, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant