When constructing AI brokers, builders battle with organizing reminiscence throughout periods, which ends up in irrelevant context retrieval and safety vulnerabilities. AI brokers that keep in mind context throughout periods want greater than solely storage. They want organized, retrievable, and safe reminiscence. In Amazon Bedrock AgentCore Reminiscence, namespaces decide how long-term reminiscence information are organized, retrieved, and who can entry them. Getting the namespace design proper is important to constructing an efficient reminiscence system.
On this put up, you’ll discover ways to design namespace hierarchies, select the fitting retrieval patterns, and implement AWS Id and Entry Administration (IAM)-based entry management for AgentCore Reminiscence. In case you’re new to AgentCore Reminiscence, we suggest studying our introductory weblog put up first: Amazon Bedrock AgentCore Reminiscence: Constructing context-aware brokers.
What are namespaces?
Namespaces are hierarchical paths that arrange long-term reminiscence information inside an AgentCore Reminiscence useful resource. Consider them like listing paths in a file system. They supply logical construction, allow scoped retrieval, and assist entry management.
When AgentCore Reminiscence extracts long-term reminiscence information out of your conversations, every reminiscence file is saved underneath a namespace. For instance, a consumer’s preferences may dwell underneath /actor/customer-123/preferences/, whereas their session summaries is likely to be saved at /actor/customer-123/session/session-789/abstract/. With this construction, you may retrieve reminiscence information at precisely the fitting stage of granularity.
In case you’ve labored with partition keys in Amazon DynamoDB or folder buildings in Amazon Easy Storage Service (Amazon S3), the psychological mannequin transfers effectively. Simply as you suppose via entry patterns earlier than selecting a partition key or designing your S3 folder hierarchy, you need to suppose via your retrieval patterns earlier than designing your namespace construction. Decide:
- Who must entry these reminiscences: A single consumer? All customers of an agent?
- Granularity of retrieval you want: Is it per-session summaries? Cross-session preferences?
- Isolation boundaries that matter: Ought to one consumer’s reminiscences ever be seen to a different? Agent-scoped reminiscences?
The principle distinction from a partition secret’s that namespaces assist hierarchical retrieval along with actual match. You’ll be able to question at every stage of the hierarchy, not solely on the leaf stage. You need to use a well-designed namespace to retrieve reminiscences scoped to a single session, a single consumer throughout periods, or a broader grouping, from the identical reminiscence useful resource. Namespaces are logical groupings inside the identical underlying storage. They supply organizational construction and entry management, however long-term reminiscence information throughout completely different namespaces co-exist inside the identical reminiscence useful resource. Your hierarchy is your major device for organizing information for efficient retrieval patterns.
Namespace templates and determination
When making a reminiscence useful resource, you outline namespace templates utilizing the namespaceTemplate area inside every technique configuration. Templates assist three pre-defined variables:
{actorId}– resolves to the actor identifier from the occasions being processed{sessionId}– resolves to the session identifier from the occasions{memoryStrategyId}– resolves to the technique identifier
Right here’s an instance of making a reminiscence useful resource with namespace templates:
When occasions arrive for actorId=customer-456 in sessionId=session-789, the resolved namespaces grow to be:
/actor/customer-456/info//actor/customer-456/session/session-789/abstract/
Namespace design per reminiscence technique
Every reminiscence technique has completely different scoping wants, and the namespace design ought to replicate how that information might be accessed. Under are some widespread namespace design patterns for various reminiscence methods.
1. Semantic and consumer preferences: Actor-scoped
Semantic reminiscence captures info and information from conversations (for instance, “The shopper’s firm has 500 staff”). Person Choice Reminiscence captures decisions and types (for instance, “Person prefers Python for growth work”). Each reminiscence varieties accumulate over time and are related throughout periods. A truth realized in January ought to nonetheless be retrievable in March. For these methods, scope the namespace to the actor:
This implies the info and preferences for a given consumer are consolidated underneath a single namespace, no matter which session they had been extracted from. The consolidation engine merges associated reminiscences inside the identical namespace. Take a look at determine 1 for an instance of how scoping impacts the consolidation logic.
The next diagram illustrates how actor-scoped semantic and choice reminiscences are organized:
In some use instances, an admin may have to retrieve data throughout actors whereas holding reminiscences organized per actor. For instance, a buyer assist agent may have to lookup recognized points reported by different clients, or a gross sales agent may want to seek out related buyer profiles throughout its consumer base. For such instances, construction the namespace with the actor identifier as a toddler of the reminiscence kind relatively than because the guardian:
With this inverted construction, you should utilize namespacePath="/customer-issues/" to retrieve widespread points raised throughout all clients, whereas nonetheless sustaining a per-actor group. A question scoped to namespace="/customer-issues/customer-123/" returns solely that actor’s reported points, preserving isolation when wanted.
2. Abstract: Session-scoped
Abstract reminiscence creates working narratives of conversations, capturing details and choices. As a substitute of feeding a complete dialog historical past into the massive language mannequin’s (LLM) context window, you may retrieve a compact abstract that preserves the important thing data whereas considerably lowering token utilization. As a result of summaries are inherently tied to a selected dialog, they need to embody the session identifier:/actor/{actorId}/session/{sessionId}/abstract/This scoping signifies that every session will get its personal abstract, whereas nonetheless being organized underneath the actor for cross-session retrieval when wanted.
3. Episodic: Session-scoped with reflection hierarchy
Episodic reminiscence captures full reasoning traces, together with the purpose, steps taken, outcomes, and reflections. As a result of every episode represents what occurred throughout a selected interplay, episodes ought to be scoped to the session, much like summaries. For instance, a flight reserving agent may retailer an episode capturing the way it looked for flights, in contrast choices, dealt with a fare class restriction, and finally rebooked the shopper on another route. That episode belongs to the session the place it occurred. Reflections are cross-episode insights saved at a guardian stage. They generalize learnings throughout periods, as an example “when a fare class restriction blocks a modification, instantly seek for various flights relatively than simply explaining the coverage.” The namespace for reflections have to be a sub-path of the namespace for episodes:
Retrieval patterns
Retrieval APIs
AgentCore Reminiscence supplies three major retrieval APIs for long-term reminiscence, every suited to completely different entry patterns. Selecting the best one is vital to constructing efficient brokers.
1. Semantic search with RetrieveMemoryRecords
Use RetrieveMemoryRecords to seek out reminiscences which might be semantically related to a question. That is the first retrieval methodology throughout agent interactions, surfacing essentially the most related reminiscences primarily based on that means, relatively than actual textual content matching.
The search question can come from two sources:
- Straight from the consumer question – Move the consumer’s query as-is when it naturally maps to the type of data saved in reminiscence. For instance, if the consumer asks “What’s my funds?”, that question works effectively for retrieving choice or truth reminiscences.
- LLM-generated question – For extra complicated situations, have your agent’s LLM formulate a focused search question. That is helpful when the consumer’s uncooked enter doesn’t immediately map to saved reminiscences. For instance, if the consumer says “Assist me plan my subsequent journey,” the LLM may generate a search question like “journey preferences, vacation spot historical past, funds constraints” to retrieve essentially the most related reminiscences. Notice that this provides latency.
2. Direct retrieval with ListMemoryRecords
Use ListMemoryRecords when you could enumerate reminiscences inside a selected namespace reminiscent of, displaying a consumer’s saved preferences in a console UI, auditing what reminiscences exist, or performing bulk operations.
3. GetMemoryRecord and DeleteMemoryRecord
When you realize the precise reminiscence file ID (for instance, from a earlier listing or retrieve name), use GetMemoryRecord for direct lookup or DeleteMemoryRecord to take away a selected reminiscence:
These are helpful for reminiscence administration workflows which might be used to assist customers view, right, or delete particular reminiscences via your utility’s UI.
Namespace vs. NamespacePath: Precise match vs. hierarchical retrieval
AgentCore Reminiscence supplies two distinct fields for scoping retrieval, and understanding the distinction is crucial for proper habits.
1. namespace — Precise match
The namespace area performs an actual match. It returns solely reminiscence information saved at that exact namespace path.
That is the fitting selection when you realize precisely which namespace you wish to question and wish exact scoping. For instance, retrieving solely a consumer’s preferences with out pulling of their info or summaries.
2. namespacePath — Hierarchical retrieval
The namespacePath area performs a hierarchical match, returning the reminiscence information whose namespace falls underneath the required path.
That is helpful whenever you wish to search throughout the consumer’s reminiscences no matter kind, or when constructing options like “present me all the things we find out about this buyer.” Notice that it’s essential that you just suppose via your isolation and retrieval patterns to be sure that tree traversal doesn’t expose unintended information.
When to make use of which
| State of affairs | API | Area | Instance | |
| 1 | Retrieve semantically related consumer preferences | RetrieveMemoryRecords | namespace | /actor/customer-123/preferences/ |
| 2 | Retrieve a selected session abstract | ListMemoryRecords | namespace | /actor/customer-123/session/session-001/abstract/ |
| 3 | Record all preferences for a consumer | ListMemoryRecords | namespace | /actor/customer-123/preferences/ |
| 4 | Search throughout a consumer’s reminiscences | RetrieveMemoryRecords | namespacePath | /actor/customer-123/ |
| 5 | Record summaries throughout periods for a consumer | ListMemoryRecords | namespacePath | /actor/customer-123/session/ |
Writing IAM insurance policies for namespace entry management
Namespaces combine with AWS Id and Entry Administration (IAM) via situation keys that limit which namespaces a principal can embody of their Reminiscence API requests.
1. Precise match insurance policies
Use StringEquals with the bedrock-agentcore:namespace situation key to limit entry to a selected namespace:
This coverage makes certain {that a} consumer can solely retrieve reminiscences from their very own preferences namespace, utilizing the userId principal tag (injected) for dynamic scoping.
2. Hierarchical retrieval insurance policies
Use StringLike with the bedrock-agentcore:namespacePath situation key for hierarchical entry:
With this, a consumer can carry out hierarchical retrieval throughout their namespaces (info, preferences, summaries) whereas serving to forestall entry to different customers’ information.
Conclusion
Namespace design is foundational to constructing efficient reminiscence methods with AgentCore Reminiscence. Very like designing a key schema for a database or a prefix construction in object storage, considering via your entry patterns upfront helps you create a namespace hierarchy that helps exact retrieval, clear isolation between customers, and IAM-based entry management.The important thing takeaways:
- Assume via your entry patterns and isolation boundaries earlier than developing with namespace templates
- Scope semantic and choice reminiscences to the actor (
/actor/{actorId}/) for cross-session consolidation - Scope summaries to the session (
/actor/{actorId}/session/{sessionId}/) since they’re conversation-specific (the place wanted reminiscent of summaries or episodes) - Use
namespacefor actual match when you realize the exact path, andnamespacePathfor hierarchical retrieval when you could search throughout a subtree - Use main and trailing slashes in namespace paths to maintain them constant and assist forestall prefix collisions
- Use IAM situation keys (
bedrock-agentcore:namespaceandbedrock-agentcore:namespacePath) to regulate what namespaces could be requested
To get began, go to the next assets:
In regards to the authors



