Class ToolCallAdvisor.Builder<T extends ToolCallAdvisor.Builder<T>>

java.lang.Object
org.springframework.ai.chat.client.advisor.ToolCallAdvisor.Builder<T>
Type Parameters:
T - the builder type, used for self-referential generics to support method chaining in subclasses
Enclosing class:
ToolCallAdvisor

public static class ToolCallAdvisor.Builder<T extends ToolCallAdvisor.Builder<T>> extends Object
Builder for creating instances of ToolCallAdvisor.

This builder uses the self-referential generic pattern to support extensibility.

  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
  • Method Summary

    Modifier and Type
    Method
    Description
    advisorOrder(int advisorOrder)
    Sets the order of the advisor in the advisor chain.
    Builds and returns a new ToolCallAdvisor instance with the configured properties.
    conversationHistoryEnabled(boolean conversationHistoryEnabled)
    Sets whether internal conversation history is enabled.
    Disables internal conversation history.
    protected int
    Returns the configured advisor order.
    protected org.springframework.ai.model.tool.ToolCallingManager
    Returns the configured ToolCallingManager.
    protected boolean
    Returns whether tool call responses should be streamed.
    protected T
    Returns this builder cast to the appropriate type for method chaining.
    streamToolCallResponses(boolean streamToolCallResponses)
    Sets whether intermediate tool call responses should be streamed to downstream consumers.
    Disables streaming of intermediate tool call responses.
    toolCallingManager(org.springframework.ai.model.tool.ToolCallingManager toolCallingManager)
    Sets the ToolCallingManager to be used by the advisor.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Builder

      protected Builder()
  • Method Details

    • self

      protected T self()
      Returns this builder cast to the appropriate type for method chaining. Subclasses should override this method to return the correct type.
      Returns:
      this builder instance
    • toolCallingManager

      public T toolCallingManager(org.springframework.ai.model.tool.ToolCallingManager toolCallingManager)
      Sets the ToolCallingManager to be used by the advisor.
      Parameters:
      toolCallingManager - the ToolCallingManager instance
      Returns:
      this Builder instance for method chaining
    • advisorOrder

      public T advisorOrder(int advisorOrder)
      Sets the order of the advisor in the advisor chain.
      Parameters:
      advisorOrder - the order value, must be between HIGHEST_PRECEDENCE and LOWEST_PRECEDENCE
      Returns:
      this Builder instance for method chaining
    • conversationHistoryEnabled

      public T conversationHistoryEnabled(boolean conversationHistoryEnabled)
      Sets whether internal conversation history is enabled. If false, you need a ChatMemory Advisor registered next in the chain.
      Parameters:
      conversationHistoryEnabled - true to enable, false to disable
      Returns:
      this Builder instance for method chaining
    • disableMemory

      public T disableMemory()
      Disables internal conversation history. You need a ChatMemory Advisor registered next in the chain.
      Returns:
      this Builder instance for method chaining
    • streamToolCallResponses

      public T streamToolCallResponses(boolean streamToolCallResponses)
      Sets whether intermediate tool call responses should be streamed to downstream consumers. When enabled (default), all chunks including tool call responses are streamed in real-time. When disabled, only the final answer chunks are streamed, and intermediate tool call responses are filtered out.
      Parameters:
      streamToolCallResponses - true to stream tool call responses (default), false to filter them out
      Returns:
      this Builder instance for method chaining
    • suppressToolCallStreaming

      public T suppressToolCallStreaming()
      Disables streaming of intermediate tool call responses. Only the final answer will be streamed to downstream consumers.
      Returns:
      this Builder instance for method chaining
    • getToolCallingManager

      protected org.springframework.ai.model.tool.ToolCallingManager getToolCallingManager()
      Returns the configured ToolCallingManager.
      Returns:
      the ToolCallingManager instance
    • getAdvisorOrder

      protected int getAdvisorOrder()
      Returns the configured advisor order.
      Returns:
      the advisor order value
    • isStreamToolCallResponses

      protected boolean isStreamToolCallResponses()
      Returns whether tool call responses should be streamed.
      Returns:
      true if tool call responses should be streamed
    • build

      public ToolCallAdvisor build()
      Builds and returns a new ToolCallAdvisor instance with the configured properties.
      Returns:
      a new ToolCallAdvisor instance
      Throws:
      IllegalArgumentException - if toolCallingManager is null or advisorOrder is out of valid range