Skip to main content
Give your CrewAI agents a shared, persistent knowledge base powered by cognee. Agents store information with add_tool and retrieve it via natural language with search_tool — memory that survives across crews and runs.

Why Use This Integration

  • Shared crew memory: Multiple agents read and write the same knowledge graph
  • Semantic recall: Retrieve information using natural language queries
  • Session isolation: Multi-tenant support with per-user/session data separation
  • Drop-in tools: Add add_tool and search_tool to any CrewAI agent

Installation

pip install cognee-integration-crewai
Requires Python 3.10+. Pins cognee>=0.4.0, crewai>=1.5.0, and crewai-tools>=1.5.0.

Quick Start

Set your LLM key, then attach the tools to a CrewAI agent:
export LLM_API_KEY="your-openai-api-key-here"   # or OPENAI_API_KEY
import asyncio
from dotenv import load_dotenv
import cognee
from crewai import Agent
from cognee_integration_crewai import add_tool, search_tool

load_dotenv()

async def main():
    # Optional: start from a clean knowledge base
    await cognee.prune.prune_data()
    await cognee.prune.prune_system(metadata=True)

    agent = Agent(
        role="Research Analyst",
        goal="Find and analyze information using the knowledge base",
        backstory="You are an expert analyst with access to a comprehensive knowledge base.",
        tools=[add_tool, search_tool],
        verbose=True,
    )

    # Store information
    response = agent.kickoff(
        "Remember that our company signed a contract with HealthBridge Systems "
        "in the healthcare industry, starting Feb 2023, ending Jan 2026, worth £2.4M"
    )
    print(response.raw)

    # Query the stored information
    response = agent.kickoff("What contracts do we have in the healthcare industry?")
    print(response.raw)

if __name__ == "__main__":
    asyncio.run(main())

Tools

ToolSignatureDescription
add_tooladd_tool(data: str, node_set: Optional[List[str]] = None)Store information in the knowledge base for later retrieval
search_toolsearch_tool(query_text: str)Search and retrieve stored information with natural language
add_tool queues writes and runs cognee.cognify() after each batch, so data is indexed before searches. Async operations have a default 120-second timeout.

Session Management

Use get_sessionized_cognee_tools(session_id) to isolate data per user or session:
from cognee_integration_crewai import get_sessionized_cognee_tools

user1_add, user1_search = get_sessionized_cognee_tools("user-123")
user2_add, user2_search = get_sessionized_cognee_tools("user-456")

agent1 = Agent(
    role="Assistant",
    goal="Help user 1",
    backstory="You are a helpful assistant.",
    tools=[user1_add, user1_search],
)
If you omit session_id, a UUID-based session ID is generated automatically. Session isolation is implemented by injecting the session ID into the node_set of add_tool.

How It Works

  1. Add Tool: Stores data in cognee’s knowledge graph with embeddings, then cognifies it
  2. Search Tool: Retrieves relevant information via cognee.search()
  3. Auto-Processing: cognee extracts entities, relationships, and context automatically
  4. Background loop: cognee’s async API runs on a dedicated background event loop with safe concurrent writes

GitHub Repository

View source code and examples

Examples

Runnable example scripts