// Build async client — note AcpAsyncClient return type
AcpAsyncClient client = AcpClient.async(transport)
.sessionUpdateConsumer(notification -> {
// Async consumer must return Mono<Void>
var update = notification.update();
if (update instanceof AgentMessageChunk msg) {
if (msg.content() instanceof TextContent text) {
System.out.print(text.text());
}
}
return Mono.empty();
})
.build();
// Chain operations reactively with flatMap
client.initialize()
.flatMap(init -> client.newSession(
new NewSessionRequest(".", List.of())))
.flatMap(session -> client.prompt(
new PromptRequest(session.sessionId(),
List.of(new TextContent("What is 2+2?")))))
.flatMap(response -> client.closeGracefully())
.subscribe(
unused -> {},
error -> System.err.println("Error: " + error.getMessage()),
() -> System.out.println("Done!")
);