memory¶
memory
¶
Redis memory services for ADK.
RedisLongTermMemoryService
¶
RedisLongTermMemoryService(config: RedisLongTermMemoryServiceConfig | None = None)
Bases: BaseMemoryService
Long-term memory service implementation using Redis Agent Memory Server.
This service provides production-grade memory capabilities including: - Two-tier memory architecture (working memory + long-term memory) - Automatic memory extraction (semantic facts, episodic events, preferences) - Topic and entity extraction - Auto-summarization when context window is exceeded - Recency-boosted semantic search - Deduplication and memory compaction - https://github.com/redis/agent-memory-server
Requires the agent-memory-client package to be installed.
Example
from adk_redis import (
RedisLongTermMemoryService,
RedisLongTermMemoryServiceConfig,
)
config = RedisLongTermMemoryServiceConfig(
api_base_url="http://localhost:8000",
default_namespace="my_app",
recency_boost=True,
)
memory_service = RedisLongTermMemoryService(config=config)
# Use with ADK agent
agent = Agent(
name="my_agent",
memory_service=memory_service,
)
Initialize the Redis Long-Term Memory Service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
RedisLongTermMemoryServiceConfig | None
|
Configuration for the service. If None, uses defaults. |
None
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If agent-memory-client package is not installed. |
Source code in src/adk_redis/memory/long_term_memory.py
add_session_to_memory
async
¶
Add a session's events to the Agent Memory Server.
Converts ADK Session events to WorkingMemory messages and stores them in the Agent Memory Server. The server will automatically: - Extract semantic and episodic memories based on the configured strategy - Perform topic and entity extraction - Summarize context when the token limit is exceeded - Promote memories to long-term storage via background tasks
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
'Session'
|
The ADK Session containing events to store. |
required |
Source code in src/adk_redis/memory/long_term_memory.py
search_memory
async
¶
Search for memories using the Agent Memory Server.
Performs semantic search against long-term memory with optional recency boosting. Results are filtered by namespace (derived from app_name) and user_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
The application name (used as namespace if not configured). |
required |
user_id
|
str
|
The user ID to filter memories. |
required |
query
|
str
|
The search query for semantic matching. |
required |
Returns:
| Type | Description |
|---|---|
SearchMemoryResponse
|
SearchMemoryResponse containing matching MemoryEntry objects. |
Source code in src/adk_redis/memory/long_term_memory.py
close
async
¶
Close the memory service and cleanup resources.
Source code in src/adk_redis/memory/long_term_memory.py
RedisLongTermMemoryServiceConfig
¶
Bases: BaseModel
Configuration for Redis Long-Term Memory Service.
Attributes:
| Name | Type | Description |
|---|---|---|
api_base_url |
str
|
Base URL of the Agent Memory Server. |
timeout |
float
|
HTTP request timeout in seconds. |
default_namespace |
str | None
|
Default namespace for memory operations. |
search_top_k |
int
|
Maximum number of memories to retrieve per search. |
distance_threshold |
float | None
|
Maximum distance threshold for search results (0.0-1.0). |
recency_boost |
bool
|
Enable recency-aware re-ranking of search results. |
semantic_weight |
float
|
Weight for semantic similarity in recency boosting (0.0-1.0). |
recency_weight |
float
|
Weight for recency score in recency boosting (0.0-1.0). |
freshness_weight |
float
|
Weight for freshness component within recency score. |
novelty_weight |
float
|
Weight for novelty component within recency score. |
half_life_last_access_days |
float
|
Half-life in days for last_accessed decay. |
half_life_created_days |
float
|
Half-life in days for created_at decay. |
extraction_strategy |
Literal['discrete', 'summary', 'preferences', 'custom']
|
Memory extraction strategy (discrete, summary, preferences, custom). |
extraction_strategy_config |
dict[str, Any]
|
Additional configuration for the extraction strategy. |
model_name |
str | None
|
Model name for context window management and summarization. |
context_window_max |
int | None
|
Maximum context window tokens (overrides model default). |