feat(memory): add memory manager#2544
Open
opieter-aws wants to merge 1 commit into
Open
Conversation
ce8787d to
97a0c1d
Compare
notowen333
reviewed
Jun 1, 2026
| throw new Error('MemoryManager: no writable store matched') | ||
| } | ||
|
|
||
| const settled = await Promise.allSettled(writableStores.map((s) => s.add!(content, options?.metadata))) |
Contributor
There was a problem hiding this comment.
We have 2 paths here as I see it:
- awaiting at the callsite like we see here. What we gain from this is the lines below which is observability into the outcomes of the calls. The implicit invariant we want with this approach is that every
addimplementer fast returns and then fire-and-forgets the network call/API call.
It can also be noted that the fast return could also signal a success and then silently fail later
- We
voidnotawaitat this callsite. Then we are guaranteed to not block the thread no matter what eachaddmethod does.
|
|
||
| const results: MemoryEntry[] = [] | ||
| for (let i = 0; i < settled.length; i++) { | ||
| const r = settled[i]! |
Contributor
There was a problem hiding this comment.
nit: here and elsewhere I prefer to avoid the single char names
| * defaults on the store. | ||
| */ | ||
| export interface SearchOptions { | ||
| /** Maximum number of results to return. */ |
Contributor
There was a problem hiding this comment.
this is representing the max per store, so lets make that clear in docstring and/or var name
| return found | ||
| }) | ||
| } else { | ||
| writableStores = this._config.stores.filter((s) => s.writable) |
Contributor
There was a problem hiding this comment.
Isn't it this.addStores here?
| * ``` | ||
| */ | ||
| export class MemoryManager implements Plugin { | ||
| readonly name = 'strands:memory-manager' |
Contributor
There was a problem hiding this comment.
Re-iterating offline conversation that we intend to make the manager unique per agent
|
|
||
| private _createAddTool(config: MemoryToolConfig): Tool { | ||
| let description = config.description ?? ADD_TOOL_DESCRIPTION | ||
| const storeDescriptions = this._addStores.filter((s) => s.description).map((s) => `- ${s.name}: ${s.description}`) |
Contributor
There was a problem hiding this comment.
maybe it is nice to consolidate the description appending logic here and above maybe inline is better
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
Adds the
MemoryManagerprimitive: a construct that manages one or more memory storebackends and exposes
search_memory/add_memorytools for agent-driven recall andpersistence, plus programmatic
search()/add()methods.What's included
MemoryManager(implementsPlugin): registers its tools viagetTools(), andaggregates any tools a store exposes via
MemoryStore.getTools().MemoryStoreinterface: every store is searchable; a requiredwritableflag declareswhether it accepts writes.
search_memorytargets all stores;add_memorytargets onlywritable stores. The constructor fails fast if a store is
writable: truewithoutadd().MemoryStoreConfig: shared base config that concrete store implementations extend.are dropped (with a warning), or an actionable error is thrown if all requested names
are out of scope. Omitted/empty
storestargets all in-scope stores.AgentConfig.memoryManagerfield accepting aMemoryManagerinstance or a
MemoryManagerConfigobject (auto-wrapped).Scope (intentionally minimal)
This PR ships the
MemoryManagerandMemoryStoreinterface only, to unblock downstreamconsumers (e.g. AgentCore memory) from building against a stable interface. Two pieces are
deferred to dedicated follow-up PRs:
built on the upcoming middleware system (sdk-typescript#1068) rather than lifecycle hooks,
which avoids mutating durable session history.
BedrockKnowledgeBaseStore— a concrete store implementation, tracked separately(needs its own tests + optional AWS peer-dependency wiring).
initAgentis currently a no-op; tools auto-register through thePluginRegistryviagetTools(). Will be populated when adding injection and extraction.Related Issues
#2393
Documentation PR
No new docs in this PR. A documentation PR will accompany the injection follow-up once the
full feature surface (injection + a shipped store backend) is finalized.
Type of Change
New feature
Testing
Comprehensive unit tests in
strands-ts/src/memory/__tests__/memory-manager.test.ts(50tests) cover: constructor validation (empty stores, duplicate names, writable-without-add,
add-tool enablement), tool registration, store-tool scoping (in-scope/out-of-scope/partial,
omit-vs-empty),
search()/add()fan-out and partial-failure handling, store-providedtool aggregation, and
AgentConfigauto-wrapping.hatch run prepare(N/A — TypeScript package; rannpm test/type-check/lint/format:checkinstead)Checklist
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.