Skip to main content

Module decision

Module decision 

Source
Expand description

Decision models: typed questions about shared state, answered with calibrated probabilities instead of text.

A decision model (a “System One” model, such as TypeSafe AI’s Jev on Vercel AI Gateway) takes a state (a string, an object or an array) and a map of named questions. Each answer comes back typed:

QuestionAnswer
Question::Booleanprobability that the statement is true
Question::Choicethe chosen option and each option’s probability
Question::Scorea probability-weighted position on an ordered scale

A decision model writes no text, so it cannot fill an open slot such as a name or a date. It can pick among options the session already holds (the time slots a tool offered) and decide categorical things (a confirmation, an intent, which stage comes next), usually far faster than a language model. Decisions holds the questions a session asks and asks them against the rolling conversation; guards name them with the decided atom (see crate::flow::decided). GatewayDecisionModel (feature ai-gateway) calls Vercel AI Gateway.

use gemini_adk_rs::decision::{Answer, DecisionRequest, MockDecisionModel, Question, DecisionModel};
use serde_json::json;

let model = MockDecisionModel::new(|_| {
    Ok([("confirmed".to_string(), Answer::boolean(0.97))].into())
});
let response = model
    .decide(DecisionRequest::new(
        json!("Caller: yes, book it."),
        [("confirmed", Question::boolean("Did the caller agree to book?"))],
    ))
    .await
    .unwrap();
assert_eq!(response.answers["confirmed"].probability(), Some(0.97));

Structs§

BooleanCriteria
What the true and false cases of a boolean question mean.
Conversation
The conversation a decision model reads: caller and agent lines and tool results in order, the facts the active stages ground the model in, and which stages are active.
Decision
One question in the bank.
DecisionRequest
A decision request: one state and its questions.
DecisionResponse
A decision model’s answers and what it cost.
DecisionUsage
Token usage of one decision.
Decisions
A bank of questions asked of a decision model against the rolling conversation.
GatewayDecisionModel
A decision model served by Vercel AI Gateway, such as TypeSafe AI’s Jev.
MockDecisionModel
A DecisionModel whose answers come from a closure, for offline tests. It records every request it receives.
Round
What one ask did.

Enums§

Answer
One answer, typed like its question.
FallbackWhen
When AI Gateway should rerun a decision with another model.
Question
One typed question, as the decision API takes it.

Constants§

DEFAULT_BOOLEAN_THRESHOLD
The P(true) a boolean answer needs to count as yes (and 1 - this to count as no), unless the question sets its own.
DEFAULT_CERTAINTY_THRESHOLD
The certainty a choice or score answer needs, unless the question sets its own.
DEFAULT_DECISION_TIMEOUT
How long a round waits for the decision model.
DEFAULT_HISTORY_TURNS
How many turns of the conversation the decision model reads.
MAX_CHOICE_OPTIONS
The most options a choice question may have.
NONE_OPTION
The option a choice gets from Decision::or_none.
SCORE_LEVELS
The fewest and most levels a score question may have.

Traits§

DecisionModel
A model that answers typed questions about a state.