Add persistent memory to Agno agents.
Agno Integration
Agno is a Python framework for building agents with toolkits. Register CortexDB recall + capture as toolkit functions.
Install
pip install cortexdbai[agno]
LLM provider note. This example uses OpenAI for the agent's chat model, but CortexDB itself is LLM-agnostic. The only model CortexDB invokes internally is the one used by
POST /v1/answerandPOST /v1/understanding/synthesize(Claude Opus 4.6 by default, configurable). Your agent's chat model is independent — swapOpenAIChat/gpt-4ofor Anthropic, Gemini, Mistral, Groq, or any local model. CortexDB does not care.
Memory toolkit
import os
from cortexdb import Cortex
from cortexdb.integrations.agno import CortexDBTools
from agno.agent import Agent
from agno.models.openai import OpenAIChat
client = Cortex(
api_url="https://api-v1.cortexdb.ai",
actor="user:alice",
bearer=os.environ["CORTEX_TOKEN"],
)
# CortexDBTools is an Agno Toolkit exposing search / store / forget memory ops.
agent = Agent(
model=OpenAIChat(id="gpt-4o"),
tools=[CortexDBTools(client=client, scope="org:acme/user:alice")],
instructions="Search memory before answering and store new facts after.",
)
CortexDBMemory(client=client, scope=...) is also exported as a plain add / search / clear memory object.
Prefer manual control?
import os
from datetime import datetime, timezone
from uuid import uuid4
from agno.agent import Agent
from agno.tools import Toolkit
from agno.models.openai import OpenAIChat
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 CortexMemoryToolkit(Toolkit):
def __init__(self):
super().__init__(name="cortex_memory")
self.register(self.recall_long_term)
self.register(self.capture)
def recall_long_term(self, query: str) -> str:
"""Recall 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)"
def capture(self, text: str, role: str = "assistant") -> str:
"""Capture a turn into long-term memory."""
client.experience(scope=SCOPE, text=text, role=role,
observed_at=datetime.now(timezone.utc).isoformat(),
idempotency_key=f"agno-{role}-{uuid4()}")
return "captured"
agent = Agent(
model=OpenAIChat(id="gpt-4o"),
tools=[CortexMemoryToolkit()],
instructions="Always recall_long_term before answering and capture after.",
)