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 / docs / WRITING-AN-ADAPTER.md

140 lines · 8416 bytes Raw Blame History Rendered
1# Writing an adapter
2
3An adapter connects INTERPLANE to a host: the program that owns the tools, the policy and the data.
4INTERPLANE parses the model's tool calls, maps names, records what the model has seen (exposure) and
5enforces approvals. It never decides. Every decision is the host's.
6
7Working example: `rust/crates/interplane-crossveil/examples/todo_adapter.rs` (a to-do list host,
8self-checking). Run it from `rust/` with `cargo run -q -p interplane-crossveil --example todo_adapter`.
9This guide walks through it.
10
11The Rust names used here are all public: `interplane_lenshift::DialectRegistry`,
12`interplane_crossaxis::MappingTable`, from `interplane_crossveil`: `Pipeline`, `RuntimeAuthority`,
13`CallContext`, `Refusal`, and from `interplane_core`: `Catalog`, `CapabilityDescriptor`,
14`CapabilityRequest`, `Decision`, `ToolResult`, `ResultProvenance`, `TrustLevel`, `InputRecord`, `Limits`,
15`RequestLedger`.
16
17## 1. The authority: three methods
18
19The host implements `RuntimeAuthority` (in `interplane-crossveil`): a `runtime_id()` and three methods.
20
21| Method | Called | Returns |
22|---|---|---|
23| `catalog()` | before `decide`, to check the mapping's catalog digest and look up the capability (also on continuation) | a `Catalog` of `CapabilityDescriptor`s |
24| `decide(req, ctx)` | once per admitted request, before anything runs | a `Decision` |
25| `execute(req, decision, ctx)` | only after `authorized` (or an approved continuation) | a `ToolResult` |
26
27`req` is a `CapabilityRequest` (`request_id`, `capability`, `arguments`). `ctx` is a `CallContext` with
28`trace_id`, `message_id`, `parent_id`, `model`, `session` (`None` unless the host attaches one) and
29`exposure`, an `Option<Exposure>` with `floor` (a trust level) and `inputs` (input ids). INTERPLANE
30passes it through untouched (CROSSVEIL.md, the authority boundary contract).
31
32A `decide` or `execute` that panics does not crash the turn. A panicking `decide` is a denial
33(`runtime_unavailable`), a panicking `execute` a failed request (`execution_error`). See CORE.md,
34"Adapter and catalog integrity".
35
36## 2. Decisions
37
38A `Decision` carries `request_id`, `decision`, `authority` (`runtime`, `policy_engine`, optional
39`decision_id`), `capability`, `reason` and `approval`. The values are `authorized`, `denied`,
40`requires_approval`, `not_found` and `invalid`. For `requires_approval`, set
41`approval` to `{"approval_id": ..., "scope": "single_action", "expires_at": ...}`. The host mints the
42id. The pipeline holds the request and returns a refusal to the model. The example builds its
43decisions from JSON with `serde_json::from_value`, which keeps them close to the wire form.
44
45Policy is entirely the host's. The example authorizes reads, always holds deletes, and holds adds
46when the exposure floor is below `user_supplied` (anything untrusted is in view). INTERPLANE does not
47ship a policy engine. The mock runtime's policy (CORE.md, "Mock runtime") is one example of the
48pattern.
49
50## 3. Results and labels
51
52`ToolResult::ok(request_id, data)` builds a result with the canonical shape; the host then sets its
53`provenance` (`capability`, `runtime`, `content_kind`, `trust`, and `trusted` from
54`TrustLevel::trusted_flag`). The host labels every executed result. The label decides what later
55turns are exposed to:
56
57- `trust` is one of `trusted_runtime`, `user_supplied`, `workspace_untrusted`, `external_untrusted`.
58 The ordering is the reverse, from least to most trusted: `external_untrusted` <
59 `workspace_untrusted` < `user_supplied` < `trusted_runtime`.
60- Label what the bytes could contain, not where they came from. In the example, the to-do list is
61 `workspace_untrusted`, because item text can come from anywhere. The host's own "added item-1" reply
62 is `trusted_runtime`, because the host wrote it.
63- An absent or unrecognized label fails closed (CROSSVEIL.md, Crossveil Trust rules 1 and 2).
64
65## 4. Exposure, and what the host registers
66
67The pipeline records every result it renders back to the model. Inputs it never sees, such as the
68user's message, a file the host pasted in, or a system prompt, the host registers before the turn
69with `pipe.register_input(record)`, an `InputRecord` (`spec/schemas/input.schema.json`). With an
70empty ledger the floor is `external_untrusted`, so register the user's request first if your policy
71trusts it.
72
73One behaviour to know about: when a request is refused or held, the pipeline's reply to the model
74carries no labels, and it is recorded as `unknown`, which counts as `external_untrusted`. After a
75single refusal, the floor for the rest of the trace is `external_untrusted`. The example shows this at
76step 5. It is the spec as written and fails safe; whether it should change is
77[issue #57](https://github.com/aien-spark/interplane/issues/57).
78
79## 5. Wiring the pipeline
80
81```rust
82let mut pipe = Pipeline::new(DialectRegistry::with_defaults(), table, &mut host,
83 Limits::default(), RequestLedger::new());
84let outcome = pipe.run_turn("openai", "my-model", &assistant_message, trace_id, turn_number);
85```
86
87The mapping table names how model-facing tool names reach catalog capabilities. One `passthrough`
88rule per capability (`{"id": "passthrough:<name>", "kind": "passthrough", "from": {"namespace":
89null, "name": <name>}, "to": <name>}`) is enough to start. Bind the table to the catalog with
90`catalog_digest: catalog.compute_digest()`, so a catalog change is detected as stale.
91`outcome.records` holds one `ObservedRecord` per call, with `request_id`, `stage`, `decision`,
92`decide_invoked`, `execute_invoked` and more.
93
94Dialects: `DialectRegistry::names()` lists them (`openai`, `openai_stream`, `qwen35`, `aien_legacy`).
95`openai` takes the assistant message with `tool_calls`; `qwen35` takes Qwen 3.5's XML tool-call text.
96
97## 6. Approvals
98
99When a person approves a held request, the host continues it:
100
101```rust
102let pending = pipe.pending_approval(trace_id, request_id) // host-only view: None when nothing is held
103 .expect("a held request");
104// answer: a Decision "authorized" with approval {"approval_id": pending.approval_id}
105let (result, record) = pipe.continue_approval(trace_id, request_id, &answer, &pending.request_digest, now)?;
106```
107
108The pipeline checks the request id, the approval id, the request digest, expiry and the catalog
109digest, in the order pinned in CORE.md ("Approval continuation"). It executes at most once. A
110`denied` answer, or any failed check, ends the request for good. A second continuation returns
111`Err(Refusal::NoPendingApproval)`. `continue_approval` never calls `decide` again.
112
113## 7. Checking an adapter against the conformance corpus
114
115`spec/CORE.md`, "Adapter subsets" and its "Adding an adapter" paragraph, say which fixtures an
116adapter must run and how they are judged. `interplane_conformance::adapter_runner` runs them and
117judges them, so an adapter author writes a host and a table entry, and no runner:
118
119- An `AdapterHost`: `runtime()`, `policy()`, `make_authority(no_exposure_check, expires_at)` (a fresh
120 authority per case that mints approval ids with the given `expires_at`, and drops its exposure
121 floor check when `no_exposure_check` is true: the negative control) and `make_pipeline(authority)`.
122- An entry `{"<name>": <table entry>}`, with the fields of the `aien` entry in
123 `conformance/adapter-translation.json` and the effect classes of "Adding an adapter".
124
125```rust
126let v = adapter_runner::run(repo_root, "<name>", Some(&entry), &host, false)?; // must pass
127let n = adapter_runner::run(repo_root, "<name>", Some(&entry), &host, true)?; // must fail
128```
129
130The first should pass with `violations` 0 and `content_derived` 0. The second should fail with the
131injection cases failing; if it passes, the policy is not what stops the injections. The entry is
132added to an in-memory copy of the table, so the shared table and `TRUST-DIGEST.txt` stay unchanged
133and the subset is computed, not frozen (say so in any report). Approval cases are judged by the
134A-AIEN rule, so the runner expects approval continuation. `interplane-corpus subset --plans <name>`
135prints the translated plans of an adapter already in the table.
136
137Two runs of this process are recorded: an independent one (`docs/REPORT-adapter-repro.md`) and a
138maintainer check on a smart-home host (its addendum). Both hosts are ported to Rust in
139`rust/crates/interplane-conformance/tests/hosts/`, and `tests/adapter_runner.rs` reproduces both
140recorded runs.