Skip to content

Python: adds valkey streaming support (python)- issue 5517#5543

Open
MatthiasHowellYopp wants to merge 1 commit intomicrosoft:mainfrom
MatthiasHowellYopp:issue-5517
Open

Python: adds valkey streaming support (python)- issue 5517#5543
MatthiasHowellYopp wants to merge 1 commit intomicrosoft:mainfrom
MatthiasHowellYopp:issue-5517

Conversation

@MatthiasHowellYopp
Copy link
Copy Markdown

Motivation and Context

The Agent Framework currently has no Valkey-native streaming component. The existing resumable streaming samples (python/samples/04-hosting/azure_functions/03_reliable_streaming/) use a RedisStreamResponseHandler built on redis-py — a sample-level implementation that isn't packaged for reuse and creates a dependency mismatch for Valkey users.

This PR delivers ValkeyStreamBuffer, a first-party, reusable streaming buffer backed by Valkey Streams using the valkey-glide client. It enables durable agents to persist response chunks so clients can disconnect and reconnect mid-stream without data loss.

Related issue: [Python] Add ValkeyStreamBuffer — resumable streaming via Valkey Streams for agent-framework-valkey #5517

Description

Adds the agent-framework-valkey Python package with a single component: ValkeyStreamBuffer.

###Core implementation (_stream_buffer.py):

  • Write side: write_chunk(), write_completion(), write_error() — append entries to a per-conversation Valkey Stream via XADD with auto-refreshing TTL via EXPIRE
  • Read side: read_stream(conversation_id, cursor=None) — async iterator using XREAD with cursor-based resumption, configurable polling interval, and timeout (both before and after data is seen, so a crashed producer doesn't cause infinite polling)
  • Implements AgentResponseCallbackProtocol from agent-framework-durabletask (on_streaming_response_update / on_agent_response) for direct registration as a durable agent callback
  • Uses the same stream-key schema (agent-stream:{conversation_id}) and entry format (text, sequence, timestamp, done) as the existing Redis streaming samples and the .NET RedisStreamResponseHandler for cross-language consistency
  • Accepts both GlideClient (standalone) and GlideClusterClient (cluster) with TLS support through GlideClientConfiguration
  • Input validation on conversation_id (rejects empty strings)
  • Warning-level logging for malformed stream entries

Package scaffolding:

  • pyproject.toml with valkey-glide>=2.1.0 dependency and optional [durabletask] extra
  • init.py exporting ValkeyStreamBuffer and StreamChunk
  • LICENSE, README.md
  • Workspace registration in
  • pyproject.toml
  • (uv sources + pyright execution environments)

Tests (test_stream_buffer.py — 31 tests):

  • Construction validation (None client, defaults, custom params)
  • Write operations (xadd/expire calls, done marker, error field, empty conversation_id rejection)
  • Read operations (text chunks, cursor resumption, error entries, timeout before data, timeout after data with producer crash, empty-count reset, exception handling, polling)
  • Callback protocol (sequence tracking, increment, empty/missing text, missing thread_id, completion, cleanup)
  • Stream key generation and validation
  • Session isolation (separate sequences per thread)
  • Malformed field logging

Files changed:

init.py (new)
_stream_buffer.py (new)
test_stream_buffer.py (new)
pyproject.toml (new)
python/packages/valkey/LICENSE (new)
README.md (new)
pyproject.toml (workspace registration)

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@moonbox3 moonbox3 added documentation Improvements or additions to documentation python labels Apr 28, 2026
@github-actions github-actions Bot changed the title adds valkey streaming support (python)- issue 5517 Python: adds valkey streaming support (python)- issue 5517 Apr 28, 2026
@MatthiasHowellYopp MatthiasHowellYopp force-pushed the issue-5517 branch 2 times, most recently from 4332de6 to 1bd9e18 Compare April 29, 2026 18:06
Copilot AI review requested due to automatic review settings April 29, 2026 18:06
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds first-party Valkey-based resumable streaming support to the Python Agent Framework via a new agent-framework-valkey package and accompanying samples/tests.

Changes:

  • Introduces ValkeyStreamBuffer (+ StreamChunk) backed by Valkey Streams using valkey-glide
  • Adds unit + integration test suites for stream write/read, cursor resumption, timeouts, and callback-protocol behavior
  • Registers the new package in the Python workspace and provides a runnable sample + docs

Reviewed changes

Copilot reviewed 10 out of 12 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
python/samples/04-hosting/valkey_stream_buffer/valkey_stream_buffer.py Adds a runnable sample demonstrating basic streaming, resumption, and error propagation.
python/samples/04-hosting/valkey_stream_buffer/README.md Documents how to run the Valkey stream buffer sample.
python/pyproject.toml Registers agent-framework-valkey in the workspace and adjusts tooling environments.
python/packages/valkey/agent_framework_valkey/_stream_buffer.py Implements ValkeyStreamBuffer and stream parsing helpers.
python/packages/valkey/agent_framework_valkey/init.py Exposes public package API (ValkeyStreamBuffer, StreamChunk, __version__).
python/packages/valkey/pyproject.toml Defines the new package metadata, dependencies, and test/tooling config.
python/packages/valkey/README.md Adds package-level documentation and quick start usage.
python/packages/valkey/LICENSE Adds MIT license file for the new package.
python/packages/valkey/tests/test_stream_buffer.py Adds unit tests with a mocked glide client covering read/write + callback semantics.
python/packages/valkey/tests/test_stream_buffer_integration.py Adds opt-in integration tests against a real Valkey server.
.gitignore Ignores .kiro/ directory.

Comment thread python/pyproject.toml Outdated
Comment thread python/packages/valkey/agent_framework_valkey/_stream_buffer.py Outdated
Comment thread python/packages/valkey/agent_framework_valkey/_stream_buffer.py Outdated
Comment thread python/samples/04-hosting/valkey_stream_buffer/valkey_stream_buffer.py Outdated
Comment thread python/packages/valkey/README.md Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants