Skip to content

Commit 0677210

Browse files
committed
Another round of adviser doc improvments
1 parent afc10a3 commit 0677210

File tree

1 file changed

+16
-8
lines changed
  • spring-ai-docs/src/main/antora/modules/ROOT/pages/api

1 file changed

+16
-8
lines changed

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/advisors.adoc

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[[Advisors]]
22

3-
= Spring AI Advisors API
3+
= Advisors API
44

55
The Spring AI Advisors API introduces a powerful component called `AroundAdvisor`.
66
This component dynamically intercepts chat-completion requests and responses, allowing for transformation or utilization of information within these interactions.
@@ -42,14 +42,14 @@ image::advisors-api-classes.jpg[Advisors API Classes, width=600, align="center"]
4242
The `AdvisedRequest` represents the unsealed Prompt request, while the `AdvisedResponse` represents the Chat Completion response.
4343
Both contain an `AdviserContext` object for sharing state across the advisor chain.
4444

45-
The `nextAroundCall()` and the `nextAroundStream()` are key advisor methods, typically performing these actions:
45+
The `nextAroundCall()` and the `nextAroundStream()` are the key advisor methods, typically performing actions like:
4646

47-
* Examining the unsealed Prompt data
48-
* Customizing and augmenting the Prompt data
49-
* Invoking the next entity in the advisor chain
50-
* Optionally blocking the request
51-
* Examining the chat completion response
52-
* Throwing exceptions to indicate processing errors
47+
- Examining the unsealed Prompt data
48+
- Customizing and augmenting the Prompt data
49+
- Invoking the next entity in the advisor chain
50+
- Optionally blocking the request
51+
- Examining the chat completion response
52+
- Throwing exceptions to indicate processing errors
5353

5454
In addition the `getOrder()` method determines the advisor's priority in the chain and the `getName()` method provides a unique identifier for the advisor.
5555

@@ -143,6 +143,14 @@ public Flux<AdvisedResponse> aroundStream(AdvisedRequest advisedRequest, StreamA
143143
}
144144
----
145145

146+
=== Advisor Order
147+
148+
The order of advisors in the chain is determined by the `getOrder()` method. Advisors with lower order values are executed first.
149+
Because the advisor chain is a stack, the first advisor in the chain is the last to process the request and the first to process the response.
150+
If you want to ensure that an advisor is executed last, set its order to `Integer.MAX_VALUE - 1` and vice versa.
151+
If you have multiple advisors with the same order value, the order of execution is not guaranteed.
152+
153+
For use case that needs to be first in the chain on the input side and first on the output side, you have to use separate advisors for each side and use teh advisor context to share state between them.
146154

147155
=== Best Practices
148156

0 commit comments

Comments
 (0)