Motivation
A consumer that relays agent.run() over Server-Sent Events will see clients disconnect
routinely, so what a break out of for await — or an aborted signal — does has to be a
documented promise rather than an implementation detail. The behaviour is already implemented and
covered by tests; it is not written down anywhere a caller would look.
Measured behaviour
- Breaking out of the loop calls the iterator's
return(), which closes the source and releases
the provider SDK stream.
- The run's
afterRun still runs, and the partial response is persisted. Structured-output
parsing is skipped for an abandoned run, so break never raises.
- The
invoke_agent span is ended, on both the abandon and the abort path.
An aborted run reports the failure to afterRun instead, and the default history provider stores
nothing for it.
The reference implementations disagree here
- .NET disposes the inner enumerator but never reaches its provider notification, so nothing is
persisted.
- Go falls through to its
Invoked calls after the consumer stops, persisting the partial
response.
- Python runs its cleanup hooks only on exhaustion or an exception, and exposes no
close(), so a
consumer that stops early has no supported way to finish the run at all.
This framework follows Go. Saying so explicitly makes it read as a decision rather than an
accident, and tells a caller which of the three behaviours to design against.
Scope
TSDoc on AgentRunStream and ResponseStream covering the three points above and the abort
variant. No behaviour change is expected — if writing it down turns up a case that does not hold,
that becomes a separate bug report with a failing test.
Motivation
A consumer that relays
agent.run()over Server-Sent Events will see clients disconnectroutinely, so what a
breakout offor await— or an aborted signal — does has to be adocumented promise rather than an implementation detail. The behaviour is already implemented and
covered by tests; it is not written down anywhere a caller would look.
Measured behaviour
return(), which closes the source and releasesthe provider SDK stream.
afterRunstill runs, and the partial response is persisted. Structured-outputparsing is skipped for an abandoned run, so
breaknever raises.invoke_agentspan is ended, on both the abandon and the abort path.An aborted run reports the failure to
afterRuninstead, and the default history provider storesnothing for it.
The reference implementations disagree here
persisted.
Invokedcalls after the consumer stops, persisting the partialresponse.
close(), so aconsumer that stops early has no supported way to finish the run at all.
This framework follows Go. Saying so explicitly makes it read as a decision rather than an
accident, and tells a caller which of the three behaviours to design against.
Scope
TSDoc on
AgentRunStreamandResponseStreamcovering the three points above and the abortvariant. No behaviour change is expected — if writing it down turns up a case that does not hold,
that becomes a separate bug report with a failing test.