{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.alltiply.com/schemas/four-scope-agent-memory-v1.json",
  "title": "ALLTIPLY Four-Scope Enterprise Agent Memory Record",
  "description": "Production governance contract combining MixUA 4-scope isolation, WikiTrace raw-log pointers, and Falsification-Gated staging.",
  "type": "object",
  "required": [
    "memory_id",
    "tenant_id",
    "scope",
    "owner_principal_id",
    "promotion_state",
    "claim_text",
    "evidence_trace",
    "pii_scrub_status",
    "created_at",
    "expires_at"
  ],
  "properties": {
    "memory_id": {
      "type": "string",
      "format": "uuid"
    },
    "tenant_id": {
      "type": "string",
      "minLength": 1
    },
    "scope": {
      "type": "string",
      "enum": [
        "pair",
        "user",
        "agent",
        "global"
      ],
      "description": "pair = single user+agent; user = single employee; agent = role-authorized workflow team; global = tenant-wide certified knowledge."
    },
    "owner_principal_id": {
      "type": "string",
      "description": "Immutable IAM user_id or role_group_id owning read/delete rights."
    },
    "agent_id": {
      "type": "string"
    },
    "promotion_state": {
      "type": "string",
      "enum": [
        "staged_hypothesis",
        "regression_verified",
        "owner_certified",
        "deprecated",
        "purged"
      ]
    },
    "claim_text": {
      "type": "string",
      "maxLength": 2000
    },
    "canonical_entity_ids": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "description": "Ontology Registry IDs (e.g. ONT-001) referenced by this note."
    },
    "evidence_trace": {
      "type": "object",
      "required": [
        "source_log_id",
        "source_uri",
        "captured_at",
        "verification_mode"
      ],
      "properties": {
        "source_log_id": {
          "type": "string",
          "description": "WikiTrace immutable trajectory/session log pointer."
        },
        "source_uri": {
          "type": "string",
          "description": "System-of-record table, ticket, or certified policy URI."
        },
        "source_hash_sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "captured_at": {
          "type": "string",
          "format": "date-time"
        },
        "verification_mode": {
          "type": "string",
          "enum": [
            "must_recheck_source_on_high_stakes",
            "verified_static_definition"
          ]
        }
      }
    },
    "falsification_eval": {
      "type": "object",
      "properties": {
        "eval_run_id": {
          "type": "string"
        },
        "baseline_pass_rate": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "candidate_pass_rate": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "contradicts_certified_ontology": {
          "type": "boolean"
        },
        "approved_by_owner_id": {
          "type": [
            "string",
            "null"
          ]
        }
      }
    },
    "pii_scrub_status": {
      "type": "string",
      "enum": [
        "verified_clean",
        "redacted_tokens_applied"
      ]
    },
    "retention_quota_cluster": {
      "type": "string",
      "description": "H-Mem topic cluster ID for budget-capped pruning."
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "expires_at": {
      "type": "string",
      "format": "date-time"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "scope": {
            "enum": [
              "agent",
              "global"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "promotion_state": {
            "const": "owner_certified"
          }
        }
      }
    }
  ]
}