{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.baijimu.com/contracts/agent-definition/1.0.0/schema.json",
  "title": "Baijimu Bundle Agent Definition Authoring Contract",
  "description": "baijimu bundle resource create/update 的 AGENT definition 合同。资源身份由 CLI 参数和 Bundle Owner 注入，不得出现在 definition 中。",
  "type": "object",
  "additionalProperties": false,
  "required": ["configName"],
  "properties": {
    "configName": { "$ref": "#/$defs/nonEmptyString" },
    "description": { "type": ["string", "null"] },
    "modelName": { "type": ["string", "null"] },
    "runtimeId": { "type": ["integer", "null"], "minimum": 1 },
    "runtimeVersionId": { "type": ["integer", "null"], "minimum": 1 },
    "timeoutSeconds": { "type": ["integer", "null"], "minimum": 1, "maximum": 86400 },
    "claudeJsonConfig": { "type": ["string", "null"] },
    "systemPrompt": { "type": ["string", "null"] },
    "parentAgentConfigId": { "type": ["integer", "null"], "minimum": 1 },
    "promptConfig": {
      "oneOf": [
        { "type": "null" },
        {
          "type": "object",
          "properties": { "stages": false }
        }
      ]
    },
    "inheritSystemPrompt": { "type": "boolean", "default": false },
    "mcpServersConfig": {
      "oneOf": [
        { "type": "object" },
        { "type": "string" },
        { "type": "null" }
      ]
    },
    "skills": {
      "type": "array",
      "items": { "type": "string" },
      "default": []
    },
    "enabledTools": {
      "oneOf": [
        { "type": "array" },
        { "type": "object" },
        { "type": "null" }
      ]
    },
    "toolPromptOverrides": {
      "type": ["object", "null"]
    },
    "subAgents": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["agentKey"],
        "properties": {
          "agentKey": { "$ref": "#/$defs/resourceKey" },
          "key": { "$ref": "#/$defs/nonEmptyString" },
          "description": { "type": ["string", "null"] }
        },
        "additionalProperties": true
      },
      "default": []
    },
    "containerPorts": {
      "type": "array",
      "items": true,
      "default": []
    },
    "localStorageDirs": {
      "type": "array",
      "items": true,
      "default": []
    },
    "containerUserHomePath": { "type": ["string", "null"] },
    "environmentVariables": {
      "type": "object",
      "additionalProperties": {
        "oneOf": [
          { "type": "string" },
          { "type": "number" },
          { "type": "boolean" },
          { "type": "null" }
        ]
      },
      "default": {}
    },
    "globalMount": { "type": ["string", "null"] },
    "pricingCoefficient": { "type": "number", "exclusiveMinimum": 0, "default": 1 }
  },
  "$defs": {
    "nonEmptyString": {
      "type": "string",
      "minLength": 1,
      "pattern": "\\S"
    },
    "resourceKey": {
      "type": "string",
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
    }
  }
}
