Skip to main content

a3s_apofasi/
lib.rs

1//! A3S Apofasi — typed System-1 decisions for A3S hosts.
2//!
3//! *Apófasi* (απόφαση) means **decision**. This crate owns fast, non-generative
4//! typed decisions (`choice`, `score`, `noul`) that hosts can route, gate, and
5//! specialize without parsing free-form model text.
6//!
7//! The public request / response types match the TypeSafe System One (Jev)
8//! JSON contract: `state` + `questions` map in, `model` + `answers` map +
9//! `usage` out.
10//!
11//! # Quick start
12//!
13//! ```
14//! use a3s_apofasi::{Client, Criteria, DecisionKind, Question, State, SystemOneRequest};
15//! use indexmap::IndexMap;
16//! use serde_json::json;
17//!
18//! let mut opts = IndexMap::new();
19//! opts.insert("billing".into(), Some(json!("refunds")));
20//! opts.insert("other".into(), Some(json!("else")));
21//! let mut questions = IndexMap::new();
22//! questions.insert(
23//!     "department".into(),
24//!     Question::new(
25//!         DecisionKind::Choice,
26//!         json!("Which department?"),
27//!         Some(Criteria::Choice(opts)),
28//!     )
29//!     .unwrap(),
30//! );
31//! let res = Client::default()
32//!     .system_one(SystemOneRequest {
33//!         model: None,
34//!         state: State::Text("Please refund my invoice.".into()),
35//!         questions,
36//!     })
37//!     .unwrap();
38//! assert!(res.answers.contains_key("department"));
39//! ```
40//!
41//! Default builds stay small: the lexical engine has no ML framework dependency.
42//! Enable `infer` (and optionally `metal` / `cuda`) for Candle neural System-1.
43//!
44//! See [`ARCHITECTURE.md`](../ARCHITECTURE.md).
45
46#![deny(missing_docs)]
47
48pub mod client;
49pub mod confidence;
50pub mod decode;
51pub mod detect;
52pub mod engine;
53pub mod error;
54pub mod gate;
55pub mod primitive;
56pub mod reward;
57pub mod route;
58pub mod schema;
59pub mod sequence;
60#[cfg(any(test, feature = "infer"))]
61mod wide_choice;
62
63#[cfg(feature = "router")]
64pub mod router;
65
66#[cfg(feature = "infer")]
67pub mod infer;
68
69#[cfg(feature = "train")]
70pub mod train;
71
72/// Crate version string.
73pub const VERSION: &str = env!("CARGO_PKG_VERSION");
74
75pub use client::Client;
76pub use confidence::{confidence_from_probs, temp_bucket, TemperatureTable};
77pub use decode::{answer_from_logits, softmax};
78pub use detect::{analyse, Detection};
79pub use engine::{DecisionEngine, LexicalEngine};
80pub use error::{Error, Result};
81pub use gate::{any_escalate, gate_answer, gate_response, GateAction, GatePolicy};
82pub use primitive::DecisionKind;
83pub use reward::{ece_score, proper_reward, RewardWeights};
84pub use route::{CheckpointId, RouteDecision};
85pub use schema::{
86    criterion_text, instructions_text, Answer, Criteria, Instructions, Question, State,
87    SystemOneRequest, SystemOneResponse, TokenUsage,
88};
89pub use sequence::{
90    pack_question, pack_question_with_state_ids, ByteTokenizer, PackedQuestion, SequenceConfig,
91    SpecialTokens, Tokenize,
92};
93
94#[cfg(feature = "router")]
95pub use router::Router;
96
97#[cfg(feature = "infer")]
98pub use infer::{
99    resolve_device, ActOutput, AgentConfig, CheckpointPaths, CheckpointRegistry, DeviceRequest,
100    ForwardOutput, HfTokenizer, NeuralEngine,
101};
102
103#[cfg(feature = "train")]
104pub use train::{
105    evaluate_finetune_step, mean_batch_reward, FineTuneConfig, FineTuneStepStats, PublishLayout,
106    RewardExample,
107};