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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cognee_integration_strands-0.1.1.tar.gz.
File metadata
- Download URL: cognee_integration_strands-0.1.1.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
257ecb2833366f300358fffe872b5bb6dd29c6c8356aba5a66a7d3b444bb78c7
|
|
| MD5 |
9149eb9675a90cd03e92732dccad3cc9
|
|
| BLAKE2b-256 |
f4c115431aae7f824ae44ea5ce46e83964b7972564c1eb96193c53090880d005
|
File details
Details for the file cognee_integration_strands-0.1.1-py3-none-any.whl.
File metadata
- Download URL: cognee_integration_strands-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c135b179f58ca9fe6a1dd023e5adb75789a2c4024f676c180c99ce6985681b3
|
|
| MD5 |
f134c279b697a075e9844675ef45e41c
|
|
| BLAKE2b-256 |
23d585fbe04de0223cbd7997b82ef54d0bafe9db96c1b2e2428bcd34f9789739
|