Skip to content

Rust integration

Use the Rust toolchain compatible with the included Cargo.lock and Cargo.toml. Add aiws-sdk as a path dependency pointing to crates/aiws in the source download, or unpack the supplied .crate file and point to that directory. Add serde_json when constructing JSON-backed records. This release is not published to crates.io.

Execute an adapter through the trusted coordinator · Executable local adapter demonstration; fixed demo identity and fixture evidence

import { readFileSync, writeFileSync, mkdtempSync, openSync, writeSync, fsyncSync, closeSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { parseContract, parseCommand, canonical, assessSuccess } from '@aiws/sdk';
import { SqliteStore } from '@aiws/sdk/sqlite';
import { Coordinator, type EffectAdapter } from '@aiws/sdk/runtime';
// A local demonstration. Replace this fixed demo identity with authenticated policy.
const demo = JSON.parse(readFileSync('examples/review.json', 'utf8'));
const directory = mkdtempSync(join(tmpdir(), 'aiws-review-'));
const store = new SqliteStore(join(directory, 'mission.db'), parseContract(canonical(demo.contract)));
const coordinator = new Coordinator(store, async () => ({ allowed: true, policy: 'ALLOW', mandatoryChecksOk: true,context:{actor:"demo:operator",policyRevision:"policy:1",decisionClass:"DETERMINISTIC"} }), () => '10');
const adapter: EffectAdapter = {
async execute(operation) {
const file = openSync(join(directory, 'review.txt'), 'wx');
try { writeSync(file, canonical(operation.action.payload)); fsyncSync(file); } finally { closeSync(file); }
return { effect: 'CONFIRMED_APPLIED', actualCost: '3' };
},
async reconcile(operation) { try {
return readFileSync(join(directory, 'review.txt'), 'utf8') === canonical(operation.action.payload) ? { effect: 'CONFIRMED_APPLIED', actualCost: '3' } : { effect: 'UNKNOWN', actualCost: '0' };
}
catch {
return { effect: 'UNKNOWN', actualCost: '0' };
} }
};
try {
for (const raw of demo.commands) {
const command = parseCommand(canonical(raw));
if (command.type === 'dispatch')
await coordinator.dispatch(command.attemptId, adapter, command.nodeId);
else
await coordinator.apply(command);
}
console.log(JSON.stringify({ directory, ...assessSuccess(store.snapshot(), 'r') }));
writeFileSync(join(directory, 'audit.json'), store.exportAudit());
}
finally {
store.close();
}

The full program uses a local adapter, fixed trusted demo identity and fixture evidence. Replace those three boundaries with real identity, a scoped adapter and measured validation evidence before using this pattern in production. The tab set includes equivalent Rust, TypeScript and Python implementations.

SDK 0.5.1 includes a small protocol-correlation helper that the earlier 0.3.0 packages lack. It records the exact Praxis binding revision and remote identity alongside the AIWS work/run/operation/attempt identity. It does not implement MCP, A2A or AG-UI transport behavior and always validates authoritative: false.

Correlate governed work with a protocol binding · Executable source-only SDK correlation example; no protocol client or authority is created

import assert from 'node:assert/strict';
import {createMission,parseContract,reduce,protocolCorrelation,validateProtocolCorrelation} from '@aiws/sdk';
const contract=parseContract(JSON.stringify({id:'contract:protocol',missionId:'mission:protocol',aiwsEdition:'0.4',profile:'finite-v1',budget:'20',deadline:'1000',criteria:['remote-result-reviewed'],actions:['remote.invoke'],resources:['protocol:mcp'],requiresApproval:false,maxAttempts:'2',maxAuthorizationAgeMs:'100',features:[]}));
let state=createMission(contract);
state=reduce(state,{type:'startRun',runId:'run:1'},'10');
state=reduce(state,{type:'grant',grant:{id:'grant:1',subject:'agent:1',profile:'finite-v1',actions:['remote.invoke'],resources:['protocol:mcp'],notBefore:'0',expiresAt:'1000',limit:'20',canDelegate:false,depth:'0'}},'10');
state=reduce(state,{type:'admit',runId:'run:1',operationId:'operation:1',attemptId:'attempt:1',grantId:'grant:1',subject:'agent:1',action:{capability:'remote.invoke',resource:'protocol:mcp',payload:{tool:'echo'},preconditions:{}},amount:'5',authorizationCheckedAt:'10',policy:'ALLOW',mandatoryChecksOk:true},'10');
const correlation=protocolCorrelation(
{bindingId:'mcp:official-v2',bindingRevision:'1',protocol:'MCP',protocolVersion:'2026-07-28',manifestDigest:'a'.repeat(64),capabilityDigest:'b'.repeat(64)},
{workOrderId:'mission:protocol',runId:'run:1',taskId:null,operationId:'operation:1',attemptId:'attempt:1',remoteIdentityRef:'mcp:praxis-m9-fixture@1.0.0',remoteOperationId:null}
);
assert.equal(correlation.operation.operationId,'operation:1');
assert.equal(correlation.authoritative,false);
assert.equal(state.operations['operation:1'].runId,'run:1');
// The record is portable JSON: read back from the wire, it passes the same closed check unchanged.
const wire=JSON.parse(JSON.stringify(correlation));
assert.deepEqual(validateProtocolCorrelation(wire),correlation);
// A record that claims authority, or carries a key the schema does not define, is refused.
const refused=(e:any)=>e.code==='INVALID_PROTOCOL_CORRELATION';
assert.throws(()=>validateProtocolCorrelation({...wire,authoritative:true}),refused);
assert.throws(()=>validateProtocolCorrelation({...wire,approved:true}),refused);
console.log(JSON.stringify(correlation));
console.log('PASS: protocol-correlation');

In current source, after the 0.4.0 archives, deserializing a ProtocolCorrelation takes an exact key set at every level of the record, and ProtocolCorrelation::from_value checks decoded JSON with the same error codes as TypeScript and Python, in the same order; see the API mapping.

Use official protocol SDKs and the Praxis adapters for wire behavior. Use this helper only for portable correlation in application code, evidence indexes or integration metadata.

Checked record constructors return Result and enforce the shared schema. Contract::parse and Command::parse preserve strict JSON ingress checks; from_value is suitable for already-decoded trusted values. Inspect snapshots with as_value(); do not circumvent the record constructors by manipulating internal state.

The crate contains these public modules:

Module Contents
aiws_sdk Checked records and finite-v1 semantics at the crate root: Contract, Command, Snapshot, reduce, AiwsError and the protocol-correlation records
aiws_sdk::workflow validate_graph, diagnose_graph (with GraphDiagnostic), ready_nodes and due_slots
aiws_sdk::runtime Coordinator and the Authorizer, Clock and EffectAdapter traits
aiws_sdk::sqlite SqliteStore and import_audit
aiws_sdk::observability Correlated records, OTLP/HTTP JSON, metrics and alert evaluation (observability)
aiws_sdk::handoff, aiws_sdk::handoff_records, aiws_sdk::handoff_store The opt-in handoff profile: journal semantics, checked records, and the SQLite journal with owned artifacts (handoffs)
aiws_sdk::limits, aiws_sdk::limits_store Opt-in nested resource accounting and its SQLite ledger (budgets)
aiws_sdk::dynamic_controls, aiws_sdk::dynamic_types The aiws-dynamic-controls/1 client and its generated types (dynamic controls)
aiws_sdk::readiness, aiws_sdk::readiness_types, aiws_sdk::readiness_types_v1 Advisory readiness records, with generated types for the current and the frozen readiness versions (readiness)
aiws_sdk::access_policy, aiws_sdk::access_policy_types The access-policy contract codec and its generated types (access policy)
aiws_sdk::protocol Protocol-correlation records, also re-exported at the crate root

Implement runtime::Authorizer, runtime::Clock and runtime::EffectAdapter in your host, and limits_store::LimitAuthorizer for the nested resource ledger. The coordinator owns a SqliteStore and its mutable methods serialize work through that object. These APIs are synchronous. In an async server, run blocking database and adapter work in a controlled blocking worker rather than on an executor thread that must stay responsive.

Propagate errors with ? until a boundary can inspect AiwsError.code, preserve state and choose a recovery decision. Do not unwrap external input. Dropping a coordinator does not cancel an already-applied external action. A timeout at the host still requires read-back or human intervention for ambiguous outcomes.

The guide examples form an independent Cargo workspace under examples/guide/rust. Use cargo run –manifest-path examples/guide/rust/Cargo.toml –bin coordinator from the repository root. Cargo builds native Rust; no Node or Python process implements these SDK operations.

Use the API mapping to translate native calls without changing camelCase wire keys. Use observability for exporter configuration and recovery for interrupted effects. All examples are included as individual executable source files under examples/guide/.

The crate’s aiws-sdk binary offers aiws-sdk validate FILE for a contract, aiws-sdk graph FILE for a graph, aiws-sdk replay FILE for an audit export, aiws-sdk fixtures FILE for a shared scenario file, and aiws-sdk snapshot FILE and aiws-sdk observe FILE for a SQLite mission database. The source build, not the 0.4.0 archives, also provides aiws-sdk agents sync, which copies the version-matched agent docs pack into .aiws/agent-docs/rust/, gitignored through .aiws/.gitignore, writes the Rust line of the managed AGENTS.md block beside any other languages’ lines, and adds @AGENTS.md to an existing CLAUDE.md, and aiws-sdk agents check, which exits 1 when the copied pack, the block’s Rust line or the synced skills are missing or differ from the installed SDK version. Sync also installs the aiws skills shipped in the crate’s skills/ folder beside its agent-docs/: it copies each aiws-* skill folder into .claude/skills/ and .agents/skills/, writes a .gitignore containing * inside each copied folder, so the copies are never committed and your own skills beside them are untouched, and records the SDK version in the folder’s .aiws-skill.json. When the installed skills are at another version and another language’s synced pack in .aiws/agent-docs/ also differs from this SDK, sync still syncs the Rust pack, leaves the skills unchanged and prints one stderr line naming both versions; aiws-sdk agents check exits 1 until the skills match. The installed skills’ version is read from the stamps of the aiws-* skills present in either folder, so the rule holds when this SDK ships a skill the installed set lacks. Install the binary from your project’s own aiws-sdk dependency, so its version matches the library you build against: cargo install --locked --path <dir>, where <dir> is the dependency’s folder, the path in your Cargo.toml for a source checkout. The installed SDK is that dependency: sync runs cargo metadata on the project’s Cargo.toml and copies the pack and the skills from the agent-docs/ and skills/ folders beside the resolved aiws-sdk package’s manifest, so a dependency upgrade is drift until the next sync; when cargo metadata fails, both commands report FILE_ERROR. A project without a Cargo.toml, or one that does not depend on aiws-sdk, gets the pack of the source the binary was built from. Both commands take an optional project directory; without one they use the working directory or the nearest directory above it that has an AGENTS.md, a .aiws folder or a Cargo.toml depending on aiws-sdk. Sync refuses with FILE_ERROR, before writing anything, when .aiws, its agent-docs folders, .aiws/.gitignore, AGENTS.md, .claude, .agents, their skills folders or a synced skill folder is a symlink or junction, and leaves a linked CLAUDE.md alone. When the project’s pack has drifted, the other commands print one line on stderr, except when CI is set, and keep their exit status. The file commands’ output, error codes and exit statuses match the TypeScript and Python CLIs (command-line tools). In the 0.4.0 archives its usage text omits snapshot and observe, and a usage error exits 1 with the usage inside an error record. Its observe projection uses a fixed test timestamp and is not a live monitoring service. Run observability::operational_summary with a trusted current timestamp in your application instead.