Every public Rust struct and enum that crosses the HTTP/MCP/CLI boundary. Field-level types, defaults, serde tags, since-when annotations. The contract a client implements when it wires up to ai-memory.
Grouped by responsibility: core domain (Tier, Memory, MemoryLink), request/response shapes (Create/Update/Search/List/Recall), governance (GovernanceLevel, ApproverType, GovernancePolicy, GovernedAction, GovernanceDecision), federation (VectorClock, SyncStateEntry, AgentRegistration, NamespaceMetaEntry), pending-action queue (PendingAction, PendingDecision, Approval).
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] · #[serde(rename_all = "snake_case")]#[derive(Debug, Clone, Serialize, Deserialize)]GET /memories/:id and MCP memory_get. Persisted into the memories table; mirrored to FTS5 + HNSW vector index. 26 fields at v0.7.0 (was 15 at v0.6.x; canonical truth in src/models/memory.rs::Memory, FIELD_COUNT = 26) — adds reflection_depth (Task 1/8 recursive learning), memory_kind (Batman Form-6 vocabulary), entity_id + persona_version (QW-2 persona artefact), citations + source_uri + source_span (Form-4 fact provenance), confidence_source + confidence_signals + confidence_decayed_at (Form-5 calibration), and the version BIGINT (Gap-1 optimistic concurrency, schema v45).| field | type | notes |
|---|---|---|
| id | String | REQUUIDv4 primary key. |
| tier | Tier | REQOne of short · mid · long. |
| namespace | String | REQHierarchical path; up to 8 segments; default "global". |
| title | String | REQ1–512 chars (MAX_TITLE_LEN); required. |
| content | String | REQ1–65 536 bytes (MAX_CONTENT_SIZE). |
| tags | Vec<String> | DEFDefault []; max 50 tags (MAX_TAGS_COUNT), 128 bytes each (MAX_TAG_LEN). |
| priority | i32 | DEFDefault 5; range 1-10. |
| confidence | f64 | DEFDefault 1.0; range 0.0-1.0. |
| source | String | DEFDefault "api"; closed set (VALID_SOURCES): user · nhi · claude (deprecated) · hook · api · cli · import · consolidation · system · chaos · notify. |
| access_count | i64 | Server-tracked; bumps on each memory_get/memory_recall hit. |
| created_at | String | RFC3339; server-stamped. |
| updated_at | String | RFC3339; updated on each memory_update. |
| last_accessed_at | Option<String> | OPTRFC3339; skip_serializing_if = None. |
| expires_at | Option<String> | OPTRFC3339; computed from ttl_secs or tier default. |
| metadata | serde_json::Value | DEFDefault {}; carries governance, scope, agent_id, taxonomy fields. |
| reflection_depth | i32 | DEFv0.7.0 Task 1/8: recursion depth in the substrate-native reflection tree. 0 for caller-minted (or legacy) rows; positive for reflection-pass outputs. Stored on memories.reflection_depth NOT NULL DEFAULT 0 (schema v29 sqlite / v31 postgres). |
| memory_kind | MemoryKind | DEFv0.7.0 L1-1: Batman Form-6 typed discriminator (observation / reflection / persona / concept / entity / claim / relation / event / conversation / decision). Schema v30 column default 'observation' for pre-v30 rows. |
| entity_id | Option<String> | OPTv0.7.0 QW-2: persona artefact subject. Populated only when memory_kind == Persona. Stored on memories.entity_id NULL (schema v36). |
| persona_version | Option<i32> | OPTv0.7.0 QW-2: monotonic (entity_id, namespace) version counter; PersonaGenerator::generate bumps. Older rows remain queryable for audit/rollback. |
| citations | Vec<Citation> | DEFv0.7.0 Form 4 (#757): fact-provenance citation array. Each entry: { uri, accessed_at, hash?, span? }. Schema v38 column; legacy rows default to '[]'. Validator: validate_citation. |
| source_uri | Option<String> | OPTv0.7.0 Form 4 (#757): first-class URI pointer (uri: / doc: / file: schemes). Distinct from the role-label source column. Schema v38; validator: validate_source_uri. |
| source_span | Option<SourceSpan> | OPTv0.7.0 Form 4 (#757): byte-range into the parent source body, JSON {start, end}. Populated by the WT-1-B atomisation writer per atom. Validator: validate_source_span. |
| confidence_source | ConfidenceSource | DEFv0.7.0 Form 5 (#758): typed discriminator naming the provenance of confidence. Defaults to CallerProvided. Schema v39 sqlite / v38 postgres column default 'caller_provided'. |
| confidence_signals | Option<ConfidenceSignals> | OPTv0.7.0 Form 5: JSON snapshot of the signals that produced an auto-derived or calibrated confidence. NULL on legacy rows and on CallerProvided writes. |
| confidence_decayed_at | Option<String> | OPTv0.7.0 Form 5: RFC3339 stamp of the last decay-sweep touch. NULL on legacy / never-decayed rows. |
| version | i64 | DEFv0.7.0 Provenance Gap 1 (#884, schema v45 sqlite): optimistic-concurrency counter. Bumped on every storage::update; two writers against the same expected_version race; loser receives a typed CONFLICT envelope. Legacy rows land at version = 1 via SQL DEFAULT + serde default_memory_version. |
#[derive(Debug, Clone, Serialize, Deserialize)]memory_links. 6 MemoryLinkRelation variants at v0.7.0 (was 4 at v0.6.x); canonical enum in src/models/link.rs::MemoryLinkRelation.| field | type | notes |
|---|---|---|
| source_id | String | REQFK to memories.id. |
| target_id | String | REQFK to memories.id. |
| relation | MemoryLinkRelation | REQOne of: related_to · supersedes · contradicts · derived_from · reflects_on (v0.7.0 Task 1/8 recursive learning) · derives_from (v0.7.0 WT-1-A atomisation atom→parent, schema v36 sqlite / v35 postgres). |
| created_at | String | RFC3339; server-stamped. |
| valid_from / valid_until | Option<String> | OPTv0.6.3 temporal validity window; valid_until = None means still valid. |
| observed_by | Option<String> | OPTagent_id of the observer; powers per-agent visibility. |
| signature | Option<Vec<u8>> | OPTv0.7.0 H4 — Ed25519 per-link attestation bytes. |
| attest_level | Option<String> | OPTv0.7.0 H4 — unsigned · self_signed · peer_attested · signed_by_peer · daemon_signed. |
#[derive(Debug, Deserialize)]POST /memories and memory_store. Every field has a server-side default except title + content.| field | type | notes |
|---|---|---|
| tier | Tier | DEFDefault Mid. |
| namespace | String | DEFDefault "global". |
| title | String | REQ1–512 chars (MAX_TITLE_LEN). |
| content | String | REQ1–65 536 bytes. |
| tags | Vec<String> | DEFDefault []. |
| priority | i32 | DEFDefault 5. |
| confidence | f64 | DEFDefault 1.0. |
| source | String | DEFDefault "api". |
| expires_at | Option<String> | OPTRFC3339; explicit override. |
| ttl_secs | Option<i64> | OPTConvenience: expires_at = now + ttl_secs. |
| metadata | Value | DEFDefault {}. |
| agent_id | Option<String> | OPTAuto-resolved by identity when omitted. |
| scope | Option<String> | OPTOne of VALID_SCOPES; default "private". |
| on_conflict / detect_conflicts / force | Option<String> / Option<bool> / bool | OPTDedup-and-synthesis controls (Form 1): conflict disposition, contradiction probe, duplicate-gate override. |
| citations / source_uri / source_span | Vec<Citation> / Option<String> / Option<SourceSpan> | OPTv0.7.0 Form-4 fact provenance (#757). |
| kind | Option<String> | OPTv0.7.0 Batman Form-6 memory_kind discriminator. |
| signature | Option<String> | OPTv0.7.0 Layer-3 — caller-presented Ed25519 write attestation (verified against the agent's bound key). |
| created_at | Option<String> | OPTRFC3339 backdating for imports; server-stamped when omitted. |
#[derive(Debug, Deserialize)]PUT /memories/:id and memory_update. Every field is optional — only the present fields are mutated; the rest are preserved.| field | type | notes |
|---|---|---|
| title | Option<String> | OPT1–512 chars (MAX_TITLE_LEN) when set. |
| content | Option<String> | OPT1–65 536 bytes when set. |
| tier | Option<Tier> | OPTPromoting Mid→Long passes through governance. |
| namespace | Option<String> | OPTRe-namespacing; depth ≤ 8. |
| tags | Option<Vec<String>> | OPTReplaces tag set entirely (not merged). |
| priority | Option<i32> | OPT1-10 range. |
| confidence | Option<f64> | OPT0.0-1.0 range. |
| expires_at | Option<String> | OPTRFC3339. |
| metadata | Option<Value> | OPTReplaces metadata wholesale (not merged); metadata.agent_id is preserved. |
| source_uri | Option<String> | OPTv0.7.0 Form-4 provenance pointer update. |
| agent_id | Option<String> | OPTCaller identity for owner-write checks; the stored row's metadata.agent_id remains immutable. |
#[derive(Debug, Deserialize)]POST /links and memory_link. Creates a directed edge in the KG.| field | type | notes |
|---|---|---|
| source_id | String | REQUUID; must exist in memories. |
| target_id | String | REQUUID; must exist in memories. |
| relation | String | DEFDefault "related_to". |
#[derive(Debug, Deserialize)]POST /api/v1/forget and memory_forget (v0.7.0: route registered at /api/v1/forget, not /api/v1/memories/forget). Pattern-based delete; archives matched memories rather than hard-deleting.| field | type | notes |
|---|---|---|
| namespace | Option<String> | OPTRestricts the sweep to a namespace. |
| pattern | Option<String> | OPTFTS5 pattern; matches title+content. |
| tier | Option<Tier> | OPTRestricts to one tier. |
#[derive(Debug, Deserialize)]GET /search and body for memory_search. FTS5-backed.| field | type | notes |
|---|---|---|
| q | String | REQFTS5 expression; supports AND/OR/NEAR/"phrase". |
| namespace | Option<String> | OPTRestricts to one namespace prefix. |
| tier | Option<Tier> | OPT |
| limit | Option<usize> | DEFDefault 20. |
| min_priority | Option<i32> | OPT |
| since / until | Option<String> | OPTRFC3339 created_at window. |
| tags | Option<String> | OPTComma-separated; AND semantics. |
| agent_id | Option<String> | OPTFilters by metadata.agent_id exact. |
| as_agent | Option<String> | OPTQuerying agent's namespace position; drives scope filtering. |
#[derive(Debug, Deserialize)]GET /memories and memory_list. Pagination + filter by namespace/tier/tags.| field | type | notes |
|---|---|---|
| namespace | Option<String> | OPT |
| tier | Option<Tier> | OPT |
| limit | Option<usize> | DEFDefault 20. |
| offset | Option<usize> | OPT |
| min_priority | Option<i32> | OPT |
| since / until | Option<String> | OPTRFC3339 window. |
| tags | Option<String> | OPTComma-separated. |
| agent_id | Option<String> | OPT |
#[derive(Debug, Deserialize)]GET /recall. Hybrid FTS5 + HNSW fusion with adaptive blending — semantic weight 0.50 (short content) → 0.15 (long content), cosine gate RECALL_COSINE_GATE = 0.2; optional context-budget pruning.| field | type | notes |
|---|---|---|
| context | Option<String> | OPTFree-form context to retrieve against. |
| namespace | Option<String> | OPT |
| limit | Option<usize> | DEFDefault 10. |
| tags | Option<String> | OPT |
| since / until | Option<String> | OPT |
| as_agent | Option<String> | OPTVisibility filter (Task 1.5). |
| budget_tokens | Option<usize> | OPTCap on cumulative tokens; top-N items that fit (Task 1.11). |
#[derive(Debug, Deserialize)]POST /recall and memory_recall. Same shape as RecallQuery but context is required.| field | type | notes |
|---|---|---|
| context | String | REQ |
| namespace | Option<String> | OPT |
| limit | Option<usize> | DEFDefault 10. |
| tags / since / until / as_agent / budget_tokens | … | Same as RecallQuery. |
#[derive(Debug, Serialize)]GET /stats and memory_stats.| field | type | notes |
|---|---|---|
| total | usize | Count of non-archived memories. |
| by_tier | Vec<TierCount> | 3 rows: short / mid / long. |
| by_namespace | Vec<NamespaceCount> | One row per distinct namespace. |
| expiring_soon | usize | Count expiring within 24h. |
| links_count | usize | Total memory_links rows. |
| db_size_bytes | u64 | SQLite file size. |
#[derive(Debug, Serialize)]Stats.by_tier.| field | type | notes |
|---|---|---|
| tier | String | "short" · "mid" · "long" |
| count | usize |
#[derive(Debug, Serialize)]Stats.by_namespace.| field | type | notes |
|---|---|---|
| namespace | String | |
| count | usize |
#[derive(Debug, Clone, PartialEq, Eq)]Allow, MUST reject on Deny, and SHOULD queue + return the pending_id on Pending.Display reads "<action> denied by governance: <reason>") plus the structured policy context (denied_level, namespace, owner, agent_id, reason). Wire shape byte-identical to the pre-#963 Deny(String) envelope; pattern-match consumers read refusal.reason for the bare string.pending_id.#[derive(Debug, Clone, Copy, PartialEq, Eq)]action_type column in pending_actions; discriminator for enforcement calls.memory_reflect approval gate; queued when the proposed reflection depth exceeds require_approval_above_depth.#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] · #[serde(rename_all = "snake_case")]metadata.governance._agents namespace).metadata.agent_id owner may perform the action.ApproverType.#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)] · #[serde(rename_all = "snake_case")]GovernanceLevel::Approve. Externally-tagged."human"; interactive or out-of-band approval.{"agent": "alice"}; specific registered agent must approve.{"consensus": 3}; consensus of N approvers required.#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]metadata.governance. Default policy: { write: Any, promote: Any, delete: Owner, approver: Human }. v0.6.2 (S34) made promote/delete/approver tolerant of missing fields for partial-policy payloads.| field | type | notes |
|---|---|---|
| write | GovernanceLevel | REQRequired — core knob a policy is setting. |
| promote | GovernanceLevel | DEFDefault Any. |
| delete | GovernanceLevel | DEFDefault Owner. |
| approver | ApproverType | DEFDefault Human. |
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]| field | type | notes |
|---|---|---|
| agent_id | String | Approving agent's id. |
| approved_at | String | RFC3339. |
#[derive(Debug, Clone, Serialize, Deserialize)]db::list_pending_actions. Mirrors the pending_actions table.| field | type | notes |
|---|---|---|
| id | String | UUID. |
| action_type | String | store · delete · promote · reflect (v0.7.0). |
| memory_id | Option<String> | Set for delete/promote; null for pending stores. |
| namespace | String | |
| payload | Value | Action-shaped JSON for replay. |
| requested_by | String | agent_id of requester. |
| requested_at | String | RFC3339. |
| status | String | pending · approved · rejected. |
| decided_by | Option<String> | OPT |
| decided_at | Option<String> | OPT |
| approvals | Vec<Approval> | Consensus vote log (Task 1.10); empty for Human/Agent paths. |
#[derive(Debug, Clone, Serialize, Deserialize)]sync_push.pending_decisions field; peers apply via db::decide_pending_action.| field | type | notes |
|---|---|---|
| id | String | pending_action UUID. |
| approved | bool | true → approve; false → reject. |
| decider | String | agent_id of decider. |
#[derive(Debug, Clone, Serialize, Deserialize)]broadcast_store_quorum) but not the (namespace, standard_id, parent_namespace) tuple, so inheritance-chain walks fall back to auto_detect_parent.| field | type | notes |
|---|---|---|
| namespace | String | |
| standard_id | String | UUID of the standard memory. |
| parent_namespace | Option<String> | OPT |
| updated_at | String | RFC3339. |
#[derive(Debug, Deserialize)]POST /agents/register. Persists into the _agents namespace.| field | type | notes |
|---|---|---|
| agent_id | String | REQStable identifier; max 64 chars. |
| agent_type | String | REQOne of VALID_AGENT_TYPES. |
| capabilities | Option<Vec<String>> | OPTFree-form capability tags. |
#[derive(Debug, Serialize)]POST /agents/register and rows in GET /agents.| field | type | notes |
|---|---|---|
| agent_id | String | |
| agent_type | String | |
| capabilities | Vec<String> | Empty when none registered. |
| registered_at | String | RFC3339. |
| last_seen_at | String | RFC3339; bumps on agent activity. |
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]updated_at this peer has seen from each known remote. Populated lazily on /sync/push and /sync/since. CRDT-lite merge semantics arrive in Task 3a.1; the foundation ships the wire format so adding semantics later does not force a schema migration.| field | type | notes |
|---|---|---|
| entries | BTreeMap<String, String> | DEFpeer agent_id → latest RFC3339 updated_at. |
#[derive(Debug, Clone, Serialize, Deserialize)]sync_state table serialized for diagnostic / API responses. Consumed by Task 3b.2 sync diagnostics.| field | type | notes |
|---|---|---|
| agent_id | String | Local agent's id. |
| peer_id | String | Remote peer's id. |
| last_seen_at | String | RFC3339; latest updated_at seen on receive. |
| last_pulled_at | String | RFC3339; cursor advanced on send. |
usize = 65_536 — hard cap on memory content bytes. Validated at write time.usize = 8 — maximum number of /-delimited segments in a namespace path. Sample: alphaone/engineering/platform/team/squad/pod/role/agent.&[&str] = &["private", "team", "unit", "org", "collective"] — closed set stamped into metadata.scope (Task 1.5). Drives hierarchical visibility matching.POST /agents/register. NOT a hard closed set since red-team #235: any ai:<name> form matching ^ai:[A-Za-z0-9_.-]{1,60}$ is also accepted (max 64 bytes total), so operators can register future models without a code release.&str = "_agents" — namespace reserved for agent registrations (Task 1.3). Listed via memory_agent_list./-delimited segments. Flat namespaces return 1; empty returns 0.