feat(session): 实现 context compress — token 预算模式的上下文压缩#12
Merged
Conversation
Session.send()/stream() 支持通过 contextWindow 配置按 token 预算压缩上下文: - 新增 ContextWindowOptions(maxContextTokens + countTokens 回调) - 配置后 L2 作为摘要前缀注入,L3 按剩余预算从最近往前填充 - 新增 trimRecords() 方法用于 consolidate 后物理裁剪旧 L3 - 不配置时行为完全向后兼容
Difficult-Burger
added a commit
to Difficult-Burger/stello
that referenced
this pull request
Mar 31, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <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
send()/stream()添加基于 token 预算的上下文压缩能力contextWindow: { maxContextTokens, countTokens }配置,适配不同 LLM 的上下文窗口和 tokenizertrimRecords(keepRecent)方法,支持 consolidate 后物理裁剪旧 L3contextWindow时行为完全向后兼容改动范围
types/functions.tsCountTokensFn、ContextWindowOptions,四个 Options 均添加contextWindow?types/storage.tsSessionStorage新增trimRecords()types/session-api.ts/main-session-api.tstrimRecords()context-utils.tsselectHistoryByBudget、assembleSessionContext、assembleMainSessionContext)create-session.ts/create-main-session.tsin-memory-storage.tstrimRecordspg-session-storage.tstrimRecords(SQL)设计决策
contextWindow时,L2 作为压缩前缀注入子 Session 的 send() 上下文(原约束为「L2 对子 Session 不可见」)Test plan