Repository navigation
feat(cascade): Bound conversation history sent to the llm and kept in memory - #74
Merged
Merged
Conversation
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.
Description:
Fixes #xxx
No linked issue. Found while reviewing vRT's context management:
CascadeSession.historyonly grew, so long voice sessions would eventually exceed the text LLM's context window and memory grew with session length.Behaviours Completed
session.historyitself is capped (default twicemaxMessages), so memory no longer grows with session length.history.processlets apps replace the default trim;trimHistoryandestimateTokensare exported to build on.Files Changed
packages/cascade/src/history.ts(new):HistoryLimits,estimateTokens,trimHistory.packages/cascade/src/index.ts:CascadeOptions.history; all history writes go through#remember, requests through#window.packages/cascade/test/cascade.test.ts: tests for the budget, tool call/result pairing, the stored cap, customprocess, and unchanged behaviour for short sessions.Brief Explanation
trimHistorymarks every index that would orphan a tool result if the window started there, then walks back from the newest message accumulating the token estimate (about 4 characters per token) and picks the earliest valid start within budget, preferring a user message. If nothing fits, it falls back to the latest valid start.#rememberapplies the same function with the stored cap after each push.Testing
npx vitest run packages: 551 tests pass across 34 files, including the new cascade tests. Typecheck in the worktree was not meaningful because it had nonode_modulesand resolved@vrealtime/*from an older checkout; relying on CI typecheck.Unsure About
The token estimate is a character heuristic, not a real tokenizer, so the budget is approximate. Older history is dropped rather than summarized; summarization/compaction could be a follow-up.