RSS Spring

Create Self-Improving AI Agents Using Spring AI Recursive Advisors

Spring AI ChatClient uses a fluent API for AI model communication, building prompts easily. Key to this are advisors, which intercept and modify requests and responses. Advisors encapsulate Generative AI patterns and ensure portability across models. They process `ChatClientRequest` and `ChatClientResponse` objects, chained by `getOrder()`. Spring AI provides built-in and custom advisor options for various tasks. Introduced in Spring AI 1.1.0-M4, Recursive Advisors enable iterative workflows not handled by single-pass advisors. Recursive Advisors involve looping through the advisor chain multiple times, repeatedly calling the LLM. The `CallAdvisorChain.copy(CallAdvisor after)` method enables controlled iteration within the advisor chain. Two built-in recursive advisors are the ToolCallAdvisor and the StructuredOutputValidationAdvisor. The ToolCallAdvisor enables explicit control over tool execution. The StructuredOutputValidationAdvisor validates JSON output and retries with feedback. Using recursive advisors efficiently requires careful termination conditions, proper ordering, and monitoring to avoid performance issues. Developers need to evaluate the use of recursive advisors carefully, considering the potential impact on cost and latency.
favicon
spring.io
spring.io
Image for the article: Create Self-Improving AI Agents Using Spring AI Recursive Advisors