from agents import Agent, Runnerfrom cognee_integration_openai_agents import get_sessionized_cognee_tools# Session 1: Store informationadd_tool, search_tool = get_sessionized_cognee_tools("user-123")agent_1 = Agent( name="assistant", instructions="You are a helpful assistant.", tools=[add_tool, search_tool],)await Runner.run(agent_1, "I'm working on authentication")# Session 2: Different instance, same memoryadd_tool, search_tool = get_sessionized_cognee_tools("user-123")agent_2 = Agent( name="assistant", instructions="You are a helpful assistant.", tools=[add_tool, search_tool],)result = await Runner.run(agent_2, "What was I working on?")# Returns: "authentication"
Pre-load documents into cognee before creating agents:
Copy
import cogneefrom agents import Agent, Runnerfrom cognee_integration_openai_agents import search_tool# Pre-load documentsfor doc_path in document_paths: with open(doc_path, 'r') as f: await cognee.add(f.read())await cognee.cognify()# Query across all documentsagent = Agent( name="analyst", instructions="You have access to our knowledge base.", tools=[search_tool])result = await Runner.run(agent, "Find information about contract terms")
Context-Aware Assistance
Maintain user context across work sessions:
Copy
# Mondayawait Runner.run(agent, "Debugging payment flow")# Wednesdayresult = await Runner.run(agent, "What was I debugging?")
Multi-Tenant Applications
Isolate data per user or organization:
Copy
add_tool, search_tool = get_sessionized_cognee_tools(session_id=user_id)agent = Agent( name="assistant", instructions="You are a helpful assistant.", tools=[add_tool, search_tool])
Multi-Agent Workflows
Share knowledge between specialized agents:
Copy
from cognee_integration_openai_agents import add_tool, search_tool# Data collector agentdata_agent = Agent( name="data_collector", instructions="You collect and store important information.", tools=[add_tool])# Research agentresearch_agent = Agent( name="researcher", instructions="You search and analyze the knowledge base.", tools=[search_tool])
Agent Handoffs
Route requests to specialized agents with shared memory:
Copy
storage_agent = Agent( name="storage_specialist", instructions="You specialize in storing information.", tools=[add_tool])search_agent = Agent( name="search_specialist", instructions="You specialize in finding information.", tools=[search_tool])triage_agent = Agent( name="triage", instructions="Route to storage_specialist for saving, search_specialist for queries.", handoffs=[storage_agent, search_agent])result = await Runner.run(triage_agent, "Find our healthcare contracts")