Class AbstractToolCallSupport
java.lang.Object
org.springframework.ai.chat.model.AbstractToolCallSupport
- Direct Known Subclasses:
AnthropicChatModel
,AzureOpenAiChatModel
,BedrockProxyChatModel
,FunctionCallingHelper
,MiniMaxChatModel
,MistralAiChatModel
,MoonshotChatModel
,OllamaChatModel
,OpenAiChatModel
,VertexAiGeminiChatModel
,ZhiPuAiChatModel
Abstract base class for tool call support. Provides functionality for handling function
callbacks and executing functions.
- Since:
- 1.0.0
- Author:
- Christian Tzolov, Grogdunn, Thomas Vitale, Jihoon Kim
-
Field Summary
Modifier and TypeFieldDescriptionprotected final Map<String,
FunctionCallback> The function callback register is used to resolve the function callbacks by name.protected final FunctionCallbackResolver
The function callback resolver is used to resolve the function callbacks by name from the Spring context.protected static final boolean
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractToolCallSupport
(FunctionCallbackResolver functionCallbackResolver) protected
AbstractToolCallSupport
(FunctionCallbackResolver functionCallbackResolver, FunctionCallingOptions functionCallingOptions, List<FunctionCallback> toolFunctionCallbacks) -
Method Summary
Modifier and TypeMethodDescriptionbuildToolCallConversation
(List<Message> previousMessages, AssistantMessage assistantMessage, ToolResponseMessage toolResponseMessage) protected ToolResponseMessage
executeFunctions
(AssistantMessage assistantMessage, ToolContext toolContext) handleToolCalls
(Prompt prompt, ChatResponse response) protected boolean
isProxyToolCalls
(Prompt prompt, FunctionCallingOptions defaultOptions) Check if the proxyToolCalls is enabled for the given prompt or the default tool call options.protected boolean
isToolCall
(ChatResponse chatResponse, Set<String> toolCallFinishReasons) protected boolean
isToolCall
(Generation generation, Set<String> toolCallFinishReasons) Check if the generation is a tool call.protected List<FunctionCallback>
resolveFunctionCallbacks
(Set<String> functionNames) Resolve the function callbacks by name.runtimeFunctionCallbackConfigurations
(FunctionCallingOptions runtimeFunctionOptions) Handle the runtime function callback configurations.
-
Field Details
-
IS_RUNTIME_CALL
protected static final boolean IS_RUNTIME_CALL- See Also:
-
functionCallbackRegister
The function callback register is used to resolve the function callbacks by name. -
functionCallbackResolver
The function callback resolver is used to resolve the function callbacks by name from the Spring context. It is optional and usually used with Spring auto-configuration.
-
-
Constructor Details
-
AbstractToolCallSupport
-
AbstractToolCallSupport
protected AbstractToolCallSupport(FunctionCallbackResolver functionCallbackResolver, FunctionCallingOptions functionCallingOptions, List<FunctionCallback> toolFunctionCallbacks)
-
-
Method Details
-
getFunctionCallbackRegister
-
runtimeFunctionCallbackConfigurations
protected Set<String> runtimeFunctionCallbackConfigurations(FunctionCallingOptions runtimeFunctionOptions) Handle the runtime function callback configurations. Register the function callbacks- Parameters:
runtimeFunctionOptions
- FunctionCallingOptions to handle.- Returns:
- Set of function names to call.
-
handleToolCalls
-
buildToolCallConversation
protected List<Message> buildToolCallConversation(List<Message> previousMessages, AssistantMessage assistantMessage, ToolResponseMessage toolResponseMessage) -
resolveFunctionCallbacks
Resolve the function callbacks by name. Retrieve them from the registry or try to resolve them from the Application Context.- Parameters:
functionNames
- Name of function callbacks to retrieve.- Returns:
- list of resolved FunctionCallbacks.
-
executeFunctions
protected ToolResponseMessage executeFunctions(AssistantMessage assistantMessage, ToolContext toolContext) -
isToolCall
-
isToolCall
Check if the generation is a tool call. The tool call finish reasons are used to determine if the generation is a tool call.- Parameters:
generation
- the generation to check.toolCallFinishReasons
- the tool call finish reasons to check.- Returns:
- true if the generation is a tool call, false otherwise.
-
isProxyToolCalls
Check if the proxyToolCalls is enabled for the given prompt or the default tool call options. The prompt options take precedence over the default options. When the proxyToolCalls is enabled the ChatModel implementation will not handle the function calling internally. The tool call and tool response messages are exposed outside the ChatModel implementation.- Parameters:
prompt
- the prompt to check.defaultOptions
- the default tool call options to check.- Returns:
- true if the proxyToolCalls is enabled, false otherwise.
-