Skip to main content

bedrock-memorysync

MemorySync reference architecture for AWS Bedrock agents — two runnable patterns:

  1. MemoryConverseLoop — a memory-augmented bedrock-runtime.converse loop: recall injected as a system block under a hard budget, and the user's message sent to fact extraction after each reply (only durable facts become memories; assistant replies are not stored).
  2. 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.
  • After the reply, the user's message goes to fact extraction with a deterministic seed: MemorySync stores the durable facts in it (preferences, personal details, decisions), not the text itself, and recognises a retried turn so it is processed once. Assistant replies are not stored as memories, so the loop does not send them.
  • 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 send what the user said to fact extraction — only the durable facts in it are stored; agent retries are recognised and not processed twice
recall_context prompt-ready block of relevant memories
search_memories scored JSON list (≤25)
forget_memory delete exactly ONE memory by id, loudly

remember tells the agent what happened: status: "accepted" with stored_as: "facts" when the text went to fact extraction, or status: "skipped" with the reason in processing_status and message — an assistant turn (not stored as a memory), nothing worth remembering, the monthly quota, or already_exists: true when the same text was already sent. It never reports a memory id: facts are extracted asynchronously and get their own ids.

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   # 41 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.

Metadata

Release files for bedrock-memorysync 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bedrock-memorysync 1.1.0
File Size Uploaded Provenance
bedrock_memorysync-1.1.0.tar.gz 13.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bedrock-memorysync 1.1.0
File Interpreter ABI Platform
bedrock_memorysync-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 29.8 kB

Release files / bedrock_memorysync-1.1.0.tar.gz

Download URL bedrock_memorysync-1.1.0.tar.gz
Size 13.7 kB
Tags Source
SHA-256 checksum
How to use checksums
85b79a744b9b3437b68971f2c3f5cdc774323bd386be440074bf6d689f58259a
BLAKE2b-256 checksum
How to use checksums
cea679760a4523eb215818da3b8f1fa0421ce5ede4fc27b4723b926e4291c0be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.5

Release files / bedrock_memorysync-1.1.0-py3-none-any.whl

Download URL bedrock_memorysync-1.1.0-py3-none-any.whl
Size 16.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7b27ec7384f36bb158d7686bd624c55d4fb4aeb30e6fee71587eb97babc3169c
BLAKE2b-256 checksum
How to use checksums
a667668b57f1fda4f00e4783eec1409d2447ef7f64b886f1b19256f350f8def2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.5

Security for bedrock-memorysync 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page