Skip to main content

agentic_contract/
lib.rs

1//! # AgenticContract
2//!
3//! Policy engine for AI agents. Models policies, risk limits,
4//! approvals, conditions, obligations, and violations
5//! in a single `.acon` file.
6
7pub mod approval;
8pub mod condition;
9pub mod contract_engine;
10pub mod contracts;
11pub mod error;
12pub mod file_format;
13pub mod inventions;
14pub mod obligation;
15pub mod policy;
16pub mod risk_limit;
17pub mod violation;
18
19pub use approval::{ApprovalDecision, ApprovalRequest, ApprovalRule, ApprovalStatus, DecisionType};
20pub use condition::{Condition, ConditionStatus, ConditionType};
21pub use contract_engine::ContractEngine;
22pub use error::{ContractError, ContractResult};
23pub use file_format::{ContractFile, EntityType, FileHeader};
24pub use obligation::{Obligation, ObligationStatus};
25pub use policy::{Policy, PolicyAction, PolicyScope, PolicyStatus};
26pub use risk_limit::{LimitType, RiskLimit};
27pub use violation::{Violation, ViolationSeverity};
28
29use serde::{Deserialize, Serialize};
30use uuid::Uuid;
31
32/// Unique identifier for contract entities.
33#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
34pub struct ContractId(pub Uuid);
35
36impl ContractId {
37    /// Generate a new random contract ID.
38    pub fn new() -> Self {
39        Self(Uuid::new_v4())
40    }
41}
42
43impl Default for ContractId {
44    fn default() -> Self {
45        Self::new()
46    }
47}
48
49impl std::fmt::Display for ContractId {
50    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
51        write!(f, "{}", self.0)
52    }
53}
54
55impl std::str::FromStr for ContractId {
56    type Err = uuid::Error;
57
58    fn from_str(s: &str) -> Result<Self, Self::Err> {
59        Ok(Self(Uuid::parse_str(s)?))
60    }
61}