Class FunctionNode.Builder<I,O>

java.lang.Object
com.google.adk.workflow.FunctionNode.Builder<I,O>
Enclosing class:
FunctionNode<I,O>

public static final class FunctionNode.Builder<I,O> extends Object
Fluent builder for FunctionNode. Any property left unset falls back to the default of the matching Node property, except that rerunOnResume defaults to true for a node that requires confirmation; name and body are required.
  • Method Details

    • name

      @CanIgnoreReturnValue public FunctionNode.Builder<I,O> name(String name)
      Sets the node's name, unique within its graph. Required.
    • description

      @CanIgnoreReturnValue public FunctionNode.Builder<I,O> description(String description)
      Sets what the node does, for humans and for a model that may call it.
    • rerunOnResume

      @CanIgnoreReturnValue public FunctionNode.Builder<I,O> rerunOnResume(boolean rerunOnResume)
      Sets whether a resume runs the node again rather than using the resuming answer. Unset, it is true for a node that requires confirmation and false otherwise. A body that runs child nodes through Context.runNode(Node, Object, RunNodeConfig) requires true: on resume the body runs again from the start, a child that asked resumes with its answer, and the other children resume as RunNodeConfig.runId() describes.
    • waitForOutput

      @CanIgnoreReturnValue public FunctionNode.Builder<I,O> waitForOutput(boolean waitForOutput)
      Sets whether the node stays re-triggerable until it produces an output or a route.
    • config

      @CanIgnoreReturnValue public FunctionNode.Builder<I,O> config(NodeConfig config)
      Sets the node's retry policy and execution timeout.
    • inputSchema

      @CanIgnoreReturnValue public FunctionNode.Builder<I,O> inputSchema(@Nullable com.google.genai.types.Schema inputSchema)
      Sets the schema that describes the node's input, in place of one inferred from its type. On a Content port, the schema describes the message's text.
    • outputSchema

      @CanIgnoreReturnValue public FunctionNode.Builder<I,O> outputSchema(@Nullable com.google.genai.types.Schema outputSchema)
      Sets the schema that describes the node's output, in place of one inferred from its type.
    • stateSchema

      @CanIgnoreReturnValue public FunctionNode.Builder<I,O> stateSchema(@Nullable com.google.genai.types.Schema stateSchema)
      Sets the state keys the node uses, which child nodes inherit unless they declare their own.
    • requireConfirmation

      @CanIgnoreReturnValue public FunctionNode.Builder<I,O> requireConfirmation(boolean requireConfirmation)
      Sets whether each run first asks the user to approve it; either overload replaces the other. Such a node reruns on resume, so a body that asks for input reads its answer from Context.resumeInputs() before asking. An approved run reads the user's decision from Context.toolConfirmation(), and a rejected run skips the body and outputs {"error": "This tool call is rejected."} whatever the output type, so a successor that must handle a rejection takes Object.
    • requireConfirmation

      @CanIgnoreReturnValue public FunctionNode.Builder<I,O> requireConfirmation(ConfirmationPredicate<? super I> predicate)
      Sets a predicate that decides for each input whether a run asks the user to approve it, as the boolean overload does for every input. Once the node has asked, the answer decides.
    • body

      @CanIgnoreReturnValue public FunctionNode.Builder<I,O> body(NodeBody<? super I, ? extends O> body)
      Sets the function the node runs on each input. Required.
    • scheduler

      @CanIgnoreReturnValue public FunctionNode.Builder<I,O> scheduler(@Nullable io.reactivex.rxjava3.core.Scheduler scheduler)
      Sets the scheduler that decodes the input and runs the confirmation predicate and the body, or null (the default) for the Runner's scheduler. A body that calls Context.emit(Event) cannot run inline, and bodies that wait for one another need a thread each, so a small fixed-size scheduler can hang the run; ADK Kotlin instead defaults to Dispatchers.IO, which gives each waiting body a thread. Once that work ends, even when a confirmation skips the body, the outcome is handed back on the Runner's scheduler, unless that scheduler equals this one (two Schedulers.from of one executor do not) or runs work inline, in which case it stays on this thread. The scheduler must accept this work: a rejected body leaves the run waiting, as a Runner scheduler that rejects work does.
    • build

      public FunctionNode<I,O> build()
      Builds the node.
      Throws:
      IllegalStateException - if the name or the body is not set
      WorkflowConfigurationException - if the node requires confirmation but rerunOnResume is set to false