555e282cc4
pi-agent-plugin checks / lint (push) Has been cancelled
pi-agent-plugin checks / test (20) (push) Has been cancelled
pi-agent-plugin checks / test (22) (push) Has been cancelled
pi-agent-plugin checks / build (push) Has been cancelled
TypeScript SDK CI / check_changes (push) Has been cancelled
TypeScript SDK CI / changelog_check (push) Has been cancelled
ci / changelog_check (push) Has been cancelled
ci / check_changes (push) Has been cancelled
ci / build_mem0 (3.10) (push) Has been cancelled
ci / build_mem0 (3.11) (push) Has been cancelled
ci / build_mem0 (3.12) (push) Has been cancelled
CLI Node CI / lint (push) Has been cancelled
CLI Node CI / test (20) (push) Has been cancelled
CLI Node CI / test (22) (push) Has been cancelled
CLI Node CI / build (push) Has been cancelled
CLI Python CI / lint (push) Has been cancelled
CLI Python CI / test (3.10) (push) Has been cancelled
CLI Python CI / test (3.11) (push) Has been cancelled
CLI Python CI / test (3.12) (push) Has been cancelled
CLI Python CI / build (push) Has been cancelled
openclaw checks / lint (push) Has been cancelled
openclaw checks / test (20) (push) Has been cancelled
openclaw checks / test (22) (push) Has been cancelled
openclaw checks / build (push) Has been cancelled
opencode-plugin checks / build (push) Has been cancelled
TypeScript SDK CI / build_ts_sdk (20) (push) Has been cancelled
TypeScript SDK CI / build_ts_sdk (22) (push) Has been cancelled
TypeScript SDK CI / integration_ts_sdk (20) (push) Has been cancelled
TypeScript SDK CI / integration_ts_sdk (22) (push) Has been cancelled
147 lines
3.8 KiB
Plaintext
147 lines
3.8 KiB
Plaintext
---
|
||
title: Camel AI
|
||
description: "Plug Mem0 cloud memory into Camel's agents with the built‑in Mem0Storage."
|
||
partnerBadge: "Camel AI"
|
||
---
|
||
|
||
# Camel AI integration
|
||
|
||
Connect Camel's agent framework to Mem0 so every agent can persist and recall conversation context across sessions with minimal setup.
|
||
|
||
<Info>
|
||
**Prerequisites**
|
||
- Mem0: `MEM0_API_KEY` (or self-hosted endpoint), `pip install mem0ai`
|
||
- Camel AI: `pip install camel-ai` (requires Python 3.9+)
|
||
- Optional: OpenAI API key if you run LLM-backed agents
|
||
</Info>
|
||
|
||
<Note>Camel provides a Python SDK today. A TypeScript path is not available yet.</Note>
|
||
|
||
## Configure credentials
|
||
|
||
<Tabs>
|
||
<Tab title="Mem0">
|
||
<Steps>
|
||
<Step title="Export your API key">
|
||
```bash
|
||
export MEM0_API_KEY="sk-..."
|
||
```
|
||
</Step>
|
||
<Step title="(Self-host) Point to your Mem0 API">
|
||
```bash
|
||
export MEM0_BASE_URL="https://your-mem0-domain"
|
||
```
|
||
</Step>
|
||
</Steps>
|
||
</Tab>
|
||
<Tab title="Camel">
|
||
<Steps>
|
||
<Step title="Install Camel with Mem0 dependency">
|
||
```bash
|
||
pip install "camel-ai>=0.2.0" mem0ai
|
||
```
|
||
</Step>
|
||
<Step title="(Optional) Add your model credentials">
|
||
```bash
|
||
export OPENAI_API_KEY="sk-openai..."
|
||
```
|
||
</Step>
|
||
</Steps>
|
||
</Tab>
|
||
</Tabs>
|
||
|
||
<Tip>
|
||
Mem0Storage reads `MEM0_API_KEY` automatically. Pass `api_key` explicitly only when you need to override the environment.
|
||
</Tip>
|
||
|
||
## Wire Mem0 into a Camel agent
|
||
|
||
<Steps>
|
||
<Step title="Create a Mem0-backed memory store">
|
||
```python
|
||
import os
|
||
from camel.storages import Mem0Storage
|
||
|
||
mem0_store = Mem0Storage(
|
||
api_key=os.environ.get("MEM0_API_KEY"),
|
||
agent_id="travel_agent",
|
||
user_id="alice",
|
||
metadata={"source": "camel-demo"},
|
||
)
|
||
```
|
||
</Step>
|
||
<Step title="Attach it to Camel memory">
|
||
```python
|
||
from camel.memories import ChatHistoryMemory, ScoreBasedContextCreator
|
||
from camel.utils import OpenAITokenCounter
|
||
from camel.types import ModelType
|
||
|
||
memory = ChatHistoryMemory(
|
||
context_creator=ScoreBasedContextCreator(
|
||
token_counter=OpenAITokenCounter(ModelType.GPT_4O_MINI),
|
||
token_limit=1024,
|
||
),
|
||
storage=mem0_store,
|
||
agent_id="travel_agent",
|
||
)
|
||
```
|
||
</Step>
|
||
<Step title="Let your agent read and write Mem0">
|
||
```python
|
||
from camel.agents import ChatAgent
|
||
from camel.messages import BaseMessage
|
||
|
||
agent = ChatAgent(
|
||
system_message=BaseMessage.make_assistant_message(
|
||
role_name="Agent",
|
||
content="You are a helpful travel assistant. Reuse stored memories."
|
||
)
|
||
)
|
||
|
||
agent.memory = memory
|
||
|
||
response = agent.step(
|
||
BaseMessage.make_user_message(
|
||
role_name="User",
|
||
content="I prefer boutique hotels in Paris."
|
||
)
|
||
)
|
||
|
||
print(response.msgs[0].content)
|
||
```
|
||
</Step>
|
||
</Steps>
|
||
|
||
<Info icon="check">
|
||
Run `python camel_mem0_demo.py` (or the snippet above in a REPL). You should see the agent respond and the memory persisted to Mem0. Re-running with a new prompt should include the stored preference.
|
||
</Info>
|
||
|
||
## Verify the integration
|
||
|
||
- Mem0 dashboard shows new memories under `agent_id=travel_agent` and `user_id=alice`.
|
||
- `mem0_store.load()` returns the records you just wrote.
|
||
- Camel agent replies reference prior user preferences on subsequent runs.
|
||
|
||
## Troubleshooting
|
||
|
||
- **Missing MEM0_API_KEY**: set `export MEM0_API_KEY="sk-..."` or pass `api_key` into `Mem0Storage`.
|
||
- **No memories returned**: ensure `agent_id`/`user_id` in your query match what you used when writing.
|
||
- **Network errors to Mem0**: if self-hosting, set `MEM0_BASE_URL` to your deployment URL.
|
||
|
||
<CardGroup cols={2}>
|
||
<Card
|
||
title="Memory types in Mem0"
|
||
description="Choose between chat history and semantic search for your Camel agents."
|
||
icon="sparkles"
|
||
href="/core-concepts/memory-types"
|
||
/>
|
||
<Card
|
||
title="Try LangChain next"
|
||
description="Wire the same Mem0 project into LangChain workflows."
|
||
icon="rocket"
|
||
href="/integrations/langchain"
|
||
/>
|
||
</CardGroup>
|
||
|
||
<Snippet file="star-on-github.mdx" />
|