> ## Documentation Index
> Fetch the complete documentation index at: https://docs.maximem.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Maximem Synap is a managed memory layer for AI agents: it ingests conversations and documents, extracts structured memory, and returns scoped context to the agent at retrieval time.
> The Python and JavaScript/TypeScript SDKs are the supported way to use Synap. Write integration code with SDK calls, not raw HTTP requests.
> Start with the Quickstart: https://docs.maximem.ai/getting-started/quickstart.md. Every SDK method is documented in the SDK reference: https://docs.maximem.ai/sdk-reference/overview.md.
> For requests about adding Vity memory to OpenClaw, Hermes, an MCP client, or a browser, start with the Vity Quickstart: https://docs.maximem.ai/vity/quickstart.md.

# CAMEL-AI

> Synap as a native AgentMemory for CAMEL-AI: long-term recall, conversation recording and compacted history layered over the agent's own history.

Give a [CAMEL-AI](https://github.com/camel-ai/camel) `ChatAgent` persistent memory through Synap. CAMEL exposes a first-class pluggable memory interface (`ChatAgent(memory=...)` accepts any `AgentMemory`), and `SynapAgentMemory` plugs Synap in there, plus `@tool` functions and a short-term context helper. The memory also records each turn, tool call and tool result to Synap, and once Synap has compacted the conversation it sends the model Synap's compaction in place of CAMEL's earlier turns.

> [!NOTE]
>
> Requires Python 3.11+ and `camel-ai>=0.2.90`.

## Overview

Three surfaces, mapped onto CAMEL's own extension points. Adopt only the ones you need.

| Surface | CAMEL extension point | Purpose |
| - | - | - |
| `SynapAgentMemory` | `AgentMemory` → `ChatAgent(memory=...)` | Long-term recall, turn recording and compacted history, layered over CAMEL's conversation history |
| `create_synap_tools` | `FunctionTool` | Explicit `search_memory` / `store_memory` the model can call |
| `synap_st_system_message` | `ChatAgent(system_message=...)` | Fold Synap's compaction into the system prompt once, for an agent that does not use `SynapAgentMemory` |

All three take an already-constructed `MaximemSynapSDK`. Your app owns the SDK and its credentials.

## Setup

```bash pip theme={null}
pip install maximem-synap-camel-ai camel-ai
```

```bash uv theme={null}
uv add maximem-synap-camel-ai camel-ai
```

Installing the package also installs `maximem-synap` (0.5.3 or later) and `maximem-synap-integrations-common` (0.2.3 or later). Set `SYNAP_API_KEY` in your environment; `MaximemSynapSDK()` reads it.

```bash theme={null}
export SYNAP_API_KEY=synap_your_key_here
```

## Basic integration

Register Synap as the agent's `AgentMemory`; CAMEL then calls it for context on every turn.

```python theme={null}
import asyncio
import uuid
from camel.agents import ChatAgent
from camel.models import ModelFactory
from maximem_synap import MaximemSynapSDK
from synap_camel_ai import SynapAgentMemory

sdk = MaximemSynapSDK()
asyncio.run(sdk.initialize())  # required: without it every Synap call fails
memory = SynapAgentMemory(
    sdk,
    user_id="alice",
    customer_id="acme",
    conversation_id=str(uuid.uuid4()),  # one UUID per conversation
)

agent = ChatAgent(
    system_message="You are a helpful assistant.",
    model=ModelFactory.create(model_platform="openai", model_type="gpt-4o"),
    memory=memory,            # constructor only, not agent.memory = ...
)
print(agent.step("What did we decide about the rollout?").msgs[0].content)
```

## Core concepts

### SynapAgentMemory

Unlike a bolt-on store, CAMEL's `AgentMemory.get_context()` is the **sole** source of the model's input: it returns whatever the memory's `retrieve()` yields. So Synap **augments** CAMEL's history rather than replacing it: `SynapAgentMemory` subclasses `ChatHistoryMemory` (which keeps the live conversation) and adds two things.

* **Recall.** `retrieve()` returns the real conversation (system + user + assistant) with Synap's long-term memories prepended as a system context block, fetched via `sdk.fetch` using the latest user turn as the query. A Synap blip degrades to the plain local history; recall never crashes the turn.
* **Recording.** Each user and assistant turn is written to Synap as a conversation message under the memory's `conversation_id`. Synap compacts that conversation and turns it into long-term memory in the background, so future sessions remember it.

Attach the memory through the **constructor** (`ChatAgent(memory=...)`). Do not assign `agent.memory = ...` afterward; that path re-runs retrieve/clear/write and would amplify the injected context.

#### What gets recorded

You do not call `listen()` yourself. The first write opens the gRPC stream, and the turn goes on it. The stream gets up to 10 seconds to open. If it cannot open, the turn is written over REST instead, never both, and the stream is tried once more a few seconds later, then no more than once a minute. A stream you opened yourself is used as is. To keep the memory on REST, set `SYNAP_AUTO_LISTEN=false`. See [gRPC vs REST](https://docs.maximem.ai/concepts/grpc-vs-rest.md).

| CAMEL writes | What Synap receives |
| - | - |
| A user record | A user turn |
| An assistant record | An assistant turn, after any reasoning the provider returned |
| An assistant record with tool calls | A tool call for each, with its arguments and the provider's call id |
| A function record | A tool result, under the same id as its call |

Tool calls, tool results and reasoning exist only on the stream, so they are dropped while it is down. A tool result is usually your own customer's data. Synap uses it only as an anticipation hint and never stores it as a long-term memory, but it does leave your process.

CAMEL's own summaries are never written back as turns. When CAMEL's summarizer compacts the history, it adds an assistant `[CONTEXT_SUMMARY]` message and rewrites the last user message; the real turns were already recorded, so those two are skipped, and so is Synap's own history block.

#### Pass your own conversation\_id

By default the conversation id is a UUID derived from the CAMEL agent's id (0.1.4 or later), so the same agent keeps the same conversation across restarts. Pass `conversation_id=` with your own UUID to continue one conversation across different agents or processes, and give the same one to `synap_st_system_message` if you use it.

#### What the model sees

`ChatAgent` builds its input from the memory's `retrieve()`, so that is where Synap's compaction goes. Once Synap has compacted the conversation, every record before the current turn is replaced by CAMEL's system messages, Synap's compaction block (in `<synap_conversation_history>` tags), and the turns recorded after it. The current turn is untouched. CAMEL's own summarizer stays installed: on a history that short it does not fire, and when Synap has no compaction yet, or cannot answer, CAMEL's records are left as they were.

### create\_synap\_tools

For agents that want model-driven memory instead of, or alongside, `SynapAgentMemory`. Returns `search_memory` and `store_memory` as CAMEL `FunctionTool` objects.

```python theme={null}
from synap_camel_ai import create_synap_tools

agent = ChatAgent(
    system_message="You are a helpful assistant.",
    model=ModelFactory.create(model_platform="openai", model_type="gpt-4o"),
    tools=create_synap_tools(sdk, user_id="alice", customer_id="acme"),
)
```

### synap\_st\_system\_message

CAMEL's `system_message` is a static string, so Synap's compaction is folded into it once at construction, inside `<synap_short_term_context>` tags. Nothing is added until Synap has compacted the conversation. With `SynapAgentMemory` on the agent, the live compaction replaces this snapshot on every step, so you only need it for an agent that does not use the memory.

```python theme={null}
import uuid
from synap_camel_ai import SynapAgentMemory, synap_st_system_message

conversation_id = str(uuid.uuid4())  # the same UUID for the memory and the system message

agent = ChatAgent(
    system_message=synap_st_system_message(
        sdk, conversation_id=conversation_id,
        system_message="You are a support agent.",
    ),
    memory=SynapAgentMemory(sdk, user_id="alice", conversation_id=conversation_id),
)
```

`conversation_id` is required. Empty context is a no-op; SDK failures are swallowed by default (`on_error="fallback"`), or set `on_error="raise"` for strict environments.

## Complete example: multi-user support agent

```python theme={null}
import asyncio
import uuid
from camel.agents import ChatAgent
from camel.models import ModelFactory
from maximem_synap import MaximemSynapSDK
from synap_camel_ai import SynapAgentMemory, synap_st_system_message

sdk = MaximemSynapSDK()
asyncio.run(sdk.initialize())  # required: without it every Synap call fails

def build_agent(user_id: str, conversation_id: str) -> ChatAgent:
    return ChatAgent(
        system_message=synap_st_system_message(
            sdk, conversation_id=conversation_id,
            system_message="You are a concise, friendly support agent.",
        ),
        model=ModelFactory.create(model_platform="openai", model_type="gpt-4o"),
        memory=SynapAgentMemory(
            sdk,
            user_id=user_id,
            customer_id="acme",
            conversation_id=conversation_id,
        ),
    )

# One UUID per conversation; store it with the user so a later session can reuse it.
alice_conversation = str(uuid.uuid4())
agent = build_agent("alice", alice_conversation)
print(agent.step("Remind me what plan I'm on and my open ticket.").msgs[0].content)
# → recalls prior context from Synap, answers, and records the turn.
```

## Advanced patterns

### Sync interface, async SDK

CAMEL's `AgentMemory` methods are synchronous, so `SynapAgentMemory` bridges to the async Synap SDK internally (via the shared `run_async` helper). This works whether you drive the agent with `agent.step(...)` (sync) or `agent.astep(...)` (async), but construct the SDK, the memory, and run the agent on **one** asyncio event loop.

### Error policy

* **Reads** (recall, `search_memory`) degrade: a Synap failure returns no recall and the turn continues. A failed compaction lookup leaves CAMEL's own history in place.
* **Turn writes** run inside the agent loop, so they are best-effort by default (`on_error="fallback"`): a transient outage never discards the model's just-produced response. Set `SynapAgentMemory(..., on_error="raise")` to get `SynapIntegrationError` when a turn could not be written.
* **The explicit `store_memory` tool** raises `SynapIntegrationError` on failure.

### Not a vector store

`SynapAgentMemory` deliberately does not reduce Synap to a `VectorDBBlock` behind CAMEL's storage. It owns both the recall shape (Synap's formatted context) and the write pipeline (server-side extraction), which a dumb vector backend would throw away.

## Going further

* **Scoping.** `user_id` and `customer_id` flow straight to Synap; per-user isolation and B2C/B2B scope are derived server-side from the ids you pass.

## Next steps

> [card] [SDK: Ingestion](https://docs.maximem.ai/sdk/ingestion.md)
>
> How `memories.create` extraction differs from conversation recording.

> [card] [Integrations overview](https://docs.maximem.ai/integrations/overview.md)
>
> Every framework Synap plugs into.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.