ParallelAgent

class ParallelAgent(name: String, description: String = "", subAgents: List<BaseAgent> = emptyList(), beforeAgentCallbacks: List<BeforeAgentCallback> = emptyList(), afterAgentCallbacks: List<AfterAgentCallback> = emptyList()) : BaseAgent

A shell agent that runs its sub-agents in parallel in an isolated manner.

This approach is beneficial for scenarios requiring multiple perspectives or attempts on a single task, such as:

  • Running different algorithms simultaneously.

  • Generating multiple responses for review by a subsequent evaluation agent.

Constructors

Link copied to clipboard
constructor(name: String, description: String = "", subAgents: List<BaseAgent> = emptyList(), beforeAgentCallbacks: List<BeforeAgentCallback> = emptyList(), afterAgentCallbacks: List<AfterAgentCallback> = emptyList())

Types

Link copied to clipboard
class Builder

Fluent builder for ParallelAgent, provided primarily for Java callers. Any property left unset falls back to the same default as the constructor.

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

List of callbacks to run after the agent executes.

Link copied to clipboard

List of callbacks to run before the agent executes.

Link copied to clipboard
open override val config: NodeConfig

The node's retry policy and execution timeout.

Link copied to clipboard
open override val description: String

What the node does, for humans and for a model that may call it.

Link copied to clipboard

When true, the framework will not route the next user turn back to this agent after the parent transfers control to it; instead the next turn falls back to the root agent. Set this on utility sub-agents the parent calls and returns from (translators, summarizers, classifiers). Leave at the default false for sub-agents that should keep handling follow-up turns directly (e.g. billing, support).

Link copied to clipboard

When true, prevents this agent from transferring sideways to a peer agent under the same parent. Typically set together with disallowTransferToParent on one-shot utility agents. Violations are surfaced by the runner as IllegalArgumentException.

Link copied to clipboard
open override val inputSchema: Schema?

Validates the node's input before it runs.

Link copied to clipboard
override val name: String

Identifies the node within its graph.

Link copied to clipboard
open override val outputSchema: Schema?

Validates the output value the node emits. A value assigned to Context.output and a message-as-output event's content are not checked.

Link copied to clipboard
open override val requiresAllPredecessors: Boolean

Whether the node runs only once every predecessor has completed, receiving all their outputs keyed by node name. A fan-in node overrides this to true.

Link copied to clipboard
open override val rerunOnResume: Boolean

On resume, whether to run the node again from scratch rather than completing it with the resuming answer as its output.

Link copied to clipboard
open override val stateSchema: Schema?

Declares the state keys the node uses. Child nodes inherit it unless they declare their own.

Link copied to clipboard

List of sub-agents.

Link copied to clipboard
open override val waitForOutput: Boolean

Whether the node stays re-triggerable until it produces an output or a route, instead of completing when runNode returns. A node that never produces either then waits forever, which is a graph-authoring error.

Functions

Link copied to clipboard
fun BaseAgent.findAgent(targetName: String): BaseAgent?

Finds an agent with the given name in this agent's subtree (including itself).

Link copied to clipboard
fun run(context: Context, nodeInput: Any?): Flow<Event>

Runs the node and emits its events. It drives runNode and normalizes each raw emission into an Event, so every node behaves the same way at its edges: null and Unit are skipped, an Event passes through with its output validated (a message-as-output event's content is not), and any other value becomes the output.

Link copied to clipboard
fun runAsync(parentContext: InvocationContext): Flow<Event>

Public entry point for executing the agent asynchronously (text-based).

Link copied to clipboard
open override fun runNode(context: Context, nodeInput: Any?): Flow<Any?>

Runs this agent as a graph node by driving its runAsync lifecycle, so an agent placed in a workflow graph executes exactly as it would under a runner. Its events are forwarded as the node's output and its author is tracked; the node runner stamps each event's path.