1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//! [`DecisionProvider`] -- typed, calibrated machine decisions.
//!
//! Where [`AgentProvider`](crate::provider::AgentProvider) drives a conversational
//! LLM (a single prompt, opaque text or JSON out), a [`DecisionProvider`] answers a
//! *map of typed questions* about a *state* and returns *typed answers* with a
//! calibrated confidence. This is the shape of TypeSafe AI's System One model
//! (`Jev`): classify, route, score, yes/no -- fast and cheap, with a probability
//! distribution instead of free text.
//!
//! The trait lives beside [`AgentProvider`](crate::provider::AgentProvider) rather
//! than inside it: Jev has no single prompt, no tools, and no streaming, so forcing
//! it into the agent mould would leak abstraction. A run wires a decision provider
//! independently of its agent provider.
//!
//! # Examples
//!
//! ```
//! use ironflow_core::decision::{DecisionRequest, DecisionQuestion, NoulCriteria};
//! use std::collections::BTreeMap;
//! use serde_json::json;
//!
//! let mut questions = BTreeMap::new();
//! questions.insert(
//! "is_urgent".to_string(),
//! DecisionQuestion::Noul {
//! instructions: json!("Does this convey urgency?"),
//! criteria: NoulCriteria::default(),
//! },
//! );
//! let request = DecisionRequest {
//! state: json!("Help! My payouts have been failing for 3 days."),
//! model: "jev-latest".into(),
//! questions,
//! };
//! assert_eq!(request.model, "jev-latest");
//! ```
use Future;
use Pin;
use crateAgentError;
pub use ;
pub use ;
/// Boxed future returned by [`DecisionProvider::decide`].
pub type DecideFuture<'a> =
;
/// A backend that answers a [`DecisionRequest`] with typed, calibrated answers.
///
/// Implement this to plug in any System One decision backend. The built-in
/// `TypeSafeProvider` (feature `provider-typesafe`) speaks the Jev HTTP API;
/// [`RecordReplayDecisionProvider`](crate::providers::record_replay_decision::RecordReplayDecisionProvider)
/// replays captured fixtures for deterministic tests.
///
/// # Examples
///
/// ```
/// use ironflow_core::decision::{DecideFuture, DecisionProvider, DecisionRequest, DecisionOutput, DecisionUsage};
/// use std::collections::BTreeMap;
///
/// struct AlwaysEmpty;
/// impl DecisionProvider for AlwaysEmpty {
/// fn decide<'a>(&'a self, _request: &'a DecisionRequest) -> DecideFuture<'a> {
/// Box::pin(async {
/// Ok(DecisionOutput { model: None, answers: BTreeMap::new(), usage: DecisionUsage::default() })
/// })
/// }
/// }
/// ```