Add long-term memory to IBM BeeAI Framework agents.

BeeAI Integration

IBM's BeeAI Framework builds agents with composable tools. Register CortexDB recall + capture as Tools.

Install

pip install cortexdbai[beeai]

Persistent memory

import os
from cortexdb import Cortex
from cortexdb.integrations.beeai import CortexDBMemory

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

# CortexDBMemory implements BeeAI's memory interface.
memory = CortexDBMemory(client=client, scope="org:acme/user:alice")
memory.add("The deployment cadence is every two weeks.")
context = memory.recall("deployment schedule")

Search / store / forget are also available as agent tools — CortexDBSearchTool, CortexDBStoreTool, CortexDBForgetTool, each constructed as (client=client, scope=...).

Prefer manual control?

import os
from datetime import datetime, timezone
from uuid import uuid4
from beeai_framework.tools import Tool
from cortexdb.v1 import V1Client

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


class RecallTool(Tool):
    name = "recall_long_term"
    description = "Recall prior context from long-term memory."

    async def _run(self, input):
        pack = client.recall(scope=SCOPE, view="holistic", query=input["query"],
                             include=["events", "beliefs", "facts", "episodes"],
                             budgets={"max_tokens": 3000})
        return pack.get("context_block", "") or "(no relevant context)"


class CaptureTool(Tool):
    name = "capture"
    description = "Capture a conversation turn into long-term memory."

    async def _run(self, input):
        client.experience(scope=SCOPE, text=input["text"], role=input.get("role", "assistant"),
                          observed_at=datetime.now(timezone.utc).isoformat(),
                          idempotency_key=f"beeai-{uuid4()}")
        return "captured"

See also