Spring
Follow
Tool Calling in Spring AI 2.0: A Composable, Agentic Architecture
Spring AI 2.0 revamps tool calling, making it a core, composable feature within advisor chains. Agents now leverage this capability to discover information and act towards a goal. Tools are defined using the @Tool annotation on methods, with Spring AI automatically generating JSON schemas for parameters. The ToolCallingAdvisor orchestrates the tool execution loop, recursively calling the LLM until no more tool calls are generated. Placing memory advisors inside this loop allows richer context capture by persisting full tool request and response histories. However, this requires specific ChatMemoryRepository implementations like InMemoryChatMemoryRepository. For large tool sets, ToolSearchToolCallingAdvisor offers incremental tool disclosure to avoid context bloat. This advisor uses a tool index to progressively expose relevant tools based on natural language queries. Tool argument augmentation enables dynamic extension of tool input schemas without modifying tool code, useful for inner thinking. MCP tools integrate remote and local tool definitions, allowing applications to consume or expose Spring-managed tools via MCP servers. Both local @Tool annotations and remote MCP tools use the same ToolCallback interface, seamlessly integrating them into the advisor chain.