Skip to content

feat: add ValkeySession provider for session memory#3583

Open
Oxygen56 wants to merge 1 commit into
openai:mainfrom
Oxygen56:feat/valkey-session-3017
Open

feat: add ValkeySession provider for session memory#3583
Oxygen56 wants to merge 1 commit into
openai:mainfrom
Oxygen56:feat/valkey-session-3017

Conversation

@Oxygen56
Copy link
Copy Markdown

@Oxygen56 Oxygen56 commented Jun 5, 2026

Adds a ValkeySession session provider that uses the valkey-glide client library.

Valkey is the Linux Foundation's open-source, BSD-licensed, high-performance key-value store, forked from Redis 7.2.5. It is wire-compatible with Redis, but organizations using Valkey deserve a first-class session provider that uses the dedicated Valkey-GLIDE client, which is optimized for Valkey and will diverge from redis-py as Valkey adds its own features.

Changes

  • New file: src/agents/extensions/memory/valkey_session.pyValkeySession class implementing the Session protocol
  • Updated: src/agents/extensions/memory/__init__.py — lazy-import registration with optional valkey extra
  • Updated: pyproject.tomlvalkey = ["valkey-glide>=2.1"] optional dependency + dev dependency + mypy override
  • New file: tests/extensions/memory/test_valkey_session.py — comprehensive test suite (27 tests covering direct ops, runner integration, isolation, limits, unicode, concurrency, TTL, key prefix isolation, client ownership, counter, metadata, settings, and more)

API

Direct construction with an existing client

from agents.extensions.memory import ValkeySession
from glide import GlideClient, GlideClientConfiguration, NodeAddress

config = GlideClientConfiguration(addresses=[NodeAddress("localhost", 6379)])
glide_client = await GlideClient.create(config)

session = ValkeySession(session_id="user-123", glide_client=glide_client)

URL-based construction

session = await ValkeySession.from_url(
    session_id="user-123",
    url="valkey://localhost:6379/0",
)

Supported URL schemes: valkey://, valkeys://, redis://, rediss://

Testing

Tests require a running Valkey/Redis instance (set via VALKEY_URL env var, defaults to valkey://localhost:6379/15).

Run with:

pytest tests/extensions/memory/test_valkey_session.py -v

Closes #3017

Adds ValkeySession session provider using valkey-glide client library.
Valkey is the Linux Foundation's BSD-licensed, Redis-compatible key-value store.

- Implement ValkeySession class following the same patterns as RedisSession
- Uses valkey-glide (>=2.1) with GlideClient for async operations
- Supports from_url factory method (valkey://, valkeys://, redis://, rediss://)
- Supports TTL-based session expiration
- Supports injecting an existing GlideClient for connection reuse
- Uses Batch API for efficient pipelined writes
- Includes comprehensive test suite using testcontainers or local Valkey
- Registered as lazy import in extensions.memory with optional 'valkey' extra

Closes openai#3017

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: eb5c6e6ae2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

import shutil
import sys
import time

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Skip Valkey tests when no server is provisioned

Because CI runs make sync with --all-extras in .github/workflows/tests.yml, the new valkey-glide extra is installed and this import skip no longer skips the file. The workflow does not start a Valkey service or set VALKEY_URL, and the helpers call GlideClient.create/ValkeySession.from_url before any pytest.skip, so the serial test suite will try to connect to localhost and fail instead of skipping on every CI job without a Valkey server. Gate these tests on an explicit server/container being available or catch client-creation failures and skip before attempting operations.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ValkeySession provider for session memory

1 participant