跪拜 Guibai
← All articles
Backend · Interview · AIGC

Spring AI 2.0 Source Code Deep-Dive Series Kicks Off with a 24-Part Call-Chain Breakdown

By 一只叫煤球的猫 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Spring AI's abstractions make the happy path trivial, but when a production issue hits—a missing tool execution, a bloated context, or a silent model-switch failure—developers need to know exactly which layer to breakpoint. This series maps the real call chain so teams can debug with confidence instead of guessing.

Summary

A planned 24-article series will dissect the Spring AI 2.0 source code by following a single conversation request through the entire framework. The series starts with the four-line `ChatClient` call that most developers use daily and traces it through auto-configuration, `Prompt` assembly, the `ChatModel` abstraction, and into the provider SDK. Streaming responses and structured output are examined along this same main chain.

Once the core path is clear, the series moves to the Advisor Chain, where `ToolCallingAdvisor` orchestrates multi-turn tool execution loops. It then covers MCP for remote tool, resource, and prompt discovery, and finishes with RAG pipelines, embedding models, vector stores, retry logic, and custom model-provider integration. The analysis is pinned to version 2.0.0, which restructured Options, null safety, and tool-calling loops on top of Spring Boot 4 and Spring Framework 7.

Each article tackles one problem by following the actual execution path with a debugger, keeping only the source code that affects the flow. The goal is to replace the black-box feeling of Spring's abstractions with a clear, debuggable mental model of where every feature hooks into the request lifecycle.

Takeaways
Spring AI 2.0.0 targets Spring Boot 4 and Spring Framework 7, reworking Options, null safety, and model integration.
The tool-calling loop now lives inside the Advisor Chain, so multi-turn tool execution and structured-output retries share the same infrastructure.
A four-line `ChatClient` call hides auto-configuration, Prompt assembly, Advisor interception, and provider-SDK translation.
MCP integration changes the call chain by introducing remote tool discovery and registration before the request ever reaches the model.
The series follows a debugger-driven approach: set a breakpoint at the business entry and trace the actual execution path, not the package structure.
Conclusions

Most Spring AI users treat the framework as a black box, which works until a multi-turn tool call fails silently or context management balloons costs. The series addresses a real gap between 'it runs' and 'I can fix it.'

Pinning the analysis to a single commit (ef502da) and a single version avoids the common trap of source-code walkthroughs that mix behaviors from different releases, making the material reliable as a reference even after upstream changes.

Spring's abstraction layers are a double-edged sword: they shrink boilerplate but scatter the call chain across interfaces, auto-configuration, and Advisors. A debugger-first reading strategy is the only practical way to reconstruct the real execution order.

Concepts & terms
Advisor Chain
A Spring AI interceptor mechanism that wraps model calls. Advisors can modify prompts, handle tool-calling loops, inject chat memory, or perform retries before and after the model is invoked.
Tool Calling Loop
A multi-turn execution pattern where the model returns a tool request, the framework executes the corresponding Java method, feeds the result back as a new message, and repeats until the model produces a final text response or a termination condition is met.
MCP (Model Context Protocol)
A protocol for exposing tools, resources, and prompts from a remote server. Spring AI's MCP client discovers and registers these remote capabilities so they appear in the same tool-calling chain as locally defined functions.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗