Skip to main content

Module 05: Streaming Updates

Receive real-time updates from an agent while it processes your prompt.

What You’ll Learn

  • Registering a sessionUpdateHandler on the client
  • Dispatching on SessionUpdate types with instanceof
  • Handling message chunks, thoughts, tool calls, and plans

The Code

The client registers an update consumer that receives each SessionUpdate as it arrives:
The handler uses 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 GitHub

Running the Example

Requires the Grok CLI on your PATH, signed in once with grok login. The module launches it as grok agent stdio; no API key is needed.

Next Module

Module 12: Echo Agent — build your first ACP agent (no API key required).