DEV Community

Cover image for Amazon OpenSearch Memory: Give Your Strands Agent Persistent Memory Without Building a Memory System
Jon Handler
Jon Handler

Posted on Edited on Originally published at Medium

Amazon OpenSearch Memory: Give Your Strands Agent Persistent Memory Without Building a Memory System

Your agent already has a model, tools, and a prompt. The fourth piece shouldn't be a side project.

Once an agent talks to the same people more than once, it needs memory, the same way a stateful application needs a database. Teams know this, and many of them end up building it: an embedding pipeline, an extraction prompt, a vector index, deduplication logic, retention jobs, and per-user isolation, all running next to the agent they actually wanted to ship. Amazon OpenSearch Memory, generally available as of November 18, 2026, turns that stack into a service built on Amazon OpenSearch Serverless. This post makes the case that memory belongs in every agent's architecture, explains how OpenSearch Memory works, and wires it into a Strands agent with two calls per turn.

Memory is part of the architecture

Alongside a model to reason, tools to act, and a prompt to set its role, every agent needs a fourth component. Memory lets the agent improve across conversations. A support agent that recalls the open case and the customer's product configuration doesn't ask the customer to repeat themselves. A coding agent that recalls repository conventions and past decisions doesn't make the same mistake twice. An operations agent that recalls how last month's incident was resolved can propose the fix before anyone opens the runbook.

On paper, passing the whole conversation history to the model every time looks like a shortcut. It gets slower and more expensive as history grows, and the one relevant detail gets harder for the model to find. The OpenSearch Service team measured the difference on LongMemEval-S, a public benchmark of 500 questions spread across about 50 chat sessions per user. With the full history in context, the answering model scored 95.2 percent at about 167,000 input tokens per question. With the top 30 results from OpenSearch Memory, it scored 93.0 percent at about 13,500 tokens, roughly one-twelfth the input. Retrieving raw conversation turns with BM25 alone scored 88.6 percent. Your results will differ from this one tested configuration, but extracted and consolidated memory kept most of the accuracy at a fraction of the token cost.

What building it yourself involves

Beyond the transcripts themselves, a working memory system has to extract facts and summaries from raw turns, embed them, and reconcile each new fact with what it already knows. Reconciliation means an updated address replaces the old one instead of sitting next to it. The system also has to retrieve the right few items for the current question, keep one user's memories from ever surfacing for another, and age data out on a schedule your compliance team can sign off on. Then someone has to run it, scale it, and check that the retrieved memories actually make the agent's answers better.

Put together, those pieces add up to a search system with an extraction pipeline attached. For a team whose goal is a better agent, all of that is undifferentiated work.

How Amazon OpenSearch Memory works

At the center of OpenSearch Memory is a space, an AWS resource that acts as the memory store for one application. Your application writes events into the space, and the service derives memories from them.

On the write side, an event records what happened: one or more conversation turns, each with a role and text, or a structured JSON record such as the result of a deployment. OpenSearch Memory stores each event verbatim. It's readable as soon as the write returns and searchable with keyword, semantic, or hybrid queries within seconds. Verbatim storage gives an agent that restarts mid-conversation the exact turns it needs to pick up where it left off.

On the learning side, a memory captures what the agent took away from those events. Memory strategies on the space extract memories in the background, using an Amazon Bedrock model that you choose. A SEMANTIC strategy extracts lasting facts and preferences, a SUMMARY strategy maintains a running summary of each session, and a CUSTOM strategy extracts whatever your own prompt describes, such as every case ID and its status. A space can run up to 10 strategies over the same events. Extraction fires on the first of three triggers: a message count (12 by default), an optional token count, or a period of silence (60 seconds by default). With default settings, new memories are searchable within about a minute after a conversation goes quiet.

Without consolidation, a memory store fills up with every version of every fact. When a strategy extracts a new memory, the service compares it with similar memories it already holds for that user and adds it, updates an existing memory with the newer information, or skips it as a duplicate. If a customer mentions switching from the starter plan to the business plan, the next search returns the business plan, not both. Every memory carries the IDs of the events it came from, so you can trace any fact back to the conversation that produced it.

For scoping, every request carries two IDs. The actor is the end user the data belongs to, and the session groups the turns of one conversation. Every search covers exactly one actor, so one user's memories never surface in another user's results.

Wiring it into a Strands agent

In a Strands agent, memory takes two calls per turn: search before the agent responds, and write after. The setup is a one-time create_space call with the AWS SDK for Python (Boto3) 1.44.4 or later. The launch blog walks through it, along with the event and search calls this wrapper builds on. The space used here runs the SEMANTIC and SUMMARY strategies and keeps raw events for 90 days and memories for a year.

Before each response, the recall step runs a hybrid query against the user's memories and returns them as plain text for the prompt.

def recall(actor_id, question):
    query = {"hybrid": {"queries": [
        {"match": {"memory_text": question}},
        {"neural": {"memory_vector": {"query_text": question, "k": 10}}},
    ]}}
    hits = osm.search_memories(spaceId=SPACE_ID, actorId=actor_id,
                               query=query, maxResults=10)
    return "\n".join(m["content"] for m in hits["memories"])
Enter fullscreen mode Exit fullscreen mode

After each response, the remember step writes the exchange back to the space as one conversational event.

def remember(actor_id, session_id, question, answer):
    turns = [{"role": "USER", "content": {"text": question}},
             {"role": "ASSISTANT", "content": {"text": answer}}]
    payload = {"conversational": {"unified": {"source": {"object": {"messages": turns}}}}}
    osm.create_event(spaceId=SPACE_ID, actorId=actor_id,
                     sessionId=session_id, payload=payload)
Enter fullscreen mode Exit fullscreen mode

With those two functions in place, the Strands side stays short.

from strands import Agent

agent = Agent(system_prompt="You are a support agent for a software company.")

def ask(actor_id, session_id, question):
    context = recall(actor_id, question)
    answer = str(agent(f"Known about this user:\n{context}\n\nUser: {question}"))
    remember(actor_id, session_id, question, answer)
    return answer
Enter fullscreen mode Exit fullscreen mode

Around that wrapper, Strands still runs its own loop over the model and any tools you've given it. The recall step adds what the agent knows about this user to the prompt, and the remember step writes the exchange back as an event. Because the write returns as soon as the event is stored and extraction runs afterward, memory never adds extraction time to the agent's response.

To let the agent decide what to save, wrap CreateMemory in a Strands @tool. The agent can then record its own findings, such as what a case is waiting on. Tag those memories with metadata like writtenBy, because agent-written memories feed later prompts and deserve a review path.

Searching memory like OpenSearch

Because memory search uses a subset of the OpenSearch Query DSL, the queries look familiar. A hybrid query, as in the recall function above, is usually the right fit for agent recall. The keyword half finds exact strings like a case number or a product name, and the semantic half finds paraphrases, such as a question about "how they like to be contacted" matching a stored preference for email.

Inside a bool query, you can filter by metadata tags or creation time without changing the score. A decay function on a time field prefers recent memories without excluding older ones. Once a space holds facts, summaries, and custom records side by side, you can target searches at specific strategies. You can also search events directly to find an exact phrase, such as a commitment the agent made earlier in the conversation.

Isolation, retention, and control

For isolation, the docs recommend one space per application, with users separated by actor ID and environments such as development and production in separate spaces. When end users call the service with their own credentials, the osm:actorId IAM condition key limits each principal to that user's data. Data is encrypted with AWS Key Management Service, with an optional customer managed key. AWS CloudTrail records API activity, and Amazon CloudWatch reports metrics.

On retention, each space sets its own limits. Events can stay from 1 to 365 days, and memories from 1 day to 10 years or indefinitely. OpenSearch Memory removes expired data for you. OpenSearch Memory is available in US East (N. Virginia), US West (Oregon), Asia Pacific (Tokyo), and Europe (Frankfurt).

Bringing it together

Like the model and the tools, memory is a basic part of every agent. Building it yourself means running a search engine, an extraction pipeline, and a consolidation process, plus isolation and retention, alongside the agent. Amazon OpenSearch Memory, built on Amazon OpenSearch Serverless, takes all of that on as a service. For a Strands agent, the change is two calls per turn: search before responding, write after. Create a space, add those two calls, and your agent remembers the next time the same user comes back.

Top comments (0)