Skip to content
Merged
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
12 changes: 6 additions & 6 deletions src/agents/extensions/memory/redis_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import json
import time
from dataclasses import dataclass
from typing import Any
from typing import Any, cast

from ._optional_imports import raise_optional_dependency_error

Expand Down Expand Up @@ -675,7 +675,7 @@ async def _decode_messages(raw_messages: list[Any]) -> list[TResponseInputItem]:
self._check_not_closed()
if session_limit is None:
# Get all messages in chronological order
raw_messages = await self._redis.lrange(self._messages_key, 0, -1) # type: ignore[misc] # Redis library returns Union[Awaitable[T], T] in async context
raw_messages = await self._redis.lrange(self._messages_key, 0, -1)
return await _decode_messages(raw_messages)

if session_limit <= 0:
Expand All @@ -687,7 +687,7 @@ async def _decode_messages(raw_messages: list[Any]) -> list[TResponseInputItem]:
# limit counts valid conversation items, matching pop_item and the other backends.
window = session_limit
while True:
raw_messages = await self._redis.lrange(self._messages_key, -window, -1) # type: ignore[misc] # Redis library returns Union[Awaitable[T], T] in async context
raw_messages = await self._redis.lrange(self._messages_key, -window, -1)
items = await _decode_messages(raw_messages)
if len(items) >= session_limit:
return items[-session_limit:]
Expand Down Expand Up @@ -743,8 +743,8 @@ async def pop_item(self) -> TResponseInputItem | None:
async def _pop_item_locked(self) -> TResponseInputItem | None:
"""Claim one item while the caller retains the session lock."""
while True:
# Use RPOP to atomically remove and return the rightmost (most recent) item
raw_msg = await self._redis.rpop(self._messages_key) # type: ignore[misc] # Redis library returns Union[Awaitable[T], T] in async context
# Without a count, RPOP returns one item rather than a list of items.
raw_msg = cast("bytes | str | None", await self._redis.rpop(self._messages_key))

if raw_msg is None:
return None
Expand Down Expand Up @@ -823,7 +823,7 @@ async def ping(self) -> bool:
# Checked outside the try block; the except clause below would swallow it.
self._check_not_closed()
try:
await self._redis.ping() # type: ignore[misc] # Redis library returns Union[Awaitable[T], T] in async context
await self._redis.ping()
return True
except Exception:
return False
2 changes: 1 addition & 1 deletion tests/extensions/memory/test_redis_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ async def test_external_client_not_closed():
# Should still be able to use the client for other operations
await shared_client.set("test_key", "test_value")
value = await shared_client.get("test_key")
assert value.decode("utf-8") == "test_value"
assert value == b"test_value"

finally:
# Clean up
Expand Down
6 changes: 3 additions & 3 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading