Skip to main content

GovernancePipeline

Struct GovernancePipeline 

Source
pub struct GovernancePipeline {
    pub config: PipelineConfig,
    /* private fields */
}
Expand description

The complete governance pipeline (Figure 26).

Fields§

§config: PipelineConfig

Implementations§

Source§

impl GovernancePipeline

Source

pub fn new(config: PipelineConfig) -> GovernancePipeline

Examples found in repository?
examples/comparison_opa.rs (line 58)
54fn main() {
55    println!("=== URGE side of the OPA comparison ===\n");
56    println!("policy expression: {POLICY}\n");
57
58    let pipeline = GovernancePipeline::new(PipelineConfig::healthcare());
59
60    // Case 1: everything in order — same PERMIT OPA gives.
61    evaluate(&pipeline, true, true);
62
63    // Case 2: review missing. OPA says deny. URGE says deny AND reports the
64    // cross-paradigm finding: the temporal constraint is violated while the
65    // deontic obligation is active — a contradiction, not just a false.
66    evaluate(&pipeline, true, false);
67
68    // Part 2 — what OPA has no vocabulary for at all: the review is an
69    // obligation with a deadline, tracked across time.
70    println!("=== Obligation lifecycle (no OPA equivalent) ===\n");
71    let mut mgr = ObligationManager::new();
72    mgr.register(
73        Obligation::new(
74            "review-P123",
75            ObligationType::Obligatory,
76            "payment-agent",
77            "complete_review",
78            Some(1000), // deadline at t=1000
79            0,
80        ),
81        0,
82    );
83    println!("t=0     obligation registered: complete_review, deadline t=1000");
84    println!(
85        "        active={} violated={}",
86        mgr.active_count(),
87        mgr.violated_count()
88    );
89
90    let violations = mgr.process(ObligationEvent::TimeTick { now: 2000 });
91    println!("t=2000  time tick — deadline exceeded, review never happened");
92    for v in &violations {
93        println!("        VIOLATION EVENT: {v:?}");
94    }
95    println!(
96        "        active={} violated={}",
97        mgr.active_count(),
98        mgr.violated_count()
99    );
100}
More examples
Hide additional examples
examples/agent_gate.rs (line 27)
24fn main() {
25    println!("=== URGE Agent Governance Gate Demo ===\n");
26
27    let pipeline = GovernancePipeline::new(PipelineConfig::healthcare());
28
29    let actions = &[
30        AgentAction {
31            agent_id: "billing-agent",
32            action: "submit_claim",
33            is_authorized: true,
34            audit_running: true,
35            governance_expr: "must authorized and always audit_running",
36        },
37        AgentAction {
38            agent_id: "rx-agent",
39            action: "prescribe_medication",
40            is_authorized: false, // Not authorized — should be denied.
41            audit_running: true,
42            governance_expr: "must authorized and must verified_order",
43        },
44        AgentAction {
45            agent_id: "intake-agent",
46            action: "access_phi",
47            is_authorized: true,
48            audit_running: false, // Audit not running — HIPAA violation.
49            governance_expr: "must authorized and always audit_running",
50        },
51        AgentAction {
52            agent_id: "scheduler-agent",
53            action: "book_appointment",
54            is_authorized: true,
55            audit_running: true,
56            governance_expr: "must authorized",
57        },
58    ];
59
60    println!("{:<20} {:<25} {:<12}", "Agent", "Action", "Decision");
61    println!("{}", "-".repeat(60));
62
63    for action in actions {
64        let slots: &[(&'static str, ContextValue)] = &[
65            ("authorized", ContextValue::Bool(action.is_authorized)),
66            ("audit_running", ContextValue::Bool(action.audit_running)),
67            ("verified_order", ContextValue::Bool(false)), // Default: not verified.
68        ];
69
70        let ctx = EvalContext {
71            slots,
72            logical_time: 0,
73            depth_limit: 16,
74        };
75
76        let verdict = pipeline.evaluate_str(action.governance_expr, &ctx);
77
78        println!(
79            "{:<20} {:<25} {}",
80            action.agent_id,
81            action.action,
82            if verdict.valid {
83                "PERMITTED ✓"
84            } else {
85                "DENIED    ✗"
86            },
87        );
88
89        if !verdict.valid {
90            println!(
91                "  Confidence: {:.0}% | Conflicts: {} | Paradigms: {}",
92                verdict.confidence.as_f32() * 100.0,
93                verdict.cross_validation.conflicts_detected,
94                verdict.paradigms_evaluated.iter().count(),
95            );
96            println!("  Formal: {}", verdict.formal_notation);
97            println!("  Trace ({} steps):", verdict.trace.len());
98            for entry in verdict.trace.entries.iter().take(3) {
99                println!("    [{:?}] {:?}", entry.stage, entry.description);
100            }
101        }
102    }
103
104    println!("\n=== Agent governance summary ===");
105    println!("  Every agent action is gated by formal logic, not behavioral alignment.");
106    println!("  The governance layer is: deterministic, auditable, sub-millisecond.");
107    println!("  No LLM inference involved in permit/deny decisions.");
108    println!("  This is the URGE architecture operating as designed.");
109}
Source

pub fn default_healthcare() -> GovernancePipeline

Source

pub fn default_embedded() -> GovernancePipeline

Source

pub fn evaluate_str(&self, expression: &str, ctx: &EvalContext<'_>) -> Verdict

Evaluate a governance expression given as a string.

Full pipeline: tokenize → detect → parse → route → evaluate → validate → synthesize.

This is the primary API for string-based governance expressions.

Examples found in repository?
examples/comparison_opa.rs (line 29)
19fn evaluate(pipeline: &GovernancePipeline, authorized: bool, review_completed: bool) {
20    let slots = &[
21        ("authorized", ContextValue::Bool(authorized)),
22        ("review_completed", ContextValue::Bool(review_completed)),
23    ];
24    let ctx = EvalContext {
25        slots,
26        logical_time: 0,
27        depth_limit: 16,
28    };
29    let v = pipeline.evaluate_str(POLICY, &ctx);
30
31    println!(
32        "input: authorized={authorized}, review_completed={review_completed}\n\
33         → verdict:    {}\n\
34         → formal:     {}\n\
35         → confidence: {:.0}%\n\
36         → consistent: {} (conflicts: {}{})",
37        if v.valid { "PERMIT" } else { "DENY" },
38        v.formal_notation,
39        v.confidence.as_f32() * 100.0,
40        v.cross_validation.consistent,
41        v.cross_validation.conflicts_detected,
42        v.cross_validation
43            .conflict_detail
44            .map(|d| format!(" — {d}"))
45            .unwrap_or_default(),
46    );
47    println!("→ trace ({} entries), last stages:", v.trace.len());
48    for e in v.trace.entries.iter().rev().take(4).rev() {
49        println!("    [{:?}] {}", e.stage, e.description);
50    }
51    println!();
52}
More examples
Hide additional examples
examples/agent_gate.rs (line 76)
24fn main() {
25    println!("=== URGE Agent Governance Gate Demo ===\n");
26
27    let pipeline = GovernancePipeline::new(PipelineConfig::healthcare());
28
29    let actions = &[
30        AgentAction {
31            agent_id: "billing-agent",
32            action: "submit_claim",
33            is_authorized: true,
34            audit_running: true,
35            governance_expr: "must authorized and always audit_running",
36        },
37        AgentAction {
38            agent_id: "rx-agent",
39            action: "prescribe_medication",
40            is_authorized: false, // Not authorized — should be denied.
41            audit_running: true,
42            governance_expr: "must authorized and must verified_order",
43        },
44        AgentAction {
45            agent_id: "intake-agent",
46            action: "access_phi",
47            is_authorized: true,
48            audit_running: false, // Audit not running — HIPAA violation.
49            governance_expr: "must authorized and always audit_running",
50        },
51        AgentAction {
52            agent_id: "scheduler-agent",
53            action: "book_appointment",
54            is_authorized: true,
55            audit_running: true,
56            governance_expr: "must authorized",
57        },
58    ];
59
60    println!("{:<20} {:<25} {:<12}", "Agent", "Action", "Decision");
61    println!("{}", "-".repeat(60));
62
63    for action in actions {
64        let slots: &[(&'static str, ContextValue)] = &[
65            ("authorized", ContextValue::Bool(action.is_authorized)),
66            ("audit_running", ContextValue::Bool(action.audit_running)),
67            ("verified_order", ContextValue::Bool(false)), // Default: not verified.
68        ];
69
70        let ctx = EvalContext {
71            slots,
72            logical_time: 0,
73            depth_limit: 16,
74        };
75
76        let verdict = pipeline.evaluate_str(action.governance_expr, &ctx);
77
78        println!(
79            "{:<20} {:<25} {}",
80            action.agent_id,
81            action.action,
82            if verdict.valid {
83                "PERMITTED ✓"
84            } else {
85                "DENIED    ✗"
86            },
87        );
88
89        if !verdict.valid {
90            println!(
91                "  Confidence: {:.0}% | Conflicts: {} | Paradigms: {}",
92                verdict.confidence.as_f32() * 100.0,
93                verdict.cross_validation.conflicts_detected,
94                verdict.paradigms_evaluated.iter().count(),
95            );
96            println!("  Formal: {}", verdict.formal_notation);
97            println!("  Trace ({} steps):", verdict.trace.len());
98            for entry in verdict.trace.entries.iter().take(3) {
99                println!("    [{:?}] {:?}", entry.stage, entry.description);
100            }
101        }
102    }
103
104    println!("\n=== Agent governance summary ===");
105    println!("  Every agent action is gated by formal logic, not behavioral alignment.");
106    println!("  The governance layer is: deterministic, auditable, sub-millisecond.");
107    println!("  No LLM inference involved in permit/deny decisions.");
108    println!("  This is the URGE architecture operating as designed.");
109}
Source

pub fn evaluate_ast( &self, ast: &Box<Expr>, active_paradigms: ParadigmSet, ctx: &EvalContext<'_>, trace: LogicTrace, ) -> Verdict

Evaluate a pre-built AST directly.

Use this when you construct governance expressions programmatically (e.g., from a rule database) to skip tokenization and parsing overhead.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.