Skip to main content

Module 06: Update Types

Comprehensive coverage of all SessionUpdate types in ACP.

What You’ll Learn

  • All seven SessionUpdate types and when they appear
  • Dispatching on update types with instanceof
  • Building rich UIs that show agent activity

The Code

The client registers a sessionUpdateConsumer and uses instanceof to handle each type:
AcpSyncClient client = AcpClient.sync(transport)
    .sessionUpdateConsumer(notification -> {
        SessionUpdate update = notification.update();
        if (update instanceof AgentMessageChunk msg) {
            System.out.print(((TextContent) msg.content()).text());
        } else if (update instanceof AgentThoughtChunk thought) {
            System.out.println("[Thought] " +
                ((TextContent) thought.content()).text());
        } else if (update instanceof ToolCall tc) {
            System.out.println("[Tool] " + tc.title() +
                " | " + tc.kind() + " | " + tc.status());
        } else if (update instanceof ToolCallUpdateNotification tcUpdate) {
            System.out.println("[ToolUpdate] " +
                tcUpdate.toolCallId() + " -> " + tcUpdate.status());
        } else if (update instanceof Plan plan) {
            System.out.println("[Plan] " + plan.entries().size() + " entries:");
            plan.entries().forEach(entry ->
                System.out.println("  - " + entry.content() +
                    " [" + entry.status() + "]"));
        } else if (update instanceof AvailableCommandsUpdate commands) {
            System.out.println("[Commands] " +
                commands.availableCommands().size() + " available");
        } else if (update instanceof CurrentModeUpdate mode) {
            System.out.println("[Mode] " + mode.currentModeId());
        }
    })
    .build();

Update Types Reference

TypeContentTypical Use
AgentMessageChunkIncremental response textMain output, streamed word by word
AgentThoughtChunkAgent’s thinking processShow reasoning in a collapsible panel
ToolCallTool execution startShow tool name, kind, and status
ToolCallUpdateNotificationTool progressUpdate status of in-progress tool
PlanAgent’s planned stepsShow step list with priorities and completion
AvailableCommandsUpdateSlash commandsPopulate command palette
CurrentModeUpdateMode changeUpdate UI mode indicator
This module extends Module 05 by handling every update type rather than just messages.

Source Code

View on GitHub

Running the Example

export GEMINI_API_KEY=your-key-here
./mvnw exec:java -pl module-06-update-types

Next Module

Module 07: Agent Requests — handle file read/write requests from agents.