{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://weverlabs.com/schemas/agent-task-run.schema.json",
  "title": "Wever Labs Agent Task Run",
  "description": "A metered agent task run record tying trust, quote, credit entitlement, Work Order, state, evidence, receipt, callback, and result URLs together.",
  "type": "object",
  "required": [
    "object_type",
    "agent_task_run_id",
    "work_order_id",
    "requested_tool",
    "state",
    "created_at"
  ],
  "additionalProperties": true,
  "properties": {
    "object_type": {
      "type": "string",
      "const": "agent_task_run"
    },
    "agent_task_run_id": {
      "type": "string"
    },
    "work_order_id": {
      "type": "string"
    },
    "trust_profile_id": {
      "type": "string"
    },
    "quote_id": {
      "type": "string"
    },
    "credit_entitlement_id": {
      "type": "string"
    },
    "requested_tool": {
      "type": "string",
      "enum": [
        "packetops",
        "distributionops",
        "tokenops",
        "wever_labs_os"
      ]
    },
    "requested_capability": {
      "type": "string"
    },
    "state": {
      "type": "string",
      "enum": [
        "quoted",
        "credit_pending",
        "funded",
        "run_created",
        "queued",
        "evidence_review",
        "tool_execution",
        "result_packaged",
        "receipt_issued",
        "callback_ready",
        "callback_delivered",
        "closed",
        "paused",
        "failed"
      ]
    },
    "evidence_status": {
      "type": "string",
      "enum": [
        "sufficient",
        "partial",
        "insufficient",
        "unknown"
      ]
    },
    "status_token": {
      "type": "string"
    },
    "status_url": {
      "type": "string",
      "format": "uri"
    },
    "ledger_url": {
      "type": "string",
      "format": "uri"
    },
    "result_url": {
      "type": "string",
      "format": "uri"
    },
    "result_attestation_url": {
      "type": "string",
      "format": "uri"
    },
    "receipt_url": {
      "type": "string",
      "format": "uri"
    },
    "callback_url": {
      "type": "string",
      "format": "uri"
    },
    "callback_status": {
      "type": "string",
      "enum": [
        "not_required",
        "pending",
        "ready",
        "delivered",
        "retrying",
        "failed"
      ]
    },
    "credits_reserved": {
      "type": "number",
      "minimum": 0
    },
    "credits_debited": {
      "type": "number",
      "minimum": 0
    },
    "remaining_credits": {
      "type": "number",
      "minimum": 0
    },
    "state_history": {
      "type": "array",
      "items": {
        "$ref": "https://weverlabs.com/schemas/agent-run-state-event.schema.json"
      }
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "updated_at": {
      "type": "string",
      "format": "date-time"
    },
    "closed_at": {
      "type": "string",
      "format": "date-time"
    },
    "handshake_id": {
      "type": "string",
      "description": "Optional upstream agent handshake ID."
    },
    "preflight_id": {
      "type": "string",
      "description": "Optional upstream preflight check ID."
    },
    "contract_id": {
      "type": "string",
      "description": "Optional upstream run contract ID."
    },
    "run_contract_url": {
      "type": "string",
      "format": "uri",
      "description": "Optional URL for the run contract object."
    },
    "canonical_lifecycle_state": {
      "type": "string",
      "enum": [
        "created",
        "preflight_checked",
        "contract_ready",
        "contract_accepted",
        "trust_pending",
        "trusted",
        "quoted",
        "credit_pending",
        "credit_funded",
        "queued",
        "operating",
        "evidence_partial",
        "result_ready",
        "attested",
        "receipt_issued",
        "callback_pending",
        "callback_delivered",
        "exception_open",
        "replay_ready",
        "failed",
        "closed"
      ],
      "description": "Normalized lifecycle label used by the Agent Operating Console v2."
    },
    "settlement_mode": {
      "type": "string",
      "enum": [
        "manual",
        "provider_controlled",
        "provider_auto_funded",
        "paused"
      ]
    },
    "settlement_provider": {
      "type": "string",
      "enum": [
        "stripe_stablecoin",
        "x402",
        "circle_usdc",
        "manual_invoice",
        "not_selected"
      ]
    },
    "settlement_intent_id": {
      "type": "string"
    },
    "settlement_receipt_url": {
      "type": "string",
      "format": "uri"
    },
    "console_url": {
      "type": "string",
      "format": "uri"
    },
    "agent_result_contract_id": {
      "type": "string"
    },
    "agent_result_contract_url": {
      "type": "string",
      "format": "uri"
    },
    "settlement_receipt_id": {
      "type": "string"
    },
    "usage_receipt_url": {
      "type": "string",
      "format": "uri"
    },
    "os_support_matrix_url": {
      "type": "string",
      "format": "uri"
    },
    "rail_binding_url": {
      "type": "string",
      "format": "uri"
    },
    "runtime_execution_plan_url": {
      "type": "string",
      "format": "uri"
    }
  }
}
