Customers of a knowledge-grounded software count on it to recollect them, not solely to go looking properly. They ask follow-up questions that make sense solely within the context of the earlier flip. They count on a solution a few coverage or a process to mirror what they instructed the appliance about themselves final month. They usually nonetheless count on each reply to be grounded within the paperwork they’re allowed to learn, with citations. Whether or not the appliance is a buyer assist assistant, a doc chat inside a SaaS product, or an inside assistant over firm insurance policies, the expectation is similar.
Assembly that expectation is tough, as a result of the context that will sharpen a search lives exterior the information base. A consumer’s location, function, or product tier was usually talked about in an unrelated dialog weeks in the past. To make use of it, the appliance has to retailer each dialog, extract sturdy details from it, determine which details matter for the present query, and inject them into the request. When many customers share the appliance, each a kind of steps additionally needs to be remoted per consumer, and so does each doc.
Amazon Bedrock Managed Information Base and Amazon Bedrock AgentCore reminiscence, a functionality of Amazon Bedrock AgentCore, now take over these steps: storing every dialog, extracting details from it, and bringing the related details into the search. You flip this on by including a memoryConfiguration to the AgenticRetrieveStream request, which makes AgentCore reminiscence a retrieval supply alongside your information base. Inside the similar name, the service restores the dialog, and the planner decides by itself when a truth concerning the consumer would assist. It retrieves that truth from long-term reminiscence and makes use of it to compose the sub-queries it sends to the information base. After producing the reply, the service saves the flip again to reminiscence. The identical request carries a userContext, so the information base returns solely the paperwork that the consumer’s entry management lists (ACLs) permit. The combination is opt-in and backward suitable. Your software retains solely what’s genuinely yours: authenticating the consumer and passing who they’re.
This publish exhibits the best way to construct such an assistant for a lot of customers who share one information base and one reminiscence useful resource. Every consumer sees solely the paperwork they might learn, and every consumer’s reminiscence stays personal. The working instance is an inside worker assistant for AnyCompany, a fictional firm. Workers sign up with Amazon Cognito and ask questions over HR insurance policies, IT guides, engineering runbooks, and gross sales plans. We present the best way to learn the consumer’s id from the Cognito ID token, the best way to move it to AgenticRetrieveStream for doc ACLs and for reminiscence, the best way to design reminiscence namespaces for a lot of customers, and the best way to learn the hint to see when the planner used reminiscence. Lastly, we make AWS Identification and Entry Administration (IAM) implement per-user reminiscence isolation even when software code will get it improper. In the event you deployed the appliance from Construct multi-tenant agentic chat functions on enterprise information with Amazon Bedrock Managed Information Base, this publish replaces its “persist dialog historical past your self” step.
Resolution overview
AnyCompany retains its paperwork in Amazon Easy Storage Service (Amazon S3). One managed information base syncs them by an ACL-enabled Amazon S3 information supply. A worldwide ACL file in the identical bucket says which staff could learn every folder: everybody reads HR and IT, solely engineers learn the engineering runbooks, and solely salespeople learn the fee plan. One AgentCore reminiscence useful resource is shared by each worker. Amazon Cognito authenticates staff, and its ID token provides two claims: the sub (consumer ID) identifies the consumer’s reminiscence, and the verified e mail identifies the consumer to the information base’s ACL filter. Three check customers sign up: two engineers, Maya and Liam, and one salesperson, Sofia. The hint excerpts on this publish are taken from a run of the pattern software within the GitHub repository.
Determine 1: Structure of the memory-aware worker assistant. The applying authenticates the consumer and constructs the request (steps 1–4). Amazon Bedrock Managed Information Base restores the session, retrieves data, returns a solution, and saves the trade to AgentCore reminiscence (steps 5–8). Quick-term occasions and long-term information belong to the identical reminiscence useful resource.
- The worker indicators in with Cognito and receives an ID token, a JSON Internet Token (JWT) signed by the consumer pool.
- The applying’s API validates the token — an Amazon API Gateway JWT authorizer in manufacturing, a small FastAPI service within the pattern. Unauthenticated requests don’t attain the handler.
- The handler reads two claims from the verified token:
subturns into the reminiscenceactorIdand namespace, ande mailturns into theuserContext.userId. The consumer physique carries solely{ query, sessionId? }. The handler then assumes the appliance’s IAM function for this consumer, with the session taguserId=. - The handler calls
AgenticRetrieveStreamwith the information base because the retriever,userContext, and amemoryConfigurationsure to this consumer. - Managed Information Base restores the dialog historical past from short-term reminiscence (STM) in AgentCore reminiscence for the actor and session recognized by
sessionBinding. - Managed Information Base retrieves from the information base with ACL filtering based mostly on
userContext. It may additionally retrieve the consumer’s configured long-term reminiscence by speculative retrieval or reminiscence searches chosen by the planner. - Managed Information Base streams a cited reply and hint occasions again to the handler. The handler information the traces with a correlation ID and forwards the reply and hint data to the UI.
- With
persistenceMode: DEFAULT, the service saves the query and generated reply to the session. AgentCore reminiscence then extracts long-term information asynchronously based on the configured methods.
Determine 2: One AgenticRetrieveStream flip with userContext and memoryConfiguration. Every thing between the primary and final arrow is the service’s work.
Managed Information Base owns ingestion, ACL filtering, indexing, rating, planning, retrieval, and technology. With memoryConfiguration, it additionally owns session restore, reminiscence search, and persistence. AgentCore reminiscence owns storage, retention, encryption, and extraction. Your software owns authentication, the UI, and studying the consumer’s id from the token. There isn’t any dialog desk: when the UI lists or reopens a dialog, it reads the identical reminiscence useful resource.
How id maps to the request
Each worth is derived by the appliance from the verified ID token. None comes from the request physique.
| Request subject | Derived from | What it scopes | Enforced by |
userContext.userId |
ID token e mail (verified, immutable within the pool) |
Which paperwork will be retrieved | Information base ACL filtering |
memoryConfiguration.sessionBinding.actorId |
ID token sub |
Whose short-term reminiscence is restored and written, and the {actorId} in long-term namespaces |
AgentCore reminiscence keying, plus an IAM situation |
memoryConfiguration.sessionBinding.sessionId |
Generated by the appliance for a brand new dialog. Listed with ListSessions |
Which dialog inside that actor | Keyed underneath the actorId |
memoryConfiguration.retrievalConfigs[0].namespacePath |
/anycompany/ |
Which long-term information the planner could search | IAM situation |
Two completely different claims do two completely different jobs. The information base identifies customers by e mail, as a result of that’s what the related information supply information in its ACLs. Reminiscence wants an actorId that by no means modifications and is rarely reused. The Cognito sub is each. An e mail deal with will be modified, or reassigned to a brand new worker after somebody leaves, and that individual would then inherit the previous reminiscence. You need to use one other secure consumer ID from your individual consumer retailer because the actorId. What issues is that it by no means strikes to a special individual.
Conditions
- This walkthrough makes use of a managed information base and an AgentCore reminiscence useful resource within the US West (Oregon) Area (us-west-2). As described within the agentic retrieval documentation, the reminiscence useful resource used with this integration have to be in the identical AWS account because the information base and within the
ACTIVEstate. - Python 3.10 or later and Boto3 1.43.72 or later.
- Permission to create an S3 bucket, a Cognito consumer pool, IAM roles, a information base, and a reminiscence useful resource. The pattern’s
infra/setup.pycreates all of those assets idempotently.
Resolution walkthrough
The next steps create the information base and its information supply, arrange the reminiscence useful resource and Amazon Cognito, construct the request, and skim the hint to verify the consequence.
Step 1: Create the information base with an ACL-enabled information supply
A managed information base wants no vector retailer:
Configure the service function in your setup by following Create a service function for managed Amazon Bedrock Information Bases, and move its ARN in roleArn. For mannequin entry necessities, additionally assessment the stipulations for managed and customized fashions.
Paperwork dwell within the bucket underneath docs/. Amazon S3 has no permission system of its personal to crawl, so that you provide the ACLs in a world ACL file in the identical bucket. Every entry maps an S3 prefix to the emails that will learn it:
The pattern’s file additionally provides everybody docs/it/. Then create the info supply. For a managed information base, each connector has the sort MANAGED_KNOWLEDGE_BASE_CONNECTOR, and connectorParameters.sort picks the supply:
aclEnabled can’t be modified after the info supply is created. CreateDataSource is asynchronous, so watch for the standing AVAILABLE. Then name StartIngestionJob and watch for COMPLETE. The sync reads the paperwork and the ACL file and indexes every doc with its ACL. Within the pattern, all 11 paperwork had been scanned and listed with 0 failures. A doc that no ACL entry covers just isn’t ingested, and a consumer whose e mail matches no entry receives no outcomes from this information supply.
The identical mannequin applies to connectors that crawl permissions from the supply system, reminiscent of Microsoft SharePoint, Google Drive, and Atlassian Confluence. There, the permissions come from the supply, teams are resolved from the supply, and the information base additionally checks every consequence in opposition to the supply in actual time. Your software code doesn’t change: it nonetheless passes the consumer’s e mail in userContext. For the total listing, see Entry Management Lists consciousness enablement.
Step 2: Create the reminiscence useful resource and design namespaces
One reminiscence useful resource serves each consumer. Per-user separation comes from {actorId} within the namespace templates, which AgentCore reminiscence resolves from every occasion at extraction time. Two decisions matter.
Methods. The 2 methods extract various things. The abstract technique summarizes every dialog, so it captures details {that a} consumer mentions in passing, reminiscent of “I’m on a Mac within the Frankfurt workplace.” These details are what personalize a later reply about, say, PTO. The user-preference technique extracts said preferences into structured information (“Prefers quick bullet-point solutions with out tables”, “At all times deploys to eu-central-1 first”) and doesn’t deal with incidental mentions as preferences. Summaries offer you “what we mentioned.” Preferences offer you “how this individual desires to be answered.” Use each.
Structure. retrievalConfigs accepts one entry, so a single namespacePath should attain every thing the planner ought to see for a consumer. Put {actorId} instantly underneath the basis: namespacePath: "/anycompany/" then covers the profile and each dialog abstract. A format reminiscent of /anycompany/profile/{actorId} and /anycompany/summaries/{actorId} would let one entry attain solely one among them.
Await the reminiscence to achieve ACTIVE. Creating the reminiscence doesn’t want a consumer or actorId, so the order of Step 2 and Step 3 doesn’t matter. Nothing is provisioned per consumer: a brand new Cognito consumer turns into a brand new actor the primary time they ask a query.
Step 3: Arrange Cognito and grant the appliance permissions
Create a consumer pool and an app consumer with out a consumer secret. The e-mail decides which paperwork a consumer could learn, so make it required, verified, and never changeable by the consumer:
Mutable can’t be modified after the pool is created. With a mutable e mail, a signed-in consumer may change their e mail to a colleague’s deal with. In case your customers federate from Okta or Microsoft Entra ID, map the IdP’s e mail to this attribute in order that it matches the e-mail in your information supply’s ACLs.
The pattern allows USER_PASSWORD_AUTH so the native UI and checks can sign up instantly. Manufacturing functions usually use Cognito managed login or AWS Amplify.
Arrange an IAM function for the appliance. The backend assumes it as soon as per consumer, with the session tag userId=, and each reminiscence assertion is conditioned on that tag. That is the entire coverage the pattern runs with:
ListEvents is required with sessionBinding, RetrieveMemoryRecords with retrievalConfigs, and CreateEvent when persistenceMode is DEFAULT. ListSessions and ListMemoryRecords are for the appliance’s personal reads (dialog listing and the “what reminiscence is aware of about you” view), not for AgenticRetrieveStream. The function’s belief coverage permits sts:AssumeRole, sts:TagSession, and sts:SetSourceIdentity from the backend’s personal id (an AWS Lambda execution function or an Amazon Elastic Container Service (Amazon ECS) activity function in manufacturing). If the reminiscence makes use of a buyer managed key, add kms:Decrypt on that key.
Step 4: Learn the consumer from the token, then construct the request
Confirm the ID token and skim the 2 claims. Solely the ID token carries e mail. The entry token doesn’t:
jwt.decode checks the signature, the issuer (your consumer pool), the expiry, and the viewers (your app consumer). For particulars of the claims, see Understanding the id (ID) token. With API Gateway, a JWT authorizer does the identical checks and passes the claims to your handler.
Subsequent, get the consumer’s AWS credentials. The backend assumes the appliance function for this consumer and caches the session till shortly earlier than it expires:
Each name for this consumer, together with the reminiscence calls that agentic retrieval makes on the caller’s behalf, now runs as assumed-role/anycompany-assistant-app-role/user- and carries the tag that the coverage in Step 3 checks.
Resolve the sessionId. For a brand new dialog, the appliance generates one, reminiscent of "conv-" + uuid4().hex, and returns it to the consumer. To proceed a dialog, the consumer sends it again. To point out a consumer their conversations, name ListSessions with the consumer’s actorId:
You do not want your individual desk that maps customers to periods. Accepting a sessionId from the consumer is secure as a result of short-term reminiscence is keyed by (memoryId, actorId, sessionId), and the actorId comes from the token. If Liam sends Maya’s sessionId, it names a session inside Liam’s personal house, which is empty. Agentic retrieval itself doesn’t confirm that the actorId, sessionId, or namespace you provide belong to the consumer who’s asking, so they need to by no means come from the consumer. Preserve your individual session desk provided that you want information that reminiscence doesn’t maintain, reminiscent of dialog titles.
Then construct the request:
With out userContext, an ACL-enabled information supply returns no outcomes in any respect. Examine the request with the stateless handler it replaces:
The question earlier than the decision and the write after it are gone, and messages has one aspect. Three guidelines include sessionBinding, and every is enforced with a particular ValidationException. First, messages carries solely the present query, so that you select one historical past supply per request. Second, persistenceMode: DEFAULT (the default) writes the query and the generated reply as one occasion, so it requires generateResponse: true. Third, memoryId alone is invalid. persistenceMode: NONE restores historical past and writes nothing, for audit or replay views.
Step 5: Replace the consumer contract and render historical past
The consumer sends { query, sessionId? }. On a brand new dialog, the appliance generates a sessionId and returns it as the primary streamed body. The consumer echoes it on later turns and omits it to begin over.
As a result of the reminiscence useful resource is yours, the appliance reads it on to render a dialog:
Every continued flip is precisely one occasion with two payloads: the consumer’s query and the ultimate reply. The historical past subsequently renders as a clear transcript and stays usable by different AgentCore reminiscence shoppers.
Step 6: Confirm from the hint
The hint tells you, per flip, what the information base and reminiscence did:
| Hint occasion | When it seems | What to take a look at |
SessionHistoryLoad |
First occasion, at any time when sessionBinding is ready |
_memory_event_count and _memory_message_count, each 0 on a brand new session |
SpeculativeRetrieval |
Earlier than planning | On a brand new session, retrievalMetadata additionally lists BedrockAgentCoreMemory. Reminiscence gadgets carry _memory_* metadata and no textual content. Information base gadgets carry _source_uri |
Planning |
Every iteration | actions[].memoryRetrieve means the planner selected to go looking reminiscence, with a question it composed |
Retrieval with retrievalType: BedrockAgentCoreMemory |
Per deliberate reminiscence motion | _memory_record_count. A depend of 0 is a traditional consequence |
A reminiscence occasion with standing: FAILED |
Reminiscence unavailable or entry denied | failures[].message. Reminiscence is best-effort: the request continues and the reply is generated from the information base |
The next runs present the conduct. Excerpts are verbatim, trimmed for size.
Doc ACLs: Maya and Sofia, similar query. “What’s the weekly on-call stipend?” The on-call information is in docs/engineering/. Maya’s retrieval included docs/engineering/oncall.md, and the reply was “500 USD or 450 EUR per week.” Sofia’s speculative retrieval and the planner’s follow-up sub-query returned solely HR and gross sales chunks:
Her reply mentioned that no on-call stipend is documented within the sources she will be able to entry. The applying made no entry resolution. It handed userContext.userId: "sofia@instance.com", and the information base did the filtering. The reverse holds for the fee plan: Sofia will get the 12% accelerator, and Maya’s retrieval doesn’t comprise docs/gross sales/.
Flip 1: Maya, new dialog. “How do I arrange the VPN on my laptop computer? I’m on a Mac within the Frankfurt workplace.”
The reply provides the Frankfurt gateway (vpn-fra.anycompany.instance) and the macOS steps. Afterwards, ListEvents on the session exhibits one occasion with two payloads.
Flip 2: Maya, similar dialog. “It retains disconnecting each jiffy. What ought to I attempt?” The request carried solely that sentence:
The planner despatched retrieve("VPN disconnects each jiffy troubleshooting") and retrieve("Cisco Safe Consumer macOS frequent disconnect repair"). The reply resolved “it” and pointed at iCloud Personal Relay, the macOS-specific trigger within the information. On a continued session, SpeculativeRetrieval queries solely the information base. The long-term reminiscence lookup in that step occurs on new periods.
Flip 3: Maya, a brand new dialog, later. “What number of days of PTO do I get per 12 months, and do unused days carry over?” Her workplace decides the reply, and she or he by no means talked about it on this dialog. Speculative retrieval searched long-term reminiscence with the uncooked query and located one report:
Information base and reminiscence gadgets share one retrievalResponse. Inform them aside by sourceRetriever.identifier or by the _memory_* keys. The report was the abstract of her VPN dialog. That was sufficient: the planner went straight to the reply, which mentioned “Since your reminiscence signifies you’re based mostly within the Frankfurt workplace … you get 30 days of PTO per 12 months, granted in full on January 1, and any unused days have to be utilized by March 31 of the next 12 months.” A truth from an IT dialog customized an HR reply.
Flip 4: Liam, new dialog, similar query. Similar handler, similar reminiscence useful resource, a special token. Speculative retrieval discovered nothing about him, so the planner determined to go looking reminiscence with its personal question:
Liam obtained the desk of all three places of work and a request to say which one he’s in. The applying chooses the place the planner could look. The planner decides whether or not to look and what to ask: a memoryRetrieve motion seems solely when the planner decides that one other reminiscence search would assist. Studying Maya’s sessionId by the historical past endpoint with Liam’s token returned an empty listing.
![]() |
![]() |
Determine 3: The identical query from two customers. Maya’s hint exhibits a reminiscence hit and a Frankfurt-specific reply. Liam’s hint exhibits zero reminiscence information and the generic desk.
Lengthy-term extraction is asynchronous and runs after the flip is continued. In our run, the primary report appeared 81 seconds after flip 2, however the timing just isn’t a dedication. Design for eventual availability. A truth said on this dialog just isn’t assured to be retrievable within the subsequent one instantly. The pattern polls ListMemoryRecords earlier than working flip 3.
Safety and multi-user isolation
On this walkthrough, the appliance authenticates. The information base filters. ACL-aware retrieval is filtering, not authorization. Take the e-mail solely from a verified ID token with email_verified: true, make it immutable within the pool, and deal with e mail reuse: if an deal with is reassigned to a special individual, that individual will get the previous proprietor’s doc entry. The information base fails closed: a doc with no ACL, or an ACL error, means fewer outcomes, not further ones. If outcomes are lacking, verify that the e-mail matches the ACL entry.
Identification comes from the token (Step 4) for reminiscence too: actorId and namespace come from the verified sub, by no means from the consumer.
IAM situation keys, as protection in depth. AgentCore reminiscence exposes bedrock-agentcore:actorId on ListEvents, CreateEvent, and ListSessions, and bedrock-agentcore:namespacePath on RetrieveMemoryRecords and ListMemoryRecords. The reminiscence calls that agentic retrieval makes throughout a request are approved in opposition to the calling id. That’s the reason the caller’s coverage should grant these actions, and why the circumstances in Step 3 apply to them. With the session assumed for Maya, a request sure to Maya’s actorId proceeds usually. A request that binds Liam’s actorId is the bug that this coverage guards in opposition to, and it’s denied at each reminiscence operation:
Nothing was written to Liam’s reminiscence: his session depend stayed at 0. The reply was nonetheless generated from the information base. As a result of every consumer has their very own function session, AWS additionally sees which consumer every name is for: the caller is assumed-role/anycompany-assistant-app-role/user- with SourceIdentity=, which the session holder can not change.
Two additional factors. The reminiscence is a customer-owned useful resource that different techniques in your account can also write to. Deal with its contents as enter, and connect an Amazon Bedrock guardrail to the request by policyConfiguration. And plan the info lifecycle. Uncooked occasions expire per eventExpiryDuration, however extracted information don’t. A user-deletion workflow subsequently covers DeleteEvent for the actor’s periods and DeleteMemoryRecord underneath the actor’s namespace.
Observability and failure conduct
Log the total hint with a correlation ID per flip. The planner’s sub-queries are as value auditing as its closing outcomes. AWS/Bedrock/KnowledgeBases stories Invocations, ClientErrors, and TotalIterationCount for Operation=AgenticRetrieveStream. AWS/Bedrock-AgentCore stories Invocations, Latency, Errors, and UserErrors per reminiscence operation, and InputTokenUsage/OutputTokenUsage per technique for extraction. With Amazon CloudWatch Transaction Search enabled, AgentCore Observability, a functionality of Amazon Bedrock AgentCore, exhibits a flip’s spans finish to finish.
Reminiscence operations are best-effort by design. If a reminiscence name fails or is denied, the request doesn’t fail. The hint carries a FAILED reminiscence occasion with the failure message, and the flip continues with out that reminiscence. The reply is generated from the information base. Resolve whether or not your UI surfaces that degraded state.
Issues
- Use a secure
sessionIdfor the lifetime of a dialog. The API accepts a contemporary ID per request, however a contemporary ID silently breaks continuity and produces one abstract report per flip. - Use
namespacePathto achieve all of a consumer’s long-term information.retrievalConfigsaccepts one entry with as much as 5metadataFilters.namespacematches by prefix andnamespacePathmatches by hierarchy, sonamespacePathmatches per-user IDs underneath the basis. Provide namespaces absolutely resolved, as a result of a template reminiscent of/anycompany/{actorId}is rejected. - Count on solely
USERandASSISTANTconversational occasions to be restored. Occasions with theTOOLorOTHERfunction that different techniques write are skipped. - Preserve sending
messagesas a substitute ofsessionBindingwhen your software wants to regulate precisely which historical past every request carries. For instance, your present historical past retailer stands out as the system of report for conversations, or you could edit or redact historical past earlier than sending it. WithsessionBinding, the service restores and persists the dialog for you. You may’t mix the 2 in a single request. - A request can carry as much as 5 information bases. With a couple of retriever, the planner routes every sub-query based mostly on the information base
description, so write it fastidiously. - Plan for latency and value. The session restore provides on the order of 200 milliseconds. In our runs, a full flip with one information base, ACLs, and reminiscence took 4–10 seconds with the managed mannequin. Planning iterations drive that point, not reminiscence. These are noticed figures, not service commitments. Agentic retrieval is priced per name plus underlying retrievals, and the reminiscence operations made in the course of the name are billed as AgentCore reminiscence utilization. For particulars, see Amazon Bedrock pricing and Amazon Bedrock AgentCore pricing.
Clear up
Run python infra/teardown.py within the pattern to delete the information base, the S3 bucket and its objects, the reminiscence useful resource (together with dialog historical past and long-term information), the Cognito consumer pool, and the IAM roles.
Conclusion
Amazon Bedrock Managed Information Base already gave you the retrieval stack as a service. That stack covers ingestion, doc ACLs, indexing, rating, and the planning loop in AgenticRetrieveStream that turns a tough query right into a cited reply. With memoryConfiguration, the identical name now carries the dialog and the consumer’s historical past. For a multi-user software, that eliminated the dialog retailer, the historical past replay, and the extraction pipeline. What remained was a brief listing of tasks. Authenticate the consumer and skim two claims from the ID token: move the verified e mail as userContext in order that the information base filters paperwork, and use the sub because the actorId for one reminiscence useful resource with {actorId}-rooted namespaces. Use IAM situation keys on a per-user function session as a second line of protection that holds by the agentic path.
To get began, deploy the pattern from the GitHub repository. Then learn the AgenticRetrieveStream API reference, Entry Management Lists consciousness enablement, and Use AgentCore reminiscence with agentic retrieval. For the retrieval loop itself, see Agentic retrieval for Amazon Bedrock Managed Information Base. For reminiscence ideas, see Amazon Bedrock AgentCore reminiscence: Constructing context-aware brokers.
In regards to the authors




