Class FunctionNodes
java.lang.Object
com.google.adk.workflow.FunctionNodes
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 Summary
Modifier and TypeMethodDescriptionstatic <I,O> FunctionNode.Builder <I, O> builder(com.fasterxml.jackson.core.type.TypeReference<I> inputType, com.fasterxml.jackson.core.type.TypeReference<O> outputType) Likebuilder(Class, Class), for generic port types.static <I,O> FunctionNode.Builder <I, O> Likebuilder(Class, Class), for a generic input type.static <I,O> FunctionNode.Builder <I, O> Likebuilder(Class, Class), for a generic output type.static <I,O> FunctionNode.Builder <I, O> Returns a builder for a node with these port types, for propertiesof(String, Class, Class, NodeBody)does not take.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) Likeof(String, Class, Class, NodeBody), for generic port types.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) Likeof(String, Class, Class, NodeBody), for a generic input type.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) Likeof(String, Class, Class, NodeBody), for a generic output type.static <I,O> FunctionNode <I, O> Returns a node namednamethat runsbodyon each input read asinputTypeand writes itsoutputTypeoutput in JSON form.static <T> TLikerequestInput(String, String, Object, Schema), with a random interrupt ID.static <T> TrequestInput(RequestInput request) LikerequestInput(String, String, Object, Schema), for a builtrequest.static <T> TrequestInput(String interruptId) LikerequestInput(String, String, Object, Schema), with neither message nor data.static <T> TrequestInput(String interruptId, @Nullable String message) LikerequestInput(String, String, Object, Schema), with only a message.static <T> TrequestInput(String interruptId, @Nullable String message, @Nullable Object payload) LikerequestInput(String, String, Object, Schema), without a response schema.static <T> TrequestInput(String interruptId, @Nullable String message, @Nullable Object payload, @Nullable com.google.genai.types.Schema responseSchema) Asks the user for input; it never returns.
-
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 namednamethat runsbodyon each input read asinputTypeand writes itsoutputTypeoutput in JSON form. The body may send events first withContext.emit(Event).- Throws:
WorkflowConfigurationException- if Jackson cannot read and writeinputTypeor writeoutputType, or if a port type has no single concrete JSON shape or is an interface or abstract class without a Jackson creator, such asZoneId; 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) Likeof(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) Likeof(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) Likeof(String, Class, Class, NodeBody), for a generic input type. -
builder
Returns a builder for a node with these port types, for propertiesof(String, Class, Class, NodeBody)does not take.- Throws:
WorkflowConfigurationException- asof(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) Likebuilder(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) Likebuilder(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) Likebuilder(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 anyresponseSchema, becomes the node's output without being read as its output type; if it reruns, the body runs again and must ask only whenctx.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, whichcatch (Exception e)lets through andcatch (Throwable t)stops.- Parameters:
interruptId- the ID the answer carries; keep it stable across rerunsmessage- the text to show the user, ornullpayload- data for rendering the request, written in JSON form as a node output is, ornullresponseSchema- the schema the answer must match, ornull- Throws:
IllegalArgumentException- if the payload has no JSON form
-
requestInput
public static <T> T requestInput(String interruptId, @Nullable String message, @Nullable Object payload) LikerequestInput(String, String, Object, Schema), without a response schema. -
requestInput
LikerequestInput(String, String, Object, Schema), with only a message. -
requestInput
LikerequestInput(String, String, Object, Schema), with neither message nor data. -
requestInput
public static <T> T requestInput()LikerequestInput(String, String, Object, Schema), with a random interrupt ID. -
requestInput
LikerequestInput(String, String, Object, Schema), for a builtrequest.
-