Spring AI 2.0 in Practice: A Getting-Started Guide to AI Agents for Java Developers

Spring AI 2.0 brings native Agent capabilities to Java, enabling autonomous AI agents within the Spring ecosystem.
Spring AI 2.0's most significant update is its Agent foundation layer, enabling Java developers to build autonomous AI agents without leaving the Spring ecosystem. This tutorial guide covers a hands-on project that reverse-engineers Claude Code's approach using Spring AI Agent Utils, walking through tool calling, streaming output, MCP protocol integration, task planning, proactive questioning, and long-term memory.
From Chatbot to Agent: The Critical Leap in Spring AI 2.0
Spring AI 2.0 has been out for a while now, and many Java developers are curious about what substantive changes it actually brings. A tutorial series by Bilibili creator Xu Shu offers a clear answer: the most pivotal update in version 2.0 is the completion of the Agent foundation layer.
The concept of AI Agents originates from classical theories in artificial intelligence research, but it has taken on entirely new meaning in the era of large language models. A traditional chatbot is essentially a "request-response" system: the user asks a question, the model answers, and the interaction ends. The fundamental difference with an agent is that it has a continuously running decision loop — perceiving the environment, formulating plans, executing actions, observing results, and making decisions again until the goal is achieved. This loop is known in academia as the "Perception-Action Loop." In engineering practice, an Agent typically requires four key components: a large language model as the reasoning engine, a set of Tools as the means of execution, a Memory system to maintain context, and Orchestration logic to control the entire loop. It is precisely this orchestration layer that determines whether a framework is merely "a tool that can call LLMs" or "a true agent foundation."
In the 1.0 era, Spring AI was essentially an "LLM invocation framework" — it could connect to various LLMs, call Tools, maintain conversation memory, and ultimately help you build a chatbot. But that was still a distance away from a true AI Agent. A genuine agent needs the ability to think autonomously, invoke tools, execute actions, and iterate in a loop until the task is complete — and this is precisely the critical gap that 2.0 fills.
It's worth emphasizing that over 90% of Spring AI 2.0's content is actually inherited from 1.0 — including foundational capabilities like ChatClient, ChatModel, various LLM integrations, and structured output, none of which have fundamentally changed. The real incremental value is concentrated in the Agent ecosystem layer. Therefore, if you've already mastered 1.0, the learning curve for 2.0 is not steep — you just need to focus on thoroughly understanding the new Agent components.

Alibaba's Open-Source Framework Was Once the Only Path to Agent Development
Before Spring AI 2.0, if you wanted to develop agents within the Spring ecosystem, it was nearly impossible to avoid Spring AI Alibaba Agent Framework, an open-source framework created by Alibaba. It built extensive extensions on top of Spring AI, supporting ReAct Agents (autonomous planning and reasoning) and workflow-based Agent applications with customizable orchestration paths.
ReAct (Reasoning + Acting) is an agent reasoning paradigm proposed by Google Research in 2022. Its core idea is to have the LLM alternate between "reasoning" and "acting" steps when executing tasks: the model first "thinks" in natural language about what it should do next (Thought), then performs a concrete action such as calling a tool (Action), then observes the result returned by that action (Observation), and enters the next round of thinking. This Thought-Action-Observation loop enables the model to dynamically adjust its strategy based on intermediate results, rather than generating a final answer in one shot. Compared to pure reasoning (Chain-of-Thought), ReAct can interact with the external world; compared to pure action (directly calling tools), ReAct has an explicit reasoning process, making decisions more controllable and explainable. This paradigm has become the core design pattern of mainstream Agent frameworks today.
The significance of 2.0 is that Spring AI's native framework itself now possesses the most fundamental Agent capabilities. This means Java developers no longer need to rely heavily on external frameworks in many scenarios to achieve the complete loop of "think → call tools → execute → iterate."
Hands-On Project: Reverse-Engineering Claude Code's Code Generation Assistant
The most interesting aspect of this tutorial series is its choice of a substantial hands-on project: building a code generation assistant using Spring AI Agent Utils (an Agent utility library).
This utility library reportedly reverse-engineered Claude Code's implementation approach. Claude Code is a command-line AI coding tool released by Anthropic, officially launched in early 2025. Built on the Claude model, it can directly understand codebase context in the terminal, write and modify code, execute commands, manage Git operations, and more. The reason Claude Code has been so well-received in the developer community lies in the maturity of its Agent architecture: rather than simply generating code snippets, it completes coding tasks through a full agent loop — analyzing requirements, reading project files, formulating implementation plans, writing code step by step, running tests for verification, and automatically fixing errors. This "autonomous coding" capability sets it apart from traditional code completion tools (such as early versions of GitHub Copilot). Anthropic's tool-calling design for Claude Code — including how it wraps system-level tools like file read/write, command execution, and search — is considered one of the most engineering-mature implementations to date, which is why reverse-engineering its approach has such high learning value.
With this ready-made utility library, developers can replicate similar code generation capabilities at extremely low cost.

Why This Hands-On Entry Point Is Worth Learning
From a learning path perspective, this project is quite cleverly designed, achieving two goals with one effort:
- On one hand, through a complete hands-on project, you can quickly get up to speed with the core usage of Spring AI 2.0;
- On the other hand, you gain mastery of the Spring AI Agent Utils library and understand the agent logic behind a mature AI coding tool.
Compared to simply walking through API documentation, using a real, runnable Java agent project to tie together knowledge points gives developers a much more intuitive understanding of how Agents work.

A Progressive Knowledge Framework
The tutorial adopts a progressive structure, transitioning from the most basic capabilities to advanced Agent features, with a clear overall trajectory:
Foundation Layer: Conversation and Interaction
- Basic LLM Conversation: The most fundamental Q&A capability, understanding how to use ChatClient
- Streaming Output: Achieving a typewriter-style real-time response effect. Streaming output is a key technique for improving user experience in LLM applications. Large language models generate text through token-by-token prediction — each time predicting the next token based on existing context, then adding the new token to the context to continue predicting. With the traditional HTTP request-response model, users must wait for the model to finish generating all tokens before seeing any results, which could take tens of seconds for long-form text. Streaming output uses technologies like Server-Sent Events (SSE) to push each token to the client immediately after generation. In Spring AI, this is typically implemented through Flux reactive streams — ChatClient returns not a complete string but a stream of tokens, and the frontend can progressively render each received token, reducing the user's perceived wait time from "total generation time" to "time to first token" (TTFT), typically just a few hundred milliseconds.
- Memory: Maintaining multi-turn conversation context for more coherent interactions
Capability Layer: Tool Calling and Protocol Integration
- Tools (Tool Calling): Giving LLMs the ability to invoke external functions, which is the foundation for building agents
- MCP (Model Context Protocol): A standardized protocol for context and tool integration. MCP is an open standard protocol introduced by Anthropic in late 2024, designed to address the standardization of connections between LLMs and external data sources/tools. Before MCP, every AI application that needed to integrate external tools (such as database queries, API calls, file operations, etc.) required custom adapter code, creating a massive M×N integration problem — M AI applications connecting to N tools required M×N adapters. MCP simplifies this to M+N by defining a unified communication protocol: AI applications only need to implement an MCP client, and tool providers only need to implement an MCP server, enabling interoperability. MCP uses JSON-RPC 2.0 as its communication foundation and supports three core capabilities: tool invocation (Tools), resource access (Resources), and prompt templates (Prompts). Spring AI 2.0's native MCP support means Java developers can directly tap into the entire MCP tool ecosystem without writing a separate adapter layer for each tool.
Agent Layer: Core Features of Spring AI Agent Utils
This is the centerpiece of the entire tutorial, covering the core capabilities that truly differentiate Agents from chatbots:
- Ask User Question (Proactive Questioning): When the prompt lacks sufficient information, the LLM proactively asks the user to fill in the missing details. This mechanism elevates the Agent from "passively receiving instructions" to "actively clarifying requirements" — a critical element in agent interaction design.
- Skills (Skill Encapsulation): Packaging reusable capability units for the Agent to improve development efficiency
- Task Planning: Enabling the Agent to autonomously decompose complex tasks and orchestrate execution paths
- Long-Term Memory: Breaking through single-session limitations to achieve memory persistence across sessions. In AI Agent memory system design, short-term memory and long-term memory solve problems at entirely different levels. Short-term memory (also called session memory) refers to contextual information maintained within a single conversation session, technically implemented by concatenating historical messages into the Prompt. Its main challenge is the LLM's limited context window, requiring strategies like sliding windows and summary compression for management. Long-term memory, on the other hand, is persistent memory across sessions, allowing the Agent to remember user preferences, project backgrounds, technology stack choices, and other information expressed in previous sessions. Long-term memory is typically implemented using vector databases (such as Chroma or Milvus) — encoding important information as vectors and persisting them, then retrieving relevant memories via semantic search when a new session begins. This enables the Agent to "know" the user like a real assistant, rather than starting from scratch with every conversation.

Practical Value for Java Developers
For Java developers working within the Spring technology stack, the arrival of Spring AI 2.0's Agent capabilities means they don't have to switch to the Python ecosystem to build autonomous agent applications within their familiar framework. This is especially important in enterprise development scenarios — a vast number of existing systems are already built on Spring, and native AI integration can significantly reduce the cost of architectural refactoring.
From the tutorial's positioning, it emphasizes being "beginner-friendly" and "practice-driven," avoiding complex theory and instead using projects to drive learning. The advantage of this approach is a fast start and a strong sense of accomplishment. However, it's worth noting that if you want to dive deeper into underlying principles (such as the source code implementation of ChatClient and ChatModel), you'll still need to go back to the 1.0 systematic courses to build your foundation, since 2.0 made no major changes at these foundational layers.
Overall, Spring AI 2.0 has filled the gap in Agent foundation capabilities, and combined with community-provided Agent utility libraries, it is making Java a pragmatic choice for building AI agents. For developers who want to get started with AI Agent development without leaving the Java ecosystem, this is a technical direction well worth following closely.
Related articles

Cursor Tutorial: Building a Python Student Management System from Scratch with AI
Learn Cursor AI editor's Agent, Ask, and Manual modes with a hands-on demo building a Python student management system using Claude, from tech stack selection to deployment.

NotebookLM Usage Limits Are Here: A Complete Guide to Google's Flexible Quota System
Google introduces flexible usage limits for NotebookLM. Learn how the new quota system affects free and paid users, and what it means for the AI industry's shift toward sustainable operations.

AI Agent Performance Optimization in Practice: Three Key Upgrades That Dramatically Improved Output Quality
Deep dive into three key AI Agent upgrades: eliminating silent failures, setting approval gates, and sub-agent parallel processing. Practical tips for building trustworthy automated workflows.