Add long-term memory to Agno agents with CortexDB.
Agno
CortexDB provides persistent long-term memory for Agno agents, enabling them to learn, remember, and build context across sessions and conversations.
Installation
pip install cortexdb-agno
Quick Start
from agno.agent import Agent
from cortexdb import Cortex
from cortexdb_agno import CortexDBMemory, CortexDBTools
client = Cortex(base_url="http://localhost:3141")
# Create a memory backend
memory = CortexDBMemory(client=client, tenant_id="my-app")
# Create agent tools
toolkit = CortexDBTools(client=client, tenant_id="my-app")
agent = Agent(
name="Research Assistant",
memory=memory,
tools=toolkit.get_tools(),
)
As a Memory Backend
Use CortexDBMemory as Agno's memory provider to give agents persistent recall:
from cortexdb import Cortex
from cortexdb_agno import CortexDBMemory
client = Cortex(base_url="http://localhost:3141")
memory = CortexDBMemory(
client=client,
tenant_id="my-app",
namespace="research",
top_k=10,
)
# Store memories
memory.add("The quarterly report deadline is March 15th.")
memory.add("Budget for Q2 was approved at $50,000.")
# Search for relevant context
results = memory.search("upcoming deadlines")
# Get formatted context for a prompt
context = memory.get_context("budget information", max_tokens=4096)
# Clear all memories
memory.clear()
Shared vs Per-Agent Memory
# Shared memory — all agents see the same memories
shared = CortexDBMemory(client=client, tenant_id="my-app", namespace="shared")
# Per-agent memory — isolated to each agent
researcher_mem = CortexDBMemory(client=client, tenant_id="my-app", namespace="researcher")
writer_mem = CortexDBMemory(client=client, tenant_id="my-app", namespace="writer")
As Agent Tools
Use CortexDBTools to give agents explicit store, search, and forget capabilities:
from agno.agent import Agent
from cortexdb import Cortex
from cortexdb_agno import CortexDBTools
client = Cortex(base_url="http://localhost:3141")
toolkit = CortexDBTools(client=client, tenant_id="my-app", namespace="tools")
agent = Agent(
name="Knowledge Manager",
tools=toolkit.get_tools(),
instructions="Use CortexDB to store and retrieve important information.",
)
The toolkit provides three tools:
- cortexdb_search — Search for relevant memories using natural language
- cortexdb_store — Save important information for future retrieval
- cortexdb_forget — Remove memories for privacy or data correction
Configuration
| Parameter | Default | Description |
|---|---|---|
| client | Required | Initialized Cortex client instance |
| tenant_id | "default" | Tenant identifier for multi-tenant isolation |
| namespace | None | Namespace for organizing memories |
| top_k | 5 | Maximum results per memory search |
Complete Example
from agno.agent import Agent
from cortexdb import Cortex
from cortexdb_agno import CortexDBMemory, CortexDBTools
client = Cortex(base_url="http://localhost:3141")
# Shared memory backend
memory = CortexDBMemory(client=client, tenant_id="engineering", namespace="standup")
# Tools for the agent to manage its own memory
toolkit = CortexDBTools(client=client, tenant_id="engineering", namespace="standup")
agent = Agent(
name="Standup Bot",
memory=memory,
tools=toolkit.get_tools(),
instructions=(
"You are a standup assistant. Use your memory to track what each "
"team member is working on. Store updates and recall previous "
"context when someone asks about project status."
),
)
# The agent can now:
# 1. Automatically recall relevant past context via memory
# 2. Explicitly store new information via the store tool
# 3. Search for specific information via the search tool
# 4. Remove outdated info via the forget tool