Commit 323c590
feat(advisors): Enable recursive advisor execution with two new built-in advisors
Add support for recursive (repetitive) advisor execution patterns, allowing advisors to re-invoke
themselves or the remaining chain multiple times. This enables advanced patterns like retry logic,
iterative refinement, and multi-pass processing.
- Add AdvisorUtils.copyChainAfterAdvisor() utility to enable recursive chain invocation
- Implement ToolCallAdvisor for recursive tool calling with configurable tool execution
- Implement StructuredOutputValidationAdvisor for recursive output validation with retry logic
- Add MCP JSON Jackson2 dependency for JSON schema validation
- Add test suites for both new advisors and utility methods
- Add documentation for recursive advisor patterns
refactor(advisor): enhance StructuredOutputValidationAdvisor with validation feedback loop
Refactor retry logic to provide validation error feedback to LLM for self-correction.
Extract validation into separate method and augment prompts with error messages on retry.
Add comprehensive test coverage for various validation scenarios including nested objects,
lists, malformed JSON, and type mismatches.
Improve StructuredOutputValidationAdvisor logic
feat: Add return direct support and null safety to ToolCallAdvisor
Implements return direct functionality allowing tools to bypass the LLM
and return results directly to clients. Adds null safety checks for
chatResponse and comprehensive test coverage.
refactor: Move chain copying logic from AdvisorUtils to CallAdvisorChain interface
- Add CallAdvisorChain.copy(CallAdvisor after) method to replace AdvisorUtils.copyChainAfterAdvisor()
- Implement copy() method in DefaultAroundAdvisorChain
- Update StructuredOutputValidationAdvisor and ToolCallAdvisor to use new copy() API
- Add ObjectMapper parameter support to StructuredOutputValidationAdvisor for custom JSON processing
- Improve ToolCallAdvisor return direct logic using break instead of flag
- Move tests from AdvisorUtilsTests to DefaultAroundAdvisorChainTests
- Update documentation to reflect API changes
This refactoring improves the API design by moving chain manipulation logic
closer to where it belongs (on the chain itself) rather than in a utility class.
Signed-off-by: Christian Tzolov <christian.tzolov@broadcom.com>1 parent 0b0024e commit 323c590
File tree
16 files changed
+2428
-3
lines changed- spring-ai-client-chat
- src
- main/java/org/springframework/ai/chat/client/advisor
- api
- test/java/org/springframework/ai/chat/client/advisor
- spring-ai-docs/src/main/antora/modules/ROOT
- images
- pages/api
- spring-ai-model/src/test/java/org/springframework/ai/util/json
16 files changed
+2428
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
47 | 53 | | |
48 | 54 | | |
49 | 55 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
Lines changed: 19 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
| |||
133 | 134 | | |
134 | 135 | | |
135 | 136 | | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
136 | 155 | | |
137 | 156 | | |
138 | 157 | | |
| |||
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
95 | | - | |
| 95 | + | |
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| |||
0 commit comments