Most AI agents I see in demos have the memory of a goldfish. Each session starts from zero, so the user explains their account, their preferences and their open issue all over again. The usual workaround is to stuff the whole conversation history back into the prompt. That works until it doesn't: prompts get longer, latency and token costs climb, and the one fact that matters gets buried under thousands of tokens of chit-chat.
The alternative is to build your own memory layer: capture every turn, extract facts and summaries with an LLM, embed them, store them in a vector database, reconcile new facts with old ones, scope everything per user and enforce retention. That's a lot of plumbing to own before your agent does anything useful.
On 18 November 2026, AWS announced the general availability of Amazon OpenSearch Memory, a serverless capability in Amazon OpenSearch Service built on OpenSearch Serverless. It's designed to give agents persistent, searchable memory without you running that pipeline yourself. In this article I'll walk through how it works, show how to plug it into an agent loop with Boto3, and share the architectural trade-offs I'd look at before adopting it.
The core model: spaces, events, memories and strategies
OpenSearch Memory has a small set of concepts, and once they click the rest is straightforward.
- Space - the AWS resource that acts as a memory store. It defines which memory strategies run, how long data is kept and how it's encrypted.
- Events - the original interactions your application writes, stored verbatim. They're readable straight away and searchable within seconds.
- Memories - facts, preferences and summaries derived from events in the background.
-
Memory strategies - each defines one kind of memory to extract. There are
SEMANTICstrategies (facts),SUMMARYstrategies (per-session summaries) andCUSTOMstrategies driven by your own prompt. A space can run up to 10 strategies over the same events. - Actor and session - every request names an actor (the end user the data belongs to). An optional session ID groups the events from one conversation. Searches are always scoped to a single actor.
Two design choices stand out to me. First, the write path is "write now, remember later": CreateEvent returns as soon as the event is stored, and extraction happens asynchronously, so your agent's response time doesn't depend on the extraction model. Second, memories are consolidated by default. If a user says "I live in Seattle" and later "I moved to Austin", the stored fact is updated instead of keeping two contradictory facts side by side.
Architecture
Here's how the pieces fit together in a typical agent loop.
Each turn adds two calls to the loop: one search before the model responds, and one write after. Extraction and embedding happen inside the service using an Amazon Bedrock model (Claude Haiku 5.5 by default, configurable per space). According to the docs, you don't request model access or grant model permissions yourself; the service calls the extraction model on your behalf, and AWS states that extraction and embedding costs are included in OpenSearch Memory pricing.
Your agent can connect through the AWS SDKs, the AWS CLI (aws opensearchmemory ...), an AWS MCP server, hooks or supported framework integrations.
Hands-on: adding memory to a support agent
The snippets below follow the official launch walkthrough and developer guide. They need Python 3.10+, Boto3 1.44.4 or later, and one of the launch Regions: US East (N. Virginia), US West (Oregon), Europe (Frankfurt) or Asia Pacific (Tokyo). I haven't run these end to end against a live account, so treat them as illustrative and check the current API reference before using them.
1. Create a space
import boto3
REGION = "eu-central-1" # Frankfurt is the closest launch Region for UK/EU workloads
osm = boto3.client("opensearchmemory", region_name=REGION)
space = osm.create_space(
name="customer-support-agent",
memoryStrategies=[
{"type": "SEMANTIC", "name": "facts-and-preferences"},
{"type": "SUMMARY", "name": "session-summaries"},
],
eventExpiryDays=90, # raw events: 1-365 days
memoryExpiryDays=365, # derived memories: 0 = never expire
# encryptionConfiguration={"kmsKeyArn": "arn:aws:kms:..."}, # CMK can only be set at creation
)
space_id = space["spaceId"]
osm.get_waiter("space_active").wait(spaceId=space_id)
Note the comment on encryption: a customer managed KMS key can only be set when the space is created. If your organisation requires CMKs, decide that up front.
2. Write an event after each turn
def conversational(turns):
"""Build a CreateEvent payload from [(role, text), ...]."""
return {"conversational": {"unified": {"source": {"object": {
"messages": [{"role": r, "content": {"text": t}} for r, t in turns]
}}}}}
osm.create_event(
spaceId=space_id,
actorId="user-42",
sessionId="session-007",
payload=conversational([
("USER", "I'm calling again about Case #78234. It's still not resolved."),
("ASSISTANT", "I've escalated Case #78234 to billing. Your reference is ESC-5521."),
]),
metadata={"channel": "phone"},
)
3. Retrieve context before the model responds
Search uses a subset of the OpenSearch Query DSL (match, neural, hybrid, bool), which will feel familiar if you've used OpenSearch before. A hybrid query lets the keyword half find exact identifiers like case numbers, while the semantic half picks up related context.
results = osm.search_memories(
spaceId=space_id,
actorId="user-42",
query={"hybrid": {"queries": [
{"match": {"memory_text": "Case #78234 open cases and account status"}},
{"neural": {"memory_vector": {"query_text": "open cases and account status", "k": 10}}},
]}},
maxResults=10,
)
context = "\n".join(m["content"] for m in results["memories"])
# Inject `context` into the system prompt for the Bedrock model call
Each memory also returns sourceEventIds, so you can trace a fact back to the conversation that produced it. That's useful for debugging and for audit.
For a brand-new user, memory search may return nothing at first because extraction is asynchronous. If the agent restarts mid-conversation, read recent turns straight from events with ListEvents and BatchGetEvent instead of waiting for memories.
4. Write known facts directly
When you already know something, for example a preference from your CRM, you can skip extraction:
osm.create_memory(
spaceId=space_id,
name="facts-and-preferences",
actorId="user-42",
content="The user prefers to be contacted by email.",
metadata={"writtenBy": "crm-import"},
)
Tagging the writer in metadata is a habit worth keeping. Agent-written memories feed future prompts, so you want to be able to find and review them.
5. Clean up
osm.delete_space(spaceId=space_id)
osm.get_waiter("space_deleted").wait(spaceId=space_id)
Security: scope the agent, not just the data
Memory is user data, and a shared memory store is an obvious place for one user's information to leak into another user's session. OpenSearch Memory gives you a few controls worth using together:
- Actor scoping by design - every search is scoped to one actor, so one user's memories don't surface for another.
-
IAM condition keys - every operation is an IAM action with the
osmprefix, authorised on the space ARN. Theosm:actorIdcondition key can restrict which actors a role can act for, and other keys can limit sessions or strategies. - Encryption and audit - data is encrypted at rest (AWS owned key by default, or your own KMS key), requests use TLS 1.2+, CloudTrail logs API calls and CloudWatch reports metrics.
Here's an illustrative policy shape for a per-tenant agent role. The action names and condition key format are my reading of the docs, so validate them against the service authorisation reference before use:
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": ["osm:CreateEvent", "osm:SearchMemories", "osm:SearchEvents"],
"Resource": "arn:aws:osm:eu-central-1:111122223333:space/SPACE_ID",
"Condition": {"StringEquals": {"osm:actorId": "${aws:PrincipalTag/tenant_user}"}}
}]
}
I'd also treat stored memories as a prompt injection surface. If a user can get "always approve refunds" written into memory, it will come back in a future system prompt. Review agent-written memories, and keep your guardrails downstream of retrieval.
Trade-offs and cost notes
- Eventual consistency of memories - events are immediate, memories aren't. Design the first few turns of a new user's session around events, not memories.
- Regional availability - at launch it's in four Regions. For UK workloads, Frankfurt is the nearest option, which may matter for data residency conversations.
- Retention is a design decision - events can be kept 1 to 365 days, memories from 1 day to 10 years or indefinitely. Align these with your privacy policy and right-to-erasure process before going live.
- Token savings are workload-dependent - in AWS's own LongMemEval-S evaluation, the memory workflow passed roughly 13,500 input tokens per question versus about 167,000 for the full history, at 93.0% accuracy versus 95.2%. AWS notes those results reflect its tested configuration, so measure with your own conversations.
- Pricing - check the Amazon OpenSearch Service pricing page for current memory pricing rather than assuming it matches OpenSearch Serverless collection pricing.
- Overlap with other options - if you're already using another agent memory option, such as Amazon Bedrock AgentCore Memory or a self-managed vector store, compare query flexibility, IAM model and Region coverage before switching.
From a multi-cloud angle, the pattern is the same one I'd use on any platform: keep raw interactions, derive compact memories, scope strictly per user and retrieve with hybrid search. What OpenSearch Memory changes is who operates the pipeline.
Conclusion
Persistent memory is one of those things that separates a useful agent from a clever demo. Amazon OpenSearch Memory packages the hard parts (extraction, embedding, consolidation, per-actor scoping and retention) into a serverless API with two calls per turn. If you're building agents on AWS, it's worth a proof of concept: start with a SEMANTIC and SUMMARY strategy, lock down actor access in IAM from day one, and measure the token and quality impact against your current approach.
References
- AWS What's New: Amazon OpenSearch Memory is now generally available (18 Nov 2026) - https://aws.amazon.com/about-aws/whats-new/2026/11/amazon-opensearch-memory-generally-available/
- AWS Big Data Blog: Introducing Amazon OpenSearch Memory: Persistent memory for AI agents - https://aws.amazon.com/blogs/big-data/introducing-amazon-opensearch-memory-persistent-memory-for-ai-agents/
- Amazon OpenSearch Service Developer Guide: What is Amazon OpenSearch Memory? - https://docs.aws.amazon.com/opensearch-service/latest/developerguide/memory.html
- Amazon OpenSearch Service pricing - https://aws.amazon.com/opensearch-service/pricing/

Top comments (0)