Skip to main content

agentic_reality/types/
reality.rs

1//! Reality physics types — "What is real?"
2
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5
6use super::ids::AnchorId;
7
8/// Multiple layers of reality the agent perceives.
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct RealityLayers {
11    pub current_layer: RealityLayer,
12    pub layers: Vec<LayerStatus>,
13    pub consistency: LayerConsistency,
14    pub transitions: Vec<LayerTransition>,
15    pub confidence: f64,
16}
17
18/// A layer of reality.
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub enum RealityLayer {
21    Physical {
22        substrate: String,
23        certainty: f64,
24    },
25    Virtual {
26        virtualization: String,
27        host: Option<String>,
28    },
29    Container {
30        runtime: String,
31        orchestrator: Option<String>,
32    },
33    Sandbox {
34        isolation_type: String,
35        restrictions: Vec<String>,
36    },
37    TestEnvironment {
38        test_type: String,
39        mocked_components: Vec<String>,
40    },
41    Simulation {
42        fidelity: SimulationFidelity,
43        purpose: String,
44        simulated_time: Option<i64>,
45    },
46    Replay {
47        source: String,
48        timestamp: i64,
49    },
50    Preview {
51        what_would_happen: String,
52        commit_possible: bool,
53    },
54    Unknown {
55        clues: Vec<String>,
56    },
57}
58
59#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
60pub enum SimulationFidelity {
61    Perfect,
62    High,
63    Medium,
64    Low,
65    Stub,
66}
67
68#[derive(Debug, Clone, Serialize, Deserialize)]
69pub struct LayerStatus {
70    pub layer: RealityLayer,
71    pub active: bool,
72    pub confidence: f64,
73    pub verified: bool,
74}
75
76#[derive(Debug, Clone, Serialize, Deserialize)]
77pub struct LayerConsistency {
78    pub consistent: bool,
79    pub conflicts: Vec<String>,
80    pub confidence: f64,
81}
82
83#[derive(Debug, Clone, Serialize, Deserialize)]
84pub struct LayerTransition {
85    pub from: String,
86    pub to: String,
87    pub reason: String,
88    pub timestamp: i64,
89}
90
91/// Information freshness perception.
92#[derive(Debug, Clone, Serialize, Deserialize)]
93pub struct FreshnessPerception {
94    pub overall: FreshnessLevel,
95    pub by_source: HashMap<String, SourceFreshness>,
96    pub stalest: Option<StaleData>,
97    pub requirements: Vec<FreshnessRequirement>,
98    pub recommendations: Vec<String>,
99}
100
101#[derive(Debug, Clone, Serialize, Deserialize)]
102pub enum FreshnessLevel {
103    Live { latency_ms: u64 },
104    Fresh { age_secs: u64 },
105    Acceptable { age_secs: u64 },
106    Aging { age_secs: u64, concern: String },
107    Stale { age_secs: u64, usable: bool },
108    Ancient { age_secs: u64, archival: bool },
109    Unknown { last_known: Option<i64> },
110}
111
112#[derive(Debug, Clone, Serialize, Deserialize)]
113pub struct SourceFreshness {
114    pub source: String,
115    pub level: FreshnessLevel,
116    pub last_updated: i64,
117    pub update_frequency_secs: Option<u64>,
118}
119
120#[derive(Debug, Clone, Serialize, Deserialize)]
121pub struct StaleData {
122    pub source: String,
123    pub age_secs: u64,
124    pub impact: StaleImpact,
125    pub recommendation: String,
126}
127
128#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
129pub enum StaleImpact {
130    None,
131    Low,
132    Medium,
133    High,
134    Critical,
135}
136
137#[derive(Debug, Clone, Serialize, Deserialize)]
138pub struct FreshnessRequirement {
139    pub source: String,
140    pub max_age_secs: u64,
141    pub reason: String,
142}
143
144/// Reality anchor — a verifiable ground truth point.
145#[derive(Debug, Clone, Serialize, Deserialize)]
146pub struct RealityAnchor {
147    pub id: AnchorId,
148    pub anchor_type: AnchorType,
149    pub verification: VerificationMethod,
150    pub last_value: AnchorValue,
151    pub trust: f64,
152    pub frequency_secs: u64,
153    pub dependents: Vec<String>,
154}
155
156#[derive(Debug, Clone, Serialize, Deserialize)]
157pub enum AnchorType {
158    Time { source: String },
159    Identity { verifier: String },
160    Configuration { source: String },
161    State { source: String },
162    External { api: String, field: String },
163    Cryptographic { chain: String },
164    Human { verifier: String },
165}
166
167#[derive(Debug, Clone, Serialize, Deserialize)]
168pub enum VerificationMethod {
169    Direct,
170    Api { endpoint: String },
171    Consensus { quorum: u32 },
172    Cryptographic { algorithm: String },
173    Manual,
174}
175
176#[derive(Debug, Clone, Serialize, Deserialize)]
177pub struct AnchorValue {
178    pub value: String,
179    pub verified_at: i64,
180    pub confidence: f64,
181}
182
183/// Drift detected in an anchor.
184#[derive(Debug, Clone, Serialize, Deserialize)]
185pub struct AnchorDrift {
186    pub anchor_id: AnchorId,
187    pub expected: String,
188    pub actual: String,
189    pub drift_magnitude: f64,
190    pub assessment: DriftAssessment,
191    pub detected_at: i64,
192}
193
194#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
195pub enum DriftAssessment {
196    Normal,
197    Concerning,
198    Significant,
199    Critical,
200}
201
202/// Hallucination detection state.
203#[derive(Debug, Clone, Serialize, Deserialize)]
204pub struct HallucinationState {
205    pub risk_level: HallucinationRisk,
206    pub detected: Vec<DetectedHallucination>,
207    pub patterns: Vec<HallucinationPattern>,
208    pub grounding: GroundingStatus,
209    pub pending_verification: Vec<UnverifiedClaim>,
210}
211
212#[derive(Debug, Clone, Serialize, Deserialize)]
213pub enum HallucinationRisk {
214    Low { confidence: f64 },
215    Moderate { concerns: Vec<String> },
216    Elevated { high_risk_claims: Vec<String> },
217    High { indicators: Vec<String> },
218}
219
220#[derive(Debug, Clone, Serialize, Deserialize)]
221pub struct DetectedHallucination {
222    pub id: String,
223    pub hallucination_type: HallucinationType,
224    pub claim: String,
225    pub evidence: String,
226    pub detection_method: DetectionMethod,
227    pub detected_at: i64,
228    pub resolved: bool,
229}
230
231#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
232pub enum HallucinationType {
233    FactualError,
234    TemporalConfusion,
235    ContextBleed,
236    Confabulation,
237    WishfulThinking,
238    PatternOverextension,
239    SourceConfusion,
240}
241
242#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
243pub enum DetectionMethod {
244    AnchorVerification,
245    ConsistencyCheck,
246    ExternalValidation,
247    PatternAnalysis,
248    SelfReport,
249    PeerVerification,
250}
251
252#[derive(Debug, Clone, Serialize, Deserialize)]
253pub struct HallucinationPattern {
254    pub pattern: String,
255    pub frequency: u32,
256    pub trigger: HallucinationTrigger,
257    pub mitigation: String,
258}
259
260#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
261pub enum HallucinationTrigger {
262    StaleData,
263    AnchorDrift,
264    ContextSwitch,
265    HighLoad,
266    InsufficientGrounding,
267    Ambiguity,
268}
269
270#[derive(Debug, Clone, Serialize, Deserialize)]
271pub struct GroundingStatus {
272    pub grounded: bool,
273    pub anchor_count: u32,
274    pub verified_count: u32,
275    pub last_verification: Option<i64>,
276    pub confidence: f64,
277}
278
279#[derive(Debug, Clone, Serialize, Deserialize)]
280pub struct UnverifiedClaim {
281    pub claim: String,
282    pub source: String,
283    pub submitted_at: i64,
284    pub priority: ClaimPriority,
285}
286
287#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
288pub enum ClaimPriority {
289    Low,
290    Medium,
291    High,
292    Critical,
293}