{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://example.invalid/agentplaykit/scenario.schema.json",
  "title": "AgentPlay scenario (agentplay: 1)",
  "type": "object",
  "required": [
    "agentplay",
    "name",
    "world"
  ],
  "additionalProperties": false,
  "properties": {
    "agentplay": {
      "const": 1,
      "description": "Scenario schema version"
    },
    "name": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9_-]*$"
    },
    "description": {
      "type": "string"
    },
    "seed": {
      "type": "integer",
      "default": 0
    },
    "world": {
      "$ref": "#/$defs/component"
    },
    "agents": {
      "type": "array",
      "minItems": 1,
      "items": {
        "allOf": [
          {
            "$ref": "#/$defs/agent"
          }
        ],
        "if": {
          "required": [
            "use"
          ]
        },
        "then": {
          "required": [
            "id"
          ]
        }
      }
    },
    "tournament": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "roles",
        "entrants"
      ],
      "properties": {
        "roles": {
          "type": "array",
          "minItems": 2,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "pattern": "^[A-Za-z0-9_-]+$"
          }
        },
        "entrants": {
          "type": "array",
          "minItems": 2,
          "items": {
            "allOf": [
              {
                "$ref": "#/$defs/entrant"
              }
            ],
            "if": {
              "required": [
                "use"
              ]
            },
            "then": {
              "required": [
                "name"
              ]
            }
          }
        },
        "games": {
          "type": "integer",
          "minimum": 1,
          "default": 2
        },
        "max_total_cost_usd": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0
        }
      }
    },
    "limits": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "max_steps": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 1
        },
        "max_seconds": {
          "type": [
            "number",
            "null"
          ],
          "exclusiveMinimum": 0
        },
        "max_cost_usd": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0
        },
        "max_illegal": {
          "type": "integer",
          "minimum": 1
        },
        "max_message_chars": {
          "type": "integer",
          "minimum": 1
        },
        "max_messages_per_turn": {
          "type": "integer",
          "minimum": 0
        },
        "max_tokens": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 1
        }
      }
    },
    "log": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "path": {
          "type": "string",
          "pattern": "\\.jsonl$"
        }
      }
    },
    "evaluators": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/component"
      }
    }
  },
  "$defs": {
    "component": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]+$"
        },
        "use": {
          "type": "string",
          "minLength": 1
        },
        "file": {
          "type": "string",
          "minLength": 1
        },
        "config": {
          "type": "object"
        }
      },
      "additionalProperties": false,
      "oneOf": [
        {
          "required": [
            "use"
          ]
        },
        {
          "required": [
            "file"
          ]
        }
      ],
      "description": "Either `use` (a reference) or `file` (split layout: a YAML file holding this component, relative to the scenario). An agent with `use` needs `id`; with `file`, `id` may come from the file."
    },
    "agent": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]+$"
        },
        "use": {
          "type": "string",
          "minLength": 1
        },
        "file": {
          "type": "string",
          "minLength": 1
        },
        "config": {
          "type": "object"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64
        }
      },
      "additionalProperties": false,
      "oneOf": [
        {
          "required": [
            "use"
          ]
        },
        {
          "required": [
            "file"
          ]
        }
      ],
      "description": "An agent: a component with an optional display `name` (SCN-015)."
    },
    "entrant": {
      "type": "object",
      "properties": {
        "use": {
          "type": "string",
          "minLength": 1
        },
        "file": {
          "type": "string",
          "minLength": 1
        },
        "config": {
          "type": "object"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 64
        }
      },
      "additionalProperties": false,
      "oneOf": [
        {
          "required": [
            "use"
          ]
        },
        {
          "required": [
            "file"
          ]
        }
      ],
      "description": "A tournament entrant: `name` plus `use`/`config` or `file` (SPEC-013 RPT-003)."
    }
  },
  "description": "Exactly one of `agents` and `tournament` (SCN-016)."
}
