multica/src/agent
Jiayuan 67cd46a072
feat(agent): add context window management with token-aware compaction (#14)
* feat(agent): add context window guard to prevent token overflow

Implement token-aware context management that validates context window
size on agent initialization and provides intelligent message compaction
based on actual token usage rather than simple message count.

Key changes:
- Add context-window module with guard, token estimation, and types
- Support both "count" (legacy) and "tokens" (new default) compaction modes
- Warn when context window < 32K tokens, block when < 16K tokens
- Trigger compaction at 80% utilization, target 50% after compaction

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* feat(agent): add summary-based compaction using LLM

Implement intelligent compaction that uses LLM to generate summaries
of older messages instead of simply truncating them. This preserves
important context like key decisions, TODOs, and technical details.

Key changes:
- Add summarization.ts with compactMessagesWithSummary functions
- Support chunked summarization for very large histories
- Add "summary" compaction mode alongside "count" and "tokens"
- Auto-resolve API key from environment based on provider
- Graceful fallback to "tokens" mode if model/apiKey unavailable

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 03:46:11 +08:00
..
context-window feat(agent): add context window management with token-aware compaction (#14) 2026-01-30 03:46:11 +08:00
profile feat(agent): add profile system and improve tools 2026-01-30 02:47:30 +08:00
session feat(agent): add context window management with token-aware compaction (#14) 2026-01-30 03:46:11 +08:00
tools fix(agent): prevent memory leak and buffer overflow in process tool 2026-01-30 03:08:24 +08:00
cli.ts feat(agent): add profile system and improve tools 2026-01-30 02:47:30 +08:00
index.ts feat(agent): add context window management with token-aware compaction (#14) 2026-01-30 03:46:11 +08:00
interactive-cli.ts feat(agent): add interactive CLI for agent interaction 2026-01-30 03:29:45 +08:00
output.ts chore(agent): drop bash tool alias 2026-01-30 01:51:29 +08:00
profile-cli.ts feat(agent): add profile system and improve tools 2026-01-30 02:47:30 +08:00
runner.ts feat(agent): add context window management with token-aware compaction (#14) 2026-01-30 03:46:11 +08:00
tools.ts feat(agent): add profile system and improve tools 2026-01-30 02:47:30 +08:00
types.ts feat(agent): add context window management with token-aware compaction (#14) 2026-01-30 03:46:11 +08:00