Package-level declarations

Types

Link copied to clipboard
abstract class BaseNode(val name: String, val description: String = "", val rerunOnResume: Boolean = false, val waitForOutput: Boolean = false, val config: NodeConfig = NodeConfig(), val inputSchema: Schema? = null, val outputSchema: Schema? = null, val stateSchema: Schema? = null) : Node

The base class for units of work in a workflow graph. A Workflow is itself a node, so graphs nest, and every agent is one too.

Link copied to clipboard

Decides for each input whether a FunctionNode run asks the user to approve it, set through FunctionNode.Builder.requireConfirmation. It runs on the workflow's coroutine before the body, so it must not block, and an exception it throws fails the run.

Link copied to clipboard

Thrown by com.google.adk.kt.agents.Context.runNode when the dispatched child fails: error is the child's failure and errorNodePath the path of the node that failed.

Link copied to clipboard
data class Edge @JvmOverloads constructor(val from: Node, val to: Node, val routes: List<Route> = emptyList())

A connection between two nodes.

Link copied to clipboard

A chain of edges for Java callers, positioned at a node. EdgesBuilder.from starts a chain, and each call adds the same edges as the edges DSL function of the same name and continues from its target.

Link copied to clipboard

The receiver that collects the edges declared in an edges or workflow block. A node is identified by its instance, so create each node once and reuse it. To add a tool as a step, convert it once with asNode and reuse that node.

Link copied to clipboard

A block that declares edges or routes on a T builder. In Kotlin, pass a lambda with the builder as its receiver. In Java, pass a lambda that takes the builder as an argument, with no Unit to return.

Link copied to clipboard

A workflow Node backed by a suspending function that returns an O and may emit Events. An input that does not decode as I throws NodeInputValidationException; an output that is not an O or a Content, has no JSON form, or fails an explicit schema throws IllegalArgumentException.

Link copied to clipboard

A workflow graph failed validation. Raised when the graph is built, not when it runs.

Link copied to clipboard
class JoinNode @JvmOverloads constructor(name: String, description: String = "", inputSchema: Schema? = null, outputSchema: Schema? = null) : BaseNode

Waits for every predecessor to complete, then outputs their outputs keyed by predecessor name.

Link copied to clipboard
interface Node

A unit of work in a workflow graph.

Link copied to clipboard

The body of a FunctionNode set through FunctionNode.Builder.body. A Java body is blocking code, so it does not run on the dispatcher of the coroutine that collects the run: it runs on the dispatcher passed to FunctionNodes, by default a view of Dispatchers.IO without its thread limit, so it may block, for example to wait for a child or for InteropContextView.emit, without stalling the workflow. A waiting body holds its thread: the default starts one thread per body that waits at the same time, and a dispatcher an app passes needs a free thread for every such body, so a single-threaded or small bounded one can hang the run. Bound a fan-out with the maxParallelWorkers of parallelOf, or pass a bounded dispatcher when bodies wait for nothing.

Link copied to clipboard
data class NodeConfig(val retryConfig: RetryConfig? = null, val timeout: Duration? = null)

Bundles a node's retry policy and execution timeout. A null timeout imposes no limit, so an attempt is then bounded only by any ambient deadline. Validation lives here, so every Node implementation inherits it.

Link copied to clipboard
open class NodeExecutionException @JvmOverloads constructor(message: String, cause: Throwable? = null) : RuntimeException

Base class for node failures raised by the workflow runtime, such as NodeTimeoutException. A node can also throw this class or a subclass it defines; error events and RetryConfig.exceptions name each failure by its simple class name. List it in RetryConfig.exceptionClasses to retry this class and every subclass.

Link copied to clipboard

Nodes grouped by nodes(...) or a fan-out then, which EdgesBuilder.joinTo connects to a JoinNode.

Link copied to clipboard

A chain of edges for Java callers, positioned at a NodeGroup from a fan-out or EdgesBuilder.from.

Link copied to clipboard
data class NodeInfo(val path: String = "", val outputFor: List<String>? = null, val messageAsOutput: Boolean = false)

Identifies the workflow-node activation that emitted an com.google.adk.kt.events.Event; null outside a workflow.

Link copied to clipboard

Raised when a node's runtime input fails validation.

Link copied to clipboard

A node exceeded its configured timeout. An ordinary exception, so a timed-out node is still eligible for retry.

Link copied to clipboard

An edge started by EdgesBuilder.on, which has a source and its routes but no target yet. EdgesBuilder.then completes it.

Link copied to clipboard

A chain of edges for Java callers, positioned at a routed edge started by EdgeChain.on; then completes it.

Link copied to clipboard
data class RequestInput(val interruptId: String = Uuid.random(), val message: String? = null, val payload: Any? = null, val responseSchema: Schema? = null)

A node's request for user input, which pauses the workflow until a matching response arrives.

Link copied to clipboard
data class RetryConfig(val maxAttempts: Int = DEFAULT_MAX_ATTEMPTS, val initialDelay: Duration = DEFAULT_INITIAL_DELAY, val maxDelay: Duration = DEFAULT_MAX_DELAY, val backoffFactor: Double = DEFAULT_BACKOFF_FACTOR, val jitter: Double = DEFAULT_JITTER, val exceptions: List<String>? = null, val exceptionClasses: List<KClass<out Exception>>? = null)

How a node is retried when it raises.

Link copied to clipboard
sealed interface Route

A value on a workflow edge, and the value a node emits to select which of its outgoing edges are followed. An edge fires when the value it carries matches one the node emitted.

Link copied to clipboard

The receiver of an EdgesBuilder.route block, which maps each route the source node may emit to a target node, written on("billing") then billing or "billing" then billing. Mapping one route to several nodes fans out on that route.

Link copied to clipboard

A routing-map entry started by RouteMapBuilder.on whose routes have no target yet. then completes it.

Link copied to clipboard

Routes that select a single edge, which fires once when its source emits any of them. Separate edges to the same target would fire once each. Build one with anyOf(...) in the workflow DSL.

Link copied to clipboard

Marks where a graph starts. Never runs: the scheduler seeds its successors directly.

Link copied to clipboard
class Workflow(name: String, val edges: List<Edge> = emptyList(), description: String = "", val maxConcurrency: Int? = null, rerunOnResume: Boolean = true, waitForOutput: Boolean = false, config: NodeConfig = NodeConfig(), inputSchema: Schema? = null, outputSchema: Schema? = null, stateSchema: Schema? = null) : BaseNode

A graph of nodes, and a Node itself so graphs nest, assembled and validated on construction (throwing GraphValidationException if malformed) and run concurrently as predecessors finish.

Link copied to clipboard

Thrown when a workflow or node configuration is invalid.

Functions

Link copied to clipboard
fun BaseTool.asNode(name: String = this.name, config: NodeConfig = NodeConfig()): Node

Returns a workflow node that runs this tool as a fixed step: the predecessor's output becomes the tool's arguments, and the tool's result becomes the node's output.

Link copied to clipboard

Returns the edges declared by graphDefinition for a Workflow; workflow builds both in one step.

Link copied to clipboard

Emits content from a node body as a message, which is not the node's output. In a custom Node's flow {}, emit(content) emits a raw value instead, which becomes the output. A Java body uses InteropContextView.of(context).emit(content).

Link copied to clipboard
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.

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.

Link copied to clipboard
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.

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.

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.

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.

Link copied to clipboard
fun FlowCollector<Nothing>.requestInput(interruptId: String = Uuid.random(), message: String? = null, responseSchema: Schema? = null): Nothing

From a node's body, asks the user for input once per run and ends it. With rerunOnResume = true the body reruns and reads the answer from ctx.resumeInputs[interruptId]; ctx.resumeInputs[id] ?: requestInput(id) asks again on a null answer responseSchema allows. Otherwise the answer, checked against any responseSchema, is the node's output.

inline fun <P> FlowCollector<Nothing>.requestInput(interruptId: String = Uuid.random(), message: String? = null, payload: P, responseSchema: Schema? = null): Nothing

Like the overload without a payload, and also sends payload in its JSON form under P's serializer, as Context.setOutput writes an output.

Link copied to clipboard
fun workflow(name: String, description: String = "", maxConcurrency: Int? = null, rerunOnResume: Boolean = true, waitForOutput: Boolean = false, config: NodeConfig = NodeConfig(), inputSchema: Schema? = null, outputSchema: Schema? = null, stateSchema: Schema? = null, graphDefinition: EdgesDslBlock<EdgesBuilder>): Workflow

Builds a Workflow from the edges graphDefinition declares.