Spring AI Agent Explained: Type-Safe AI Agents for Java

On December 3, 2026, the Spring team announced Spring AI Agent, a new project for building AI agents in Java and Kotlin. It was built together with JetBrains, and it is experimental for now.

If you have used Spring AI to call a model, this is the next step. It helps you build agents that are easier to test, easier to follow, and safer to run. In this post, I will explain what it is, why it exists, and how its main parts work. I will also show small examples, so the ideas feel less abstract.

Table of Contents

Quick Facts

Item Detail
Announced December 3, 2026
Status Experimental, incubating
Repository spring-projects-experimental/spring-ai-agent
Built on Spring AI 2.1
First release 0.8.0
Languages Java and Kotlin
Plan Merge into Spring AI 3.0, planned for May 2027

What Is an AI Agent?

A normal model call is simple. You send a prompt and you get text back.

An agent does more. It works in several steps. It can call tools, such as a weather service or a database. It remembers what happened earlier. And it decides what to do next.

The Spring team describes it in one short line: an agent is a model plus a harness. The model does the thinking, and the harness is the code around it that handles tools, memory, and control.

You can already build an agent with ChatClient in Spring AI. Spring AI 2.1 added session memory with compaction, tool call confirmation, and reasoning that survives round trips to the model. Spring AI Agent builds on top of that.

Why a New Project?

The problem is control. If you leave the whole flow to the model, the result is hard to predict and hard to test. One run works, and the next one takes a strange path.

Spring AI Agent tries to fix that with a few ideas:

  • Type safety: inputs and outputs are real Java types, not loose text.
  • Graphs: you describe the steps and transitions of an agent as a graph, so you decide the path.
  • Durability: a run can resume after a crash or after waiting for a person.
  • Interoperability: agents can talk to other agents using the A2A protocol.

JetBrains had already used type safety and graph-based workflows in Koog, their agent framework. The two teams started sharing ideas, and Spring AI Agent draws inspiration from the best parts of Koog's design.

The Agent<I, O> Type

The central idea is a new type called Agent<I, O>. It has an input type I and an output type O. These are usually Java records or Kotlin data classes from your own domain, or just String.

You can run an agent in two ways:

  • Synchronously: call result(input) and wait for the answer.
  • Asynchronously: call run(input), which returns right away with a run object.

There are also resume methods. They let you continue a run that paused, for example while waiting for a human answer.

Because every agent has the same shape, you can combine them like building blocks. One agent can become a step inside another.

ChatClientAgent

The easiest way in is ChatClientAgent. It wraps a ChatClient you already have and exposes it as an Agent. When the output type is not String, it uses structured output, so the model's answer is turned into your record.

Here is a small example in the same style. The types are my own illustration, so treat it as a sketch, and check the project's documentation for the exact API of the version you use.

// Your domain types
record SupportMessage(String text) {}

record Ticket(String category, String priority, String summary) {}

// Wrap an existing ChatClient as a typed agent
Agent<String, Ticket> triage =
    ChatClientAgent.of(chatClient, Ticket.class);

// Run it and read a typed result
Ticket ticket = triage
    .result("My invoice is wrong and I need it fixed today")
    .output();

System.out.println(ticket.priority());

The nice part is that ticket is a real Ticket object. You do not parse text yourself.

It also works the other way around. A plain ChatClient can use any Agent<I, O> as a tool, and the model decides whether to call it based on its description.

ModelGraphAgent: Agents as Graphs

ModelGraphAgent is an alternative to ChatClient. Instead of letting the model run free, you compose the agent as a type-safe graph.

A graph is a set of steps (called nodes) joined by connections (called edges). Nodes can be:

  • Model calls and tool calls, available as reusable subgraphs.
  • Deterministic checks, like a guardrail that reviews the output.
  • Human-in-the-loop interrupts, where a person must approve something.

The Spring team's own example is a financial research assistant. The agent researches a ticker over a number of months and builds a report. A guardrail node then reviews the report. If the review is clean, the run finishes. If it is flagged, an interrupt asks a person to approve the report first.

Here is the flow in plain words:

Start → Research (model + tools) → Guardrail check
                                      ├─ clean   → End
                                      └─ flagged → Human approval → End

Every node and edge is type-safe. The announcement points out that the compiler or your IDE catches type mismatches before runtime, and refactoring stays safe. It also means each node can be tested on its own.

One detail matters here. A graph only processes complete outputs. So a node after a model call, such as a guardrail, applies to the final output of the run and not to text that was already streamed to the user.

Kotlin gets a DSL

Kotlin has first-class support through dedicated extensions. The same research agent can be written with a short, readable DSL, with steps joined using words like then. JetBrains is working on more Kotlin extensions and on documentation for it.

GraphAgent: Several Agents Together

GraphAgent uses the same graph model, but each node is a whole agent. This is how you orchestrate several agents.

The announcement shows a travel example. A passenger writes that a flight was cancelled. A triage agent turns that message into a structured disruption. Then three agents search at the same time for a way to rebook: one for the airline's own flights, one for partner airlines, and one for trains. The first option found wins, and the other searches are cancelled, all within a 30-second limit.

That parallel step uses a selection policy. Some of the policies named in the announcement are first(), all(), firstMatching(..), and atLeast(n, timeout).

Why separate agents help

  • Each subagent can have its own model, tools, instructions, and permissions. That lets you apply least privilege.
  • In a graph, the next agent is chosen deterministically. When an agent is used as a tool, the model makes that choice instead.
  • When an agent calls a subagent, you control what the subagent sees from the conversation. A delegated call adds its request and answer to the parent's conversation. Parallel branches get a copy of the conversation and return only their output.

Streaming with Virtual Threads

Spring AI Agent is the first Spring project to build on stream-source, a new library from the Spring team. It supports streaming in a plain, imperative style and uses virtual threads underneath when they are available.

That means you do not need to learn reactive programming to stream. You read events in a simple loop with the new Source<T> type. Each receiveNext() call blocks, which costs very little on a virtual thread.

Here is a short sketch of the idea. It is my own simplified version, so check the real event types in the project:

try (AgentRun<String> run = agent.run("What is the weather in Paris?")) {
    Source<AgentEvent> events = run.events();

    while (events.receiveNext()) {
        AgentEvent event = events.next();
        // handle each event as it arrives, for example print text
    }
}

These events are an observation channel. They let you follow a run while it is happening.

When virtual threads are not available, for example on Java 17, execution falls back to a pool of platform threads. Adapters between Source<T> and Reactive Streams Publisher<T> are also provided, so you can still use Reactor or WebClient if you need them.

The Spring team also says that in Spring AI 3.0 they plan to use the same virtual-thread-friendly model across all APIs. That would remove the mandatory dependency on Reactor and recommend Spring MVC and RestClient with virtual threads on Java 25 and later, while still supporting Java 17 and 21.

Features for Real Systems

A Feature plugs into the agent through three mechanisms:

  • Hooks: synchronous code that runs when a run starts, completes, fails, or is interrupted.
  • Interceptors: synchronous wrappers around model calls, tool calls, nodes, and conversation updates. They can modify, retry, or skip them.
  • Listeners: asynchronous observers of typed events, which can also trigger long tasks.

Features installed on the top-level agent also apply to every subagent.

Durability

Two features handle durability:

  • SessionFeature connects to Spring AI Session for conversation memory with compaction.
  • CheckpointFeature lets a run resume after a crash, or after waiting for human input. For now, in-memory and file checkpoint stores are included.

With checkpointing on, a checkpoint is saved after every node and after every tool round of a ChatClientAgent. This happens at any depth, including inside subgraphs and subagents.

The announcement shows how features are enabled on a builder. It looks roughly like this:

GraphAgent.builder(graph)
    .enable(new SessionFeature(sessionService))
    .enable(new CheckpointFeature(checkpointStore))
    .interceptor(piiRedaction)
    .listener(auditTrail)
    .build();

Here piiRedaction and auditTrail are your own components. This is a good place to add things like redacting personal data or writing an audit log.

A2A Support

A2A is a protocol that lets agents talk to other agents. Because every agent here implements Agent<I, O>, they compose naturally, and the built-in A2A support builds on that.

  • You can call a remote agent exposed as an A2A server through A2ARemoteAgent.
  • You can combine it with local agents inside a GraphAgent or ModelGraphAgent.
  • You can use it as a tool with your ChatClient.
  • You can expose any Agent<I, O> as an A2A server.

The Spring team says more detail on the graph design and on A2A will come in follow-up blog posts.

What About Koog?

Koog is JetBrains' open-source agent framework for Java and Kotlin. Spring AI Agent was inspired by it, and the Spring team asks Koog users to share which features they miss most. They also say they do not aim to support every Koog feature.

JetBrains says that, for teams running Koog with Spring, Spring AI Agent is a natural step forward. A JetBrains post titled "What Spring AI Agent Means for Koog Users" says Koog's core ideas continue in Spring AI Agent and that Koog itself will not receive new features. If you use Koog today, read that post before planning a move.

On the Kotlin side, the DSL works in any Spring Boot application. Even in a Java project, you could write one agent in Kotlin and run it alongside your services in the same build.

Should You Use It Now?

Be careful. The project is experimental. It is incubating for the next few months so the team can collect feedback, and the API may change before the merge into Spring AI 3.0.

Good reasons to try it now:

  • You want to learn how agents will be built in Spring.
  • You can build a small prototype or an internal tool.
  • You want to give the Spring team feedback.

Reasons to wait:

  • You need a stable API for a production system.
  • You cannot afford to rewrite code when names or packages change.

How to give feedback

The team says it prefers to discuss ideas before implementing them. So open an issue in the repository instead of sending a pull request directly. Kotlin developers can also join the #spring-ai-agent channel on the Kotlin Slack.

A safe way to start

  1. Make sure you have a working Spring AI 2.1 application with a ChatClient.
  2. Open the repository and read its README for the dependency setup of release 0.8.0.
  3. Wrap your ChatClient in a ChatClientAgent with a record as the output type.
  4. Move to a ModelGraphAgent only when you need guardrails or approval steps.
  5. Add checkpointing if your runs are long or wait for people.

FAQs

What is Spring AI Agent?

It is a new experimental Spring project for building AI agents in Java and Kotlin. It adds type-safe agents, graph-based workflows, durability, and A2A support on top of Spring AI 2.1.

Is Spring AI Agent production ready?

Not yet. It is incubating in an experimental repository, and the first release is 0.8.0. The team plans to merge it into Spring AI 3.0 in May 2027.

What is the difference between Spring AI and Spring AI Agent?

Spring AI gives you the building blocks, such as ChatClient, tool calling, and memory. Spring AI Agent adds a structured way to build and orchestrate agents with typed graphs and enterprise features.

What is a ModelGraphAgent?

It is an agent built as a type-safe graph. The graph can mix model calls, tool calls, deterministic checks, and human approval steps.

What is a GraphAgent?

A GraphAgent orchestrates several agents. Each node in the graph is an agent, and the graph decides which one runs next.

Do I need reactive programming?

No. Spring AI Agent offers an imperative streaming API called Source<T> that uses virtual threads when they are available. Reactive adapters are available if you want them.

Which Java version do I need?

The announcement uses Java 25 in its streaming example. It also says execution falls back to platform threads when virtual threads are unavailable, such as on Java 17.

What happens to Koog?

JetBrains says Koog's core ideas continue in Spring AI Agent and that Koog itself will not receive new features. Check JetBrains' dedicated post for the latest guidance.

Final Thoughts

Spring AI Agent is the Spring team's answer to a real problem: agents that are powerful but hard to predict. Typed inputs and outputs, explicit graphs, checkpoints, and clean streaming make agents easier to build and test.

It is early, so treat it as something to learn and prototype with. Try a small agent, read the repository, and share your feedback while the design is still open.

Comments