decisionEdge

fun <State> StateGraph<State>.decisionEdge(from: NodeRef, model: DecisionModel, instructions: String, routes: Map<NodeRef, String?>, minConfidence: Double = 0.0, fallback: NodeRef? = null, state: suspend (State) -> String)

Adds a conditional edge from from on which a DecisionModel picks the next node: a router that understands language, at the speed and price of a decision model.

decisionEdge(
from = read,
model = jev,
instructions = "Which team should handle this email?",
routes = mapOf(
refund to "The customer wants money back",
technical to "Something does not work",
),
// An email the model is not sure about goes to a person.
minConfidence = 0.7,
fallback = escalate,
) { email -> email.body }

The model sees the names of the nodes in routes as its options, so name the nodes for what they do. It picks one of them also when none fits, and can be sure of that pick, so give it a route for what the others do not cover. The decision is not written into the state. When the state should keep it, or the next step needs the probabilities, ask the model in a node with choose and route with conditionalEdge on what the node stored.

A failure of the model fails the run with an EdgeConditionException, which has the DecisionModelException as its cause.

Parameters

routes

the nodes the model may pick, each with a description of when it applies, or null when the name of the node says enough. Use NodeRef.END for "nothing more to do".

minConfidence

the confidence below which the edge goes to fallback instead of the node the model picked, from 0 to 1.

fallback

where an unsure decision goes. It may be one of routes.

state

reads what the model judges out of the state of the graph.

Throws

if routes is empty, minConfidence is not between 0 and 1, or it is above 0 and there is no fallback.


fun <State> StateGraph<State>.decisionEdge(from: String, model: DecisionModel, instructions: String, routes: Map<NodeRef, String?>, minConfidence: Double = 0.0, fallback: NodeRef? = null, state: suspend (State) -> String)

Adds a decision edge from the node named from, usually START. See the overload taking a NodeRef.