feat(agent-memory): Phase 6 — consolidate()#254
Open
jamby77 wants to merge 1 commit into
Open
Conversation
6e7c2e9 to
2dc4339
Compare
5cdeb4c to
c317978
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c317978. Configure here.
2dc4339 to
e4646ec
Compare
c317978 to
d5a95b9
Compare
- consolidate() summarizes old/low-importance memories into one durable source:'summary' memory via a caller-supplied summarize(items) callback - Select candidates by scope/tags + olderThanSeconds + maxImportance; write the summary before deleting sources so a failure never destroys memories without leaving the replacement - deleteSources defaults true; summaryImportance defaults 0.7 - Require at least one selection criterion to prevent whole-store consolidation (mirrors forgetByScope's mass-delete guard) - Fetch only the fields parseMemoryItem needs (no vector blobs) on the candidate scan - Add ConsolidateOptions/ConsolidateResult types
d5a95b9 to
e27477f
Compare
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.

Stacked on #253 (Phase 5 — eviction & TTL).
What
Phase 6 of
@betterdb/agent-memory: consolidation — summarize many old/low-value memories into fewer durable ones. Callable, not scheduled (per spec).consolidate(options):threadId/agentId/namespace+tags) filtered byolderThanSecondsandmaxImportance.summarize(items) => Promise<string>(the library never hard-codes an LLM — mirrors the judge-injection pattern).source: 'summary'atsummaryImportance(default0.7), scoped/tagged to the request.deleteSources(defaulttrue) removes the originals; returns{ consolidated, created, deleted }.Design / review notes
olderThanSeconds, ormaxImportance) — a criteria-lessconsolidate({summarize})would otherwise summarize+delete the entire store. MirrorsforgetByScope's guard.RETURNof only the fieldsparseMemoryItemneeds, so it never transfers vector blobs.CONSOLIDATE_SCAN_LIMIT); a singlesummarize()over a whole huge scope is impractical anyway, and the remainder consolidates on subsequent calls.Tests (
MemoryStore.consolidate.test.ts, 8)candidate summarize+write+delete+counts ·
olderThanSecondsfilter ·maxImportancefilter · summary scope+summaryImportance·deleteSources:falsekeeps sources · nothing-matches → zeros & no summarize/write · no-criteria guard throws · defaults (0.7/ delete).55/55 package tests green ·
tsc --noEmitclean · prettier clean.Note
Medium Risk
The operation can bulk-delete stored memories if criteria match; guards and write-before-delete reduce accidental loss, but misconfigured scope or summarize failures still need careful caller handling.
Overview
Adds
MemoryStore.consolidate()so callers can merge many scoped memories into one durable summary memory, with optional removal of the originals.Candidates are found via scoped
FT.SEARCH, then filtered byolderThanSecondsandmaxImportance. The caller suppliessummarize(items)(no built-in LLM). The summary is stored throughremember()withsource: 'summary', defaultsummaryImportance0.7, and the same scope/tags.deleteSourcesdefaults to true; the API returns{ consolidated, created, deleted }.Safety: consolidation requires at least one selection criterion (scope, tags, age, or importance cap) to block whole-store runs. The summary is written before source deletes. Scans are capped at
CONSOLIDATE_SCAN_LIMITand use a narrowRETURNlist (no vector payloads). NewConsolidateOptions/ConsolidateResulttypes are exported; behavior is covered byMemoryStore.consolidate.test.ts.Reviewed by Cursor Bugbot for commit e27477f. Bugbot is set up for automated code reviews on this repo. Configure here.