aien-protocols-mv
Canonical specifications, wire protocols, and schemas for the AIEN sovereign ecosystem
Brought by drakestapleton
GitHub aien-dev/aien-protocols-mv#1 (code only)
Apply it
git checkout -b patch-44af25f8dffe0acc ada80cc7b0f99a1f1333c1cbb2787245144e0dd9 curl -fsSL https://interplane.io/drakestapleton/aien-protocols-mv/patches/44af25f8dffe0acc.patch | git am
Provenance
github-import 1
aien-dev/aien-protocols-mv
1
91b5d602f181384ec2ffd93492d5a7d4572f3a87
{"kind":"github-import","owner":"aien-dev","repo":"aien-protocols-mv","number":1,"url":"https://github.com/aien-dev/aien-protocols-mv/pull/1","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:39:42Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..5897986 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,622 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "aien-action-protocol" +version = "0.1.0" +dependencies = [ + "aien-protocol-types", + "serde", + "serde_json", + "thiserror", + "uuid", +] + +[[package]] +name = "aien-agent-state-abi" +version = "0.1.0" +dependencies = [ + "aien-action-protocol", + "aien-evaluation-protocol", + "aien-inference-client", + "aien-inference-protocol", + "aien-protocol-types", + "aien-provenance", + "serde", + "serde_json", + "thiserror", + "tokio", + "uuid", +] + +[[package]] +name = "aien-evaluation-protocol" +version = "0.1.0" +dependencies = [ + "aien-protocol-types", + "aien-provenance", + "async-trait", + "serde", + "serde_json", + "thiserror", + "uuid", +] + +[[package]] +name = "aien-event-protocol" +version = "0.1.0" +dependencies = [ + "aien-protocol-types", + "serde", + "serde_json", + "thiserror", + "uuid", +] + +[[package]] +name = "aien-inference-client" +version = "0.1.0" +dependencies = [ + "aien-inference-protocol", + "aien-protocol-types", + "async-trait", + "thiserror", +] + +[[package]] +name = "aien-inference-protocol" +version = "0.1.0" +dependencies = [ + "aien-protocol-types", + "aien-provenance", + "async-trait", + "serde", + "serde_json", + "thiserror", + "uuid", +] + +[[package]] +name = "aien-protocol-types" +version = "0.1.0" +dependencies = [ + "hex", + "serde", + "serde_json", + "thiserror", + "uuid", +] + +[[package]] +name = "aien-provenance" +version = "0.1.0" +dependencies = [ + "aien-protocol-types", + "hex", + "serde", + "serde_json", + "sha2", + "thiserror", +] + +[[package]] +name = "async-trait" +version = "0.1.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82f6aeea286b8eb4dd3431a1be1b59d290ace00f5bfd8e2a159bc2a05e2c1667" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "bitflags" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "bumpalo" +version = "3.20.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" + +[[package]] +name = "bytes" +version = "1.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc652a48c352aef3ea3aed32080501cf3ef6ed5da78602a020c991775b0aff04" + +[[package]] +name = "cfg-if" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-core", + "futures-task", + "pin-project-lite", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "libc", + "r-efi", +] + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + +[[package]] +name = "js-sys" +version = "0.3.105" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce57d20d1ea864ce2ac172ab472d409214f4fd359f0b2a2775abdf522e2af99e" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + +[[package]] +name = "libc" +version = "0.2.189" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "mio" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b18443e9c262bfe8fa82f51666e2642c53393f7e5c27b3e1aeab922cff5b9d8" +dependencies = [ + "libc", + "wasi", + "windows-sys", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "serde_json" +version = "1.0.151" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c841b55ecdae098c80dcae9cf767f6f8a0c2cdb3416bbef72181df4d0fe73f14" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures", + "digest", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba467056f1b547ed52077911161fc86985becbc60e8e1857c8a144dab0def891" + +[[package]] +name = "socket2" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8593e8e72159ed2257d083c7a454a85cbf854f37a0966d8d483aff8c8a3ebcee" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "tokio" +version = "1.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed" +dependencies = [ + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys", +] + +[[package]] +name = "tokio-macros" +version = "2.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78773a2a397f451582ce068015985c33193cf6dea8b74d2a639fe457b2f07b0e" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.6", +] + +[[package]] +name = "typenum" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" + +[[package]] +name = "unicode-ident" +version = "1.0.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d245f478577f809a851594d02313b640fb437e0bb33866753cff937863096954" + +[[package]] +name = "uuid" +version = "1.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ef6dac1e96601b4fb3acccccff2139741fcb757cb9a36089bf5be91cfb285ce" +dependencies = [ + "getrandom", + "js-sys", + "serde_core", + "wasm-bindgen", +] + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasm-bindgen" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aecb87a33d3b0c5e3b7aa46336eaf486cffafbd281b195e4c8b80d50df2351bf" +dependencies = [ + "cfg-if", + "once_cell", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a690d511e3c1a8b3a55e33511e3c2c00c78415cd23650f32b808627f5696b9ed" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "411e4887f0071ef2d2164a9d5fdf2d20efbef78fccd3a78b0c10a1dc5295e48a" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 3.0.6", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.128" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81941cd78d0c92026c33e5e01312845a4cb1e9af3407f9134b100dd03144103e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/crates/aien-action-protocol/Cargo.toml b/crates/aien-action-protocol/Cargo.toml new file mode 100644 index 0000000..e8a2dd8 --- /dev/null +++ b/crates/aien-action-protocol/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "aien-action-protocol" +version = "0.1.0" +edition = "2021" +license = "Apache-2.0" +description = "Action execution, capability grants, and confinement authorization protocol" + +[dependencies] +aien-protocol-types = { path = "../aien-protocol-types" } +serde = { workspace = true } +serde_json = { workspace = true } +uuid = { workspace = true } +thiserror = { workspace = true } diff --git a/crates/aien-action-protocol/src/lib.rs b/crates/aien-action-protocol/src/lib.rs new file mode 100644 index 0000000..538edd4 --- /dev/null +++ b/crates/aien-action-protocol/src/lib.rs @@ -0,0 +1,59 @@ +use aien_protocol_types::{ActionId, AgentId, Digest32, RunId, Timestamp}; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct CapabilityGrant { + pub capability: String, + pub scope: String, + pub granted_at: Timestamp, + pub expires_at: Option<Timestamp>, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct ContainmentState { + pub isolated_network: bool, + pub read_only_fs: bool, + pub seccomp_profile: String, + pub allowed_subprocesses: Vec<String>, +} + +impl Default for ContainmentState { + fn default() -> Self { + Self { + isolated_network: true, + read_only_fs: true, + seccomp_profile: "strict".to_string(), + allowed_subprocesses: Vec::new(), + } + } +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct ActionRequest { + pub action_id: ActionId, + pub run_id: RunId, + pub agent_id: AgentId, + pub capability: String, + pub parameters: serde_json::Value, + pub timestamp: Timestamp, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct ActionAuthorization { + pub authorization_id: uuid::Uuid, + pub action_id: ActionId, + pub approved_by: String, + pub granted_capabilities: Vec<CapabilityGrant>, + pub timestamp: Timestamp, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct ActionReceipt { + pub receipt_id: uuid::Uuid, + pub action_id: ActionId, + pub success: bool, + pub output: serde_json::Value, + pub error: Option<String>, + pub execution_digest: Digest32, + pub completed_at: Timestamp, +} diff --git a/crates/aien-agent-state-abi/Cargo.toml b/crates/aien-agent-state-abi/Cargo.toml new file mode 100644 index 0000000..95dfb59 --- /dev/null +++ b/crates/aien-agent-state-abi/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "aien-agent-state-abi" +version = "0.1.0" +edition = "2021" +license = "Apache-2.0" +description = "Canonical Agent State ABI: snapshot, transition events, and lineage verification" + +[dependencies] +aien-protocol-types = { path = "../aien-protocol-types" } +aien-inference-protocol = { path = "../aien-inference-protocol" } +aien-action-protocol = { path = "../aien-action-protocol" } +aien-provenance = { path = "../aien-provenance" } +serde = { workspace = true } +serde_json = { workspace = true } +uuid = { workspace = true } +thiserror = { workspace = true } + +[dev-dependencies] +tokio = { workspace = true } +aien-evaluation-protocol = { path = "../aien-evaluation-protocol" } +aien-inference-client = { path = "../aien-inference-client" } diff --git a/crates/aien-agent-state-abi/src/lib.rs b/crates/aien-agent-state-abi/src/lib.rs new file mode 100644 index 0000000..f22e446 --- /dev/null +++ b/crates/aien-agent-state-abi/src/lib.rs @@ -0,0 +1,212 @@ +use aien_action_protocol::{CapabilityGrant, ContainmentState}; +use aien_inference_protocol::InferenceContextRef; +use aien_protocol_types::{ + ActionId, AgentId, ApprovalId, ArtifactRef, Digest32, EventId, ProtocolVersion, RunId, + SequenceNumber, SessionId, Timestamp, +}; +use aien_provenance::compute_canonical_json_digest; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct AgentIdentity { + pub agent_id: AgentId, + pub name: String, + pub model_profile: String, + pub created_at: Timestamp, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct SessionState { + pub session_id: SessionId, + pub title: String, + pub created_at: Timestamp, + pub closed_at: Option<Timestamp>, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct Objective { + pub objective_id: uuid::Uuid, + pub description: String, + pub success_criteria: Vec<String>, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct MessageRef { + pub message_id: uuid::Uuid, + pub role: String, + pub digest: Digest32, + pub token_count: u32, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct MemoryRef { + pub memory_id: uuid::Uuid, + pub space: String, + pub canonical_name: String, + pub digest: Digest32, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct ContextState { + pub conversation: Vec<MessageRef>, + pub pinned: Vec<ArtifactRef>, + pub summaries: Vec<ArtifactRef>, + pub cortex: Vec<MemoryRef>, + pub inference: Option<InferenceContextRef>, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct AuthorityState { + pub principal: uuid::Uuid, + pub policy_profile: String, + pub capabilities: Vec<CapabilityGrant>, + pub restrictions: Vec<String>, + pub containment: ContainmentState, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct ResourceBudget { + pub max_tokens: Option<u64>, + pub max_cost_micro_usd: Option<u64>, + pub max_duration_seconds: Option<u64>, + pub max_subagents: Option<u32>, +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub enum AgentExecutionStatus { + Idle, + Running, + Suspended, + AwaitingApproval, + Terminated, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct ExecutionState { + pub active_run: Option<RunId>, + pub status: AgentExecutionStatus, + pub pending_actions: Vec<ActionId>, + pub pending_approvals: Vec<ApprovalId>, + pub last_event: Option<EventId>, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct StateRef { + pub state_id: uuid::Uuid, + pub digest: Digest32, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct AgentState { + pub abi_version: ProtocolVersion, + pub agent: AgentIdentity, + pub session: SessionState, + pub objective: Option<Objective>, + pub context: ContextState, + pub authority: AuthorityState, + pub budget: ResourceBudget, + pub execution: ExecutionState, + pub parent: Option<StateRef>, + pub sequence: SequenceNumber, +} + +impl AgentState { + pub fn compute_digest(&self) -> Result<Digest32, serde_json::Error> { + compute_canonical_json_digest(self) + } +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub enum AgentEvent { + SessionCreated, + MessageAdded(MessageRef), + RunStarted(RunId), + InferenceRequested(uuid::Uuid), + InferenceCompleted(uuid::Uuid), + ActionRequested(ActionId), + ActionAuthorized(ActionId), + ActionDenied(ActionId), + ActionCompleted(ActionId), + ApprovalRequested(ApprovalId), + ApprovalResolved(ApprovalId), + ContextBranched(uuid::Uuid), + BudgetUpdated(ResourceBudget), + ContainmentChanged(ContainmentState), + RunSuspended, + RunResumed, + RunCompleted(String), + SessionClosed, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct AgentStateEvent { + pub abi_version: ProtocolVersion, + pub event_id: EventId, + pub agent_id: AgentId, + pub session_id: SessionId, + pub run_id: Option<RunId>, + pub sequence: SequenceNumber, + pub timestamp: Timestamp, + pub previous_state: Digest32, + pub event: AgentEvent, + pub resulting_state: Digest32, +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_agent_state_digest_deterministic() { + let state = AgentState { + abi_version: ProtocolVersion::new(1, 0), + agent: AgentIdentity { + agent_id: AgentId::new_v4(), + name: "Atlas".to_string(), + model_profile: "GB10-MAX-Qwen".to_string(), + created_at: Timestamp::from_micros(1000), + }, + session: SessionState { + session_id: SessionId::new_v4(), + title: "Test Session".to_string(), + created_at: Timestamp::from_micros(1000), + closed_at: None, + }, + objective: None, + context: ContextState { + conversation: Vec::new(), + pinned: Vec::new(), + summaries: Vec::new(), + cortex: Vec::new(), + inference: None, + }, + authority: AuthorityState { + principal: uuid::Uuid::new_v4(), + policy_profile: "autonomous-safe".to_string(), + capabilities: Vec::new(), + restrictions: Vec::new(), + containment: ContainmentState::default(), + }, + budget: ResourceBudget { + max_tokens: Some(4096), + max_cost_micro_usd: None, + max_duration_seconds: Some(60), + max_subagents: Some(4), + }, + execution: ExecutionState { + active_run: None, + status: AgentExecutionStatus::Idle, + pending_actions: Vec::new(), + pending_approvals: Vec::new(), + last_event: None, + }, + parent: None, + sequence: SequenceNumber(1), + }; + + let digest1 = state.compute_digest().unwrap(); + let digest2 = state.compute_digest().unwrap(); + assert_eq!(digest1, digest2); + assert_ne!(digest1, Digest32::ZERO); + } +} diff --git a/crates/aien-agent-state-abi/tests/integration_tests.rs b/crates/aien-agent-state-abi/tests/integration_tests.rs new file mode 100644 index 0000000..fe6c970 --- /dev/null +++ b/crates/aien-agent-state-abi/tests/integration_tests.rs @@ -0,0 +1,155 @@ +use aien_action_protocol::{CapabilityGrant, ContainmentState}; +use aien_agent_state_abi::*; +use aien_inference_client::MockInferenceClient; +use aien_inference_protocol::*; +use aien_protocol_types::*; +use aien_provenance::compute_sha256; + +#[test] +fn test_agent_state_roundtrip_and_lineage_verification() { + let agent_id = AgentId::new_v4(); + let session_id = SessionId::new_v4(); + let initial_timestamp = Timestamp::from_micros(1700000000); + + let initial_state = AgentState { + abi_version: ProtocolVersion::new(1, 0), + agent: AgentIdentity { + agent_id, + name: "Atlas-Sovereign".to_string(), + model_profile: "GB10-Grace-Blackwell".to_string(), + created_at: initial_timestamp, + }, + session: SessionState { + session_id, + title: "Autonomous Agent State ABI Verification".to_string(), + created_at: initial_timestamp, + closed_at: None, + }, + objective: Some(Objective { + objective_id: uuid::Uuid::new_v4(), + description: "Verify agent state ABI transitions".to_string(), + success_criteria: vec!["Deterministic state hash".to_string(), "Zero unslop".to_string()], + }), + context: ContextState { + conversation: Vec::new(), + pinned: Vec::new(), + summaries: Vec::new(), + cortex: Vec::new(), + inference: None, + }, + authority: AuthorityState { + principal: uuid::Uuid::new_v4(), + policy_profile: "autonomous-strict".to_string(), + capabilities: vec![CapabilityGrant { + capability: "shell.execute".to_string(), + scope: "sandbox:/tmp".to_string(), + granted_at: initial_timestamp, + expires_at: None, + }], + restrictions: vec!["zero_network_leak".to_string()], + containment: ContainmentState::default(), + }, + budget: ResourceBudget { + max_tokens: Some(8192), + max_cost_micro_usd: None, + max_duration_seconds: Some(120), + max_subagents: Some(16), + }, + execution: ExecutionState { + active_run: None, + status: AgentExecutionStatus::Idle, + pending_actions: Vec::new(), + pending_approvals: Vec::new(), + last_event: None, + }, + parent: None, + sequence: SequenceNumber(1), + }; + + let initial_digest = initial_state.compute_digest().expect("Failed to compute initial digest"); + assert_ne!(initial_digest, Digest32::ZERO); + + // Transition 1: RunStarted + let run_id = RunId::new_v4(); + let event1 = AgentStateEvent { + abi_version: ProtocolVersion::new(1, 0), + event_id: EventId::new_v4(), + agent_id, + session_id, + run_id: Some(run_id), + sequence: SequenceNumber(2), + timestamp: Timestamp::from_micros(1700000050), + previous_state: initial_digest, + event: AgentEvent::RunStarted(run_id), + resulting_state: Digest32::ZERO, // updated below + }; + + let mut state_after_run = initial_state.clone(); + state_after_run.sequence = SequenceNumber(2); + state_after_run.execution.active_run = Some(run_id); + state_after_run.execution.status = AgentExecutionStatus::Running; + state_after_run.execution.last_event = Some(event1.event_id); + let digest_after_run = state_after_run.compute_digest().unwrap(); + assert_ne!(initial_digest, digest_after_run); + + // Verify state can be serialized to and from JSON + let json_str = serde_json::to_string_pretty(&state_after_run).unwrap(); + let deserialized: AgentState = serde_json::from_str(&json_str).unwrap(); + assert_eq!(state_after_run, deserialized); + assert_eq!(deserialized.compute_digest().unwrap(), digest_after_run); +} + +#[tokio::test] +async fn test_inference_client_cow_branching_contract() { + let client = MockInferenceClient::new(); + let parent_context = InferenceContextRef { + abi_version: 1, + context_id: ContextId::new_v4(), + branch_id: BranchId::new_v4(), + generation: Generation(1), + model: ModelFingerprint { + weights_digest: compute_sha256(b"tinyllama-1.1b-bf16"), + model_config_digest: compute_sha256(b"config-v1"), + }, + tokenizer: TokenizerFingerprint { + tokenizer_digest: compute_sha256(b"tokenizer-v1"), + }, + kv_format: KvFormatFingerprint { + format_version: 1, + dtype: "BF16".to_string(), + }, + logical_state_digest: compute_sha256(b"logical-tokens-root"), + token_count: 128, + lineage: ContextLineage { + parent_context: None, + parent_branch: None, + parent_digest: None, + fork_token_index: None, + }, + isolation: CacheIsolationKey { + domain_id: uuid::Uuid::new_v4(), + domain_digest: compute_sha256(b"tenant-sovereign"), + }, + binding: None, + recovery: ContextRecipeRef { + recipe_id: uuid::Uuid::new_v4(), + recipe_digest: compute_sha256(b"recipe-data"), + }, + }; + + let child_branch_id = BranchId::new_v4(); + let branch_req = BranchContextRequest { + operation_id: uuid::Uuid::new_v4(), + parent_context: parent_context.clone(), + child_branch_id, + isolation: parent_context.isolation, + }; + + let receipt = client.branch_context(branch_req).await.expect("Failed to branch context"); + assert_eq!(receipt.child_context.branch_id, child_branch_id); + assert_eq!(receipt.child_context.generation, Generation(2)); + assert_eq!(receipt.child_context.lineage.parent_context, Some(parent_context.context_id)); + assert_eq!(receipt.child_context.lineage.parent_branch, Some(parent_context.branch_id)); + assert_eq!(receipt.shared_pages, 10); + assert_eq!(receipt.copied_pages, 0); +} diff --git a/crates/aien-evaluation-protocol/Cargo.toml b/crates/aien-evaluation-protocol/Cargo.toml new file mode 100644 index 0000000..db58dfc --- /dev/null +++ b/crates/aien-evaluation-protocol/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "aien-evaluation-protocol" +version = "0.1.0" +edition = "2021" +license = "Apache-2.0" +description = "Unified Evaluator Protocol, verifier attestations, and immutable evaluation receipts" + +[dependencies] +aien-protocol-types = { path = "../aien-protocol-types" } +aien-provenance = { path = "../aien-provenance" } +serde = { workspace = true } +serde_json = { workspace = true } +uuid = { workspace = true } +async-trait = { workspace = true } +thiserror = { workspace = true } diff --git a/crates/aien-evaluation-protocol/src/lib.rs b/crates/aien-evaluation-protocol/src/lib.rs new file mode 100644 index 0000000..02c8eb6 --- /dev/null +++ b/crates/aien-evaluation-protocol/src/lib.rs @@ -0,0 +1,134 @@ +use aien_protocol_types::{ArtifactRef, Digest32, EvaluationId, Timestamp}; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct EvaluationClaim { + pub claim_type: String, + pub statement: String, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct EvaluationRequest { + pub protocol_version: u32, + pub request_id: EvaluationId, + pub proposer: String, + pub subject: ArtifactRef, + pub parent: Option<ArtifactRef>, + pub profile: String, + pub claims: Vec<EvaluationClaim>, + pub nonce: [u8; 32], +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct EvaluatorDescriptor { + pub evaluator_id: String, + pub version: String, + pub required: bool, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct EvaluationPlan { + pub evaluation_id: EvaluationId, + pub subject: ArtifactRef, + pub profile: String, + pub evaluators: Vec<EvaluatorDescriptor>, + pub baseline: Option<ArtifactRef>, + pub sandbox_profile: String, + pub policy_digest: Digest32, + pub evaluator_manifest_digest: Digest32, + pub plan_digest: Digest32, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct EvaluatorIdentity { + pub evaluator_id: String, + pub version: String, + pub binary_digest: Digest32, + pub config_digest: Digest32, +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub enum EvaluatorStatus { + Passed, + Failed, + Inconclusive, + TimedOut, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct Finding { + pub severity: String, + pub rule_id: String, + pub message: String, + pub location: Option<String>, +} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct Measurement { + pub metric: String, + pub value: f64, + pub unit: String, +} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct EvaluatorOutcome { + pub evaluator: EvaluatorIdentity, + pub status: EvaluatorStatus, + pub findings: Vec<Finding>, + pub measurements: Vec<Measurement>, + pub evidence: Vec<ArtifactRef>, + pub execution_digest: Digest32, +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub enum Verdict { + Pass, + Fail, + Indeterminate, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct VerifierIdentity { + pub principal_id: String, + pub key_id: String, + pub trust_epoch: u64, + pub trusted_build_digest: Digest32, + pub policy_bundle_digest: Digest32, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct EvaluationReceipt { + pub protocol_version: u32, + pub evaluation_id: EvaluationId, + pub request_digest: Digest32, + pub subject_digest: Digest32, + pub plan_digest: Digest32, + pub evidence_root: Digest32, + pub outcomes_root: Digest32, + pub verdict: Verdict, + pub verifier: VerifierIdentity, + pub started_at: Timestamp, + pub completed_at: Timestamp, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct SignedEvaluationReceipt { + pub receipt: EvaluationReceipt, + pub signature: Vec<u8>, +} + +#[derive(thiserror::Error, Debug)] +pub enum EvaluationError { + #[error("Evaluator execution failed: {0}")] + ExecutionFailed(String), + #[error("Plan digest mismatch")] + PlanDigestMismatch, + #[error("Verifier verification error: {0}")] + VerificationFailed(String), +} + +#[async_trait::async_trait] +pub trait Evaluator: Send + Sync { + fn descriptor(&self) -> EvaluatorDescriptor; + async fn evaluate(&self, plan: &EvaluationPlan, subject: &ArtifactRef) -> Result<EvaluatorOutcome, EvaluationError>; +} diff --git a/crates/aien-event-protocol/Cargo.toml b/crates/aien-event-protocol/Cargo.toml new file mode 100644 index 0000000..1c5b92b --- /dev/null +++ b/crates/aien-event-protocol/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "aien-event-protocol" +version = "0.1.0" +edition = "2021" +license = "Apache-2.0" +description = "Canonical event envelopes and streaming telemetry contracts" + +[dependencies] +aien-protocol-types = { path = "../aien-protocol-types" } +serde = { workspace = true } +serde_json = { workspace = true } +uuid = { workspace = true } +thiserror = { workspace = true } diff --git a/crates/aien-event-protocol/src/lib.rs b/crates/aien-event-protocol/src/lib.rs new file mode 100644 index 0000000..37c3281 --- /dev/null +++ b/crates/aien-event-protocol/src/lib.rs @@ -0,0 +1,13 @@ +use aien_protocol_types::{Digest32, EventId, SequenceNumber, Timestamp}; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct EventEnvelope { + pub event_id: EventId, + pub topic: String, + pub producer: String, + pub sequence: SequenceNumber, + pub timestamp: Timestamp, + pub payload_digest: Digest32, + pub payload: serde_json::Value, +} diff --git a/crates/aien-inference-client/Cargo.toml b/crates/aien-inference-client/Cargo.toml new file mode 100644 index 0000000..8c328cd --- /dev/null +++ b/crates/aien-inference-client/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "aien-inference-client" +version = "0.1.0" +edition = "2021" +license = "Apache-2.0" +description = "Reusable inference client implementations for the AIEN Inference Protocol" + +[dependencies] +aien-protocol-types = { path = "../aien-protocol-types" } +aien-inference-protocol = { path = "../aien-inference-protocol" } +async-trait = { workspace = true } +thiserror = { workspace = true } diff --git a/crates/aien-inference-client/src/lib.rs b/crates/aien-inference-client/src/lib.rs new file mode 100644 index 0000000..fd00249 --- /dev/null +++ b/crates/aien-inference-client/src/lib.rs @@ -0,0 +1,65 @@ +use aien_inference_protocol::*; +use aien_protocol_types::ProtocolVersion; +use async_trait::async_trait; +use std::sync::Arc; + +pub struct MockInferenceClient { + capabilities: InferenceCapabilities, +} + +impl MockInferenceClient { + pub fn new() -> Self { + Self { + capabilities: InferenceCapabilities { + protocol: ProtocolVersion::new(1, 0), + context_branching: true, + physical_cow: true, + streaming: false, + cancellation: true, + max_context_tokens: Some(32768), + }, + } + } +} + +impl Default for MockInferenceClient { + fn default() -> Self { + Self::new() + } +} + +#[async_trait] +impl InferenceService for MockInferenceClient { + async fn infer(&self, req: InferenceRequest) -> Result<InferenceResponse, InferenceError> { + Ok(InferenceResponse { + request_id: req.request_id, + content: "mock inference output".to_string(), + finish_reason: "stop".to_string(), + prompt_tokens: 16, + completion_tokens: 8, + context: req.context, + }) + } + + async fn branch_context(&self, req: BranchContextRequest) -> Result<BranchContextReceipt, InferenceError> { + let mut child_context = req.parent_context.clone(); + child_context.branch_id = req.child_branch_id; + child_context.generation = child_context.generation.next(); + child_context.lineage.parent_context = Some(req.parent_context.context_id); + child_context.lineage.parent_branch = Some(req.parent_context.branch_id); + + Ok(BranchContextReceipt { + operation_id: req.operation_id, + child_context, + shared_pages: 10, + copied_pages: 0, + lease_expires_at_monotonic: 999999999, + }) + } + + async fn get_capabilities(&self) -> Result<InferenceCapabilities, InferenceError> { + Ok(self.capabilities.clone()) + } +} + +pub type DynInferenceService = Arc<dyn InferenceService>; diff --git a/crates/aien-inference-protocol/Cargo.toml b/crates/aien-inference-protocol/Cargo.toml new file mode 100644 index 0000000..99da51e --- /dev/null +++ b/crates/aien-inference-protocol/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "aien-inference-protocol" +version = "0.1.0" +edition = "2021" +license = "Apache-2.0" +description = "Inference execution contract, leased KV pinning, and copy-on-write context branching" + +[dependencies] +aien-protocol-types = { path = "../aien-protocol-types" } +aien-provenance = { path = "../aien-provenance" } +serde = { workspace = true } +serde_json = { workspace = true } +uuid = { workspace = true } +async-trait = { workspace = true } +thiserror = { workspace = true } diff --git a/crates/aien-inference-protocol/src/lib.rs b/crates/aien-inference-protocol/src/lib.rs new file mode 100644 index 0000000..031ed0e --- /dev/null +++ b/crates/aien-inference-protocol/src/lib.rs @@ -0,0 +1,177 @@ +use aien_protocol_types::{Digest32, ProtocolVersion}; +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, PartialOrd, Ord, Serialize, Deserialize)] +pub struct ContextId(pub uuid::Uuid); + +impl ContextId { + pub fn new_v4() -> Self { + Self(uuid::Uuid::new_v4()) + } +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, PartialOrd, Ord, Serialize, Deserialize)] +pub struct BranchId(pub uuid::Uuid); + +impl BranchId { + pub fn new_v4() -> Self { + Self(uuid::Uuid::new_v4()) + } +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, PartialOrd, Ord, Serialize, Deserialize)] +pub struct Generation(pub u64); + +impl Generation { + pub fn next(&self) -> Self { + Self(self.0.saturating_add(1)) + } +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct ModelFingerprint { + pub weights_digest: Digest32, + pub model_config_digest: Digest32, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct TokenizerFingerprint { + pub tokenizer_digest: Digest32, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct KvFormatFingerprint { + pub format_version: u16, + pub dtype: String, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct ContextLineage { + pub parent_context: Option<ContextId>, + pub parent_branch: Option<BranchId>, + pub parent_digest: Option<Digest32>, + pub fork_token_index: Option<u64>, +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)] +pub struct CacheIsolationKey { + pub domain_id: uuid::Uuid, + pub domain_digest: Digest32, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct OpaqueBindingRef { + pub engine_id: String, + pub runtime_epoch: u64, + pub binding_id: uuid::Uuid, + pub lease_generation: u64, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct ContextRecipeRef { + pub recipe_id: uuid::Uuid, + pub recipe_digest: Digest32, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct InferenceContextRef { + pub abi_version: u16, + pub context_id: ContextId, + pub branch_id: BranchId, + pub generation: Generation, + pub model: ModelFingerprint, + pub tokenizer: TokenizerFingerprint, + pub kv_format: KvFormatFingerprint, + pub logical_state_digest: Digest32, + pub token_count: u64, + pub lineage: ContextLineage, + pub isolation: CacheIsolationKey, + pub binding: Option<OpaqueBindingRef>, + pub recovery: ContextRecipeRef, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub enum MergeStrategy { + FastForward, + SelectBranch { branch: BranchId }, + RebuildFrom { recipe: ContextRecipeRef }, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct InferenceMessage { + pub role: String, + pub content: String, +} + +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] +pub struct InferenceRequest { + pub request_id: uuid::Uuid, + pub model: String, + pub messages: Vec<InferenceMessage>, + pub context: Option<InferenceContextRef>, + pub max_tokens: u32, + pub temperature: f32, + pub stop_sequences: Vec<String>, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct InferenceResponse { + pub request_id: uuid::Uuid, + pub content: String, + pub finish_reason: String, + pub prompt_tokens: u32, + pub completion_tokens: u32, + pub context: Option<InferenceContextRef>, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct BranchContextRequest { + pub operation_id: uuid::Uuid, + pub parent_context: InferenceContextRef, + pub child_branch_id: BranchId, + pub isolation: CacheIsolationKey, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct BranchContextReceipt { + pub operation_id: uuid::Uuid, + pub child_context: InferenceContextRef, + pub shared_pages: u32, + pub copied_pages: u32, + pub lease_expires_at_monotonic: u64, +} + +#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)] +pub struct InferenceCapabilities { + pub protocol: ProtocolVersion, + pub context_branching: bool, + pub physical_cow: bool, + pub streaming: bool, + pub cancellation: bool, + pub max_context_tokens: Option<u64>, +} + +#[derive(thiserror::Error, Debug)] +pub enum InferenceError { + #[error("Incompatible protocol version: expected {expected}, got {received}")] + VersionMismatch { expected: String, received: String }, + #[error("Context not found: {0:?}")] + ContextNotFound(ContextId), + #[error("Stale generation: expected {expected:?}, got {actual:?}")] + StaleGeneration { expected: Generation, actual: Generation }, + #[error("Stale runtime epoch: engine restarted, must reconstruct from recipe")] + StaleRuntimeEpoch, + #[error("Cache isolation error: domain unauthorized")] + IsolationDenied, + #[error("Resource exhaustion: {0}")] + ResourceExhausted(String), + #[error("Internal execution error: {0}")] + Internal(String), +} + +#[async_trait::async_trait] +pub trait InferenceService: Send + Sync { + async fn infer(&self, req: InferenceRequest) -> Result<InferenceResponse, InferenceError>; + async fn branch_context(&self, req: BranchContextRequest) -> Result<BranchContextReceipt, InferenceError>; + async fn get_capabilities(&self) -> Result<InferenceCapabilities, InferenceError>; +} diff --git a/crates/aien-protocol-types/Cargo.toml b/crates/aien-protocol-types/Cargo.toml new file mode 100644 index 0000000..e91de5f --- /dev/null +++ b/crates/aien-protocol-types/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "aien-protocol-types" +version = "0.1.0" +edition = "2021" +license = "Apache-2.0" +description = "Fundamental identifiers, primitives, and digests shared across AIEN protocols" + +[dependencies] +serde = { workspace = true } +serde_json = { workspace = true } +uuid = { workspace = true } +hex = { workspace = true } +thiserror = { workspace = true } diff --git a/crates/aien-protocol-types/src/lib.rs b/crates/aien-protocol-types/src/lib.rs new file mode 100644 index 0000000..c6b9f89 --- /dev/null +++ b/crates/aien-protocol-types/src/lib.rs @@ -0,0 +1,220 @@ +use serde::{Deserialize, Serialize}; +use std::fmt; + +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, PartialOrd, Ord, Serialize, Deserialize)] +pub struct ProtocolVersion { + pub major: u16, + pub minor: u16, +} + +impl ProtocolVersion { + pub const fn new(major: u16, minor: u16) -> Self { + Self { major, minor } + } + + pub fn is_compatible_with(&self, other: &Self) -> bool { + self.major == other.major && self.minor <= other.minor + } +} + +impl fmt::Display for ProtocolVersion { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}.{}", self.major, self.minor) + } +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, PartialOrd, Ord, Serialize, Deserialize)] +pub struct Digest32(pub [u8; 32]); + +impl Digest32 { + pub const ZERO: Self = Self([0u8; 32]); + + pub const fn from_bytes(bytes: [u8; 32]) -> Self { + Self(bytes) + } + + pub fn as_bytes(&self) -> &[u8; 32] { + &self.0 + } + + pub fn to_hex(&self) -> String { + hex::encode(self.0) + } + + pub fn from_hex(s: &str) -> Result<Self, hex::FromHexError> { + let mut arr = [0u8; 32]; + hex::decode_to_slice(s, &mut arr)?; + Ok(Self(arr)) + } +} + +impl fmt::Display for Digest32 { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "sha256:{}", self.to_hex()) + } +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, PartialOrd, Ord, Serialize, Deserialize)] +pub struct AgentId(pub uuid::Uuid); + +impl AgentId { + pub fn new_v4() -> Self { + Self(uuid::Uuid::new_v4()) + } +} + +impl fmt::Display for AgentId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.0) + } +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, PartialOrd, Ord, Serialize, Deserialize)] +pub struct SessionId(pub uuid::Uuid); + +impl SessionId { + pub fn new_v4() -> Self { + Self(uuid::Uuid::new_v4()) + } +} + +impl fmt::Display for SessionId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.0) + } +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, PartialOrd, Ord, Serialize, Deserialize)] +pub struct RunId(pub uuid::Uuid); + +impl RunId { + pub fn new_v4() -> Self { + Self(uuid::Uuid::new_v4()) + } +} + +impl fmt::Display for RunId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.0) + } +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, PartialOrd, Ord, Serialize, Deserialize)] +pub struct ActionId(pub uuid::Uuid); + +impl ActionId { + pub fn new_v4() -> Self { + Self(uuid::Uuid::new_v4()) + } +} + +impl fmt::Display for ActionId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.0) + } +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, PartialOrd, Ord, Serialize, Deserialize)] +pub struct EventId(pub uuid::Uuid); + +impl EventId { + pub fn new_v4() -> Self { + Self(uuid::Uuid::new_v4()) + } +} + +impl fmt::Display for EventId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.0) + } +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, PartialOrd, Ord, Serialize, Deserialize)] +pub struct ApprovalId(pub uuid::Uuid); + +impl ApprovalId { + pub fn new_v4() -> Self { + Self(uuid::Uuid::new_v4()) + } +} + +impl fmt::Display for ApprovalId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.0) + } +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, PartialOrd, Ord, Serialize, Deserialize)] +pub struct EvaluationId(pub uuid::Uuid); + +impl EvaluationId { + pub fn new_v4() -> Self { + Self(uuid::Uuid::new_v4()) + } +} + +impl fmt::Display for EvaluationId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.0) + } +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, PartialOrd, Ord, Serialize, Deserialize)] +pub struct SequenceNumber(pub u64); + +impl SequenceNumber { + pub fn next(&self) -> Self { + Self(self.0.saturating_add(1)) + } +} + +impl fmt::Display for SequenceNumber { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.0) + } +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, PartialOrd, Ord, Serialize, Deserialize)] +pub struct Timestamp(pub u64); + +impl Timestamp { + pub fn from_micros(micros: u64) -> Self { + Self(micros) + } + + pub fn as_micros(&self) -> u64 { + self.0 + } +} + +#[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize, Deserialize)] +pub struct ArtifactRef { + pub artifact_id: uuid::Uuid, + pub digest: Digest32, + pub media_type: String, + pub byte_size: u64, +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_digest_hex_roundtrip() { + let original = Digest32([0xab; 32]); + let hex_str = original.to_hex(); + let parsed = Digest32::from_hex(&hex_str).unwrap(); + assert_eq!(original, parsed); + } + + #[test] + fn test_protocol_version_compatibility() { + let v1_0 = ProtocolVersion::new(1, 0); + let v1_2 = ProtocolVersion::new(1, 2); + let v2_0 = ProtocolVersion::new(2, 0); + + assert!(v1_0.is_compatible_with(&v1_2)); + assert!(!v1_2.is_compatible_with(&v1_0)); + assert!(!v1_0.is_compatible_with(&v2_0)); + } +} diff --git a/crates/aien-provenance/Cargo.toml b/crates/aien-provenance/Cargo.toml new file mode 100644 index 0000000..5b4e74d --- /dev/null +++ b/crates/aien-provenance/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "aien-provenance" +version = "0.1.0" +edition = "2021" +license = "Apache-2.0" +description = "Deterministic digest computation, Merkle trees, and cryptographic verification" + +[dependencies] +aien-protocol-types = { path = "../aien-protocol-types" } +serde = { workspace = true } +serde_json = { workspace = true } +sha2 = { workspace = true } +hex = { workspace = true } +thiserror = { workspace = true } diff --git a/crates/aien-provenance/src/lib.rs b/crates/aien-provenance/src/lib.rs new file mode 100644 index 0000000..b12a12b --- /dev/null +++ b/crates/aien-provenance/src/lib.rs @@ -0,0 +1,39 @@ +use aien_protocol_types::Digest32; +use sha2::{Digest, Sha256}; + +pub fn compute_sha256(bytes: &[u8]) -> Digest32 { + let mut hasher = Sha256::new(); + hasher.update(bytes); + let result = hasher.finalize(); + let mut arr = [0u8; 32]; + arr.copy_from_slice(&result); + Digest32::from_bytes(arr) +} + +pub fn compute_canonical_json_digest<T: serde::Serialize>(val: &T) -> Result<Digest32, serde_json::Error> { + let json_bytes = serde_json::to_vec(val)?; + Ok(compute_sha256(&json_bytes)) +} + +pub fn combine_digests(d1: &Digest32, d2: &Digest32) -> Digest32 { + let mut hasher = Sha256::new(); + hasher.update(d1.as_bytes()); + hasher.update(d2.as_bytes()); + let result = hasher.finalize(); + let mut arr = [0u8; 32]; + arr.copy_from_slice(&result); + Digest32::from_bytes(arr) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_sha256_deterministic() { + let d1 = compute_sha256(b"hello aien protocols"); + let d2 = compute_sha256(b"hello aien protocols"); + assert_eq!(d1, d2); + assert_ne!(d1, Digest32::ZERO); + } +} diff --git a/specs/agent-state/SPEC.md b/specs/agent-state/SPEC.md new file mode 100644 index 0000000..2dfadec --- /dev/null +++ b/specs/agent-state/SPEC.md @@ -0,0 +1,15 @@ +# Agent State ABI Specification + +**Status**: Draft +**Version**: 1.0.0 +**License**: Community Specification License 1.0 + +## Abstract + +The Agent State ABI defines a portable, transport-neutral specification for serializing, restoring, branching, and verifying autonomous agent lifecycle state. + +## Core Concepts + +1. **State Snapshot (`AgentState`)**: The authoritative logical snapshot encompassing identity, session metadata, context lineage, authority grants, resource budgets, and execution status. +2. **Transition Events (`AgentStateEvent`)**: An append-only sequence of typed state transitions. Given an initial state and an ordered sequence of events, any conforming runtime reconstructs an identical logical agent state. +3. **Subsystem Boundary**: Agent state strictly references semantic memory (`MemoryRef`), physical GPU KV cache (`InferenceContextRef`), and content-addressed artifacts (`ArtifactRef`). Subsystems remain independent and do not leak internal structures into the ABI. diff --git a/specs/evaluation/SPEC.md b/specs/evaluation/SPEC.md new file mode 100644 index 0000000..6f54b35 --- /dev/null +++ b/specs/evaluation/SPEC.md @@ -0,0 +1,15 @@ +# Unified Evaluator Protocol Specification + +**Status**: Draft +**Version**: 1.0.0 +**License**: Community Specification License 1.0 + +## Abstract + +The Unified Evaluator Protocol establishes the verifier boundary for autonomous candidate evaluation, self-modification, and regression testing. + +## Core Concepts + +1. **Evaluator SPI**: Independent evaluators (static analysis, regression suites, benchmarks) produce native measurements and findings under a frozen `EvaluationPlan`. +2. **Immutability Invariant**: Candidate Engine N+1 may propose an artifact but may never evaluate itself or modify evaluator rules, thresholds, or verifier keys. +3. **Protected Verifier**: Signed evaluation receipts (`SignedEvaluationReceipt`) are issued exclusively by an isolated verifier identity bound to hardware TPM 2.0 keys. diff --git a/specs/inference/SPEC.md b/specs/inference/SPEC.md new file mode 100644 index 0000000..c710b54 --- /dev/null +++ b/specs/inference/SPEC.md @@ -0,0 +1,15 @@ +# Inference Protocol Specification + +**Status**: Draft +**Version**: 1.0.0 +**License**: Community Specification License 1.0 + +## Abstract + +The Inference Protocol defines the contract between autonomous agent orchestrators (AEGIS) and model execution backends (Sovereign Core). + +## Core Concepts + +1. **Inference Context Reference (`InferenceContextRef`)**: A durable logical handle referencing reproducible inference context. It contains model and tokenizer fingerprints, logical state digests, lineage metadata, and cache isolation keys. It never contains physical GPU pointers or raw block IDs. +2. **Copy-on-Write Branching**: Sequential sequence branches share immutable prefix KV blocks with reference counting. Physical page copies occur exclusively upon divergence. +3. **Leased KV Pinning**: Blocks are held via time-bounded leases renewed during active runs.