Class ToolCallingAdvisor.Builder<T extends ToolCallingAdvisor.Builder<T>>

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

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

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

  • 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
    • toolExecutionEligibilityChecker

      public T toolExecutionEligibilityChecker(org.springframework.ai.model.tool.ToolExecutionEligibilityChecker toolExecutionEligibilityChecker)
      Sets the checker that determines whether a model response should trigger tool execution. Defaults to chatResponse -> chatResponse != null && chatResponse.hasToolCalls(). Override to apply provider-specific stop-reason logic.
      Parameters:
      toolExecutionEligibilityChecker - the checker
      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
    • disableInternalConversationHistory

      public T disableInternalConversationHistory()
      Disables internal conversation history. You need a ChatMemory Advisor registered next in the chain.
      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

      public int getAdvisorOrder()
      Returns the configured advisor order.
      Returns:
      the advisor order value
    • getToolExecutionEligibilityChecker

      public org.springframework.ai.model.tool.ToolExecutionEligibilityChecker getToolExecutionEligibilityChecker()
      Returns the configured ToolExecutionEligibilityChecker.
      Returns:
      the ToolExecutionEligibilityChecker instance
    • copy

      public ToolCallingAdvisor.Builder<?> copy()
      Creates a shallow copy of this builder with all current settings. The copy can be used as a template from which per-call overrides (e.g. conversationHistoryEnabled) are applied without mutating the original.

      Subclasses must override newCopy() to return an instance of their own type, and override this method to copy their additional fields into it.

      Returns:
      a new ToolCallingAdvisor.Builder with the same configuration
    • newCopy

      protected ToolCallingAdvisor.Builder<?> newCopy()
      Factory method called by copy() to create the blank builder instance that will receive the copied fields. Subclasses must override this to return an instance of their own builder type so that copy() preserves the full subtype.
      Returns:
      a new, unconfigured builder of the same concrete type
    • isConversationHistoryEnabled

      protected boolean isConversationHistoryEnabled()
      Returns whether internal conversation history is enabled.
      Returns:
      true if internal conversation history is enabled, false if disabled
    • build

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