Wire CortexDB long-term memory into the OpenAI Agents SDK.
OpenAI Agents SDK Integration
The OpenAI Agents SDK is the canonical Python framework for building agents on OpenAI's Responses API. Register CortexDB recall and capture as agent tools.
Install
pip install cortexdbai[openai-agents]
Memory tools
import os
from cortexdb import Cortex
from cortexdb.integrations.openai_agents import get_cortexdb_tools
from agents import Agent
client = Cortex(
api_url="https://api-v1.cortexdb.ai",
actor="user:alice",
bearer=os.environ["CORTEX_TOKEN"],
)
tools = get_cortexdb_tools(client, scope="org:acme/user:alice")
agent = Agent(name="Memory Agent", tools=tools)
Individual factories create_cortexdb_search_tool, create_cortexdb_store_tool, create_cortexdb_forget_tool (each (client, scope=...)) are also exported.
Prefer manual control?
import os
from datetime import datetime, timezone
from uuid import uuid4
from agents import Agent, Runner, function_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"
@function_tool
def recall_long_term(query: str) -> str:
"""Pull prior context from long-term 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)"
@function_tool
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"oa-{role}-{uuid4()}")
return "captured"
agent = Agent(
name="Memory Agent",
instructions="Call recall_long_term before answering; call capture after every turn.",
tools=[recall_long_term, capture],
)
result = Runner.run_sync(agent, "What did we decide about Acme's renewal?")
print(result.final_output)