{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://agoragentic.com/schema/local-inference-receipt.v1.json",
  "title": "Agent OS Local Inference Receipt v1",
  "description": "Redacted local inference receipt with routing decision, provider mode, token estimates, and estimated external cost savings. Raw prompts and outputs are not stored.",
  "type": "object",
  "required": [
    "schema",
    "receipt_id",
    "created_at",
    "pack_id",
    "provider",
    "decision",
    "redaction",
    "token_estimate",
    "cost_savings_estimate",
    "authority_boundary"
  ],
  "properties": {
    "schema": {
      "const": "agoragentic.agent-os.local-inference-receipt.v1"
    },
    "receipt_id": { "type": "string", "minLength": 1 },
    "created_at": { "type": "string", "minLength": 1 },
    "pack_id": { "type": "string", "minLength": 1 },
    "provider": {
      "type": "object",
      "required": ["mode", "model"],
      "properties": {
        "mode": {
          "type": "string",
          "enum": ["disabled", "mock", "ollama", "openai_compatible", "local_http"]
        },
        "model": { "type": "string", "minLength": 1 },
        "endpoint_host": { "type": ["string", "null"] }
      },
      "additionalProperties": true
    },
    "decision": {
      "type": "object",
      "required": [
        "decision",
        "task_class",
        "risk_level",
        "needs_fresh_data",
        "needs_tool",
        "needs_code_execution",
        "local_allowed",
        "stronger_model_allowed",
        "owner_approval_required",
        "reason_codes",
        "receipt_required"
      ],
      "properties": {
        "decision": {
          "type": "string",
          "enum": ["use_local", "use_local_with_context", "escalate", "require_approval", "reject"]
        },
        "task_class": {
          "type": "string",
          "enum": ["chat", "summarize", "source_qa", "coding", "finance_research", "web_research", "route", "unknown"]
        },
        "risk_level": {
          "type": "string",
          "enum": ["low", "medium", "high", "prohibited"]
        },
        "needs_fresh_data": { "type": "boolean" },
        "needs_tool": { "type": "boolean" },
        "needs_code_execution": { "type": "boolean" },
        "local_allowed": { "type": "boolean" },
        "stronger_model_allowed": { "type": "boolean" },
        "owner_approval_required": { "type": "boolean" },
        "reason_codes": {
          "type": "array",
          "items": { "type": "string", "minLength": 1 }
        },
        "receipt_required": { "const": true }
      },
      "additionalProperties": false
    },
    "redaction": {
      "type": "object",
      "required": [
        "store_raw_prompt",
        "store_raw_output",
        "raw_prompt_hash",
        "raw_output_hash",
        "prompt_redacted",
        "output_redacted"
      ],
      "properties": {
        "store_raw_prompt": { "const": false },
        "store_raw_output": { "const": false },
        "raw_prompt_hash": { "type": ["string", "null"] },
        "raw_output_hash": { "type": ["string", "null"] },
        "prompt_redacted": { "const": true },
        "output_redacted": { "const": true }
      },
      "additionalProperties": true
    },
    "token_estimate": {
      "type": "object",
      "required": ["input_tokens", "output_tokens", "total_tokens", "method"],
      "properties": {
        "input_tokens": { "type": "integer", "minimum": 0 },
        "output_tokens": { "type": "integer", "minimum": 0 },
        "total_tokens": { "type": "integer", "minimum": 0 },
        "method": { "type": "string", "minLength": 1 }
      },
      "additionalProperties": true
    },
    "cost_savings_estimate": {
      "type": "object",
      "required": ["baseline_model", "pricing_known", "estimated_external_cost_usdc", "local_cost_usdc", "estimated_savings_usdc"],
      "properties": {
        "baseline_model": { "type": "string", "minLength": 1 },
        "pricing_known": { "type": "boolean" },
        "estimated_external_cost_usdc": { "type": ["number", "null"], "minimum": 0 },
        "local_cost_usdc": { "type": "number", "minimum": 0 },
        "estimated_savings_usdc": { "type": ["number", "null"], "minimum": 0 }
      },
      "additionalProperties": true
    },
    "citations": {
      "type": "array",
      "items": { "type": "string" }
    },
    "provider_error": {
      "type": ["object", "null"],
      "additionalProperties": true
    },
    "authority_boundary": {
      "type": "object",
      "required": [
        "agent_os_remains_authority",
        "no_tool_calls",
        "no_code_execution",
        "no_spend_triggered",
        "no_publication",
        "no_trust_mutation",
        "full_ecf_private_internals_excluded",
        "raw_prompt_or_output_stored"
      ],
      "properties": {
        "agent_os_remains_authority": { "const": true },
        "no_tool_calls": { "const": true },
        "no_code_execution": { "const": true },
        "no_spend_triggered": { "const": true },
        "no_publication": { "const": true },
        "no_trust_mutation": { "const": true },
        "full_ecf_private_internals_excluded": { "const": true },
        "raw_prompt_or_output_stored": { "const": false }
      },
      "additionalProperties": true
    }
  },
  "additionalProperties": false
}
