Streaming
The Client SDK provides real-time access to streaming content through the message parts array. Each part has its own status, enabling responsive UIs that update as the agent generates responses.
Streaming State
Building a Streaming UI
Rendering Streaming Parts
Parts update in real-time during streaming. Use the part's status to show appropriate UI:
Tool Call States
Tool calls progress through multiple states:
Status Indicator
Handling Completion
See Error Handling for comprehensive error handling patterns.
When stop() is called:
- The HTTP request is aborted (requires
signalin transport) - Any partial text/reasoning is finalized with
donestatus - In-progress tool calls are marked as
cancelled - The
onStopcallback is invoked - Status changes to
idle
Partial content is preserved in the message, so users don't lose what was already generated.
Auto-Scroll
Chat interfaces should scroll to the bottom as new content streams in, but pause if the user has scrolled up to read earlier messages. The useAutoScroll hook handles this:
The hook returns four values:
| Return Value | Purpose |
|---|---|
scrollRef | Attach to the scrollable container's ref |
handleScroll | Attach to the container's onScroll — tracks whether the user is near the bottom |
scrollOnUpdate | Call inside a useEffect when messages change — scrolls to bottom if the user hasn't scrolled up |
resetAutoScroll | Call when the user sends a message — forces the next update to scroll to bottom |
You can customize the hook with options:
Named Thread Content
Content from named threads (like "summary") streams separately and is identified by the thread property: