Conversation
When session context_tokens reaches 80% of the configured context_window, automatically compress old messages in the background: - Soft-mark old messages as compressed (meta.compressed=true) - Generate LLM summary and insert as context_summary message - Reset context_tokens after compression - Frontend shows compressed messages as dimmed + summary divider card Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
context_tokens达到context_window的 80% 时,自动后台压缩旧消息compressed=true;插入一条 LLM 生成的摘要消息(type=context_summary)📦 以上 N 条已压缩为摘要改动清单
后端(8 个文件)
config.py/config_file.py:新增llm_context_window配置字段(默认 128000,0 = 禁用)memory/base.py/sqlite.py/hybrid.py:新增mark_compressed()方法workspace/memory_writer.py:核心压缩逻辑(maybe_compress+_compress),防重入 + 独立 DB sessionagents/base.py:_get_history_with_meta()过滤已压缩消息agents/personal_assistant.py:_record_turn_usage()末尾读回 context_tokens 触发压缩前端(2 个文件)
api/index.ts:扩展HistoryMessageMeta类型ChatPage.tsx:Message 接口 + mapHistoryToMessages + 渲染(opacity-50 + 分隔线卡片)测试(2 个新文件,17 个测试用例)
test_mark_compressed.py:SQLite/Hybrid/Base mark_compressed 测试test_memory_writer_compress.py:maybe_compress 入口条件 + _compress 核心逻辑测试Test plan
context_window: 1000,连续对话触发压缩,确认前端灰色 + 分隔线🤖 Generated with Claude Code