Skip to content

feat: implement MicroCompaction#219

Open
kermanx wants to merge 15 commits into
mainfrom
micro-compaction
Open

feat: implement MicroCompaction#219
kermanx wants to merge 15 commits into
mainfrom
micro-compaction

Conversation

@kermanx
Copy link
Copy Markdown
Collaborator

@kermanx kermanx commented May 29, 2026

Problem

Current context management only supports full compaction (summarization), which is expensive and interrupts the conversation flow. There is no lightweight mechanism to reduce token usage from old tool results when the prompt cache has likely expired.

What changed

  • Implemented "MicroCompaction" — a time-based lightweight context reduction mechanism that truncates old tool result content instead of summarizing.
  • "MicroCompaction" replaces tool result content with a fixed placeholder "[Old tool result content cleared]" for old messages beyond a configurable threshold.
  • Added "ContextMemory.lastAssistantAt" to track the timestamp of the last assistant message. Used to detect cache expiration (default: 1h idle threshold).
  • Added "ContextMemory.project()" to apply micro compaction before message projection.
  • Wired micro compaction into both regular "ContextMemory.messages" and full compaction's summarization prompt.
  • Added configurable "MicroCompactionConfig" with defaults: keep 10 recent messages, min 20 tokens to truncate, 1h cache-missed threshold.
  • Reset micro compaction cutoff on context clear and full compaction apply.
  • Added 9 integration tests covering truncation, threshold guarding, cutoff persistence, reset, min-content filtering, non-tool skipping, context-clear, full-compaction, and short-history boundaries.

Checklist

  • I have read the CONTRIBUTING document.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 29, 2026

⚠️ No Changeset found

Latest commit: 170ee64

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 29, 2026

pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@170ee64
npx https://pkg.pr.new/@moonshot-ai/kimi-code@170ee64

commit: 170ee64

Copy link
Copy Markdown

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

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: 555c3722e5

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/agent-core/src/flags/registry.ts Outdated
Comment thread packages/agent-core/src/agent/context/index.ts
Comment thread packages/agent-core/src/agent/compaction/micro.ts
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