fix: rewrite streaming path via run()+event_stream_handler - #6
Merged
Conversation
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
Fixes streaming completeness:
run_stream()/run_with_events()previously usedagent.run_stream(), whose stop-at-first-output semantics truncated the run when the model emitted preamble text alongside tool calls — the post-tool summary was never generated. The streaming path now usesagent.run()+event_stream_handler(the combination pydantic-ai recommends for "run to completion and stream at the same time"): model requests stream (token events) while the graph advances non-streamingly, so tools always execute and the second request always happens.Also adds a "Working Principles" section to
AGENTS.md(think before coding / simplicity first / surgical changes / goal-driven execution).Changes
_run_stream_impl:agent.run_stream + stream_text→agent.run()+event_stream_handleras anasyncio.Task, events forwarded through a queue. Token events = text deltas (PartStartEvent(TextPart).content+PartDeltaEvent(TextPartDelta).content_delta).run_end.output=result.output(complete summary, not delta concatenation). Early consumer abort cancels the run task cleanly.0.2.0→0.2.1(patch — bug fix).run_with_events()completeness.make check: 156 passed, 7 skipped.AGENTS.md: new Working Principles section.Verification
run_streamoutput complete 4/4;run_with_eventsevent stream complete + ordered (token/tool/run_end).make checkgreen (ruff / mypy strict / 156 passed, 7 skipped).Behavior notes (0.2.1)
TOKEN_STREAMgranularity: one event per text delta (preamble included);run_end.outputis the complete final summary.