Class FunctionNodes

java.lang.Object
com.google.adk.workflow.FunctionNodes

@Experimental public final class FunctionNodes extends Object
Creates FunctionNodes with a type per port, as a Class or, for a generic type such as List<Order>, a TypeReference, read and written as FunctionNode describes. A node's body asks the user for input with requestInput(String, String, Object, Schema).
  • Method Details

    • of

      public static <I,O> FunctionNode<I,O> of(String name, Class<I> inputType, Class<O> outputType, NodeBody<? super I, ? extends O> body)
      Returns a node named name that runs body on each input read as inputType and writes its outputType output in JSON form. The body may send events first with Context.emit(Event).
      Throws:
      WorkflowConfigurationException - if Jackson cannot read and write inputType or write outputType, or if a port type has no single concrete JSON shape or is an interface or abstract class without a Jackson creator, such as ZoneId; a field type Jackson cannot handle fails on the first value instead
    • of

      public static <I,O> FunctionNode<I,O> of(String name, com.fasterxml.jackson.core.type.TypeReference<I> inputType, com.fasterxml.jackson.core.type.TypeReference<O> outputType, NodeBody<? super I, ? extends O> body)
      Like of(String, Class, Class, NodeBody), for generic port types.
    • of

      public static <I,O> FunctionNode<I,O> of(String name, Class<I> inputType, com.fasterxml.jackson.core.type.TypeReference<O> outputType, NodeBody<? super I, ? extends O> body)
      Like of(String, Class, Class, NodeBody), for a generic output type.
    • of

      public static <I,O> FunctionNode<I,O> of(String name, com.fasterxml.jackson.core.type.TypeReference<I> inputType, Class<O> outputType, NodeBody<? super I, ? extends O> body)
      Like of(String, Class, Class, NodeBody), for a generic input type.
    • builder

      public static <I,O> FunctionNode.Builder<I,O> builder(Class<I> inputType, Class<O> outputType)
      Returns a builder for a node with these port types, for properties of(String, Class, Class, NodeBody) does not take.
      Throws:
      WorkflowConfigurationException - as of(String, Class, Class, NodeBody) does
    • builder

      public static <I,O> FunctionNode.Builder<I,O> builder(com.fasterxml.jackson.core.type.TypeReference<I> inputType, com.fasterxml.jackson.core.type.TypeReference<O> outputType)
      Like builder(Class, Class), for generic port types.
    • builder

      public static <I,O> FunctionNode.Builder<I,O> builder(Class<I> inputType, com.fasterxml.jackson.core.type.TypeReference<O> outputType)
      Like builder(Class, Class), for a generic output type.
    • builder

      public static <I,O> FunctionNode.Builder<I,O> builder(com.fasterxml.jackson.core.type.TypeReference<I> inputType, Class<O> outputType)
      Like builder(Class, Class), for a generic input type.
    • requestInput

      public static <T> T requestInput(String interruptId, @Nullable String message, @Nullable Object payload, @Nullable com.google.genai.types.Schema responseSchema)
      Asks the user for input; it never returns. Unless the node reruns on resume, the answer, checked against any responseSchema, becomes the node's output without being read as its output type; if it reruns, the body runs again and must ask only when ctx.resumeInputs() lacks the answer:
      if (!ctx.resumeInputs().containsKey("q")) {
        return FunctionNodes.requestInput("q", "How many?");
      }
      Object answer = ctx.resumeInputs().get("q");
      

      Call it on the body's thread: it ends the body by throwing an internal Error, which catch (Exception e) lets through and catch (Throwable t) stops.

      Parameters:
      interruptId - the ID the answer carries; keep it stable across reruns
      message - the text to show the user, or null
      payload - data for rendering the request, written in JSON form as a node output is, or null
      responseSchema - the schema the answer must match, or null
      Throws:
      IllegalArgumentException - if the payload has no JSON form
    • requestInput

      public static <T> T requestInput(String interruptId, @Nullable String message, @Nullable Object payload)
      Like requestInput(String, String, Object, Schema), without a response schema.
    • requestInput

      public static <T> T requestInput(String interruptId, @Nullable String message)
    • requestInput

      public static <T> T requestInput(String interruptId)
      Like requestInput(String, String, Object, Schema), with neither message nor data.
    • requestInput

      public static <T> T requestInput()
      Like requestInput(String, String, Object, Schema), with a random interrupt ID.
    • requestInput

      public static <T> T requestInput(RequestInput request)