Skip to main content

Module 22: Async Agent

The reactive, non-blocking version of Module 12 (Echo Agent).

What Youโ€™ll Learn

  • AcpAgent.async() instead of AcpAgent.sync()
  • Handlers returning Mono<T> instead of T
  • Chaining sendMessage() with then() before returning the response
  • Agent lifecycle: start().block() + awaitTermination().block()

The Code

Sync vs Async Agent Comparison

The critical difference: in the async agent, context.sendMessage() returns Mono<Void>. You must chain it with .then() before returning the response Mono. If you skip the chain, the message wonโ€™t be sent before the response.

Source Code

View on GitHub

Running the Example

Key Points

  • No API key โ€” the async agent runs entirely locally, same as Module 12
  • Same protocol โ€” sync and async agents are interchangeable from the clientโ€™s perspective
  • Reactive integration โ€” async agents work naturally with Project Reactor, R2DBC, and other reactive libraries

Previous Module

Module 21: Async Client โ€” the reactive client API.