From 1fe8fd1b3395fd04efc343065e1435bb291943fd Mon Sep 17 00:00:00 2001 From: Kaiyi Date: Fri, 3 Jul 2026 13:30:24 +0800 Subject: [PATCH] feat(agent-core): make compaction notes capture a forward plan, not just the next step MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Compaction runs at the point of maximum context for the task, and the next turn resumes with less. So the handoff note now records the plan for the remaining work — upcoming steps, settled decisions, and foreseeable obstacles, plus any work that can be pre-committed — instead of only the immediate next command. Update the affected compaction snapshots and one hardcoded input-token assertion (the instruction is ~163 tokens longer). --- .changeset/compaction-forward-plan.md | 5 ++ .../compaction/compaction-instruction.md | 13 +++++- .../test/agent/compaction/full.test.ts | 46 +++++++++---------- 3 files changed, 39 insertions(+), 25 deletions(-) create mode 100644 .changeset/compaction-forward-plan.md diff --git a/.changeset/compaction-forward-plan.md b/.changeset/compaction-forward-plan.md new file mode 100644 index 0000000000..69765325f8 --- /dev/null +++ b/.changeset/compaction-forward-plan.md @@ -0,0 +1,5 @@ +--- +"@moonshot-ai/kimi-code": patch +--- + +Have context-compaction notes capture a forward plan for the remaining work — upcoming steps, settled decisions, and foreseeable obstacles — instead of only the immediate next step, so the agent continues more coherently after auto-compaction. diff --git a/packages/agent-core/src/agent/compaction/compaction-instruction.md b/packages/agent-core/src/agent/compaction/compaction-instruction.md index f0ee851f22..d137e3ca3a 100644 --- a/packages/agent-core/src/agent/compaction/compaction-instruction.md +++ b/packages/agent-core/src/agent/compaction/compaction-instruction.md @@ -40,8 +40,17 @@ continue: conversation never established — files or paths referenced but not yet read, schemas or APIs assumed but unseen, questions the user has not answered. Name these gaps so the next turn goes and checks them instead of assuming. -- The precise next action — including the exact next command or tool call you - intend to make — and any required format for the final answer. +- The forward plan — and this is the moment to invest in it. Right now you + hold more context on this task than you ever will again; the next turn + resumes with less, so the plan you commit here is the one it will follow. + Give the exact next command or tool call, but don't stop at the next step: + set out the remaining sequence to finish, the decisions you have already + made for those upcoming steps (so the next turn doesn't reopen them), the + obstacles or edge cases you can already foresee and how you mean to handle + them, and any work you can commit to now — the exact patch, query, or shape + of the final answer you already know you will produce. Anything you settle + here is one less thing the next turn must rediscover. Include any required + format for the final answer. Your TODO list is re-attached automatically below this note from its live source, so do not transcribe it — copying it wastes space and can contradict the diff --git a/packages/agent-core/test/agent/compaction/full.test.ts b/packages/agent-core/test/agent/compaction/full.test.ts index a31a247678..cdd0567ead 100644 --- a/packages/agent-core/test/agent/compaction/full.test.ts +++ b/packages/agent-core/test/agent/compaction/full.test.ts @@ -76,10 +76,10 @@ describe('FullCompaction', () => { [wire] context.append_message { "message": { "role": "user", "content": [ { "type": "text", "text": "recent user three" } ], "toolCalls": [], "origin": { "kind": "user" } }, "time": "