ClassifierNode

class ClassifierNode @JvmOverloads constructor(name: String, val classifier: Classifier, val question: Question, threshold: Double? = null, val answerKey: String? = null, description: String = "", rerunOnResume: Boolean = false, waitForOutput: Boolean = false, config: NodeConfig = NodeConfig(), inputSchema: Schema? = null, outputSchema: Schema? = null, stateSchema: Schema? = null) : BaseNode

Routes a workflow by asking a classifier one question about the node's input and emitting the answer as the route: the chosen label of a Choice, or true or false for a Binary, decided by threshold. The output is the unchanged input, or the underlying value unwrapped from a ClassifierInput, so the routed-to node receives what the classifier saw.

When the node has routed outgoing edges, graph validation checks that every route is a possible answer and that every possible answer has an edge, unless a default or unconditional edge catches the rest.

Parameters

threshold

For a Binary, the probability in [0, 1] at or above which the route is true, or null for 0.5. Setting it for a Choice is an error.

Throws

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

if question is a Score or uses Route.DEFAULT_ROUTE_SENTINEL, or if threshold is set on a Choice or lies outside [0, 1].

Constructors

Link copied to clipboard
constructor(name: String, classifier: Classifier, question: Question, threshold: Double? = null, answerKey: String? = null, description: String = "", rerunOnResume: Boolean = false, waitForOutput: Boolean = false, config: NodeConfig = NodeConfig(), inputSchema: Schema? = null, outputSchema: Schema? = null, stateSchema: Schema? = null)

Types

Link copied to clipboard
class Builder

Fluent builder for ClassifierNode, 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

The state key where the serialized Answer is stored as a JSON map, or null to store nothing.

Link copied to clipboard
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
open override val inputSchema: Schema?

Checks the input as JSON; the node receives the checked value unless it takes a Content. An edge fails to build when the predecessor's output schema admits values this one rejects; what that schema leaves open (no type, undeclared keys, undescribed ARRAY items) is checked at run time.

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 with the same rules, and the checked value is the output. A value set with Context.setOutput and a message-as-output event's content are not checked.

Link copied to clipboard

The Choice (without Route.DEFAULT_ROUTE_SENTINEL) or Binary whose answer picks the route.

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; keys containing a colon are not checked. Child nodes inherit it unless they declare their own.

Link copied to clipboard

The probability at or above which a Binary routes true.

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 run(context: Context, nodeInput: Any?): Flow<Event>

Runs the node and normalizes each raw emission of runNode into an Event: null and Unit are skipped, a RequestInput becomes an adk_request_input interrupt event, an Event keeps its content and has its output validated, and any other value becomes the output.

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

Classifies nodeInput and emits it with the route. Throws NodeExecutionException if the input is not a ClassifierInput, text, a JSON object or array (as a Map/List or JsonElement), or Content, or if the answer is missing, a refusal, an unknown label, or of the wrong type.