voltagent icon indicating copy to clipboard operation
voltagent copied to clipboard

feat: add Valkey-backed TaskStore and ResumableStreamStore

Open rileydes-improving opened this issue 7 months ago โ€ข 5 comments

PR Checklist

Please check if your PR fulfills the following requirements:

  • [x] The commit message follows our guidelines: https://voltagent.dev/docs/community/contributing/#commit-convention

Bugs / Features

  • [x] Related issue(s) linked https://github.com/VoltAgent/voltagent/issues/1258
  • [x] Tests for the changes have been added
  • [x] Docs have been added / updated
  • [x] Changesets have been added https://voltagent.dev/docs/community/contributing/#creating-a-changeset

What is the current behavior?

The @voltagent/a2a-server and @voltagent/resumable-streams packages only support in-memory storage. Task state and stream data are lost on restart and cannot be shared across multiple server instances.

What is the new behavior?

Adds Valkey-backed store implementations to both packages using the @valkey/valkey-glide client library:

@voltagent/a2a-server

  • New ValkeyTaskStore class implementing the TaskStore interface with composite key generation, JSON serialization, and optional TTL-based expiration.
  • createValkeyTaskStore factory function for easy instantiation.
  • New taskStore option on A2AServerConfig so a store can be provided at construction time.

@voltagent/resumable-streams

  • New createResumableStreamValkeyStore factory that wires Valkey pub/sub into the resumable-stream generic context, with per-channel dedicated GlideClient connections and a configurable max subscription limit (default 1000).
  • TTL support for active stream keys via optional ttlSeconds.
  • Exports internal utilities (markResumableStreamStoreType, buildActiveStreamKey, createActiveStreamStoreFromPublisher, mergeStreamAndActiveStore) for reuse by custom store implementations.

Shared

  • @valkey/valkey-glide added as an optional peer dependency in both packages so consumers who don't use Valkey are unaffected.
  • Both stores support standalone and cluster Valkey deployments, configurable key prefixes, and optional TTL.

Example

  • New examples/with-valkey-store project demonstrating end-to-end integration of both stores with a SupportAgent, including environment config template and README.

Tests

  • Comprehensive unit tests for ValkeyTaskStore (load, save, error handling, cancellations, factory function).
  • Comprehensive unit tests for createResumableStreamValkeyStore (publisher/subscriber adapters, TTL, subscription limits, close cleanup).

Notes for reviewers

  • The @valkey/valkey-glide peer dependency is optional, no impact on existing consumers.
  • The resumable-streams Valkey store creates one dedicated GlideClient per subscription channel, which is a requirement of the Glide pub/sub model. The maxSubscriptions option (default 1000) caps resource usage.

Summary by CodeRabbit

  • New Features

    • Valkey-backed storage for task persistence and resumable streams (configurable key prefixes, optional TTL, supports standalone & cluster)
    • Example app with a sample assistant and runtime tool demonstrating Valkey integration
  • Documentation

    • Added example README, env/sample, package config and run instructions
  • Tests

    • New test suites validating Valkey-backed task and resumable-stream stores
  • Breaking Changes

    • Server config may now specify a task store that overrides injected defaults (config > deps > in-memory)

Review Change Stack

rileydes-improving avatar Apr 30 '26 19:04 rileydes-improving

๐Ÿฆ‹ Changeset detected

Latest commit: ac74499d657cde2b7dd4570ca0bb170f9105ec2a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@voltagent/a2a-server Major
@voltagent/resumable-streams Minor
@voltagent/server-elysia Patch
@voltagent/server-hono Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Apr 30 '26 19:04 changeset-bot[bot]

Review Change Stack

No actionable comments were generated in the recent review. ๐ŸŽ‰

โ„น๏ธ Recent review info
โš™๏ธ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1a915acb-ce91-44f3-b241-42aec07acf8e

๐Ÿ“ฅ Commits

Reviewing files that changed from the base of the PR and between 1e845b4c6e80d6a25ab602b0c9f1c68df5b63dfd and ac74499d657cde2b7dd4570ca0bb170f9105ec2a.

โ›” Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
๐Ÿ“’ Files selected for processing (23)
  • .changeset/add-valkey-store-providers.md
  • .gitignore
  • examples/with-valkey-store/.env.example
  • examples/with-valkey-store/.gitignore
  • examples/with-valkey-store/README.md
  • examples/with-valkey-store/package.json
  • examples/with-valkey-store/src/agents/assistant.ts
  • examples/with-valkey-store/src/index.ts
  • examples/with-valkey-store/tsconfig.json
  • packages/a2a-server/package.json
  • packages/a2a-server/src/schemas.ts
  • packages/a2a-server/src/server.ts
  • packages/a2a-server/src/types.ts
  • packages/a2a-server/src/valkey-store.spec.ts
  • packages/a2a-server/src/valkey-store.ts
  • packages/a2a-server/tsup.config.ts
  • packages/resumable-streams/package.json
  • packages/resumable-streams/src/resumable-streams.ts
  • packages/resumable-streams/src/valkey-store.spec.ts
  • packages/resumable-streams/src/valkey-store.ts
  • packages/resumable-streams/tsconfig.json
  • packages/resumable-streams/tsup.config.ts
  • packages/resumable-streams/vitest.config.ts
โœ… Files skipped from review due to trivial changes (10)
  • examples/with-valkey-store/.gitignore
  • examples/with-valkey-store/tsconfig.json
  • packages/resumable-streams/tsconfig.json
  • packages/resumable-streams/vitest.config.ts
  • .gitignore
  • packages/resumable-streams/tsup.config.ts
  • examples/with-valkey-store/.env.example
  • packages/resumable-streams/package.json
  • examples/with-valkey-store/README.md
  • .changeset/add-valkey-store-providers.md
๐Ÿšง Files skipped from review as they are similar to previous changes (13)
  • examples/with-valkey-store/package.json
  • examples/with-valkey-store/src/agents/assistant.ts
  • packages/a2a-server/tsup.config.ts
  • packages/a2a-server/package.json
  • packages/a2a-server/src/server.ts
  • packages/a2a-server/src/valkey-store.spec.ts
  • examples/with-valkey-store/src/index.ts
  • packages/a2a-server/src/valkey-store.ts
  • packages/resumable-streams/src/valkey-store.ts
  • packages/resumable-streams/src/valkey-store.spec.ts
  • packages/resumable-streams/src/resumable-streams.ts
  • packages/a2a-server/src/schemas.ts
  • packages/a2a-server/src/types.ts

๐Ÿ“ Walkthrough

Walkthrough

Adds Valkey-backed task and resumable-stream stores, updates A2A schemas, types, and server task handling, wires package exports and builds, and adds an example app with docs and tests.

Changes

Valkey persistence providers

Layer / File(s) Summary
Schemas, types, and server contract
packages/a2a-server/src/schemas.ts, packages/a2a-server/src/types.ts, packages/a2a-server/src/server.ts
Adds Zod schemas, derives task/message types from them, extends A2AServerConfig with taskStore, and expands VoltA2AError serialization and factories.
Valkey task store
packages/a2a-server/src/valkey-store.ts, packages/a2a-server/src/server.ts, packages/a2a-server/package.json, packages/a2a-server/tsup.config.ts, packages/a2a-server/src/valkey-store.spec.ts, .changeset/add-valkey-store-providers.md
Adds ValkeyTaskStore and createValkeyTaskStore, wires the new export and peer dependency, updates build inputs, adds tests, and records the package change.
Resumable stream Valkey store
packages/resumable-streams/src/valkey-store.ts, packages/resumable-streams/src/resumable-streams.ts, packages/resumable-streams/package.json, packages/resumable-streams/tsup.config.ts, packages/resumable-streams/tsconfig.json, packages/resumable-streams/vitest.config.ts, packages/resumable-streams/src/valkey-store.spec.ts
Adds createResumableStreamValkeyStore, exports internal helpers, wires package/build/test config, and adds coverage for publisher, subscriber, and lifecycle behavior.
Example app and docs
examples/with-valkey-store/*, .gitignore
Adds the Valkey example package, entrypoint, agent, env files, README, and repository ignore updates.

Sequence Diagram(s)

sequenceDiagram
  participant ExampleApp
  participant A2AServer
  participant ValkeyTaskStore
  participant GlideClient
  ExampleApp->>A2AServer: initialize(taskStore = ValkeyTaskStore)
  A2AServer->>A2AServer: apply taskStore precedence
  A2AServer->>ValkeyTaskStore: save(TaskRecord)
  ValkeyTaskStore->>GlideClient: set(namespaced key, JSON, expiry?)
  GlideClient-->>ValkeyTaskStore: ok
  ValkeyTaskStore-->>A2AServer: persisted record
sequenceDiagram
  participant ExampleApp
  participant ResumableStore
  participant PubSubClient
  participant GlideClient
  ExampleApp->>ResumableStore: createResumableStreamValkeyStore(...)
  ResumableStore->>GlideClient: create publisher/subscriber adapters
  ResumableStore->>PubSubClient: subscribe(channel, handler)
  ResumableStore->>GlideClient: set(active key, stream id, EX?)
  ExampleApp->>ResumableStore: close()
  ResumableStore->>PubSubClient: close()

Estimated code review effort

๐ŸŽฏ 4 (Complex) | โฑ๏ธ ~50 minutes

Poem

๐Ÿฐ I hopped through keys in Valkey green,
A2A tasks and streams now keen.
With schemas, stores, and docs in tow,
The little rabbit watches data flow.
Nibble, twitch, persist โ€” hooray!

๐Ÿšฅ Pre-merge checks | โœ… 4 | โŒ 1

โŒ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage โš ๏ธ Warning Docstring coverage is 64.71% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
โœ… Passed checks (4 passed)
Check name Status Explanation
Title check โœ… Passed The title accurately summarizes the main change: adding Valkey-backed stores for both packages.
Description check โœ… Passed The description covers the required checklist, behavior change, tests, docs, and changesets; only the optional fixes/issue line is omitted.
Linked Issues check โœ… Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check โœ… Passed Check skipped because no linked issues were found for this pull request.

โœ๏ธ Tip: You can configure your own custom pre-merge checks in the settings.

โœจ Finishing Touches
๐Ÿงช Generate unit tests (beta)
  • [ ] Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

โค๏ธ Share

Comment @coderabbitai help to get the list of available commands.

coderabbitai[bot] avatar Apr 30 '26 19:04 coderabbitai[bot]

@coderabbitai resume

rileydes-improving avatar May 04 '26 13:05 rileydes-improving

โœ… Actions performed

Reviews resumed.

coderabbitai[bot] avatar May 04 '26 13:05 coderabbitai[bot]

Hey @rileydes-improving ๐Ÿ‘‹

Related issue: #1310

I noticed that ValkeyTaskStore accepts a pre-built GlideClient / GlideClusterClient via options.client and doesn't create its own connection. This means CLIENT SETNAME (for connection identification in monitoring tools) needs to be set by the caller when they build the client, rather than inside the store itself.

Would you consider either:

  1. Documenting in the README/example that callers should set clientName: "voltagent_a2a_store_client" when creating their GlideClient, or
  2. Adding a default clientName in the example code (examples/with-valkey-store) so users get identifiable connections out of the box?

This makes VoltAgent connections visible in CLIENT LIST, CloudWatch metrics, and monitoring dashboards โ€” helpful when multiple services share the same Valkey cluster.

atao2004 avatar May 29 '26 16:05 atao2004

Hey @rileydes-improving ๐Ÿ‘‹

Related issue: #1310

I noticed that ValkeyTaskStore accepts a pre-built GlideClient / GlideClusterClient via options.client and doesn't create its own connection. This means CLIENT SETNAME (for connection identification in monitoring tools) needs to be set by the caller when they build the client, rather than inside the store itself.

Would you consider either:

  1. Documenting in the README/example that callers should set clientName: "voltagent_a2a_store_client" when creating their GlideClient, or
  2. Adding a default clientName in the example code (examples/with-valkey-store) so users get identifiable connections out of the box?

This makes VoltAgent connections visible in CLIENT LIST, CloudWatch metrics, and monitoring dashboards โ€” helpful when multiple services share the same Valkey cluster.

Already done

rileydes-improving avatar Jun 22 '26 18:06 rileydes-improving

Just rebased, tested, and force pushed to make sure it is still current.

rileydes-improving avatar Jun 25 '26 12:06 rileydes-improving

@omeraplak You had previously closed the associated issue for this PR, are their changes required for the approach to add proper valkey support?

rileydes-improving avatar Jun 25 '26 13:06 rileydes-improving