Skip to main content

organism_learning/
lib.rs

1//! Organizational learning.
2//!
3//! Planning priors are calibrated by execution outcomes. Adversarial firings
4//! become labeled training signals. Strategy adapts based on feedback.
5//!
6//! Learning signals must NEVER feed directly into authority — only into the
7//! priors that planning consults.
8//!
9//! Cycle: Intent → Plan → Execute → Observe → Learn → Calibrate priors.
10//!
11//! # Adapter
12//!
13//! The [`adapter`] module bridges converge experience events to organism
14//! learning types. After an engine run, call
15//! [`adapter::build_episode_from_run`] with the final context plus queried
16//! `ExperienceEventEnvelope`s, then [`adapter::calibrate_priors`] to update
17//! planning priors.
18
19pub mod adapter;
20pub mod prior_agent;
21
22use serde::{Deserialize, Serialize};
23use uuid::Uuid;
24
25pub use prior_agent::PlanningPriorAgent;
26
27// ── Learning Episode ───────────────────────────────────────────────
28
29/// Full record of a planning-to-outcome episode. Links intent, plan,
30/// predicted outcomes, governed business outcomes, engine run status,
31/// prediction errors, adversarial signals, and extracted lessons.
32/// Every field traces to converge Facts or run envelopes.
33#[derive(Debug, Clone, Serialize, Deserialize)]
34pub struct LearningEpisode {
35    pub id: Uuid,
36    pub intent_id: Uuid,
37    pub plan_id: Uuid,
38    pub predicted_outcome: String,
39    pub actual_outcome: Option<String>,
40    pub run_status: Option<String>,
41    pub prediction_error: Option<PredictionError>,
42    pub adversarial_signals: Vec<AdversarialContext>,
43    pub lessons: Vec<Lesson>,
44}
45
46// ── Prediction Error ───────────────────────────────────────────────
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct PredictionError {
50    pub magnitude: f64,
51    pub dimensions: Vec<ErrorDimension>,
52}
53
54#[derive(Debug, Clone, Serialize, Deserialize)]
55pub struct ErrorDimension {
56    pub name: String,
57    pub predicted: f64,
58    pub actual: f64,
59}
60
61// ── Lesson ─────────────────────────────────────────────────────────
62
63#[derive(Debug, Clone, Serialize, Deserialize)]
64pub struct Lesson {
65    pub insight: String,
66    pub context: String,
67    pub confidence: f64,
68    pub planning_adjustment: String,
69}
70
71// ── Prior Calibration ──────────────────────────────────────────────
72
73#[derive(Debug, Clone, Serialize, Deserialize)]
74pub struct PriorCalibration {
75    pub assumption_type: String,
76    pub context: String,
77    pub prior_confidence: f64,
78    pub posterior_confidence: f64,
79    pub evidence_count: u32,
80}
81
82// ── Adversarial Context (for cross-referencing) ────────────────────
83
84#[derive(Debug, Clone, Serialize, Deserialize)]
85pub struct AdversarialContext {
86    pub kind: String,
87    pub failed_assumption: String,
88    pub revision_summary: Option<String>,
89}
90
91// ── Signal (simplified for quick capture) ──────────────────────────
92
93#[derive(Debug, Clone, Serialize, Deserialize)]
94pub struct LearningSignal {
95    pub kind: SignalKind,
96    pub weight: f32,
97    pub note: String,
98}
99
100#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
101#[serde(rename_all = "snake_case")]
102pub enum SignalKind {
103    OutcomeMatchedExpectation,
104    OutcomeBeatExpectation,
105    OutcomeMissedExpectation,
106    AdversarialBlocker,
107    AdversarialWarning,
108}