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]

Memory toolkit

import os
from cortexdb import Cortex
from cortexdb.integrations.camel import get_cortexdb_toolkit
from camel.agents import ChatAgent

client = Cortex(
    api_url="https://api-v1.cortexdb.ai",
    actor="user:alice",
    bearer=os.environ["CORTEX_TOKEN"],
)

tools = get_cortexdb_toolkit(client, scope="org:acme/user:alice")
agent = ChatAgent(
    system_message="You are a helpful assistant with long-term memory.",
    tools=tools,
)

CortexDBMemory(client=client, scope=...) implements CAMEL's MemoryBlock (write_record / get_context_text).

Prefer manual control?

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=["events", "beliefs", "facts", "episodes"],
                         budgets={"max_tokens": 3000})
    return pack.get("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,
)

See also