Add long-term memory to CrewAI agents and crews.

CrewAI Integration

CortexDB provides persistent long-term memory for CrewAI agents, enabling crews to learn and remember across task executions.

Installation

pip install cortexdbai[crewai]

Setup

from crewai import Agent, Task, Crew
from cortexdb.integrations.crewai import CortexMemory

memory = CortexMemory(
    api_key="your-cortex-api-key",
    tenant_id="my-app",
)

researcher = Agent(
    role="Senior Researcher",
    goal="Find relevant technical context",
    backstory="You are a senior engineer with deep institutional knowledge.",
    memory=memory,
)

writer = Agent(
    role="Technical Writer",
    goal="Write clear technical documentation",
    backstory="You produce excellent technical docs.",
    memory=memory,  # Shared memory across agents
)

task = Task(
    description="Write a summary of our database migration decisions.",
    agent=writer,
)

crew = Crew(
    agents=[researcher, writer],
    tasks=[task],
)

result = crew.kickoff()

Shared vs Per-Agent Memory

# Shared memory (all agents see the same memories)
shared_memory = CortexMemory(tenant_id="my-app")

# Per-agent memory (isolated via tenant_id)
researcher_memory = CortexMemory(tenant_id="my-app-researcher")
writer_memory = CortexMemory(tenant_id="my-app-writer")

Under the Hood

The integration wraps CortexDB's REST API. Here are the equivalent calls:

# remember() — store a conversation turn
curl -X POST https://api.cortexdb.ai/v1/remember \
  -H "Authorization: Bearer your-cortex-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "Database migration decision: use PostgreSQL for the user service.",
    "tenant_id": "my-app"
  }'
# Returns: { "event_id": "evt_abc123" }

# recall() — retrieve relevant context
curl -X POST https://api.cortexdb.ai/v1/recall \
  -H "Authorization: Bearer your-cortex-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "database migration decisions",
    "tenant_id": "my-app"
  }'
# Returns: { "context": "...", "confidence": 0.91, "latency_ms": 12 }

Configuration

| Parameter | Default | Description | |---|---|---| | api_key | $CORTEX_API_KEY | CortexDB API key | | tenant_id | Required | Tenant identifier |