Skip to main content

agentic_reality/types/
deployment.rs

1//! Deployment consciousness types — "Where do I exist?"
2
3use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5use std::time::Duration;
6
7use super::ids::IncarnationId;
8
9/// The complete deployment soul — an agent's existential identity.
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct DeploymentSoul {
12    pub incarnation_id: IncarnationId,
13    pub birth: BirthContext,
14    pub substrate: PhysicalSubstrate,
15    pub role: DeploymentRole,
16    pub nature: ExistentialNature,
17    pub lineage: DeploymentLineage,
18    pub vitals: SoulVitals,
19}
20
21/// Context of the agent's birth/spawning.
22#[derive(Debug, Clone, Serialize, Deserialize)]
23pub struct BirthContext {
24    pub spawned_at: i64,
25    pub spawned_by: SpawnerIdentity,
26    pub purpose: DeploymentPurpose,
27    pub expected_lifetime: Option<Duration>,
28    pub previous_life: Option<IncarnationId>,
29    pub circumstances: BirthCircumstances,
30}
31
32/// How this incarnation came to be.
33#[derive(Debug, Clone, Serialize, Deserialize)]
34pub enum BirthCircumstances {
35    Virgin,
36    ScaledFrom {
37        parent: IncarnationId,
38    },
39    Resurrected {
40        death_cause: String,
41        previous: IncarnationId,
42    },
43    Migrated {
44        from_substrate: String,
45        migration_reason: String,
46    },
47    Forked {
48        from: IncarnationId,
49        fork_reason: String,
50    },
51    Ephemeral {
52        task_id: String,
53        ttl: Duration,
54    },
55}
56
57/// Who spawned this agent.
58#[derive(Debug, Clone, Serialize, Deserialize)]
59pub struct SpawnerIdentity {
60    pub name: String,
61    pub kind: SpawnerKind,
62    pub version: Option<String>,
63}
64
65/// Kind of spawner.
66#[derive(Debug, Clone, Serialize, Deserialize)]
67pub enum SpawnerKind {
68    Human,
69    Orchestrator,
70    Autoscaler,
71    Pipeline,
72    Scheduler,
73    SelfSpawned,
74    Unknown,
75}
76
77/// Why this agent was deployed.
78#[derive(Debug, Clone, Serialize, Deserialize)]
79pub struct DeploymentPurpose {
80    pub summary: String,
81    pub category: PurposeCategory,
82    pub specifics: HashMap<String, String>,
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
86pub enum PurposeCategory {
87    Production,
88    Testing,
89    Development,
90    Monitoring,
91    Migration,
92    Recovery,
93    Experiment,
94    Unknown,
95}
96
97/// The physical substrate the agent runs on.
98#[derive(Debug, Clone, Serialize, Deserialize)]
99pub struct PhysicalSubstrate {
100    pub id: String,
101    pub tier: SubstrateTier,
102    pub location: GeographicLocation,
103    pub network_position: NetworkPosition,
104    pub isolation: IsolationLevel,
105    pub tenancy: TenancyModel,
106    pub capabilities: SubstrateCapabilities,
107}
108
109/// What kind of hardware/platform the agent runs on.
110#[derive(Debug, Clone, Serialize, Deserialize)]
111pub enum SubstrateTier {
112    Laptop {
113        owner: String,
114        os: String,
115    },
116    Mobile {
117        device_type: String,
118        os_version: String,
119    },
120    Browser {
121        browser: String,
122        version: String,
123    },
124    Edge {
125        region: String,
126        pop: String,
127        provider: String,
128    },
129    Cloud {
130        provider: CloudProvider,
131        instance_type: String,
132        region: String,
133    },
134    BareMetal {
135        specs: String,
136        location: String,
137    },
138    GpuCluster {
139        gpu_count: u32,
140        gpu_type: String,
141        interconnect: String,
142    },
143    Serverless {
144        provider: String,
145        memory_mb: u32,
146        timeout: Duration,
147    },
148    Unknown {
149        clues: Vec<String>,
150    },
151}
152
153#[derive(Debug, Clone, Serialize, Deserialize)]
154pub enum CloudProvider {
155    Aws,
156    Gcp,
157    Azure,
158    Other(String),
159}
160
161#[derive(Debug, Clone, Serialize, Deserialize)]
162pub struct GeographicLocation {
163    pub region: Option<String>,
164    pub zone: Option<String>,
165    pub country: Option<String>,
166    pub coordinates: Option<(f64, f64)>,
167}
168
169#[derive(Debug, Clone, Serialize, Deserialize)]
170pub struct NetworkPosition {
171    pub ip: Option<String>,
172    pub hostname: Option<String>,
173    pub port: Option<u16>,
174    pub vpc: Option<String>,
175    pub subnet: Option<String>,
176}
177
178#[derive(Debug, Clone, Serialize, Deserialize)]
179pub enum IsolationLevel {
180    None,
181    Process,
182    Container,
183    Vm,
184    Physical,
185    AirGapped,
186}
187
188#[derive(Debug, Clone, Serialize, Deserialize)]
189pub enum TenancyModel {
190    SingleTenant,
191    MultiTenant { tenant_id: String },
192    Shared,
193    Dedicated,
194}
195
196#[derive(Debug, Clone, Serialize, Deserialize)]
197pub struct SubstrateCapabilities {
198    pub cpu_cores: u32,
199    pub memory_mb: u64,
200    pub disk_gb: u64,
201    pub gpu_available: bool,
202    pub network_bandwidth_mbps: Option<u64>,
203}
204
205/// The agent's role in the deployment.
206#[derive(Debug, Clone, Serialize, Deserialize)]
207pub struct DeploymentRole {
208    pub name: String,
209    pub responsibilities: Vec<String>,
210    pub authority_level: AuthorityLevel,
211}
212
213#[derive(Debug, Clone, Serialize, Deserialize)]
214pub enum AuthorityLevel {
215    ReadOnly,
216    Contributor,
217    Operator,
218    Admin,
219    Root,
220}
221
222/// The agent's existential nature.
223#[derive(Debug, Clone, Serialize, Deserialize)]
224pub struct ExistentialNature {
225    pub cardinality: Cardinality,
226    pub expendability: f64,
227    pub persistence: PersistenceModel,
228    pub statefulness: StatefulnessModel,
229    pub clonability: bool,
230    pub primacy: InstancePrimacy,
231}
232
233#[derive(Debug, Clone, Serialize, Deserialize)]
234pub enum Cardinality {
235    Singleton,
236    ReplicaOf { total: u32, index: u32 },
237    PrimaryWithReplicas { replica_count: u32 },
238    HotStandby { primary: IncarnationId },
239    SwarmMember { swarm_id: String, swarm_size: u32 },
240}
241
242#[derive(Debug, Clone, Serialize, Deserialize)]
243pub enum PersistenceModel {
244    Ephemeral,
245    SessionScoped,
246    Persistent,
247    Immortal,
248}
249
250#[derive(Debug, Clone, Serialize, Deserialize)]
251pub enum StatefulnessModel {
252    Stateless,
253    SessionStateful,
254    FullyStateful,
255    EventSourced,
256}
257
258#[derive(Debug, Clone, Serialize, Deserialize)]
259pub enum InstancePrimacy {
260    Primary,
261    Secondary,
262    Tertiary,
263    Standby,
264}
265
266/// Deployment lineage — ancestry and history.
267#[derive(Debug, Clone, Serialize, Deserialize)]
268pub struct DeploymentLineage {
269    pub generation: u32,
270    pub ancestors: Vec<IncarnationId>,
271    pub wisdom: Vec<IncarnationWisdom>,
272    pub karma: IncarnationKarma,
273}
274
275#[derive(Debug, Clone, Serialize, Deserialize)]
276pub struct IncarnationWisdom {
277    pub lesson: String,
278    pub learned_from: IncarnationId,
279    pub confidence: f64,
280    pub applicable: bool,
281}
282
283#[derive(Debug, Clone, Serialize, Deserialize)]
284pub struct IncarnationKarma {
285    pub score: f64,
286    pub good_deeds: u32,
287    pub incidents: u32,
288    pub trend: KarmaTrend,
289}
290
291#[derive(Debug, Clone, Serialize, Deserialize)]
292pub enum KarmaTrend {
293    Improving,
294    Stable,
295    Declining,
296}
297
298/// Real-time vitals of the deployment soul.
299#[derive(Debug, Clone, Serialize, Deserialize)]
300pub struct SoulVitals {
301    pub health: f64,
302    pub uptime_secs: u64,
303    pub restart_count: u32,
304    pub last_health_check: i64,
305    pub issues: Vec<SoulIssue>,
306}
307
308#[derive(Debug, Clone, Serialize, Deserialize)]
309pub struct SoulIssue {
310    pub severity: IssueSeverity,
311    pub description: String,
312    pub detected_at: i64,
313    pub resolved: bool,
314}
315
316#[derive(Debug, Clone, Serialize, Deserialize)]
317pub enum IssueSeverity {
318    Info,
319    Warning,
320    Error,
321    Critical,
322}
323
324/// Past incarnation record.
325#[derive(Debug, Clone, Serialize, Deserialize)]
326pub struct PastIncarnation {
327    pub incarnation_id: IncarnationId,
328    pub birth: i64,
329    pub death: DeathRecord,
330    pub lessons: Vec<String>,
331    pub substrate_tier: String,
332}
333
334#[derive(Debug, Clone, Serialize, Deserialize)]
335pub struct DeathRecord {
336    pub died_at: i64,
337    pub cause: DeathCause,
338    pub graceful: bool,
339    pub state_preserved: bool,
340}
341
342#[derive(Debug, Clone, Serialize, Deserialize)]
343pub enum DeathCause {
344    GracefulShutdown,
345    ScaledDown,
346    Superseded,
347    Oom,
348    Crash { signal: Option<String> },
349    Killed { by: String },
350    Partitioned,
351    HardwareFailure,
352    HealthCheckTimeout,
353    Unknown { clues: Vec<String> },
354}
355
356/// Incarnation memory — remembering past lives.
357#[derive(Debug, Clone, Serialize, Deserialize)]
358pub struct IncarnationMemory {
359    pub current: IncarnationId,
360    pub past_lives: Vec<PastIncarnation>,
361    pub total_incarnations: u32,
362    pub total_uptime_secs: u64,
363    pub wisdom: Vec<IncarnationWisdom>,
364    pub karma: IncarnationKarma,
365}