{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/codai-ro/json-schema/codai-ro-agent-run-schema.json",
  "title": "Agent run",
  "description": "Poll view of a persisted run (`GET /v1/agents/runs/{id}`).",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/codai-ro-agents-api-openapi.yml#/components/schemas/AgentRun",
  "type": "object",
  "required": [
    "id",
    "status",
    "task",
    "model",
    "result",
    "error",
    "step_count",
    "usage",
    "created_at",
    "started_at",
    "finished_at"
  ],
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid"
    },
    "status": {
      "$ref": "#/$defs/AgentRunStatus"
    },
    "task": {
      "type": "string",
      "description": "The submitted goal, verbatim."
    },
    "model": {
      "type": [
        "string",
        "null"
      ],
      "description": "Requested model alias (`codai` when omitted at submit)."
    },
    "result": {
      "type": [
        "string",
        "null"
      ],
      "description": "Final answer; set only once `status` is `completed`."
    },
    "error": {
      "type": [
        "string",
        "null"
      ],
      "description": "Failure message (≤ 2000 chars); set only when `status` is `failed`."
    },
    "step_count": {
      "type": "integer",
      "minimum": 0,
      "description": "Loop steps executed so far. Not incremented by the current executor."
    },
    "usage": {
      "$ref": "#/$defs/AgentUsage"
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "started_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "When execution was claimed; `null` while `queued`."
    },
    "finished_at": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time",
      "description": "Set on `completed`, `failed` and `cancelled`."
    }
  },
  "$defs": {
    "AgentRunStatus": {
      "type": "string",
      "description": "Run lifecycle — `queued` → `running` → one of `completed`, `failed`, `cancelled`.",
      "enum": [
        "queued",
        "running",
        "completed",
        "failed",
        "cancelled"
      ]
    },
    "AgentUsage": {
      "type": "object",
      "title": "Token usage",
      "description": "Aggregate token counts for the whole run.",
      "required": [
        "prompt_tokens",
        "completion_tokens"
      ],
      "properties": {
        "prompt_tokens": {
          "type": "integer",
          "minimum": 0
        },
        "completion_tokens": {
          "type": "integer",
          "minimum": 0
        }
      }
    }
  }
}