Skip to content

feat(agent-core): sharpen the compaction handoff prompt - #1283

Merged
RealKai42 merged 2 commits into
mainfrom
polish-compact-v2
Jul 2, 2026
Merged

feat(agent-core): sharpen the compaction handoff prompt#1283
RealKai42 merged 2 commits into
mainfrom
polish-compact-v2

Conversation

@RealKai42

Copy link
Copy Markdown
Collaborator

Summary

Improves the first-person handoff note the model writes when a conversation is compacted, so resumed sessions continue more reliably. Guiding principle: the summary should preserve what compaction drops (the assistant's reasoning and tool results), not re-transcribe what already survives beside it — the most recent user messages are kept verbatim next to the summary.

Changes

compaction-instruction.md

  • Lead with the intent of the latest request rather than a verbatim re-transcription; say which request governs when several are in play.
  • Carry forward tool results — concrete values, key lines, schemas — not just the commands that produced them.
  • Keep settled decisions separate from still-open questions.
  • Name the context the next turn must go and re-check ("what you still don't know").
  • Write in the conversation's language, keep the note proportional to the task, and don't re-transcribe the auto-attached TODO list.

system.md

  • Correct the description of the post-compaction shape: recent user messages come first, followed by a first-person summary (not a rigidly sectioned report), and a newer kept message supersedes the summary.

Tests

  • Updated the affected inline snapshots and the compaction-request token-count assertion.
  • Full agent-core suite green (3402 passed).

Refine the first-person handoff note the model writes at compaction so it
preserves what actually gets dropped instead of what already survives:

- Lead with the intent of the latest request, not a verbatim re-transcription
  (the recent user messages are already kept verbatim beside the summary);
  name which request governs when several are in play.
- Carry forward tool results — the concrete values, key lines, schemas — not
  just the commands that produced them.
- Keep settled decisions separate from still-open questions, and name the
  context the next turn must go and re-check.
- Write in the conversation's language, keep the note proportional to the task,
  and don't re-transcribe the auto-attached TODO list.

Also correct the system prompt's description of the post-compaction shape: the
recent user messages come first, followed by a first-person summary (not a
rigidly sectioned report), and a newer kept message supersedes the summary.

Update the affected inline snapshots and the compaction request token count.
@changeset-bot

changeset-bot Bot commented Jul 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8d36f25

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 1, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@8d36f25
npx https://pkg.pr.new/@moonshot-ai/kimi-code@8d36f25

commit: 8d36f25

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 65fcacb53d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +20 to +21
any ambiguity you have already resolved — not a re-transcription, since the
request itself survives verbatim in the kept messages. If several requests are

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve oversized latest requests in the handoff

When the latest user request itself exceeds the 20k-token kept-message budget, selectRecentUserMessages keeps only a truncated prefix of that message, so telling the compaction model not to re-transcribe it because it “survives verbatim” can permanently drop the tail of the active request after compaction. This affects large prompts/files pasted by the user right before overflow; the summary is the only chance to carry forward the omitted details, so the instruction should still require preserving any parts of the current request that may not fit in the kept messages.

Useful? React with 👍 / 👎.

…note

selectRecentUserMessages truncates a kept user message to the size cap,
keeping only its prefix, so when the latest request itself exceeds the cap
only its head survives verbatim beside the summary. Telling the summary
"don't re-transcribe, it survives verbatim" then permanently dropped the
tail — often the actual ask. Keep the intent-not-transcription guidance,
but require preserving the at-risk parts of a long current request.
@RealKai42
RealKai42 merged commit ea55911 into main Jul 2, 2026
9 checks passed
@RealKai42
RealKai42 deleted the polish-compact-v2 branch July 2, 2026 05:44
@github-actions github-actions Bot mentioned this pull request Jul 2, 2026
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