Class Builder

java.lang.Object
com.alibaba.cloud.ai.graph.agent.Builder
Direct Known Subclasses:
DefaultBuilder

public abstract class Builder extends Object
  • Field Details

    • name

      protected String name
    • description

      protected String description
    • instruction

      protected String instruction
    • systemPrompt

      protected String systemPrompt
    • templateRenderer

      protected org.springframework.ai.template.TemplateRenderer templateRenderer
    • model

      protected org.springframework.ai.chat.model.ChatModel model
    • chatOptions

      protected org.springframework.ai.chat.prompt.ChatOptions chatOptions
    • chatClient

      protected org.springframework.ai.chat.client.ChatClient chatClient
    • tools

      protected List<org.springframework.ai.tool.ToolCallback> tools
    • toolCallbackProviders

      protected List<org.springframework.ai.tool.ToolCallbackProvider> toolCallbackProviders
    • toolNames

      protected List<String> toolNames
    • resolver

      protected org.springframework.ai.tool.resolution.ToolCallbackResolver resolver
    • toolExecutionExceptionProcessor

      protected org.springframework.ai.tool.execution.ToolExecutionExceptionProcessor toolExecutionExceptionProcessor
    • toolContext

      protected Map<String,Object> toolContext
    • releaseThread

      protected boolean releaseThread
    • saver

      protected BaseCheckpointSaver saver
    • compileConfig

      protected CompileConfig compileConfig
    • hooks

      protected List<Hook> hooks
    • interceptors

      protected List<Interceptor> interceptors
    • modelInterceptors

      protected List<ModelInterceptor> modelInterceptors
    • toolInterceptors

      protected List<ToolInterceptor> toolInterceptors
    • includeContents

      protected boolean includeContents
    • returnReasoningContents

      protected boolean returnReasoningContents
    • outputKey

      protected String outputKey
    • outputKeyStrategy

      protected KeyStrategy outputKeyStrategy
    • inputSchema

      protected String inputSchema
    • inputType

      protected Type inputType
    • outputSchema

      protected String outputSchema
    • outputType

      protected Class<?> outputType
    • observationRegistry

      protected io.micrometer.observation.ObservationRegistry observationRegistry
    • customObservationConvention

      protected org.springframework.ai.chat.client.observation.ChatClientObservationConvention customObservationConvention
    • advisorObservationConvention

      protected org.springframework.ai.chat.client.advisor.observation.AdvisorObservationConvention advisorObservationConvention
    • enableLogging

      protected boolean enableLogging
    • stateSerializer

      protected StateSerializer stateSerializer
    • executor

      protected Executor executor
    • parallelToolExecution

      protected boolean parallelToolExecution
    • maxParallelTools

      protected int maxParallelTools
    • toolExecutionTimeout

      protected Duration toolExecutionTimeout
    • wrapSyncToolsAsAsync

      protected boolean wrapSyncToolsAsAsync
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • name

      public Builder name(String name)
    • chatClient

      @Deprecated public Builder chatClient(org.springframework.ai.chat.client.ChatClient chatClient)
      Deprecated.
    • model

      public Builder model(org.springframework.ai.chat.model.ChatModel model)
    • chatOptions

      public Builder chatOptions(org.springframework.ai.chat.prompt.ChatOptions chatOptions)
    • tools

      public Builder tools(List<org.springframework.ai.tool.ToolCallback> tools)
    • tools

      public Builder tools(org.springframework.ai.tool.ToolCallback... tools)
    • methodTools

      public Builder methodTools(Object... toolObjects)
    • toolCallbackProviders

      public Builder toolCallbackProviders(org.springframework.ai.tool.ToolCallbackProvider... toolCallbackProviders)
    • toolNames

      public Builder toolNames(String... toolNames)
    • resolver

      public Builder resolver(org.springframework.ai.tool.resolution.ToolCallbackResolver resolver)
    • toolExecutionExceptionProcessor

      public Builder toolExecutionExceptionProcessor(org.springframework.ai.tool.execution.ToolExecutionExceptionProcessor toolExecutionExceptionProcessor)
    • toolContext

      public Builder toolContext(Map<String,Object> toolContext)
    • releaseThread

      public Builder releaseThread(boolean releaseThread)
    • saver

      public Builder saver(BaseCheckpointSaver saver)
    • compileConfig

      public Builder compileConfig(CompileConfig compileConfig)
    • description

      public Builder description(String description)
    • instruction

      public Builder instruction(String instruction)
    • systemPrompt

      public Builder systemPrompt(String systemPrompt)
    • templateRenderer

      public Builder templateRenderer(org.springframework.ai.template.TemplateRenderer templateRenderer)
    • outputKey

      public Builder outputKey(String outputKey)
    • outputKeyStrategy

      public Builder outputKeyStrategy(KeyStrategy outputKeyStrategy)
    • inputSchema

      public Builder inputSchema(String inputSchema)
    • inputType

      public Builder inputType(Type inputType)
    • outputSchema

      public Builder outputSchema(String outputSchema)
    • outputType

      public Builder outputType(Class<?> outputType)
    • includeContents

      public Builder includeContents(boolean includeContents)
    • returnReasoningContents

      public Builder returnReasoningContents(boolean returnReasoningContents)
    • hooks

      public Builder hooks(List<? extends Hook> hooks)
    • hooks

      public Builder hooks(Hook... hooks)
    • interceptors

      public Builder interceptors(List<? extends Interceptor> interceptors)
    • interceptors

      public Builder interceptors(Interceptor... interceptors)
    • observationRegistry

      public Builder observationRegistry(io.micrometer.observation.ObservationRegistry observationRegistry)
    • customObservationConvention

      public Builder customObservationConvention(org.springframework.ai.chat.client.observation.ChatClientObservationConvention customObservationConvention)
    • advisorObservationConvention

      public Builder advisorObservationConvention(org.springframework.ai.chat.client.advisor.observation.AdvisorObservationConvention advisorObservationConvention)
    • enableLogging

      public Builder enableLogging(boolean enableLogging)
    • stateSerializer

      public Builder stateSerializer(StateSerializer stateSerializer)
      Sets the state serializer for the agent.
      Parameters:
      stateSerializer - the state serializer to use
      Returns:
      this builder instance
    • stateSerializer

      @Deprecated public Builder stateSerializer(SpringAIStateSerializer stateSerializer)
      Deprecated.
      Sets the state serializer for the agent.
      Parameters:
      stateSerializer - the SpringAI state serializer to use
      Returns:
      this builder instance
    • executor

      public Builder executor(Executor executor)
      Sets the executor for parallel nodes.

      This executor will be used for all parallel nodes in the agent's execution graph. When a parallel node is executed, it will use this executor to run the parallel branches concurrently.

      Parameters:
      executor - the Executor to use for parallel nodes
      Returns:
      this builder instance
    • parallelToolExecution

      public Builder parallelToolExecution(boolean parallel)
      Enables or disables parallel tool execution.

      When enabled, multiple tool calls in a single response will be executed concurrently rather than sequentially. This can significantly improve performance when tools are I/O-bound or have long execution times.

      Parameters:
      parallel - true to enable parallel execution, false for sequential
      Returns:
      this builder instance
    • maxParallelTools

      public Builder maxParallelTools(int max)
      Sets the maximum number of tools that can execute in parallel.

      This limit helps prevent resource exhaustion when many tools are called simultaneously. The default is 5.

      Parameters:
      max - the maximum number of parallel tool executions (must be at least 1)
      Returns:
      this builder instance
      Throws:
      IllegalArgumentException - if max is less than 1
    • toolExecutionTimeout

      public Builder toolExecutionTimeout(Duration timeout)
      Sets the timeout for individual tool executions.

      If a tool execution exceeds this timeout, it will be cancelled and an error will be returned. The default is 5 minutes.

      Parameters:
      timeout - the maximum duration for a single tool execution
      Returns:
      this builder instance
      Throws:
      NullPointerException - if timeout is null
    • wrapSyncToolsAsAsync

      public Builder wrapSyncToolsAsAsync(boolean wrap)
      Enables or disables automatic wrapping of synchronous tools as async.

      When enabled, tools that implement only ToolCallback (synchronous) will be automatically wrapped in an AsyncToolCallbackAdapter to enable async execution. This allows parallel execution without requiring tool implementations to be modified.

      Parameters:
      wrap - true to wrap sync tools as async, false to leave them as-is
      Returns:
      this builder instance
    • buildConfig

      protected CompileConfig buildConfig()
    • build

      public abstract ReactAgent build()