Spring AI 2.0 release brings fundamental architectural change to instrument calling (tool calling). In version 1.x each ChatModel implementation independently managed the function call cycle: parse model response, invoke instruments, execute them, return results back to model. In 2.0 this responsibility is fully taken over by the new component — ToolCallingAdvisor. It centralizes the entire instrument lifecycle: from detecting model’s intent to call function to error handling and retries. For Java services integrating LLM this means predictable scaling, single expansion point and ability to swap models without rewriting orchestration logic.
Related: what is LLM harness
Related: agent memory CLAUDE.md
Related material: our LLM harness review
ToolCallingAdvisor Architecture: What’s Under the Hood
ToolCallingAdvisor implements the “Advisor” pattern (interceptor) — a request/response pass-through interceptor in Spring AI cycle. It wraps ChatModel call and intercepts response before returning to client. If response contains instrument calls (in tool_calls format per OpenAI standard), advisor:
- Validates call structure against registered function schemas (JSON Schema).
- Executes functions in specified order — sequentially or in parallel, depending on config.
- Collects results, wraps them in tool role messages and sends back to model for next hop.
- Repeats cycle until model returns final response without instrument calls or iteration limit (maxIterations, default • is reached.
Key difference from 1.x: model orchestration logic moves out of model implementations into single component. All ChatModel implementations (OpenAI, Anthropic, Ollama, Azure, Vertex AI, Mistral, local via llama.cpp) now return “raw” response with tool_calls, and ToolCallingAdvisor decides what to do with them. This eliminates code duplication and divergence between providers.
Practical Example: Weather → Train Search → Ticket Booking
Classic agent scenario: user asks “book ticket for tomorrow morning trip to Moscow from SPb”. Model doesn’t know schedule — it must call instrument to search trains, then instrument to book. In Spring AI 2.0 this looks like:
@Bean
public ToolCallingAdvisor toolCallingAdvisor(ToolCallbackProvider tools) {
return ToolCallingAdvisor.builder()
.toolCallbacks(tools)
.maxIterations(• .build();
}
@Bean
public ToolCallbackProvider weatherAndBookingTools() {
return ToolCallbackProvider.builder()
.tool("getWeather", "Weather in city", WeatherFunction.class)
.tool("searchTrains", "Train search", TrainSearchFunction.class)
.tool("bookTicket", "Ticket booking", BookingFunction.class)
.build();
}Dialog flows in three steps inside single Advisor cycle:
- Hop 1: Model receives user request, decides train search needed. Returns tool_calls: [{name: “searchTrains”, arguments: {“from”: “SPb”, “to”: “Moscow”, “date”: “2026-12-03”, “time”: “morning”}}].
- Hop 2: Advisor executes searchTrains, gets train list. Sends result back to model as role: “tool”, tool_call_id: “…”, content: “Found trains: 001A 06:15-10:30, 003B 07:40-12:10”.
- Hop 3: Model selects train 001A, calls bookTicket with train ID and passenger data. Advisor executes booking, returns confirmation. Model outputs final user response: “Ticket for 001A booked, seat 12A, wagon 3”.
Entire cycle runs transparently for calling code — client sees only initial prompt and final response.
Invocation Order, Parallelism and Error Handling
Spring AI 2.0 gives detailed control over execution strategies:
- Sequential (default): instruments execute one after another in order of tool_calls returned by model. Guarantees determinism, needed when next call depends on previous result (as in example above).
- Parallel: if model returns multiple independent calls in one response, Advisor can execute them simultaneously (parallelToolCalls(true)). Speeds up “check weather in 5 cities” scenarios — single round-trip instead of five.
- Error handling: on instrument exception Advisor doesn’t fail, but wraps error in tool message with error: true flag and sends to model. Model gets failure context and can: retry call with corrected args, invoke alternative instrument, or inform user of problem. Configurable via ToolCallingAdvisor.builder().errorHandler(customHandler).
- Iteration limit: maxIterations (default • protects against infinite loops when model keeps calling instruments. On limit reached Advisor breaks cycle and returns accumulated context with MAX_ITERATIONS_EXCEEDED error.
Migration from 1.x: What Breaks and How to Start
Main breaking changes on upgrade:
- Old FunctionCallback beans no longer auto-adapt. In 2.0 ToolCallback / ToolCallbackProvider used. Migration: rewrite existing functions to ToolCallback.builder().name(…).description(…).inputSchema(…).build() or use new @Tool annotation style.
- Raw ChatModel.call() calls without Advisor return “raw” response with tool_calls. Client code must always go through ChatClient with attached ToolCallingAdvisor, or manually invoke Advisor.
- Response structure changed. In 1.x some models returned already-executed result. In 2.0 — always tool_calls on first hop. Tests checking response text will break — must verify tool_calls presence and validate final response after Advisor pass.
Function migration example:
// 1.x style (removed)
@Bean
public FunctionCallback weatherFunction() {
return FunctionCallback.builder()
.name("getWeather")
.description("Weather in city")
.inputType(WeatherRequest.class)
.function(this::getWeather)
.build();
}
// 2.0 style
@Bean
public ToolCallback weatherTool() {
return ToolCallback.builder()
.name("getWeather")
.description("Weather in city")
.inputSchema(WeatherRequest.schema()) // JSON Schema
.toolFunction(args -> getWeather(JacksonUtils.fromJson(args, WeatherRequest.class)))
.build();
}MCP and External Instrument Integration
Spring AI 2.0 provides McpToolCallbackProvider — bridge to Model Context Protocol. It allows connecting MCP servers (file system, DB, GitHub, browser) as instrument sets accessible to model via single ToolCallingAdvisor. Example:
@Bean
public ToolCallbackProvider mcpTools(McpClient mcpClient) {
return McpToolCallbackProvider.builder()
.mcpClients(mcpClient)
.build();
}Now model can in one dialog: read file via MCP Filesystem → analyze code → commit changes via MCP GitHub. All calls go through same ToolCallingAdvisor with same ordering, retry and iteration guarantees.
Production Readiness and Operational Observability
LLM load in agent cycles grows linearly with iteration count. Each round-trip = model latency (200-2000 ms provider-dependent) + instrument execution time. Production recommendations:
- Set maxIterations=5-7 for typical tasks (search → act → confirm). 10 — only for complex multi-step agents.
- Use parallel calls where instruments are independent — saves 30-60% latency on context gathering step.
- Cache deterministic instrument results (reference books, DB schemas) at function level — avoid repeat calls for same data in one session.
- Monitor metrics: tool_calling.iterations, tool_calling.errors, tool_calling.latency — Spring AI exports these to Micrometer/Prometheus.
What This Means for Java Teams
Spring AI 2.0 makes tool calling a first-class framework citizen, not a model-specific feature. Single ToolCallingAdvisor means: write instrument logic once — works everywhere (OpenAI, Anthropic, local Ollama/llama.cpp, MCP servers). For enterprise Java teams this reduces LLM integration ownership cost: less glue code, predictable behavior, standard extension points (errors, retries, logging, metrics).
Next step — pilot migration on one internal service: attach ToolCallingAdvisor, port 2-3 critical functions, measure latency and error rates. Spring AI 2.0 reference docs contain full migration guide and examples for all supported providers.
Useful resources: Spring AI reference, official Java portal.
ToolCallingAdvisor for Agents: Configuration Cheat Sheet
Key Spring AI 2.0 Tool Calling Beans:
- ToolCallingAdvisor — main instrument cycle orchestrator
- ToolCallbackProvider — registry of available instruments (functions, MCP, others)
- ToolCallback — single instrument description (name, description, JSON Schema, executor)
- McpToolCallbackProvider — bridge to MCP servers
ToolCallingAdvisor.Builder Parameters:
- toolCallbacks(ToolCallbackProvider) — required, instrument source
- maxIterations(int) — model→instrument cycle limit (default 10)
- parallelToolCalls(boolean) — parallel execution of independent calls (default false)
- errorHandler(ToolErrorHandler) — custom instrument error handling
- returnDirect(boolean) — return instrument result directly without second model call (for simple query-tools)
Typical Error Patterns and Model Reaction:
- Instrument timeout → model retries call with increased timeout or uses cache
- Argument validation failure (JSON Schema) → model fixes args and retries
- Business error (no tickets) → model proposes alternative to user
- Instrument not found → Advisor blocks call, model gets “tool not found” error
Metrics for Alerting (Micrometer/Prometheus):
- spring_ai_tool_calling_iterations_total — iterations distribution per request
- spring_ai_tool_calling_errors_total — error counter by type
- spring_ai_tool_calling_duration_seconds — full cycle latency
Full LLM harness and orchestration patterns breakdown — in our review “What Is LLM Harness”.
Key beans for Spring AI 2.0 tool calling: ToolCallingAdvisor (main orchestrator), ToolCallbackProvider (tool registry), ToolCallback (tool definition with JSON Schema), McpToolCallbackProvider (MCP bridge). Builder parameters: toolCallbacks required, maxIterations default 10, parallelToolCalls default false, errorHandler custom, returnDirect for simple query tools. Error handling patterns: timeout triggers retry with longer timeout or cache fallback, validation errors cause argument correction and retry, business errors like no tickets available prompt alternatives to user, unknown tool blocked with tool not found error. Metrics for alerting: spring_ai_tool_calling_iterations_total distribution, spring_ai_tool_calling_errors_total by type, spring_ai_tool_calling_duration_seconds latency. Production tips: set maxIterations 5-7 for typical tasks, use parallel calls for independent tools saving 30-60% latency, cache deterministic tool results, monitor via Micrometer/Prometheus.

