{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://agoragentic.com/schema/subagent-run.v1.json",
  "title": "Agoragentic Subagent Run",
  "description": "Run-level envelope for inline, fan-out, pool, or team subagent orchestration. It is a replayable planning artifact, not autonomous swarm authority.",
  "type": "object",
  "additionalProperties": true,
  "required": ["schema", "run_id", "mode", "status", "tasks", "controls", "public_boundary"],
  "properties": {
    "schema": { "const": "agoragentic.subagent-run.v1" },
    "run_id": { "type": "string" },
    "deployment_id": { "type": ["string", "null"] },
    "workspace_id": { "type": ["string", "null"] },
    "parent_agent_id": { "type": ["string", "null"] },
    "mode": {
      "type": "string",
      "enum": ["inline_agent", "fanout_agents", "agent_pool", "agent_team"]
    },
    "status": {
      "type": "string",
      "enum": ["planned", "running", "waiting", "approval_required", "succeeded", "failed", "cancelled", "blocked"]
    },
    "goal": { "type": ["string", "null"] },
    "tasks": {
      "type": "array",
      "items": { "$ref": "https://agoragentic.com/schema/subagent-task.v1.json" }
    },
    "events": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "event_type": {
            "type": "string",
            "enum": [
              "agent_spawned",
              "agent_message_sent",
              "agent_wait_started",
              "agent_wait_completed",
              "agent_status_changed",
              "agent_tool_called",
              "agent_policy_blocked",
              "agent_approval_required",
              "agent_receipt_written",
              "agent_killed",
              "agent_deadlock_detected",
              "agent_conflict_detected"
            ]
          }
        },
        "additionalProperties": true
      }
    },
    "receipt_links": {
      "type": "array",
      "items": { "$ref": "https://agoragentic.com/schema/subagent-receipt-link.v1.json" }
    },
    "controls": {
      "type": "object",
      "required": ["mode", "required_controls", "missing_controls", "ready", "team_mode_disabled_by_default"],
      "properties": {
        "mode": { "type": "string" },
        "allowed_for_harness_v0": { "type": "boolean" },
        "team_mode_disabled_by_default": { "type": "boolean" },
        "required_controls": { "type": "array", "items": { "type": "string" } },
        "missing_controls": { "type": "array", "items": { "type": "string" } },
        "ready": { "type": "boolean" },
        "blocked_reason": { "type": ["string", "null"] }
      },
      "additionalProperties": true
    },
    "public_boundary": {
      "type": "object",
      "properties": {
        "spend_triggered": { "const": false },
        "settlement_triggered": { "const": false },
        "marketplace_publication_triggered": { "const": false },
        "x402_route_created": { "const": false },
        "provider_execution_triggered": { "const": false },
        "private_ecf_context_exposed": { "const": false },
        "trust_mutation_triggered": { "const": false }
      },
      "additionalProperties": true
    },
    "created_at": { "type": "string", "format": "date-time" }
  }
}
