Expand description
Typed decisions: questions declared as a struct, answers read back into it.
DecisionAnswers turns a struct into the questions of a
decision step, one question
per field, and reads the provider’s answers back into it.
DecisionChoice lists the options of a choice question from the unit
variants of an enum. Both are derived:
use ironflow_engine::config::DecisionConfig;
use ironflow_engine::context::WorkflowContext;
use ironflow_engine::decision::{DecisionAnswers, DecisionChoice};
use ironflow_engine::error::EngineError;
#[derive(Debug, DecisionChoice)]
enum Team {
#[choice(description = "Payments and invoices")]
Billing,
Technical,
Sales,
}
#[derive(Debug, DecisionAnswers)]
struct Triage {
#[noul("Does this convey urgency?")]
is_urgent: f64,
#[choice("Which team should handle this?")]
team: Team,
#[score("How frustrated is the customer?", levels = ["Calm", "Frustrated", "Very angry"])]
mood: f64,
}
let triage = ctx
.decision("triage", DecisionConfig::new(ticket).answers::<Triage>().escalate_below(0.7))
.await?;
match triage.team {
Team::Billing => { /* .. */ }
Team::Technical | Team::Sales => { /* .. */ }
}§Field attributes of #[derive(DecisionAnswers)]
Every field is one question, named after the field, with exactly one of:
| Attribute | Field type | Answer |
|---|---|---|
#[noul("..")], optionally if_true = "..", if_false = ".." | f64 | Probability of “yes”, in [0, 1] |
#[choice("..")] | an enum deriving DecisionChoice | The option picked |
#[score("..", levels = ["..", ".."])] | f64 | Probability-weighted level index |
The first argument is the instruction sent to the model. A field without a question does not compile:
use ironflow_engine::decision::DecisionAnswers;
#[derive(DecisionAnswers)]
struct Triage {
is_urgent: f64,
}nor does a score without levels:
use ironflow_engine::decision::DecisionAnswers;
#[derive(DecisionAnswers)]
struct Triage {
#[score("How frustrated?")]
mood: f64,
}nor a field whose type does not fit its question:
use ironflow_engine::decision::DecisionAnswers;
#[derive(DecisionAnswers)]
struct Triage {
#[noul("Does this convey urgency?")]
is_urgent: String,
}§Variant attributes of #[derive(DecisionChoice)]
An option is labelled with its variant name in snake_case (OnCall is
on_call). #[choice(rename = "..")] overrides the label,
#[choice(description = "..")] tells the model what the option means. Doc
comments are never sent to the model. Options are unit variants:
use ironflow_engine::decision::DecisionChoice;
#[derive(DecisionChoice)]
enum Team {
Billing,
Other(String),
}Traits§
- Decision
Answers - A struct whose fields are the questions of a decision step and whose values are the answers.
- Decision
Choice - An enum whose unit variants are the options of a choice question.
Derive Macros§
- Decision
Answers - Derive
ironflow_engine::decision::DecisionAnswerson a struct whose fields are the questions of a decision step. - Decision
Choice - Derive
ironflow_engine::decision::DecisionChoiceon an enum whose unit variants are the options of a choice question.