Skip to main content

Java SDK

The AG-UI Java SDK is a modular library for the Agent User Interaction Protocol. You can use it to call a remote AG-UI agent from Java, to serve your own agent to any AG-UI front end, or both. Note: This SDK is community contributed and maintained. Source code lives in sdks/community/java. The SDK is built around a few design choices:
  • Plain JDK streaming. An agent run is a java.util.concurrent.Flow.Publisher<Event>, the Reactive Streams interface that ships with the JDK. The core needs no Reactor, RxJava or coroutines, and you can adapt the publisher to any of them.
  • No runtime dependencies in the core. java-core, java-client and java-server depend only on the JDK. JSON goes through a Serializer interface that you plug in. A ready-made Jackson implementation is available.
  • Sealed, record-based model. Event and Message are sealed interfaces implemented by records, so you can handle them with an exhaustive switch.
  • Transport-neutral server. The server core does not depend on any HTTP framework. It ships an adapter for the JDK’s built-in HTTP server, and separate Spring WebFlux, Spring WebMVC and Spring AI integrations.

Requirements

  • Java 17 or later
  • For the Spring modules: Spring Boot 4.1.x, and Spring AI 2.x for the Spring AI modules

Modules

All artifacts are published to Maven Central under the com.ag-ui.community group ID.

Core library

Spring integration

The Spring modules are versioned in two lines. The Spring Boot line follows the Spring Boot version it targets, and the Spring AI line follows the Spring AI version.

Installation

Add the modules you need. java-client and java-server pull in java-core transitively.
With Gradle:

Quick start

Implement an agent

Agent is a functional interface. It takes a RunAgentInput and returns a Flow.Publisher<Event>. Each subscription to that publisher is one run. The JDK’s SubmissionPublisher is the simplest way to produce events:

Serve it

The JDK’s built-in HTTP server is enough to expose the agent as an SSE endpoint:
Any AG-UI client can now POST a RunAgentInput to http://localhost:8080/agent.

Call it

HttpAgent is the client side. It is also an Agent, so it is consumed the same way as a local agent:

Use Spring AI without writing code

To serve an LLM through Spring AI, add ag-ui-spring-ai-spring-boot-starter (or ag-ui-spring-ai-webmvc-boot-starter for a Servlet app) together with a Spring AI model starter such as spring-ai-starter-model-openai. A SpringAiAgent is registered from the auto-configured ChatClient.Builder and served at /agent. See Spring AI.

Next steps

  • Core: the Agent interface, streaming, and serialization
  • Types: RunAgentInput, messages, tools, and interrupts
  • Events: every event record and its fields
  • Client: calling remote agents with HttpAgent
  • Server: serving agents with the JDK server or your own transport
  • Spring: WebFlux and WebMVC endpoints and starters
  • Spring AI: turning a ChatClient into an AG-UI agent