Skip to main content

camel-memorysync

MemorySync memory for CAMEL agents.

Two pieces, use either or both:

  • MemorySyncMemory — a drop-in AgentMemory for ChatAgent(memory=...): verbatim chat history plus semantic recall from MemorySync, injected as one scored context record under a hard latency budget. Zero client-side embeddings.
  • MemorySyncStorage — a lossless BaseKeyValueStorage for ChatHistoryMemory that keeps the full history locally and sends the user's turns to MemorySync out of band, where only the durable facts in them are stored.
pip install camel-memorysync

Quickstart

from camel.agents import ChatAgent
from camel_memorysync import MemorySyncMemory

memory = MemorySyncMemory(
    user_id="customer-42",      # required — who these memories belong to
    session_id="support",       # conversation scope
)
agent = ChatAgent(system_message="You are a helpful travel assistant.", memory=memory)

agent.step("I always prefer window seats on long flights")
# … days later, a new session:
agent.step("which seat should I book for the Oslo flight?")   # remembers

The API key comes from the MEMORYSYNC_API_KEY environment variable (or api_key=...).

Why not the in-repo Mem0 storage?

CAMEL ships Mem0Storage in its repo. Verified against its source:

Behavior Mem0 (Mem0Storage, in-repo) camel-memorysync
History round-trip ✗ broken — load() returns extracted facts, not your messages byte-exact: from_dict reconstructs every record
Message roles ✗ every record hardcoded role=USER — OpenAI alternation breaks preserved exactly
clear() blast radius ✗ calls client.delete_users() — the entire user entity local window only; remote wipes are explicit (forget_session() / forget_user())
agent_id filter ✗ silently overwritten by user_id filter both preserved per record
Failures ✗ every exception swallowed — callers never know conversation always works, failures logged loudly; explicit deletes raise
Multimodal ✗ image_list / video_bytes silently discarded full media round-trip (base64)
Recall latency guard none 1.2 s hard budget, fails open to history-only
Retried saves duplicated deterministic speaker seeds: a retried turn is recognised and extracted once

VectorDBMemory (CAMEL's own long-term option) needs client-side embeddings — OpenAIEmbedding() by default (extra key, cost, latency) plus a vector DB you operate. Recall here is one MemorySync query; the index lives server-side.

How recall enters the context

ScoreBasedContextCreator sorts records by timestamp. The recall block is one SYSTEM-role record with timestamp=0.0, so it lands right after the system prompt — your history is never reordered, rewritten, or role-swapped:

[system]  You are a helpful travel assistant.
[system]  Relevant long-term memories about this user:
          - Prefers window seats on long flights
[user]    which seat should I book for the Oslo flight?

Memories created by other MemorySync surfaces (LangChain, the CLI, voice agents, coding agents…) are recallable inside CAMEL too — that is the point of memory-as-a-service.

Storage-seam usage (ChatHistoryMemory)

from camel.memories import ChatHistoryMemory, ScoreBasedContextCreator
from camel.types import ModelType
from camel.utils import OpenAITokenCounter
from camel_memorysync import MemorySyncStorage

memory = ChatHistoryMemory(
    context_creator=ScoreBasedContextCreator(OpenAITokenCounter(ModelType.GPT_4O_MINI), 2048),
    storage=MemorySyncStorage(user_id="customer-42", session_id="support"),
)

save() keeps verbatim records locally (exact round-trip) and sends each user turn to MemorySync, which extracts the durable facts in it ("Prefers window seats") and stores only those; the turn text itself is not stored server-side, and filler is skipped. Assistant replies are not sent — they are not stored as memories — and system prompts and tool chatter never leave the process. A retried save is recognised server-side, so each turn is extracted once.

Deletion — designed against data loss

Call What happens
clear() resets the LOCAL conversation window only
forget_session() deletes the facts extracted from THIS session's turns and returns the number deleted (loud — failures raise)
forget_user() deletes the facts extracted from all of this user's CAMEL turns (every camel-surface memory) and returns the number deleted; other surfaces' memories survive

Configuration

Parameter Default Meaning
user_id — (required) End user the memories belong to
session_id default Conversation scope, carried by the facts extracted from its turns
top_k 5 Memories per recall
recall_timeout 1.2 Hard recall budget (seconds)
min_query_chars 8 Skip recall for trivial topics
window_size unlimited History records per turn
extraction True Send the user's turns to MemorySync for fact extraction
context_creator ScoreBased/GPT-4o-mini/2048 Any BaseContextCreator

Note on dependencies

camel-ai 0.2.x imports FastMCP from mcp.server, which mcp 2.0 moved — an unpinned install crashes at import camel.agents. This package pins mcp<2 until CAMEL supports mcp 2.

Tests

pip install -e . pytest
pytest tests -q   # 33 checks against the real camel-ai at latest

The suite drives a REAL ChatAgent turn via CAMEL's own StubModel and reproduces each in-repo Mem0Storage bug as a regression test.

License

MIT © MemorySync.

Metadata

Release files for camel-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 camel-memorysync 1.1.0
File Size Uploaded
camel_memorysync-1.1.0.tar.gz 11.9 kB Details

Built distribution (wheel)

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

Total release size: 26.8 kB

Release files / camel_memorysync-1.1.0.tar.gz

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

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

Download URL camel_memorysync-1.1.0-py3-none-any.whl
Size 14.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
341563c212c8c1c098371decd7ad7017b76a5e18b057c6de7d8a3e1b9eba070c
BLAKE2b-256 checksum
How to use checksums
204b1aa839ddf4c9f8d21bc21bbfc84ca3b10bb316f23f07f60b39491d0c4aae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.5

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

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