Add long-term memory to CAMEL-AI agents.
CAMEL-AI Integration
CAMEL is a multi-agent framework for role-playing and society simulation. Use CortexDB to give the society durable shared memory across runs.
Install
pip install cortexdbai camel-ai
Pattern
import os
from datetime import datetime, timezone
from uuid import uuid4
from camel.toolkits import FunctionTool
from camel.agents import ChatAgent
from camel.messages import BaseMessage
from cortexdb.v1 import V1Client
client = V1Client(api_url="https://api-v1.cortexdb.ai", actor="agent:society",
bearer=os.environ["CORTEX_TOKEN"])
SCOPE = "org:acme/society:research"
def recall_long_term(query: str) -> str:
"""Recall prior context from the society's shared memory."""
pack = client.recall(scope=SCOPE, view="holistic", query=query,
include=["beliefs", "facts", "episodes"],
budgets={"max_tokens": 3000})
return pack["context_block"] or "(no relevant context)"
def capture(text: str, role: str = "assistant") -> str:
client.experience(scope=SCOPE, text=text, role=role,
observed_at=datetime.now(timezone.utc).isoformat(),
idempotency_key=f"camel-{role}-{uuid4()}")
return "captured"
tools = [FunctionTool(recall_long_term), FunctionTool(capture)]
agent = ChatAgent(
system_message=BaseMessage.make_assistant_message(
role_name="Researcher",
content="Use recall_long_term before answering; capture after each turn.",
),
tools=tools,
)