Skip to content

Sessions + Memory with MCP + Tools

Use ADK's native McpToolset to connect your agent to the Agent Memory Server's MCP endpoint, or use the Python memory tools directly. The Python tools can target Redis Agent Memory or the self-hosted Agent Memory Server. The LLM decides when to search, create, update, or delete memories.

Quick Reference

Feature Details
Protocol MCP (via SSE or Streamable HTTP) or REST-based ADK tools
Control LLM-driven: the agent chooses when to remember and recall
Session storage Redis Agent Memory or Agent Memory Server working memory
Long-term memory Redis Agent Memory or Agent Memory Server with vector + full-text indexes
Language support MCP works with Python, TypeScript, and any MCP-compatible client

How It Works

flowchart TD
    U([User message]) --> A[ADK Agent]
    A -->|"LLM decides to search"| MCP{MCP or REST?}

    MCP -->|MCP| MCPS[McpToolset<br/>search · create · prompt]
    MCP -->|REST| REST[Memory Tools<br/>SearchMemoryTool · CreateMemoryTool]

    MCPS --> AMS["Redis Agent Memory<br/>or Agent Memory Server"]
    REST --> AMS

    AMS --> WM[Working Memory]
    AMS --> LTM[Long-Term Memory]

    AMS -->|results| A
    A --> R([Agent response])

    subgraph Redis [Redis 8.4+]
        J[(JSON)]
        V[(Vector index)]
        FT[(Full-text index)]
    end

    AMS --- Redis

Unlike the services approach, where the framework handles memory automatically, here the LLM explicitly calls memory tools during reasoning. This gives you fine-grained control over what gets stored and retrieved.

MCP requires the self-hosted server

The SDK tools (Option 2) target either Redis Agent Memory (redis-agent-memory) or the self-hosted Agent Memory Server (opensource-agent-memory). The MCP path (Option 1) is provided only by the self-hosted Agent Memory Server; the managed backend has no MCP endpoint.

Option 1: MCP Tools

Connect to the Agent Memory Server's MCP endpoint using ADK's McpToolset. This is the recommended approach for multi-language support and when the same memory server is shared across agents.

from google.adk import Agent
from google.adk.tools.mcp_tool import McpToolset
from google.adk.tools.mcp_tool.mcp_session_manager import SseConnectionParams

memory_tools = McpToolset(
    connection_params=SseConnectionParams(url="http://localhost:9000/sse"),
    tool_filter=[
        "search_long_term_memory",
        "create_long_term_memories",
        "memory_prompt",
    ],
)

agent = Agent(
    model="gemini-2.5-flash",
    name="my_agent",
    tools=[memory_tools],
    instruction="Search memory before answering. Store important facts.",
)

Available MCP Tools

Tool Description
search_long_term_memory Semantic, keyword, or hybrid search across memories
create_long_term_memories Store new memories with topics, types, and metadata
get_long_term_memory Retrieve a specific memory by ID
edit_long_term_memory Update an existing memory
delete_long_term_memories Remove memories by ID
memory_prompt Enrich a prompt with relevant memories
set_working_memory Write to the current session's working memory

Option 2: SDK-Based Tools

Use the Python memory tool classes for direct SDK access. Tools can call Redis Agent Memory through redis-agent-memory, or the self-hosted Agent Memory Server through agent-memory-client.

from google.adk import Agent

from adk_redis import (
    SearchMemoryTool,
    CreateMemoryTool,
    UpdateMemoryTool,
    DeleteMemoryTool,
    MemoryPromptTool,
    MemoryToolConfig,
)

from adk_redis import REDIS_AGENT_MEMORY_BACKEND

config = MemoryToolConfig(
    backend=REDIS_AGENT_MEMORY_BACKEND,  # alias for "redis-agent-memory"
    api_base_url="http://localhost:8000",
    api_key="...",
    store_id="...",
    default_namespace="my_app",
)

agent = Agent(
    model="gemini-2.0-flash",
    name="my_agent",
    tools=[
        SearchMemoryTool(config=config),
        CreateMemoryTool(config=config),
        UpdateMemoryTool(config=config),
        DeleteMemoryTool(config=config),
        MemoryPromptTool(config=config),
    ],
)

Available SDK Tools

Tool Description
SearchMemoryTool Semantic search over long-term memories
CreateMemoryTool Store a new memory (semantic, episodic, or message)
GetMemoryTool Retrieve a memory by ID
UpdateMemoryTool Update content, topics, or metadata
DeleteMemoryTool Remove memories by ID
MemoryPromptTool Enrich a system prompt with relevant memories

MCP vs SDK Decision

MCP SDK Tools
Multi-language Yes (Python, TypeScript, any MCP client) Python only
Shared server Yes, multiple agents connect to one MCP endpoint Each agent connects through the SDK
Extra service Requires MCP server running No extra service (direct HTTP)
Tool filtering tool_filter on McpToolset Choose which tool classes to instantiate

Configuration (SDK Tools)

Option Default Description
backend redis-agent-memory redis-agent-memory or opensource-agent-memory
api_base_url http://localhost:8000 Memory backend URL
api_key None Redis Agent Memory API key
store_id None Redis Agent Memory store ID
timeout 30 HTTP timeout in seconds
default_namespace default Namespace for memory isolation
search_top_k 10 Default max search results
distance_threshold None Compatibility alias for search threshold
deduplicate True Deduplicate when creating memories

For backend, you can pass the "redis-agent-memory" / "opensource-agent-memory" strings directly, or import the typo-safe REDIS_AGENT_MEMORY_BACKEND / OPENSOURCE_AGENT_MEMORY_BACKEND constants (or the MemoryBackendName type) from adk_redis.

Launch with the ADK web UI for interactive testing:

adk web .

Next Steps