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 advanced knowledge storage and retrieval system with Strands' agent framework. This integration allows you to build AI agents that can efficiently store, search, and retrieve information from a persistent knowledge base using Cognee's graph-based storage.

Features

  • Smart Knowledge Storage: Add and persist information using Cognee's advanced indexing.
  • Semantic Search: Retrieve relevant information using natural language queries.
  • Session Management: Support for user-specific data isolation using node_set.
  • Strands Integration: Seamless integration with Strands' agent framework.
  • Background Async Support: Automatically handles Cognee's async operations in a background thread, making it easy to use with Strands tools.

Installation

pip install cognee-integration-strands

Quick Start

import os
import asyncio
from cognee_integration_strands import get_sessionized_cognee_tools
from cognee_integration_strands.tools import run_cognee_task
from strands import Agent
from strands.models.openai import OpenAIModel
import cognee

# Configure your OpenAI model
model = OpenAIModel(
    client_args={"api_key": os.getenv("LLM_API_KEY")},
    model_id="gpt-4o",
)

# Get sessionized tools for a specific user
add_tool, search_tool = get_sessionized_cognee_tools("user-123")

# Create an agent with the tools
agent = Agent(
    model=model,
    tools=[add_tool, search_tool]
)

# Use the agent to store information
agent("Remember that we have signed a contract with Meditech Solutions for £1.2M.")

# Use the agent to retrieve information
response = agent("What is the value of the Meditech Solutions contract?")
print(response)

Available Tools

get_sessionized_cognee_tools(session_id: Optional[str] = None)

Returns cognee tools with optional user-specific sessionization.

Parameters:

  • session_id (optional): User identifier for data isolation. If not provided, a random session ID is auto-generated.

Returns: (add_tool, search_tool) - A list of tools for storing and searching data.

Usage:

# With sessionization (recommended for multi-user apps)
add_tool, search_tool = get_sessionized_cognee_tools("user-123")

# Without explicit session (auto-generates session ID)
add_tool, search_tool = get_sessionized_cognee_tools()

Individual Tools

  • add_tool: Stores information in the knowledge base. It handles the asynchronous addition and cognition process in the background.
  • search_tool: Searches and retrieves previously stored information from the knowledge base.

Session Management

cognee-integration-strands supports user-specific sessions to isolate data between different users or contexts. This is achieved by passing a session_id to get_sessionized_cognee_tools, which ensures that all data stored via add_tool is associated with that specific user ID (via Cognee's node_set feature).

# User 1 Session
user1_tools = get_sessionized_cognee_tools("user-123")
agent1 = Agent(model=model, tools=user1_tools)

# User 2 Session
user2_tools = get_sessionized_cognee_tools("user-456")
agent2 = Agent(model=model, tools=user2_tools)

Configuration

Copy the .env.template file to .env and fill out the required API keys:

cp .env.template .env

Then edit the .env file and set your API keys:

LLM_API_KEY=your-openai-api-key-here
# Add other configuration as needed

Examples

Check out the examples/ directory for more comprehensive usage examples:

  • examples/example.py: Demonstrates setting up Cognee, ingesting data, and using an agent to query that data.
  • examples/session_example.py: Demonstrates advanced session handling with visualization.

Requirements

  • Python 3.10+
  • Cognee
  • Strands Agents
  • 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.1.0.tar.gz (4.9 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.1.0-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for cognee_integration_strands-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fa3f0f37d9a6a8f04b638b1b94c3d1502ae4245dd9ae502aee9e5e14c9bdde7a
MD5 91616a947d4bf8fdcf7fcec526d705ea
BLAKE2b-256 3847cba34148e0aac6bcf65757390b31411dbf1b9ccc567ce8f4aacd66a0a67f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cognee_integration_strands-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f44fb81c912df89421fddf117e1e0c6629825a6130eeb81d7a9035cbed7e728f
MD5 3dba4de7efd6124ea6d6cdd20bebba69
BLAKE2b-256 4dbc370b10b92730fe3e3535602b46a2faae9ea2cd4c49eb22e8b1b2a4e8df2f

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