Skip to main content

Spring Boot

The Spring integration exposes any Agent bean as an AG-UI SSE endpoint. It comes in two variants. Both use the same routing and the same JacksonSerializer, and both work with the HttpAgent client. All of these modules are at version 4.1.0 and target Spring Boot 4.1.x. Each auto-configuration activates only for its own web application type.

Quick start

Define an Agent bean:
POST /agent with a JSON RunAgentInput now streams the agent’s events.

What gets auto-configured

You can replace any of these by defining a bean of the same type.

Endpoints

{path} defaults to /agent. Change it with a property:
Both controllers respond with text/event-stream. A body that cannot be deserialized returns 400 Bad Request. If the agent signals onError, the controller writes a final RUN_ERROR event and closes the stream.

Multiple agents

Each Agent bean is reachable under its bean name:
To use IDs other than bean names, define your own registry:

WebFlux and WebMVC differences

  • WebFlux converts the agent’s Flow.Publisher to a Flux<ServerSentEvent<String>>. Reactor handles backpressure and cancels the subscription when the client disconnects.
  • WebMVC streams through an SseEmitter with no timeout. It requests all events at once and relies on SseEmitter.send blocking on the Servlet output for flow control. If a write fails, it cancels the subscription.

Wiring without auto-configuration

The controllers are plain classes, so you can create them yourself:
AgUiController lives in com.agui.community.spring.server (WebFlux) and in com.agui.community.spring.webmvc (WebMVC).

Serving a Spring AI model

To serve a Spring AI ChatClient as an agent, see Spring AI.