Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ dmypy.json
# uv
uv.lock

# MkDocs build output
site/

# OS
.DS_Store
Thumbs.db
Expand Down
323 changes: 43 additions & 280 deletions README.md

Large diffs are not rendered by default.

35 changes: 22 additions & 13 deletions docs/concepts/memory.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# 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 REST-based memory tools directly. The LLM decides when to search, create, update, or delete memories.
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

Expand Down Expand Up @@ -80,9 +83,11 @@ agent = Agent(
| `memory_prompt` | Enrich a prompt with relevant memories |
| `set_working_memory` | Write to the current session's working memory |

## Option 2: REST-Based Tools
## Option 2: SDK-Based Tools

Use the Python memory tool classes for direct REST access. No MCP server needed; the tools call the Agent Memory Server REST API.
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`.

```python
from google.adk import Agent
Expand All @@ -97,9 +102,11 @@ from adk_redis import (
)

config = MemoryToolConfig(
backend="redis-agent-memory",
api_base_url="http://localhost:8000",
api_key="...",
store_id="...",
default_namespace="my_app",
recency_boost=True,
)

agent = Agent(
Expand All @@ -115,36 +122,38 @@ agent = Agent(
)
```

### Available REST Tools
### Available SDK Tools

| Tool | Description |
|------|-------------|
| `SearchMemoryTool` | Semantic search with optional recency boost |
| `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 REST Decision
## MCP vs SDK Decision

| | MCP | REST Tools |
| | 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 directly to REST API |
| **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 (REST Tools)
## Configuration (SDK Tools)

| Option | Default | Description |
|--------|---------|-------------|
| `api_base_url` | `http://localhost:8000` | Agent Memory Server URL |
| `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 |
| `recency_boost` | `True` | Bias scoring toward newer memories |
| `distance_threshold` | `None` | Max vector distance for search results |
| `distance_threshold` | `None` | Compatibility alias for search threshold |
| `deduplicate` | `True` | Deduplicate when creating memories |

Launch with the [ADK web UI](https://google.github.io/adk-docs/runtime/) for interactive testing:
Expand Down
86 changes: 39 additions & 47 deletions docs/concepts/sessions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,28 @@ Use `RedisWorkingMemorySessionService` and `RedisLongTermMemoryService` when you

| Feature | Details |
|---------|---------|
| **Session storage** | Agent Memory Server working memory (Redis JSON) |
| **Long-term memory** | Agent Memory Server with vector + full-text indexes |
| **Auto-summarization** | Old messages are summarized when context window fills |
| **Memory extraction** | Background promotion of facts to long-term storage |
| **Search** | Semantic, keyword, and hybrid search across sessions |
| **Session storage** | Redis Agent Memory session events or Agent Memory Server working memory |
| **Long-term memory** | Redis Agent Memory records or Agent Memory Server long-term memory |
| **Direct memory writes** | `add_memory()` stores durable semantic or episodic facts |
| **Event memory writes** | `add_session_to_memory()` stores ADK events as `message` memories |
| **Search** | Backend long-term search across scoped records |
| **Multi-process** | Safe for horizontal scaling; all state lives in Redis |

## How It Works

```mermaid
flowchart TD
U([User message]) --> R[ADK Runner]
R -->|append_event| WM[Working Memory<br/>messages · context · data]
WM -->|auto-summarize| WM
WM -->|background extraction| LTM[Long-Term Memory<br/>vector + full-text index]
R -->|append_event| WM[Session Events]
R -->|add_memory| LTM[Long-Term Memory]
R -->|add_session_to_memory| MSG[Message Memories]
MSG --> LTM
LTM -->|search_memory| R
R --> A([Agent response])

subgraph AMS [Agent Memory Server]
subgraph RAM [Configured Memory Backend]
WM
MSG
LTM
end

Expand All @@ -35,13 +37,13 @@ flowchart TD
FT[(Full-text index)]
end

AMS --- Redis
RAM --- Redis
```

1. The ADK `Runner` calls `append_event()` after every turn, forwarding the message to the Agent Memory Server.
2. When the conversation exceeds `context_window_max` tokens, the server summarizes older messages and stores the summary in a `context` field.
3. A background task extracts structured memories (facts, preferences, events) and promotes them to long-term storage.
4. On future sessions, `search_memory()` retrieves relevant memories via hybrid search.
1. The ADK `Runner` calls `append_event()` after every turn, forwarding the message to the configured memory backend.
2. ADK callbacks or API routes can call `add_session_to_memory()` to store session events as long-term `message` memories.
3. Agents and callbacks can call `add_memory()` or memory tools to store durable `semantic` or `episodic` records.
4. On future sessions, `search_memory()` retrieves relevant memories from the configured backend.

## Usage

Expand All @@ -58,18 +60,21 @@ from adk_redis import (

session_service = RedisWorkingMemorySessionService(
config=RedisWorkingMemorySessionServiceConfig(
backend="redis-agent-memory",
api_base_url="http://localhost:8000",
api_key="...",
store_id="...",
default_namespace="my_app",
model_name="gpt-4o",
context_window_max=8000,
),
)

memory_service = RedisLongTermMemoryService(
config=RedisLongTermMemoryServiceConfig(
backend="redis-agent-memory",
api_base_url="http://localhost:8000",
api_key="...",
store_id="...",
default_namespace="my_app",
recency_boost=True,
),
)

Expand All @@ -86,6 +91,10 @@ runner = Runner(
)
```

To use the open source self-hosted Agent Memory Server instead, set
`backend="opensource-agent-memory"` on both configs. Redis Agent Memory is the
default backend.

Launch with the [ADK web UI](https://google.github.io/adk-docs/runtime/) for interactive testing:

```bash
Expand All @@ -98,57 +107,40 @@ adk web .

| Option | Default | Description |
|--------|---------|-------------|
| `api_base_url` | `http://localhost:8000` | Agent Memory Server URL |
| `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.0` | HTTP request timeout in seconds |
| `default_namespace` | `None` | Logical grouping for multi-tenant isolation |
| `model_name` | `None` | Model name used for context window sizing and summarization |
| `context_window_max` | `None` | Token limit that triggers auto-summarization |
| `extraction_strategy` | `discrete` | How memories are extracted (`discrete`, `summary`, `preferences`, `custom`) |
| `session_ttl_seconds` | `None` | Optional TTL; expired sessions are cleaned up by Redis |

### Memory Service (`RedisLongTermMemoryServiceConfig`)

| Option | Default | Description |
|--------|---------|-------------|
| `api_base_url` | `http://localhost:8000` | Agent Memory Server URL |
| `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.0` | HTTP request timeout in seconds |
| `default_namespace` | `None` | Namespace for memory isolation |
| `search_top_k` | `10` | Max results returned from `search_memory()` |
| `distance_threshold` | `None` | Max vector distance for search results (0.0-1.0) |
| `recency_boost` | `True` | Bias search scoring toward newer memories |
| `semantic_weight` | `0.8` | Weight for semantic similarity (0.0-1.0) |
| `recency_weight` | `0.2` | Weight for recency score (0.0-1.0) |
| `extraction_strategy` | `discrete` | How memories are extracted (`discrete`, `summary`, `preferences`, `custom`) |

## Automatic Summarization

When conversation messages exceed `context_window_max` tokens, the server:

1. Summarizes older messages into a compact paragraph.
2. Stores the summary in the `context` field of working memory.
3. Removes the summarized messages to free space.
4. Keeps recent messages intact.

```mermaid
flowchart LR
M["msg1 msg2 ... msg10"] -->|exceeds threshold| S[Summarize]
S --> C["context: 'User discussed trip planning...'"]
S --> K["msg8 msg9 msg10<br/>(recent kept)"]
```
| `similarity_threshold` | `None` | Min similarity for search results (0.0-1.0) |
| `store_events_as_messages` | `True` | Store ADK events as `message` memories |

## Memory Types

The server extracts three types of memories from conversations:
Redis Agent Memory and Agent Memory Server support three memory types:

| Type | Description | Example |
|------|-------------|---------|
| **Semantic** | Facts, preferences, general knowledge | "User prefers window seats" |
| **Episodic** | Events with temporal context | "User visited Paris in March 2024" |
| **Message** | Conversation records (auto-generated) | Stored from working memory messages |
| **Message** | Conversation records | "user: I prefer window seats" |

## Cross-Process Scaling

Because all state lives in the Agent Memory Server (backed by Redis), multiple processes can share sessions:
Because all state lives in Redis, multiple processes can share sessions:

- **Horizontal scaling**: deploy multiple agent replicas behind a load balancer.
- **Seamless failover**: if one instance goes down, another picks up the session.
Expand Down
21 changes: 10 additions & 11 deletions docs/llms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

> Redis integrations for Google's Agent Development Kit. Provides ADK
> `BaseSessionService` and `BaseMemoryService` implementations, five
> RedisVL-backed search tools, MCP toolsets for RedisVL and Agent Memory
> Server, and semantic cache providers (self-hosted RedisVL or managed
> Redis LangCache).
> RedisVL-backed search tools, selectable Redis Agent Memory or Agent Memory
> Server memory backends, MCP toolsets, and semantic cache providers.

For agents using the library, read [AGENTS.md](../AGENTS.md) first. For
the full API surface, browse [the API reference](api/python/index.md).
Expand All @@ -14,8 +13,8 @@ For task-oriented recipes, browse the
## Concepts

- [ADK overview](concepts/adk_overview.md): how ADK abstractions map onto Redis.
- [Sessions](concepts/sessions.md): working memory backed by Agent Memory Server.
- [Memory](concepts/memory.md): long-term semantic memory with recency boosting.
- [Sessions](concepts/sessions.md): working memory backed by Redis Agent Memory or Agent Memory Server.
- [Memory](concepts/memory.md): long-term semantic memory through Redis Agent Memory or Agent Memory Server.
- [Search](concepts/search.md): vector, hybrid, range, text, and SQL search over RedisVL.
- [Caching](concepts/caching.md): semantic caching with RedisVL or LangCache.

Expand Down Expand Up @@ -58,6 +57,8 @@ When generating code that uses adk-redis:
(e.g., `from adk_redis import RedisVectorSearchTool`).
- Construct services with their `Config` dataclasses
(`RedisLongTermMemoryServiceConfig`, etc.) so options are explicit.
- Set `backend="redis-agent-memory"` for Redis Agent Memory, or
`backend="opensource-agent-memory"` for the open source self-hosted server.
- For the RedisVL MCP path, use ADK's native `McpToolset` with the
appropriate `*ConnectionParams` class. Set
`tool_filter=["search-records"]` to suppress writes, or pass
Expand All @@ -71,22 +72,20 @@ When generating code that uses adk-redis, never:
- Pass `epsilon=` to `RedisVectorQueryConfig`; it is `VECTOR_RANGE`-only
and lives on `RedisRangeQueryConfig`.
- Mix sync and async RedisVL `SearchIndex` instances in the same tool.
- Cache the `MemoryAPIClient` across ADK `Runner.run` invocations; the
session service builds a new client per call on purpose.
- Cache Redis Agent Memory SDK clients across ADK `Runner.run` invocations;
the session and memory services build short-lived clients on purpose.

When the user asks for something this library does not cover:

- For LangChain agents over Redis, use [`langchain-redis`](https://github.com/redis-developer/langchain-redis).
- For LangGraph state and checkpointers, use [`langgraph-redis`](https://github.com/redis-developer/langgraph-redis).
- For raw RedisVL search without ADK, use [`redisvl`](https://docs.redisvl.com).
- For the Redis Agent Memory Server itself, use
[`agent-memory-server`](https://github.com/redis/agent-memory-server)
and its `agent-memory-client` SDK.
- For Redis Agent Memory itself, use the `redis-agent-memory` SDK.

When the user is comparing adk-redis to another library:

- adk-redis is the ADK-native surface for Redis. It does not replace
RedisVL or Agent Memory Server; it adapts them to ADK's `BaseTool`,
RedisVL or Redis Agent Memory; it adapts them to ADK's `BaseTool`,
`BaseSessionService`, `BaseMemoryService`, and MCP interfaces.
- Pick this library when the agent runs on Google ADK and the data layer
is Redis. For other agent frameworks, the corresponding `*-redis`
Expand Down
Loading