parallelNode

inline fun <I, O> parallelNode(name: String, description: String = "", rerunOnResume: Boolean? = null, waitForOutput: Boolean = false, maxParallelWorkers: Int? = null, 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<List<I>, List<O>>

Creates a FunctionNode that runs block concurrently on each item of a list input and returns the results as a List of O in input order. A text-only Content input, unless I is Content, is read as JSON so a JSON list fans out. Any other non-list input runs as one item.

config, the schemas, rerunOnResume and requireConfirmation apply to each item's run, so each item asks for its own approval; the fan-out node shares waitForOutput and stateSchema, declares no input or output schema, has no retry or timeout, and always reruns on resume.

Java callers use FunctionNode.parallelOf.

Parameters

maxParallelWorkers

Maximum number of items run at a time, or null for no limit.

requireConfirmation

Whether each item's run first asks the user to approve it: pass true, or a predicate that decides for each item, as in node, which describes a rejected run's output.

Throws


inline fun <I, O> parallelNode(name: String, description: String = "", rerunOnResume: Boolean? = null, waitForOutput: Boolean = false, maxParallelWorkers: Int? = null, 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<List<I>, List<O>>

Creates a fan-out FunctionNode as the other block-form parallelNode does, asking to approve an item's run only when requireConfirmation returns true for it. The predicate runs on each item's run with no answer yet; once the item has asked, the answer decides. A rejected item outputs as in node.

Parameters

maxParallelWorkers

Maximum number of items run at a time, or null for no limit.

Throws


inline fun <I, O> parallelNode(node: FunctionNode<I, O>, maxParallelWorkers: Int? = null): FunctionNode<List<I>, List<O>>

Wraps node so it runs concurrently on each item of a list input and returns the results in input order. node's configuration and schemas apply to each item's run; the fan-out node declares no input or output schema. Java callers use FunctionNode.parallelOf.

Parameters

maxParallelWorkers

Maximum number of items run at a time, or null for no limit.

Throws


fun parallelNode(node: Node, maxParallelWorkers: Int? = null): Node

Returns a node that runs node once per item of a list input concurrently and outputs the items' outputs as a list in input order. A text-only Content input, unless node is a function node taking Content, is read as JSON so a JSON list fans out; text that is not JSON arrives as a string. Any other non-list input runs as a single item.

The returned node takes node's name, description, Node.stateSchema and Node.requiresAllPredecessors, and declares no input or output schema. node's Node.config and schemas apply to each item; the fan-out itself has a default NodeConfig.

Parameters

node

Single-item node to execute for each list element.

maxParallelWorkers

Maximum number of items to run concurrently; null means no limit.

Throws