memory¶
memory
¶
Redis memory services for ADK.
RedisLongTermMemoryService
¶
RedisLongTermMemoryService(config: RedisLongTermMemoryServiceConfig | None = None)
Bases: BaseMemoryService
Long-term memory service backed by Redis memory backends.
The service implements ADK's memory interface using either Redis Agent Memory or the self-hosted Agent Memory Server. Searches are scoped by user ID and namespace for both backends.
Latest ADK versions add explicit add_events_to_memory and add_memory
hooks. This service implements them while staying compatible with older ADK
versions that only call add_session_to_memory and search_memory.
Initialize the Redis long-term memory service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
RedisLongTermMemoryServiceConfig | None
|
Configuration for the service. If None, defaults are used. |
None
|
Source code in src/adk_redis/memory/long_term_memory.py
add_session_to_memory
async
¶
Add an ADK session to the configured long-term memory backend.
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
add_events_to_memory
async
¶
add_events_to_memory(*, app_name: str, user_id: str, events: Sequence[Event], session_id: str | None = None, custom_metadata: Mapping[str, object] | None = None) -> None
Add ADK events to the configured memory backend.
Source code in src/adk_redis/memory/long_term_memory.py
add_memory
async
¶
add_memory(*, app_name: str, user_id: str, memories: Sequence[MemoryEntry], custom_metadata: Mapping[str, object] | None = None) -> None
Add explicit durable memories to the configured backend.
Source code in src/adk_redis/memory/long_term_memory.py
search_memory
async
¶
Search for memories using the configured memory backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
Application name, used as namespace if no default is set. |
required |
user_id
|
str
|
Owner ID used to isolate memories. |
required |
query
|
str
|
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
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 | |
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.
Attributes:
| Name | Type | Description |
|---|---|---|
backend |
MemoryBackendName
|
Memory backend to use. |
api_base_url |
str
|
Memory API base URL. |
api_key |
str | None
|
Redis Agent Memory API key. |
store_id |
str | None
|
Redis Agent Memory store ID. |
timeout |
float
|
HTTP timeout in seconds. |
timeout_ms |
int | None
|
Optional SDK timeout in milliseconds. |
default_namespace |
str | None
|
Default namespace for memory operations. |
search_top_k |
int
|
Maximum number of memories to retrieve per search. |
similarity_threshold |
float | None
|
Minimum similarity threshold for search results. |
distance_threshold |
float | None
|
Backward-compatible alias for similarity_threshold. |
store_events_as_messages |
bool
|
Store ADK events as long-term message memories when add_session_to_memory or add_events_to_memory is called. |
default_memory_type |
MemoryTypeName
|
Default memory type for explicit add_memory writes. |
default_topics |
list[str]
|
Topics attached to created memory records. |
source |
str
|
Source label used when building deterministic IDs. |
recency_boost |
bool
|
Backward-compatible option retained from the previous Agent Memory Server client. |
semantic_weight |
float
|
Backward-compatible option retained from the previous Agent Memory Server client. |
recency_weight |
float
|
Backward-compatible option retained from the previous Agent Memory Server client. |
freshness_weight |
float
|
Backward-compatible option retained from the previous Agent Memory Server client. |
novelty_weight |
float
|
Backward-compatible option retained from the previous Agent Memory Server client. |
half_life_last_access_days |
float
|
Backward-compatible option retained from the previous Agent Memory Server client. |
half_life_created_days |
float
|
Backward-compatible option retained from the previous Agent Memory Server client. |
extraction_strategy |
Literal['discrete', 'summary', 'preferences', 'custom']
|
Backward-compatible option retained from the previous Agent Memory Server client. |
extraction_strategy_config |
dict[str, Any]
|
Backward-compatible option retained from the previous Agent Memory Server client. |
model_name |
str | None
|
Backward-compatible option retained from the previous Agent Memory Server client. |
context_window_max |
int | None
|
Backward-compatible option retained from the previous Agent Memory Server client. |