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

public abstract class AbstractToolCallSupport extends Object
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 Details

    • IS_RUNTIME_CALL

      protected static final boolean IS_RUNTIME_CALL
      See Also:
    • functionCallbackRegister

      protected final Map<String,FunctionCallback> functionCallbackRegister
      The function callback register is used to resolve the function callbacks by name.
    • functionCallbackResolver

      protected final FunctionCallbackResolver 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

  • Method Details

    • getFunctionCallbackRegister

      public Map<String,FunctionCallback> 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

      protected List<Message> handleToolCalls(Prompt prompt, ChatResponse response)
    • buildToolCallConversation

      protected List<Message> buildToolCallConversation(List<Message> previousMessages, AssistantMessage assistantMessage, ToolResponseMessage toolResponseMessage)
    • resolveFunctionCallbacks

      protected List<FunctionCallback> resolveFunctionCallbacks(Set<String> functionNames)
      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

      protected boolean isToolCall(ChatResponse chatResponse, Set<String> toolCallFinishReasons)
    • isToolCall

      protected boolean isToolCall(Generation generation, Set<String> toolCallFinishReasons)
      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

      protected boolean isProxyToolCalls(Prompt prompt, FunctionCallingOptions defaultOptions)
      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.