Class ToolCallAdvisor
java.lang.Object
org.springframework.ai.chat.client.advisor.ToolCallAdvisor
- All Implemented Interfaces:
Advisor, CallAdvisor, StreamAdvisor, org.springframework.core.Ordered
Recursive Advisor that disables the internal tool execution flow and instead implements
the tool calling loop as part of the advisor chain.
It uses the CallAdvisorChainUtil to implement looping advisor chain calls.
This enables intercepting the tool calling loop by the rest of the advisors next in the chain.
- Author:
- Christian Tzolov
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classToolCallAdvisor.Builder<T extends ToolCallAdvisor.Builder<T>>Builder for creating instances of ToolCallAdvisor. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.springframework.ai.model.tool.ToolCallingManagerFields inherited from interface Advisor
DEFAULT_CHAT_MEMORY_PRECEDENCE_ORDERFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedToolCallAdvisor(org.springframework.ai.model.tool.ToolCallingManager toolCallingManager, int advisorOrder) protectedToolCallAdvisor(org.springframework.ai.model.tool.ToolCallingManager toolCallingManager, int advisorOrder, boolean conversationHistoryEnabled) -
Method Summary
Modifier and TypeMethodDescriptionadviseCall(ChatClientRequest chatClientRequest, CallAdvisorChain callAdvisorChain) reactor.core.publisher.Flux<ChatClientResponse> adviseStream(ChatClientRequest chatClientRequest, StreamAdvisorChain streamAdvisorChain) static ToolCallAdvisor.Builder<?> builder()Creates a new Builder instance for constructing a ToolCallAdvisor.protected ChatClientResponsedoAfterCall(ChatClientResponse chatClientResponse, CallAdvisorChain callAdvisorChain) protected ChatClientRequestdoBeforeCall(ChatClientRequest chatClientRequest, CallAdvisorChain callAdvisorChain) protected ChatClientResponsedoFinalizeLoop(ChatClientResponse chatClientResponse, CallAdvisorChain callAdvisorChain) protected List<org.springframework.ai.chat.messages.Message> doGetNextInstructionsForToolCall(ChatClientRequest chatClientRequest, ChatClientResponse chatClientResponse, org.springframework.ai.model.tool.ToolExecutionResult toolExecutionResult) protected ChatClientRequestdoInitializeLoop(ChatClientRequest chatClientRequest, CallAdvisorChain callAdvisorChain) getName()Return the name of the advisor.intgetOrder()
-
Field Details
-
toolCallingManager
protected final org.springframework.ai.model.tool.ToolCallingManager toolCallingManager
-
-
Constructor Details
-
ToolCallAdvisor
protected ToolCallAdvisor(org.springframework.ai.model.tool.ToolCallingManager toolCallingManager, int advisorOrder) -
ToolCallAdvisor
protected ToolCallAdvisor(org.springframework.ai.model.tool.ToolCallingManager toolCallingManager, int advisorOrder, boolean conversationHistoryEnabled)
-
-
Method Details
-
getName
-
getOrder
public int getOrder()- Specified by:
getOrderin interfaceorg.springframework.core.Ordered
-
adviseCall
public ChatClientResponse adviseCall(ChatClientRequest chatClientRequest, CallAdvisorChain callAdvisorChain) - Specified by:
adviseCallin interfaceCallAdvisor
-
doGetNextInstructionsForToolCall
protected List<org.springframework.ai.chat.messages.Message> doGetNextInstructionsForToolCall(ChatClientRequest chatClientRequest, ChatClientResponse chatClientResponse, org.springframework.ai.model.tool.ToolExecutionResult toolExecutionResult) -
doFinalizeLoop
protected ChatClientResponse doFinalizeLoop(ChatClientResponse chatClientResponse, CallAdvisorChain callAdvisorChain) -
doInitializeLoop
protected ChatClientRequest doInitializeLoop(ChatClientRequest chatClientRequest, CallAdvisorChain callAdvisorChain) -
doBeforeCall
protected ChatClientRequest doBeforeCall(ChatClientRequest chatClientRequest, CallAdvisorChain callAdvisorChain) -
doAfterCall
protected ChatClientResponse doAfterCall(ChatClientResponse chatClientResponse, CallAdvisorChain callAdvisorChain) -
adviseStream
public reactor.core.publisher.Flux<ChatClientResponse> adviseStream(ChatClientRequest chatClientRequest, StreamAdvisorChain streamAdvisorChain) - Specified by:
adviseStreamin interfaceStreamAdvisor
-
builder
Creates a new Builder instance for constructing a ToolCallAdvisor.- Returns:
- a new Builder instance
-