node

inline fun <I, O> node(name: String, description: String = "", rerunOnResume: Boolean? = null, waitForOutput: Boolean = false, config: NodeConfig = NodeConfig(), inputSchema: Schema? = null, outputSchema: Schema? = null, stateSchema: Schema? = null, requireConfirmation: Boolean = false, crossinline block: suspend FlowCollector<Event>.(context: Context, input: I) -> O): FunctionNode<I, O>

Creates a FunctionNode that runs block, which uses context.state, context.updateState and requestInput. An edge into it builds only if the predecessor's output schema fits its input schema; inferred output schemas require every field, inferred input schemas only fields without defaults.

For example, an output DefOrder(id, total, qty = 1) feeds an input ReqOrder(id, total, qty): the output always carries qty, which the input requires.

Explicit schemas apply each run, except to a rejected confirmation's output and to a requestInput answer used as the output.

The block's return value, a Content included, is the node's output; emitting an event with an output or calling Context.setOutput fails the node. A node that talks to an agent node sends the message with emit(content). A node has no auth configuration.

Parameters

name

The node's name, required: non-empty and without '/', '@' or '.'.

inputSchema

Checks the input as it arrives, before I's defaults apply; an Any? port then gets the checked value.

rerunOnResume

Whether a resume runs the node again rather than using the resuming answer; unset, it is true when requireConfirmation is true.

requireConfirmation

Whether each run first asks the user to approve it: pass true, or a predicate that decides for each input. The request's payload holds the input's JSON form as args; a rejected run skips the block and outputs {"error": "This tool call is rejected."} unchecked; the answer is in Context.toolConfirmation.

Throws

if name is empty or contains '/', '@', or '.'.

if I or O, or a type argument inside it, is a sealed type, a nested ByteArray, or has no usable serializer and is not Content, Event, Any, or Unit, or if requireConfirmation is true with rerunOnResume = false.


inline fun <I, O> node(name: String, description: String = "", rerunOnResume: Boolean? = null, waitForOutput: Boolean = false, config: NodeConfig = NodeConfig(), inputSchema: Schema? = null, outputSchema: Schema? = null, stateSchema: Schema? = null, noinline requireConfirmation: suspend (context: Context, input: I) -> Boolean, crossinline block: suspend FlowCollector<Event>.(context: Context, input: I) -> O): FunctionNode<I, O>

Creates a FunctionNode as the other node overload does, asking the user to approve a run only when requireConfirmation returns true for its decoded input.

Parameters

rerunOnResume

Whether a resume runs the node again rather than using the resuming answer; unset, it is true.

requireConfirmation

Decides for each input whether a run asks the user to approve it; it runs on each run that has no answer yet, and once the node has asked, the answer decides. A rejected run outputs as the other node overload describes.

Throws

if name is invalid, as in the other node overload.

if I or O is not a valid port type, as in the other node overload, or with rerunOnResume = false.