feat(sdk): add streaming extensions and response accumulator#75
Open
feat(sdk): add streaming extensions and response accumulator#75
Conversation
9917354 to
7c4c222
Compare
0172097 to
ad3c581
Compare
Contributor
|
@PetrBulanek can you please review the UI part? |
…eaming support Adds a delta-based streaming protocol using JSON Patch (RFC 6902) with a custom `str_ins` operation for efficient token-by-token text delivery. Server (adk-py): - MessageAccumulator: 3-level state machine collecting string chunks, parts, and metadata into complete messages with incremental patches - Extended JSON Patch (jsonpatch_ext): str_ins operation for optimized text streaming without full-value replacement - StreamingExtensionServer/Client: extension negotiation, patch extraction, delta emission, and graceful fallback for non-streaming clients - Refactored extension base: activation lifecycle, default demand constant consolidation (DEFAULT_DEMAND_NAME), and metadata handling - RunContext: extracted shared store logic into _prepare_store_data, added store_sync for synchronous callers - New yield types: ArtifactChunk for chunked artifact streaming Client (adk-ts / adk-ui): - TypeScript streaming extension types and Zod schemas - UI patch application (streaming.ts): JSON pointer resolution, replace/add/str_ins ops with optimized cloning (skip structuredClone for primitives) - Client streaming integration: draft accumulation, patch extraction from status update metadata, replace-mode emission - Fix: text duplication on final message — detect active streaming session and emit with replace flag to prevent appending duplicate content - Batched React state updates in AgentRunProvider to reduce re-renders during streaming - Removed dead commented-out proxy header code from adk-client Tests: - Unit tests for MessageAccumulator state machine - Unit tests for extended JSON Patch operations - Unit tests for RunContext store methods - E2E streaming tests: patch application, message reconstruction, client fallback behavior - Updated yield tests for new artifact chunking Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com> Signed-off-by: Radek Ježek <radek.jezek@ibm.com>
ad3c581 to
f902343
Compare
Signed-off-by: Petr Bulánek <bulanek.petr@gmail.com>
…rray pattern Signed-off-by: Petr Bulánek <bulanek.petr@gmail.com>
…pping Signed-off-by: Petr Bulánek <bulanek.petr@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a delta-based streaming protocol using JSON Patch (RFC 6902) with a custom
str_insoperation for efficient token-by-token text delivery to the UI.Server (adk-py)
jsonpatch_ext) — adds astr_insoperation for optimized text streaming without full-value replacement on every tokenDEFAULT_DEMAND_NAMEconstant (was duplicated in 5 files), improved metadata handling_prepare_store_data, addedstore_syncfor synchronous callersArtifactChunkfor chunked artifact streaming with shared artifact IDsClient (adk-ts)
STREAMING_EXTENSION_URIconstantUI (adk-ui)
streaming.ts) — JSON pointer resolution, support forreplace/add/str_insoperations, optimized cloning (skipsstructuredClonefor immutable primitives)streamingDraft, patch extraction fromTaskStatusUpdateEventmetadata, replace-mode emissionreplace: trueupdateCurrentAgentMessagecalls per streaming tick into a single call, reducing re-renders during high-frequency token streamingadk-client.tsWire format
Streaming data is carried in
TaskStatusUpdateEvent.metadata[STREAMING_EXTENSION_URI]as amessage_updatepatch list with amessage_id. Clients that don't negotiate streaming support receive the final complete message atTASK_STATE_COMPLETED— fully backward compatible.Test plan
MessageAccumulatorstate machine (state transitions, patch output, flush)str_insoperationRunContextstore methodsmise run checkpasses (lint, typecheck, license)