Give your Google ADK agents cognee’s memory. Store structured knowledge, retrieve via natural language, and maintain context across sessions - all through two async tools.
Before using the integration, configure your environment variables:
Copy
Ask AI
export GOOGLE_API_KEY="your-google-api-key-here" # for Google ADKexport LLM_API_KEY="your-openai-api-key-here" # for cognee
Add memory tools to your Google ADK agent:
Copy
Ask AI
import asynciofrom google.adk.agents import Agentfrom google.adk.runners import InMemoryRunnerfrom cognee_integration_google_adk import add_tool, search_toolasync def main(): # Create agent with memory agent = Agent( model="gemini-2.0-flash", name="assistant", description="An assistant with persistent memory", instruction="You are a helpful assistant with access to a knowledge base.", tools=[add_tool, search_tool], ) runner = InMemoryRunner(agent=agent) # Store information await runner.run_debug( "Remember: Acme Corp, healthcare, $1.2M contract" ) # Retrieve information events = await runner.run_debug( "What healthcare contracts do we have?" ) for event in events: if event.is_final_response() and event.content: for part in event.content.parts: if part.text: print(part.text)asyncio.run(main())
from cognee_integration_google_adk import get_sessionized_cognee_tools# Session 1: Store informationadd_tool, search_tool = get_sessionized_cognee_tools("user-123")agent_1 = Agent( model="gemini-2.0-flash", name="assistant", description="Assistant with memory", instruction="You are a helpful assistant.", tools=[add_tool, search_tool],)runner_1 = InMemoryRunner(agent=agent_1)await runner_1.run_debug("I'm working on authentication")# Session 2: Different instance, same memoryadd_tool, search_tool = get_sessionized_cognee_tools("user-123")agent_2 = Agent( model="gemini-2.0-flash", name="assistant", description="Assistant with memory", instruction="You are a helpful assistant.", tools=[add_tool, search_tool],)runner_2 = InMemoryRunner(agent=agent_2)events = await runner_2.run_debug("What was I working on?")# Returns: "authentication"
Build domain knowledge incrementally over multiple sessions:
Copy
Ask AI
# Pre-load documents into cogneeimport cogneefor doc_path in document_paths: with open(doc_path, 'r') as f: content = f.read() await cognee.add(content)await cognee.cognify()# Query across all documentsevents = await runner.run_debug( "Find information about contract terms")
Context-Aware Assistance
Maintain user context across work sessions:
Copy
Ask AI
# Mondayawait runner.run_debug("Debugging payment flow")# Wednesdayevents = await runner.run_debug("What was I debugging?")
Multi-Tenant Applications
Isolate data per user/organization while sharing global knowledge:
Copy
Ask AI
# Per-user isolationadd_tool, search_tool = get_sessionized_cognee_tools(session_id=user_id)agent = Agent( model="gemini-2.0-flash", name="assistant", description="User assistant", instruction="You are a helpful assistant.", tools=[add_tool, search_tool])
Multi-Agent Workflows
Share knowledge between specialized agents:
Copy
Ask AI
# Data collector agentdata_agent = Agent( model="gemini-2.0-flash", name="data_collector", description="Collects and stores information", instruction="You collect and store important information.", tools=[add_tool])# Research agentresearch_agent = Agent( model="gemini-2.0-flash", name="researcher", description="Searches stored information", instruction="You search and analyze the knowledge base.", tools=[search_tool])