cache group chat fixed context usage (#925)

This commit is contained in:
ekko
2026-05-22 10:20:39 +08:00
committed by GitHub
parent c3538a6b44
commit 4b759c4d8a
5 changed files with 200 additions and 33 deletions
@@ -175,6 +175,12 @@ export class ContextEngine {
logger.debug(`[ContextEngine] [Path A] OVER threshold — starting INCREMENTAL compression of ${newMessages.length} msgs...`)
logger.debug(`[ContextEngine] [Path A] CONTEXT BEFORE COMPRESSION: summary(${snapshot.summary.length} chars) + ${newMessages.length} new msgs`)
meta.compressed = true
input.onProgress?.({
status: 'compressing',
path: 'snapshot',
messageCount: newMessages.length,
tokenCount: totalTokens,
})
const t0 = Date.now()
const result = await this.summarize(
@@ -233,6 +239,12 @@ export class ContextEngine {
logger.debug(`[ContextEngine] [Path B] OVER threshold — starting FULL compression of ${total} msgs...`)
logger.debug(`[ContextEngine] [Path B] CONTEXT BEFORE COMPRESSION: ${total} msgs, ~${totalTokens} tokens`)
meta.compressed = true
input.onProgress?.({
status: 'compressing',
path: 'full',
messageCount: total,
tokenCount: totalTokens,
})
const t0 = Date.now()
const result = await this.summarize(
@@ -96,6 +96,13 @@ export interface GatewayCaller {
export type SessionCleaner = (sessionId: string) => void
export type ContextProgress = (event: {
status: 'compressing'
path: 'snapshot' | 'full'
messageCount: number
tokenCount: number
}) => void
// ─── Build Context Input ───────────────────────────────────
export interface MemberInfo {
@@ -122,4 +129,5 @@ export interface BuildContextInput {
history: Array<{ role: 'user' | 'assistant'; content: string }>,
instructions: string,
) => Promise<number | null | undefined>
onProgress?: ContextProgress
}