Spring AI 2.0 in Practice: A Complete Guide to Building a Code Generation Agent from Scratch

A complete guide to building a code generation Agent with Spring AI 2.0 by reverse-engineering Claude Code.
This guide explores Spring AI 2.0's evolution from a chatbot framework to a full Agent development platform. It demonstrates how to leverage the Agent Utils toolkit—which reverse-engineers Claude Code's architecture—to build a code generation assistant from scratch, covering core capabilities like task planning, long-term memory, Skills modularization, and MCP integration for enterprise Java teams.
From Chatbot to Autonomous Agent: Spring AI 2.0's Critical Leap
Spring AI 2.0 has been out for a while now, and discussions around it are heating up. According to a course series shared by Bilibili creator Xu Shulai, the most significant update in version 2.0 isn't a refactoring of the underlying APIs—it's the completion of the Agent foundation.
In the 1.0 era, Spring AI could essentially only play the role of an "enhanced chatbot"—it could call large models, integrate Tools, maintain conversation memory, and ultimately produce a conversational application. But this was still noticeably far from a true Agent.
The term Agent in the AI field specifically refers to an intelligent system with autonomous decision-making capabilities, distinct from simple Q&A bots. A complete Agent needs four core capabilities: perception (receiving environmental information), planning (decomposing tasks and formulating strategies), action (calling tools to execute operations), and reflection (evaluating results and adjusting strategies). This concept can be traced back to the BDI (Belief-Desire-Intention) architecture in AI research, and has re-emerged as an engineering hotspot in recent years as large language models' reasoning abilities have improved.
To implement an Agent with autonomous planning and thinking in the 1.0 era, developers had to rely on Spring AI Alibaba Agent Framework, an open-source framework released by Alibaba. It extended Spring AI significantly, supporting React Agent (reasoning-action loops) and Workflow-based autonomous orchestration. React (Reasoning and Acting) is an Agent paradigm proposed by Princeton University and Google in 2022. Its core idea is to have the large model first reason (Thought) at each step, then decide what action to take (Action), observe the action's result (Observation), and then enter the next round of reasoning. This alternating cycle simulates the human problem-solving thought process, and compared to one-shot answer generation, React can significantly improve completion quality and accuracy for complex tasks.

The significance of Spring AI 2.0 is that the official native framework itself has filled this capability gap. It can now support the complete closed loop of "autonomous thinking → calling Tools → executing actions → iterating in loops" until the task is complete. This marks Spring AI's evolution from a "large model calling toolkit" to a full-fledged "Agent development framework."
Agent Utils Toolkit: A Low-Cost Shortcut by Reverse-Engineering Claude Code
The real value increment of 2.0 is concentrated at the Agent ecosystem layer. According to the course, the Spring AI community provides a set of Agent Utils tools, and a standout characteristic of this toolkit is that it directly reverse-engineered Claude Code (Anthropic's official command-line code assistant) in terms of design philosophy.
Claude Code is a command-line AI programming assistant launched by Anthropic in early 2025. It runs in a terminal environment and can directly read/write the local file system, execute shell commands, search codebases, and perform multi-step code modifications. Its core design philosophy is to give AI complete development environment operation capabilities, rather than merely generating code snippets. Claude Code adopts a tool-calling + loop-reasoning architecture, where each step can invoke file operations, search, command execution, and other tools, deciding the next action based on results until the user's programming task is complete.

This means developers don't need to figure out Agent engineering paradigms from scratch. Instead, they can stand on the shoulders of a mature product and quickly reuse a proven code generation assistant architecture. In his course, Xu Shulai leverages this toolkit to build a Claude Code-like code generation assistant project.
This "reverse-engineer + encapsulate" approach is highly instructive for enterprise development: rather than redesigning task orchestration and tool-calling protocols from scratch, it's better to learn from industry-leading products' interaction patterns and then do a second layer of encapsulation using Spring ecosystem's engineering capabilities.

From a cost perspective, this development path is extremely efficient—you can quickly get started with Spring AI 2.0 while simultaneously mastering the Agent Utils toolkit, killing two birds with one stone.
Technical Roadmap for the Hands-On Project: A Complete Pipeline from Basics to Advanced
The course adopts a progressive teaching structure, extending from the most basic capabilities of large models all the way to advanced Agent features. The overall technical roadmap can be broken down into the following layers:
Basic Conversation Layer: ChatClient and Model Integration
The bottom layer remains the capabilities already mature in Spring AI 1.0, including ChatClient, ChatModel, integration with various models, and streaming output. Streaming output means that instead of waiting for the entire content to be generated before returning, the large model pushes content to the client in real-time, token by token. Technically, this is usually implemented via Server-Sent Events (SSE) or WebSocket. For user experience, streaming output can reduce first-token response time from several seconds to milliseconds; for developers, it enables finer interrupt control and progress display. In Agent scenarios, streaming output is particularly important because Agent reasoning processes are often lengthy, and showing thinking steps in real-time significantly boosts user trust.
Interestingly, over 90% of Spring AI 2.0's content has no fundamental changes from 1.0, so developers who want to dig deep into the underlying source code can refer to the earlier 1.0 course series.
Memory and Tools Layer: The Transition from Chat to Agent
Building on the conversation foundation, capabilities like Memory, Tools invocation, and MCP (Model Context Protocol) are gradually added.
MCP is a standardized protocol open-sourced by Anthropic in late 2024, designed to solve the connection problem between large models and external tools/data sources. Before MCP, every AI application needed to write independent integration code for each external service, resulting in massive duplication of work. MCP adopts a client-server architecture with a unified communication format, enabling any MCP-compliant tool server to be directly called by any MCP client (such as an AI application). This is similar to what USB protocol does for hardware devices—once standardized, it becomes plug-and-play. Spring AI 2.0's support for MCP means developers can easily connect to the numerous MCP tool servers already available in the community.
This layer gives applications the conditions for context awareness and external capability extension, serving as the transitional stage from chat to Agent.
Agent Capability Layer: Core Features Explained
This is the core of the entire course, built around Spring AI Agent Utils, covering several key features:
-
Ask User Question: When prompt information is insufficient, the large model proactively asks the user questions to fill in context. This is a critical mechanism for solving the "ambiguous user instructions" pain point. In traditional AI applications, when facing vague instructions, models tend to give potentially inaccurate answers based on guesswork; the Ask User Question mechanism gives Agents the ability to "follow up," similar to how an experienced developer would confirm details before blindly starting work on a requirement.
-
Skills Modularization: Gives Agents composable, reusable capability units, improving code reuse. Each Skill can be understood as an encapsulated capability module containing specific prompt templates, tool collections, and execution logic. During the planning phase, the Agent can dynamically combine different Skills based on task needs.
-
Task Planning: The Agent autonomously decomposes complex tasks, forms execution paths, and achieves multi-step automation. For example, when a user says "help me refactor this module and write unit tests," the Agent automatically breaks it down into: analyze existing code structure → identify refactoring points → execute refactoring → write test cases → run tests for verification. Each step's results influence the next step's decisions.
-
Long-term Memory: Retains information across sessions, letting the assistant truly "remember" project context. Long-term memory faces multiple engineering challenges: first, information filtering—not all conversation content is worth remembering, requiring model or rule-based judgment on what key information deserves persistence; second, retrieval efficiency—when memory accumulates to a certain scale, how to find memory fragments relevant to the current task within milliseconds typically requires vector databases and semantic retrieval technology; third, memory updates—old information may become outdated or contradictory, requiring mechanisms to handle memory overwriting and invalidation. Current mainstream approaches include embedding-based vector retrieval, knowledge graph-based structured storage, and hybrid architectures combining both.

Implications for Enterprise AI Development
The value of this hands-on course lies not only in teaching how to build a code generation assistant, but also in outlining a complete methodology for enterprise-grade Agent development in the Java ecosystem.
For Java teams deeply rooted in the Spring technology stack, Spring AI 2.0 means they can build production-grade Agent applications without switching to the Python ecosystem. Previously, mainstream AI application development frameworks like LangChain and LlamaIndex were almost exclusively Python-based, forcing Java developers to either learn a new language stack or settle for limited early Java wrappers. The maturity of Spring AI 2.0 allows Java teams to build AI applications within the familiar paradigms of dependency injection, interface-oriented programming, and declarative configuration, dramatically reducing technology switching costs.
Features like Ask User Question, Task Planning, and Long-term Memory are precisely where enterprises most commonly encounter pitfalls during real-world deployment—how to handle incomplete user input, how to orchestrate multi-step tasks, and how to maintain cross-session state all have standardized solutions within this framework.
More importantly, the "reverse-engineering Claude Code" approach itself is instructive. It reminds us that AI application development is shifting from "reinventing the wheel" to "reusing best practices." When proven product forms like Claude Code already exist in the industry, borrowing their architecture and quickly encapsulating it with local technology stacks is often the most cost-effective path to production.
Summary
Spring AI 2.0's core leap lies in its native support for Agent capabilities, while the Agent Utils toolkit provides a low-cost practical entry point through reverse-engineering Claude Code. For Java developers, this is an excellent time to enter the AI Agent development field—you can reuse the familiar Spring engineering paradigms while mastering cutting-edge Agent capabilities like task planning and long-term memory. As the framework ecosystem continues to mature, Java's voice in enterprise AI applications is poised to grow even stronger.
Related articles

Google Antigravity + Gemini 3.7 Flash: An Efficient Approach to Multi-Agent Collaboration
Explore how Google's Antigravity orchestration platform and Gemini 3.7 Flash model work together to solve complex multi-agent math and engineering problems.

Max Plan Shifts from Subscription to Credits — Has Your Usage Actually Shrunk?
AI coding subscriptions shift from session-time to API credits. A $100 Max plan now offers $300 in credits at a 3:1 ratio — has actual usage really shrunk?

OpenAI Cuts Off Cursor: The Full Story Behind the Feud and China's Push for Open-Source, Affordable AI
OpenAI cuts Cursor's model access over Musk's acquisition; Cursor pivots to Claude. Meanwhile, Chinese AI models like Qwen, GLM, and Hunyuan push open-source affordability, accelerating AI democratization.