Skip to main content

A powerful integration between Strands and Cognee providing intelligent knowledge management and retrieval capabilities for AI agents

Project description

Cognee-Integration-Strands

A powerful integration between Cognee and Strands that provides intelligent knowledge management and retrieval capabilities for AI agents.

Note: This package requires Python 3.10+.

Overview

cognee-integration-strands combines Cognee's memory layer with the Strands Agents framework. Build agents that store, search, and recall information from a persistent knowledge graph — plus a fast session cache.

Features

  • Smart Knowledge Storage: Persist information into Cognee's knowledge graph.
  • Semantic Search: Retrieve relevant information with natural-language queries.
  • Two memory tiers: a permanent knowledge graph plus a fast session cache you persist with improve().
  • Strands Integration: Drop-in tools for the Strands Agent.
  • Background Async Support: Cognee's async API is driven on a background thread, so the synchronous Strands tools just work.

Upgrading from 0.1.x ⚠️

0.2.0 moves the integration to cognee v1.0 and replaces the old tool API. It's a breaking change with no compatibility shim — update your imports:

0.1.x 0.2.0
from cognee_integration_strands import add_tool, search_tool from cognee_integration_strands import cognee_tools
add_tool, search_tool = get_sessionized_cognee_tools("user-1") tools = cognee_tools(session_id="user-1")
Agent(tools=[add_tool, search_tool]) Agent(tools=cognee_tools())
cognee>=0.4.0,<0.5.4 cognee>=1.0.0,<=1.1.2
strands-agents>=1.18.0 strands-agents>=1.42.0

In 0.1.x a session_id tagged data to isolate it per user. In 0.2.0 it routes writes to cognee's session cache; run cognee.improve(session_ids=[session_id]) to persist a session into the permanent graph (see Session Management).

Installation

pip install cognee-integration-strands

The examples drive an OpenAI model, which needs the Strands openai extra:

pip install "strands-agents[openai]"

Quick Start

import os
import cognee
from cognee_integration_strands import cognee_tools, run_cognee_task
from strands import Agent
from strands.models.openai import OpenAIModel

run_cognee_task(cognee.forget(everything=True))  # optional: start fresh

model = OpenAIModel(client_args={"api_key": os.getenv("LLM_API_KEY")}, model_id="gpt-4o")
agent = Agent(model=model, tools=cognee_tools())

# Store information
agent("Remember that we signed a contract with Meditech Solutions for £1.2M.")

# Retrieve it (even from a fresh agent — memory is persistent)
print(agent("What is the value of the Meditech Solutions contract?"))

Available Tools

from cognee_integration_strands import cognee_tools

# cognee_tools() -> [remember, recall]
#   remember: store information   (cognee.remember)
#   recall:   retrieve information (cognee.recall)

Pass cognee_tools(session_id=...) to route writes through cognee's session cache.

Session Management

A session_id selects cognee's session cache tier instead of the permanent graph:

  • No session_idremember writes straight to the permanent knowledge graph.
  • With session_idremember writes to that session's cache (cheap, no graph extraction); recall is session-aware.
  • cognee.improve(session_ids=[session_id]) → promotes a session's cached entries into the permanent graph.

So an agent can capture context cheaply during a session, then persist the useful parts later. Pass remember_kwargs={"self_improvement": False} to keep cached writes out of the graph until you call improve() (otherwise cognee bridges them in the background).

import cognee
from cognee_integration_strands import cognee_tools, run_cognee_task
from strands import Agent

SESSION_ID = "mission-briefing"

session_agent = Agent(
    model=model,
    tools=cognee_tools(session_id=SESSION_ID, remember_kwargs={"self_improvement": False}),
)
# ... use session_agent to remember/recall during the session ...

# Persist everything captured in the session into the permanent graph:
run_cognee_task(cognee.improve(session_ids=[SESSION_ID]))

For a full runnable walkthrough, see examples/session_example.py.

Tool Reference

cognee_tools(session_id=None, *, remember_kwargs=None, recall_kwargs=None)

Builds the remember and recall Strands tools. Pass the result to Agent(tools=...). With session_id, writes go to cognee's session cache (persist later with cognee.improve(session_ids=[session_id])); without it, writes go straight to the permanent graph. remember_kwargs / recall_kwargs bind extra cognee params per call (e.g. remember_kwargs={"self_improvement": False}).

Returns: [remember, recall]

remember(data, **kwargs) / recall(query_text, **kwargs)

Synchronous passthroughs to cognee.remember / cognee.recall for direct use outside an agent (they run cognee on a background loop). No defaults are imposed — pass any cognee parameter. recall returns cognee's native RecallResponse list; flatten it with render_results(...).

run_cognee_task(coro, timeout=300)

Runs any async cognee coroutine (e.g. cognee.improve(...), cognee.forget(...)) from synchronous code and returns the result.

Configuration

Copy .env.template to .env and set your key:

cp .env.template .env
LLM_API_KEY=your-openai-api-key-here

Examples

  • examples/example.py: store contracts with an agent, then recall them from a fresh agent.
  • examples/session_example.py: the session cache → improve() → permanent graph flow, with before/after graph visualizations.

Requirements

  • Python 3.10+
  • Cognee >=1.0.0,<=1.1.2
  • Strands Agents >=1.42.0 (strands-agents[openai] for the examples)
  • OpenAI API key (for the example model)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cognee_integration_strands-0.2.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cognee_integration_strands-0.2.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file cognee_integration_strands-0.2.0.tar.gz.

File metadata

File hashes

Hashes for cognee_integration_strands-0.2.0.tar.gz
Algorithm Hash digest
SHA256 eaf0a76074f9f02a0d9f7d5161f60f6fd5d76cbdcc85ca6e73187fe0c0ebc45c
MD5 3154ceb3f96bf1f8efe9d2757578d966
BLAKE2b-256 7416965c9620073c983335fb0b0f2824f9385d433b028e20cbd37bd5443cd8b4

See more details on using hashes here.

File details

Details for the file cognee_integration_strands-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for cognee_integration_strands-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6454870cab36b99f01b77c1633c1ee2cad9d9de7607c565b253a5c38459fb387
MD5 03f968654cf8a946f365177c2bba95bd
BLAKE2b-256 46b19872d8dd5c6ad3c34c18b7830b99560c6f49821986e9c960175f4d158e95

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page