Budget conversation context and preserve complete tool exchanges #69
Reference in New Issue
Block a user
Delete Branch "feat/context-management"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The fixed 12-message history window can drop the current user question during a long tool turn, while full tool results and uncapped memories keep increasing prompt size. Replace it with an estimated token budget that includes system instructions and tool schemas, reserves generation space, and preserves the current question and complete tool exchanges.
Compact oversized results, select recent history by whole turns, retain bounded excerpts from older turns, and bound saved memories without changing checkpointed content. Remove incomplete exchanges left by cancelled turns. Add optional line-range reads for Obsidian and context-budget logs.
Defaults: 16,000 estimated prompt tokens, a 32,768-token context window, 4,096 generated tokens, and a 2,048-token safety reserve. Counts use UTF-8 estimates rather than a backend tokenizer; historical excerpts are not a generated rolling summary. Configuration and limitations are documented in docs/context-management.md.
Validation: 57 tests pass across tests/unit/test_context_trim.py, tests/unit/test_stream_stall.py, and tests/unit/test_tool_artifacts.py. Ruff checks and formatting hooks pass.