fix(memory): use namespacePath for hierarchical memory retrieval#95
Merged
Merged
Conversation
AgentCore Memory's RetrieveMemoryRecords API changed how the `namespace`
parameter works: it used to do prefix-match, now it does exact-match. AWS
introduced a new `namespacePath` field for the prior hierarchical
(prefix) semantics. Existing accounts get a 120-day grace period before
the legacy behavior is removed.
ABCA's episodic retrieval relies on prefix-match: per-task records live
at `/{actorId}/episodes/{sessionId}/`, but the orchestrator queries
`/{actorId}/episodes/`. Under exact-match, that query silently returns
zero records — the agent loses access to past task episodes with no
visible failure. Migrating both reads in loadMemoryContext to
`namespacePath` preserves the intended retrieval semantics and is
forward-compatible once the grace window closes.
Also bumps `@aws-sdk/client-bedrock-agentcore` from `^3.1021.0` (which
predates the new field) to `^3.1046.0`.
Refs:
- API reference: https://docs.aws.amazon.com/bedrock-agentcore/latest/APIReference/API_RetrieveMemoryRecords.html
- Best-practice blog: https://aws.amazon.com/blogs/machine-learning/organizing-agents-memory-at-scale-namespace-design-patterns-in-agentcore-memory/
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.
The orchestrator's
loadMemoryContextwas retrieving episodic records vianamespace: '/{repo}/episodes/', which used to do prefix-match on the AgentCore Memory API. AWS changednamespaceto exact-match and introduced a newnamespacePathfield for hierarchical (prefix) retrieval. Per-task episodes live one level below at/{repo}/episodes/{sessionId}/, so the previous call was about to silently return 0 records once the grace window for legacy behavior closes. Switching both reads inloadMemoryContexttonamespacePathpreserves the intended retrieval semantics.Area
cdk— infrastructure, handlers, constructsagent— Python runtime / Docker imagecli—bgagentclientdocs— guides or design sources (docs/guides/,docs/design/)tooling— rootmise.toml, scripts, CI workflowsRelated
RetrieveMemoryRecords: https://docs.aws.amazon.com/bedrock-agentcore/latest/APIReference/API_RetrieveMemoryRecords.html — documents bothnamespace(exact match) andnamespacePath(hierarchical).ListMemoryRecords: https://docs.aws.amazon.com/bedrock-agentcore/latest/APIReference/API_ListMemoryRecords.html — same shape change.Changes
cdk/src/handlers/shared/memory.ts— switched bothRetrieveMemoryRecordsCommandcalls inloadMemoryContextfromnamespacetonamespacePath. Renamed the locals (semanticNamespacePath,episodicNamespacePath) and the audit log key (namespace→namespace_path) for accuracy.cdk/test/handlers/shared/memory.test.ts— call-shape assertion now requiresnamespacePathand explicitly assertsnamespaceis not sent. Two hash-mismatch audit log assertions updated to match the renamed log key. Live API verification againstbedrock-agentcoreconfirmed sending both fields raisesValidationException: API Request contains both 'namespace' and 'namespacePath' field for memory records retrieval, only one of the fields is allowed.— so single-field correctness matters.cdk/package.json+yarn.lock— bumped@aws-sdk/client-bedrock-agentcorefrom^3.1021.0to^3.1046.0(resolved to 3.1047.0). The earlier pin was installing a build that predates thenamespacePathrequest field.docs/design/MEMORY.md(and regenerated Starlight mirror underdocs/src/content/docs/architecture/Memory.md) — added a one-sentence note that hierarchical reads usenamespacePath, with a link to the AWS API reference.No CDK construct changes were needed. The
@aws-cdk/aws-bedrock-agentcore-alphaconstruct still uses the legacynamespacesfield on its strategy props; the AgentCore Control API accepts bothnamespaces(deprecated) andnamespaceTemplates(current) and dual-emits them on read. Existing memory resources keep working unchanged.Test plan
mise //cdk:build— compile, lint, 1243/1243 tests, synth, all cleanmise //agent:quality— 527/527 pytest passmise //docs:build— Astro/Starlight site build clean; mirrors regenerated and committedmise run build(matching CI'sbuild.ymlenv) — exit 0, 0 self-mutations (CI's most common gate)mise run security:secrets(gitleaks) — no leaksmise run security:sast(semgrep) — cleanmise run security:deps(osv-scanner) — only the pre-existing high-sevdevalue@5.6.4finding from main; Dependabot PR chore(deps): bump devalue from 5.6.4 to 5.8.1 #94 already in flight to fix itus-east-1:RetrieveMemoryRecordswithnamespacePathonly → HTTP 200RetrieveMemoryRecordswithnamespaceonly → HTTP 200 (account is on the existing-customer grace allow-list)RetrieveMemoryRecordswith both fields →ValidationException(matches docs; confirms the migrated single-field call is correctly shaped)ListMemoryRecordswithnamespacePath→ HTTP 200Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.