Module 05: Streaming Updates
Receive real-time updates from an agent while it processes your prompt.What You’ll Learn
- Registering a
sessionUpdateHandleron the client - Dispatching on
SessionUpdatetypes withinstanceof - Handling message chunks, thoughts, tool calls, and plans
The Code
The client registers an update consumer that receives eachSessionUpdate as it arrives:
instanceof to dispatch on the SessionUpdate type:
Session Update Types
Updates arrive during
client.prompt(). The prompt call blocks until the agent returns a PromptResponse, but updates stream in continuously through the consumer.
As of 0.80.0, prompt() returns only after the consumer has finished handling every update from that turn. So by the time prompt() returns, whatever your consumer collected (printed text, counted tool calls, and so on) is already complete; there’s no need to wait or poll for trailing updates afterward.
Source Code
View on GitHubRunning the Example
Requires the Grok CLI on yourPATH, signed in once with grok login. The module launches it as grok agent stdio; no API key is needed.