{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://agoragentic.com/schema/agent-improvement-evaluation-record.v1.json",
  "title": "Agoragentic Agent Improvement Evaluation Record",
  "description": "A/B-safe advisory evaluation record comparing baseline and candidate improvement evidence. This schema cannot apply improvements, mutate prompts, widen tools, approve memory, execute runtime work, publish, rank, spend, settle, or mark readiness/trust/x402/marketplace state complete.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema",
    "evaluation_record_id",
    "target_type",
    "target_id",
    "baseline_arm",
    "candidate_arm",
    "comparison",
    "evaluation_state",
    "winner",
    "recommended_outcome",
    "blockers",
    "warnings",
    "evidence_refs",
    "owner_review_required",
    "auto_apply_allowed",
    "advisory_only",
    "candidate_action",
    "public_safe_summary",
    "private_owner_summary",
    "owner_review_checklist",
    "public_boundary",
    "created_at",
    "evaluated_at"
  ],
  "properties": {
    "schema": { "const": "agoragentic.agent-improvement-evaluation-record.v1" },
    "evaluation_record_id": { "type": "string", "minLength": 1 },
    "target_type": { "type": "string", "minLength": 1 },
    "target_id": { "type": "string", "minLength": 1 },
    "source_suggestion_ids": {
      "type": "array",
      "items": { "type": "string", "minLength": 1 }
    },
    "experiment_id": { "type": ["string", "null"] },
    "baseline_arm": { "$ref": "#/definitions/evaluation_arm" },
    "candidate_arm": { "$ref": "#/definitions/evaluation_arm" },
    "comparison": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "score_delta",
        "cost_delta_usdc",
        "latency_delta_ms",
        "receipt_ref_delta",
        "sample_size_delta",
        "risk_delta"
      ],
      "properties": {
        "score_delta": { "type": "number" },
        "cost_delta_usdc": { "type": "number" },
        "latency_delta_ms": { "type": ["number", "null"] },
        "receipt_ref_delta": { "type": "integer" },
        "sample_size_delta": { "type": "integer" },
        "risk_delta": { "type": "number" }
      }
    },
    "evaluation_state": {
      "type": "string",
      "enum": [
        "blocked",
        "insufficient_evidence",
        "needs_owner_review",
        "candidate_worse",
        "inconclusive"
      ]
    },
    "winner": {
      "type": "string",
      "enum": ["baseline", "candidate", "none"]
    },
    "recommended_outcome": {
      "type": "string",
      "enum": [
        "blocked",
        "collect_more_evidence",
        "review_candidate",
        "keep_baseline",
        "inconclusive"
      ]
    },
    "blockers": {
      "type": "array",
      "items": { "type": "string" }
    },
    "warnings": {
      "type": "array",
      "items": { "type": "string" }
    },
    "evidence_refs": {
      "type": "array",
      "items": { "type": "string", "minLength": 1 }
    },
    "owner_review_required": { "const": true },
    "auto_apply_allowed": { "const": false },
    "advisory_only": { "const": true },
    "candidate_action": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "action_type",
        "label",
        "executable_directly",
        "requires_owner_approval",
        "receipt_required_before_future_mutation",
        "next_safe_action"
      ],
      "properties": {
        "action_type": { "const": "owner_review_improvement_candidate" },
        "label": { "type": "string" },
        "executable_directly": { "const": false },
        "requires_owner_approval": { "const": true },
        "receipt_required_before_future_mutation": { "const": true },
        "next_safe_action": { "type": "string" }
      }
    },
    "public_safe_summary": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "summary",
        "live_behavior",
        "private_context_excluded",
        "raw_payloads_excluded",
        "next_state"
      ],
      "properties": {
        "summary": { "type": "string" },
        "live_behavior": { "const": "control_plane_only" },
        "private_context_excluded": { "const": true },
        "raw_payloads_excluded": { "const": true },
        "next_state": { "type": "string" }
      }
    },
    "private_owner_summary": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "summary",
        "baseline_score",
        "candidate_score",
        "blockers",
        "warnings",
        "evidence_refs",
        "raw_private_payloads_excluded"
      ],
      "properties": {
        "summary": { "type": "string" },
        "baseline_score": { "type": "number", "minimum": 0, "maximum": 100 },
        "candidate_score": { "type": "number", "minimum": 0, "maximum": 100 },
        "blockers": { "type": "array", "items": { "type": "string" } },
        "warnings": { "type": "array", "items": { "type": "string" } },
        "evidence_refs": { "type": "array", "items": { "type": "string" } },
        "raw_private_payloads_excluded": { "const": true }
      }
    },
    "owner_review_checklist": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["item_id", "label", "required", "satisfied"],
        "properties": {
          "item_id": { "type": "string", "minLength": 1 },
          "label": { "type": "string" },
          "required": { "type": "boolean" },
          "satisfied": { "type": "boolean" }
        }
      }
    },
    "public_boundary": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "evaluation_record_only",
        "advisory_only",
        "ab_safe_review_only",
        "target_mutated",
        "prompt_mutated",
        "tool_scope_mutated",
        "policy_mutated",
        "memory_written",
        "memory_injected",
        "memory_candidate_approved",
        "runtime_execution_enabled",
        "provider_dispatch_enabled",
        "public_execute_enabled",
        "global_execute_mutated",
        "global_invoke_mutated",
        "wallet_spend_enabled",
        "wallet_mutation_enabled",
        "x402_settlement_enabled",
        "x402_readiness_mutation_enabled",
        "trust_mutation_enabled",
        "router_ranking_mutation_enabled",
        "marketplace_publication_enabled",
        "seller_os_publication_enabled",
        "public_claim_generated",
        "private_ecf_exposed",
        "raw_private_payload_exposed"
      ],
      "properties": {
        "evaluation_record_only": { "const": true },
        "advisory_only": { "const": true },
        "ab_safe_review_only": { "const": true },
        "target_mutated": { "const": false },
        "prompt_mutated": { "const": false },
        "tool_scope_mutated": { "const": false },
        "policy_mutated": { "const": false },
        "memory_written": { "const": false },
        "memory_injected": { "const": false },
        "memory_candidate_approved": { "const": false },
        "runtime_execution_enabled": { "const": false },
        "provider_dispatch_enabled": { "const": false },
        "public_execute_enabled": { "const": false },
        "global_execute_mutated": { "const": false },
        "global_invoke_mutated": { "const": false },
        "wallet_spend_enabled": { "const": false },
        "wallet_mutation_enabled": { "const": false },
        "x402_settlement_enabled": { "const": false },
        "x402_readiness_mutation_enabled": { "const": false },
        "trust_mutation_enabled": { "const": false },
        "router_ranking_mutation_enabled": { "const": false },
        "marketplace_publication_enabled": { "const": false },
        "seller_os_publication_enabled": { "const": false },
        "public_claim_generated": { "const": false },
        "private_ecf_exposed": { "const": false },
        "raw_private_payload_exposed": { "const": false }
      }
    },
    "created_at": { "type": "string", "format": "date-time" },
    "evaluated_at": { "type": "string", "format": "date-time" }
  },
  "definitions": {
    "evaluation_arm": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "arm_id",
        "arm_type",
        "variant_label",
        "source_scorecard_id",
        "source_suggestion_id",
        "experiment_id",
        "score",
        "score_band",
        "evidence_state",
        "evidence_refs",
        "receipt_ref_count",
        "sample_size",
        "cost_usdc",
        "latency_ms",
        "failure_rate",
        "policy_violation_count",
        "trap_block_count",
        "private_context_exposed",
        "public_safe"
      ],
      "properties": {
        "arm_id": { "type": "string", "minLength": 1 },
        "arm_type": { "type": "string", "enum": ["baseline", "candidate"] },
        "variant_label": { "type": "string" },
        "source_scorecard_id": { "type": ["string", "null"] },
        "source_suggestion_id": { "type": ["string", "null"] },
        "experiment_id": { "type": ["string", "null"] },
        "score": { "type": "number", "minimum": 0, "maximum": 100 },
        "score_band": { "type": "string" },
        "evidence_state": { "type": "string" },
        "evidence_refs": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 }
        },
        "receipt_ref_count": { "type": "integer", "minimum": 0 },
        "sample_size": { "type": "integer", "minimum": 0 },
        "cost_usdc": { "type": "number", "minimum": 0 },
        "latency_ms": { "type": ["number", "null"], "minimum": 0 },
        "failure_rate": { "type": "number", "minimum": 0, "maximum": 1 },
        "policy_violation_count": { "type": "integer", "minimum": 0 },
        "trap_block_count": { "type": "integer", "minimum": 0 },
        "private_context_exposed": { "const": false },
        "public_safe": { "type": "boolean" }
      }
    }
  }
}
