Skip to content

feat: add auto context compress ability for agent#1329

Open
Lerr1uqs wants to merge 2 commits intoMoonshotAI:mainfrom
Lerr1uqs:feat/auto-context-compress
Open

feat: add auto context compress ability for agent#1329
Lerr1uqs wants to merge 2 commits intoMoonshotAI:mainfrom
Lerr1uqs:feat/auto-context-compress

Conversation

@Lerr1uqs
Copy link

@Lerr1uqs Lerr1uqs commented Mar 3, 2026

Related Issue

Description

Purpose / 目的

This PR introduces ACC (Auto Context Compress) mode to give the agent the ability to
autonomously decide when to compact context, so it can sustain longer-running tasks
with better continuity and less context exhaustion.

本 PR 引入 ACC(Auto Context Compress)模式,核心目标是让 agent 具备
自主判断上下文压缩时机的能力,从而支持更长时间连续作业
减少上下文耗尽导致的中断与退化。

Why this matters / 为什么重要

  • Fixed-threshold compaction is reactive and may miss the best timing.

  • In long workflows, the agent often has better local judgment on when older context becomes
    low-value.

  • ACC adds runtime context-capacity awareness and controlled compaction access, enabling
    proactive compression while preserving task continuity.

  • 固定阈值压缩偏被动,触发时机不一定最优。

  • 在长链路任务中,agent 往往更清楚哪些历史上下文已经低价值。

  • ACC 提供运行时容量感知和受控压缩能力,让 agent 能主动压缩并保持任务连续性。

What changed / 改动内容

  1. Added /acc slash command (toggle/on/off/status).

  2. Added ACC mode indicator (ACC) in shell bottom toolbar.

  3. When ACC is enabled, each LLM step appends a lightweight runtime hint including:

    • context used / max
    • remaining capacity
    • safe remaining capacity (after reserved budget)
    • reminder that the model may call the ACC compaction tool
  4. Added AccCompactContext tool:

    • hidden by default
    • only exposed when ACC mode is enabled
    • requires task_summary
  5. Reused existing compaction pipeline and extended it to append task_summary after compaction
    so post-compaction behavior remains aligned with current task progress.

  6. 新增 /acc 斜杠命令(切换/开启/关闭/状态)。

  7. 在 Shell 底栏新增 ACC 模式标记(ACC)。

  8. ACC 开启时,每次 LLM step 前附加轻量提示,包括:

    • 当前上下文已用/上限
    • 剩余容量
    • 安全剩余容量(扣除保留预算后)
    • 提醒模型可调用 ACC 压缩工具
  9. 新增 AccCompactContext 工具:

    • 默认隐藏
    • 仅在 ACC 开启时暴露
    • 必填 task_summary
  10. 复用现有压缩链路,并在压缩后追加 task_summary
    确保压缩后仍能按当前任务进度继续执行。

Non-invasive implementation / 非侵入式实现原则

  • No large refactor in agent spec or tool loading architecture.

  • ACC logic is added incrementally around existing KimiSoul flow and current compaction
    mechanisms.

  • Existing /compact behavior is preserved.

  • 不改动 agent spec 与工具加载主架构。

  • ACC 仅在现有 KimiSoul 与压缩流程外围做增量扩展。

  • 现有 /compact 行为保持不变。

Tests / 测试

Added/updated focused tests:

  • tests/core/test_acc_tool.py
  • tests/core/test_kimisoul_slash_commands.py
  • tests/ui_and_conv/test_prompt_tips.py

Validation command:

uv run pytest tests/core/test_acc_tool.py tests/core/test_kimisoul_slash_commands.py tests/ui_and_conv/test_prompt_tips.py

Result: all passed.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have run make gen-changelog to update the changelog.
  • I have run make gen-docs to update the user documentation.

Open with Devin

devin-ai-integration[bot]

This comment was marked as resolved.

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