Class FunctionNode<I,O>
java.lang.Object
com.google.adk.workflow.BaseNode
com.google.adk.workflow.FunctionNode<I,O>
- All Implemented Interfaces:
Node
A workflow node that runs a Java function on each input, with a type per port; build one with
FunctionNodes.of(String, Class, Class, NodeBody) or FunctionNodes.builder(Class, Class). An Object input port takes its
input as it is, a Content or Event port reads its own type, a Void port
ignores its input, and Jackson reads any other type, so a user message reaches only a
Content or Object port. Every output is written in JSON form, so a successor reads the
same value whether it comes live or from a stored session. A body that gives its output to a
child with useAsOutput outputs the child's output written as O, as if it had
returned it.
The body may send events before its output with Context.emit(Event):
- State: a write made before
emitis sent with that event, or with an event another thread sent just before it; a later write is sent with a later event or the output, and reads on the calling thread afteremitreturns see the body's own writes. - Threads: any thread the body uses may call it, and a call waits even if the body returns; a
call deadlocks in a
ctx.runNode(...)callback such asdoOnSuccess, which runs inside the dispatch. A body that calls it cannot run inline, so on aRunnerthat does, such asSchedulers.trampoline()or a direct executor, set aFunctionNode.Builder.schedulerthat does not, such asSchedulers.io(); ADK Kotlin runs bodies onDispatchers.IO, where none is needed. - Events: a missing ID is filled in; long-running tool IDs, a route or a transfer act as on a
returned event; a partial event is sent without waiting, not stored, and carries no state
writes; the events precede the output unless a
useAsOutputchild already sent it. - Cancellation: a cancel of the node, or an interrupt of the waiting thread, ends the wait
with a
CancellationException, and the event may still be stored; after a cancel every call throws one and the output is dropped. - Resumes: a body rerun after a pause sends its events again. If the turn is canceled after
an emitted event was stored, a later resume reruns the body only if the node sets
waitForOutput, or runs throughctx.runNodeor as the app's root node withrerunOnResumefalse.
Only the workflow runner runs a FunctionNode; from another node's body, run it with
ctx.runNode, since calling runNode(Context, Object) directly fails with an
IllegalStateException.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionOptional<com.google.genai.types.Schema> Returns the schema that describes the input port: the one set on the builder or, if none, one inferred from the input type, where anObject,Voidor other type with no fixed JSON shape infers none.Optional<com.google.genai.types.Schema> Returns the schema that describes the output port: the one set on the builder or, if none, one inferred from the output type.io.reactivex.rxjava3.core.Flowable<?> Runs the node onnodeInput, the output it receives from its predecessors.Returns a builder initialized with this node's properties.Methods inherited from class BaseNode
config, description, name, rerunOnResume, stateSchema, validateOutgoingEdges, waitForOutputModifier and TypeMethodDescriptionconfig()Returns the node's retry policy and execution timeout.Returns what the node does, for humans and for a model that may call it.final Stringname()Returns the name that identifies the node within its graph.booleanReturnstrueif a resumed node runs again from scratch, rather than completing with the resuming answer as its output.Optional<com.google.genai.types.Schema> Returns the schema declaring the state keys the node uses.protected voidvalidateOutgoingEdges(Collection<Edge> edges) ThrowsGraphValidationExceptionif this node cannot serve theedgesthat leave it, such as an edge for a route it never emits.booleanReturnstrueif the node stays re-triggerable until it produces an output or a route, instead of completing when its run completes.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Node
requiresAllPredecessorsModifier and TypeMethodDescriptiondefault booleanReturnstrueif the node runs only once every predecessor has completed, receiving all their outputs keyed by node name, as a fan-in node does.
-
Method Details
-
toBuilder
Returns a builder initialized with this node's properties. ArerunOnResumethe node derived from its confirmation is left unset, so the copy derives it from its own. -
inputSchema
Returns the schema that describes the input port: the one set on the builder or, if none, one inferred from the input type, where anObject,Voidor other type with no fixed JSON shape infers none. An edge into an inferred record or POJO fails at build if the producer's output schema lists a key the type does not, while a builder schema checks only the keys it lists and requires. On aContentport a builder schema describes the message text, and an edge is checked against theContentschema instead.- Specified by:
inputSchemain interfaceNode- Overrides:
inputSchemain classBaseNode
-
outputSchema
Returns the schema that describes the output port: the one set on the builder or, if none, one inferred from the output type. A returnedEventis sent as it is, so anEventoutput infers none.- Specified by:
outputSchemain interfaceNode- Overrides:
outputSchemain classBaseNode
-
runNode
Description copied from interface:NodeRuns the node onnodeInput, the output it receives from its predecessors. The workflow runner calls this method; to run a node from another node's body, callContext.runNode(Node, Object).An emitted
Eventpasses through, an emittedRequestInputpauses the workflow until the user answers it, and any other emitted value becomes the node's output (at most one per run); emit nothing for no output, since RxJava forbids null. The wildcard lets an implementation return aFlowableof its own type.
-