bedrock-memorysync
MemorySync reference architecture for AWS Bedrock agents — two runnable patterns:
MemoryConverseLoop— a memory-augmentedbedrock-runtime.converseloop: recall injected as a system block under a hard budget, both turns persisted with idempotent seeds.- Bedrock Agents action group — a Lambda handler + function schema that gives any Bedrock Agent four memory functions. No memory vendor (including Mem0) ships a Bedrock Agents action-group integration — this is the first.
pip install bedrock-memorysync
Pattern 1 — the Converse loop
import boto3
from bedrock_memorysync import MemoryConverseLoop
loop = MemoryConverseLoop(
bedrock_client=boto3.client("bedrock-runtime"),
model_id="anthropic.claude-3-haiku-20240307-v1:0",
user_id="customer-42", # required
system_prompt="You are a helpful travel assistant.",
)
loop.chat("I always prefer window seats on long flights")
# … a new session, days later:
loop.new_session("support-2")
loop.chat("which seat should I book for the Oslo flight?") # remembers
- Recall runs under
recall_timeout(default 1.2 s) and fails open to a memory-free turn — memory can never delay or break the model call. - Turns persist AFTER the reply with deterministic seeds — retries converge.
- You own the boto3 client (region, credentials, retry policy) — tests drive
it with botocore's
Stubber.
Pattern 2 — Bedrock Agents action group
Deploy the Lambda (SAM):
sam deploy --guided --parameter-overrides MemorySyncApiKey=ms_...
Attach to your agent (function-details schema, importable):
from bedrock_memorysync import FUNCTION_SCHEMA
bedrock_agent.create_agent_action_group(
agentId=agent_id, agentVersion="DRAFT",
actionGroupName="memorysync-memory",
actionGroupExecutor={"lambda": function_arn},
functionSchema={"functions": FUNCTION_SCHEMA},
)
| Function | What it does |
|---|---|
remember |
store a fact/turn (idempotent — agent retries never duplicate) |
recall_context |
prompt-ready block of relevant memories |
search_memories |
scored JSON list (≤25) |
forget_memory |
delete exactly ONE memory by id, loudly |
There is deliberately no delete-everything function — a model-reachable account wipe is a data-loss foot-gun.
Identity ladder (multi-tenant safe): sessionAttributes.memorysync_user_id
(set by your app when invoking the agent) → a user_id parameter → the
Bedrock sessionId. Every failure returns a structured
responseState: FAILURE body the agent can react to — never an unhandled
Lambda error surfaced as a wall of text.
Why not the alternatives?
| AWS AgentCore Memory | Mem0 | MemorySync | |
|---|---|---|---|
| Bedrock Agents action group | n/a (separate runtime) | ✗ none | ✅ first and only |
| Setup | control-plane resource + strategy activation polling (sleep(10) loops) |
✗ OSS-only sidecar: self-hosted Mem0 + OpenSearch you operate ($80–200+/mo) | ✅ one API key |
| Extraction control | ✗ black-box strategies | your own infra | ✅ managed pipeline, server-side gating |
| Cross-platform recall | ✗ AWS-only (actorId inside one account) |
⚠ self-hosted API | ✅ the same memories in LangChain, Flowise, Dify, voice agents… |
| Portability | ✗ total AWS lock-in | ⚠ | ✅ works with any cloud + Bedrock |
| Pricing | 12-component consumption billing | infra + ops | ✅ flat SaaS plans |
Tests
pip install -e . boto3 pytest
pytest tests -q # 28 checks
The suite drives the REAL boto3 client under botocore's Stubber
(system-block injection asserted verbatim) and the Lambda handler with the
documented Bedrock Agents event shapes — including the identity ladder,
idempotent retries, FAILURE response states, and quota modes.
License
MIT © MemorySync.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bedrock_memorysync-1.0.0.tar.gz.
File metadata
- Download URL: bedrock_memorysync-1.0.0.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a5fdfb4c37c5ad46e40923b37ad7e576793270bc64815300c95b9f83b96113a3
|
|
| MD5 |
a65bb71584a20ec3dd29f2de95d8209b
|
|
| BLAKE2b-256 |
4aa764b8791cd960a9417e1f63fc8bf4f65e20aaac86e0bade2fdb88f0eabac6
|
File details
Details for the file bedrock_memorysync-1.0.0-py3-none-any.whl.
File metadata
- Download URL: bedrock_memorysync-1.0.0-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efbff975b63746869e25021a39eba1dee561d042536a39ff94ce7602bb792bad
|
|
| MD5 |
a5a6d855ce5e21a7a23a78f919b8d387
|
|
| BLAKE2b-256 |
13aede12ec78480f07ea7c6f43c2a7550ff9e85b7156fd6b96f16bd4791c2c25
|