feat: add multi-model delegation (Phase 0) and context compaction (Phase 1)
Phase 0 — Multi-Model Delegation: - AgentOrchestrator wraps NativeAgent with delegate() for stateless single-turn calls to any model tier (fast/default/complex/local) - DelegationConfig maps task types (compaction, classification, etc.) to model tiers - Delegation prompts for compaction, memory extraction, classification, and tool summarisation - Per-tier usage tracking for cost visibility - Config schema: agents.delegation and agents.primary_tier Phase 1 — Context Compaction: - Token estimation (char/4 heuristic) with context window lookup - shouldCompact() threshold check against context window percentage - compactHistory() splits old/recent messages, delegates summary to fast tier, returns CompactionResult - Automatic compaction in AgentOrchestrator.process() when configured - Force-compact via orchestrator.compact() with session persistence - Session.replaceHistory() with atomic SQLite transaction - /compact TUI command with feedback on compacted token counts - Config schema: compaction.enabled, threshold_pct, keep_turns, summary_max_tokens Tests: 385 passing across 50 files (22 new tests in 2 new test files)
This commit is contained in:
@@ -6,6 +6,7 @@ export interface Session {
|
||||
addMessage(message: Message): void;
|
||||
getHistory(): Message[];
|
||||
clear(): void;
|
||||
replaceHistory(messages: Message[]): void;
|
||||
}
|
||||
|
||||
export class ManagedSession implements Session {
|
||||
@@ -34,6 +35,16 @@ export class ManagedSession implements Session {
|
||||
this.store.clearSession(this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the entire session history with new messages.
|
||||
* Used after compaction to persist the compacted state.
|
||||
* Updates both in-memory history and SQLite storage atomically.
|
||||
*/
|
||||
replaceHistory(messages: Message[]): void {
|
||||
this.history = [...messages];
|
||||
this.store.replaceMessages(this.id, messages);
|
||||
}
|
||||
|
||||
setHistory(messages: Message[]): void {
|
||||
this.history = [...messages];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user