Repository navigation
LCORE-4724: project a streaming-query agent run onto the SSE contract - #3376
max-svistunov wants to merge 1 commit into
Conversation
/v1/streaming_query has a public SSE contract; on the pydantic-ai agent path the run produces native events that dispatch_stream_event maps one by one. The migration replaces that dispatcher with a UIEventStream adapter, one hook per event kind, that the endpoint switch-over (LCORE-4728) will use. Add it as StreamingQueryEventStream in a new query.projector package, mirroring the Responses projector layout. This first part covers the text of a turn: before_stream opens with the start event; text starts and deltas become token events with the chunk counter the accumulator keeps; a text end folds the part into the turn's response text; the run result closes with turn_complete, with the refusal text when the model refused, exactly as the dispatcher does. The media type is a field of the stream, so plain-text clients still get the token text alone. The end event stays with the endpoint, which needs the persisted turn and the quota balances the projector cannot see. Tools, compaction, error and interruption follow in the next parts. Nothing calls the projector yet.
|
No actionable comments were generated in the recent review. WalkthroughThe query projector adds ChangesStreaming query event projection
Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Refactor Suggested reviewers: Merge Risk:
|
Description
LCORE-4724, part 1 of 3:
StreamingQueryEventStream, the projector that turns the native pydantic-ai events of a/v1/streaming_queryrun into today's SSE contract, built on pydantic-ai'sUIEventStreamwith one hook per event kind (designpai-responses-lcore-rewrite.md; ticket LCORE-4724). It is what replaces thedispatch_stream_eventchain ofutils.agents.streamingonce the endpoint switches over (LCORE-4728); nothing calls it yet and the dispatcher keeps serving production.This part covers the text of a turn:
before_streamopens with thestartevent; text starts and deltas becometokenevents with the chunk counter the accumulator keeps; a text end folds the part into the turn's response text; the run result closes withturn_complete, with the refusal text when the model refused, exactly as the dispatcher does. The media type is a field of the stream, so plain-text clients still get the token text alone. Theendevent stays with the endpoint, which needs the persisted turn and the quota balances the projector cannot see; the endpoint reads this stream's accumulator and run result after the stream.Parts 2 and 3 (tools; compaction, error and interruption) follow as one PR on top of this one, so each stays under 400 lines. Layout:
src/query/projector/, mirroring the Responses projector package.One commit, 319 lines, no API or configuration change; wire names and payload models are unchanged.
Type of change
pyproject.toml+uv.lock]requirements.*.txtfor Konflux]Tools used to create PR
Identify any AI code assistants used in this PR (for transparency and review context)
Related Tickets & Documents
Checklist before requesting a review
Testing
Four tests drive synthetic
PartStartEvent,PartDeltaEvent,PartEndEventandAgentRunResultEventthroughtransform_streamand compare the encoded lines with the contract: thestartbody, token ids and texts,turn_completewith the final text and the refusal variants, the turn summary's response text and chunk counter after the stream, and the plain-text media type. ruff, black, pydocstyle, mypy, pyright and pylint (10.00) are clean on the new package. No stack run: the projector has no caller yet.Summary by CodeRabbit