Streaming Responses, Tool Events, and Completion
Streaming displays updates while a response is being produced. Handle progress, tool activity, errors, and completion separately so a partial answer is not shown as finished.

Illustrative client dispatch logic. Map these helpers to the chosen endpoint’s documented event shape and snapshot/delta behavior. A connection closing without a completion signal is not proof of success.
Before you begin
A streaming-capable interface or documented streaming API endpoint.
Key concepts
Streaming
Delivery of incremental events or text while work is running. Updates are not the same as a completed answer.
Tool result
The returned data or error from a tool operation. The agent should base its report on this result rather than assuming the call succeeded.
Finish reason
Information indicating why generation ended, when the provider supplies it. Distinguish normal completion from a length limit, interruption, or unreported reason.
Terminal state
A state indicating that a run has ended, such as succeeded, failed, or cancelled. Stop normal completion polling only after a final state is known.
Run
One execution of a project. Use its run ID to retrieve that execution’s state, input, output, and errors.
Handle a streaming response
Start a request using the endpoint’s required streaming format.
Read events as they arrive and update the appropriate part of the interface.
Wait for completion or an explicit failure before marking the answer complete.
The user sees progress and can distinguish a complete response from an interrupted one.
Behavior and limitations
Not every event is answer text. A disconnected stream does not prove that execution stopped. Preserve the run ID and retrieve status where supported. Tool events can contain structured data that should not be appended directly to the answer. Streaming contracts differ between API versions.
Related resources
Was this helpful?

