sessions¶
sessions
¶
Redis session services for ADK.
RedisWorkingMemorySessionService
¶
RedisWorkingMemorySessionService(config: RedisWorkingMemorySessionServiceConfig | None = None)
Bases: BaseSessionService
Session service using Redis Agent Memory Server's Working Memory API.
This service provides session management backed by Agent Memory Server: - Session storage in Working Memory - Automatic context summarization when token limit exceeded - Background memory extraction to Long-Term Memory - Incremental message appending - https://github.com/redis/agent-memory-server
Requires the agent-memory-client package to be installed.
Example
from adk_redis import (
RedisWorkingMemorySessionService,
RedisWorkingMemorySessionServiceConfig,
)
config = RedisWorkingMemorySessionServiceConfig(
api_base_url="http://localhost:8000",
default_namespace="my_app",
)
session_service = RedisWorkingMemorySessionService(config=config)
# Use with ADK runner
runner = Runner(
agent=agent,
session_service=session_service,
)
Initialize the Redis Working Memory Session Service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
RedisWorkingMemorySessionServiceConfig | None
|
Configuration for the service. If None, uses defaults. |
None
|
Source code in src/adk_redis/sessions/working_memory.py
create_session
async
¶
create_session(*, app_name: str, user_id: str, state: dict[str, Any] | None = None, session_id: str | None = None) -> Session
Create a new session in Working Memory.
Uses get_or_create_working_memory to prevent accidental overwrites of existing sessions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
Application name (used as namespace if not configured). |
required |
user_id
|
str
|
User identifier. |
required |
state
|
dict[str, Any] | None
|
Initial session state. |
None
|
session_id
|
str | None
|
Optional session ID (generated if not provided). |
None
|
Returns:
| Type | Description |
|---|---|
Session
|
The created Session. |
Source code in src/adk_redis/sessions/working_memory.py
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
get_session
async
¶
get_session(*, app_name: str, user_id: str, session_id: str, config: GetSessionConfig | None = None) -> Session | None
Retrieve a session from Working Memory.
Uses get_or_create_working_memory and checks if session was newly created to determine if it exists. Passes model_name and context_window_max to enable automatic context summarization when token limit is exceeded.
NOTE: For ADK Runner compatibility, this method now returns the session even if it was just created. The Runner expects get_session to either return an existing session OR return a newly created empty session. Returning None causes the Runner to fail with "Session not found".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
Application name. |
required |
user_id
|
str
|
User identifier. |
required |
session_id
|
str
|
Session ID to retrieve. |
required |
config
|
GetSessionConfig | None
|
Optional configuration for filtering events. |
None
|
Returns:
| Type | Description |
|---|---|
Session | None
|
The Session (existing or newly created). |
Source code in src/adk_redis/sessions/working_memory.py
list_sessions
async
¶
List all sessions for a user from Working Memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
Application name. |
required |
user_id
|
str | None
|
User identifier (required for this implementation). |
None
|
Returns:
| Type | Description |
|---|---|
ListSessionsResponse
|
ListSessionsResponse containing sessions (without events). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If user_id is not provided. |
Source code in src/adk_redis/sessions/working_memory.py
delete_session
async
¶
Delete a session from Working Memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app_name
|
str
|
Application name. |
required |
user_id
|
str
|
User identifier. |
required |
session_id
|
str
|
Session ID to delete. |
required |
Source code in src/adk_redis/sessions/working_memory.py
append_event
async
¶
Append an event to the session in Working Memory.
Uses the incremental append API to add a single message without resending the full conversation history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
Session
|
The session to append to. |
required |
event
|
Event
|
The event to append. |
required |
Returns:
| Type | Description |
|---|---|
Event
|
The appended event. |
Source code in src/adk_redis/sessions/working_memory.py
RedisWorkingMemorySessionServiceConfig
¶
Bases: BaseModel
Configuration for Redis Working Memory Session 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 session operations. |
model_name |
str | None
|
Model name for context window management and summarization. |
context_window_max |
int | None
|
Maximum context window tokens. |
extraction_strategy |
Literal['discrete', 'summary', 'preferences', 'custom']
|
Memory extraction strategy. |
extraction_strategy_config |
dict[str, Any]
|
Additional config for extraction strategy. |
session_ttl_seconds |
int | None
|
Optional TTL for session expiration. |