{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Agent Definition 2.0.0",
  "description": "baijimu bundle object 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"
      ]
    },
    "timeoutSeconds": {
      "type": [
        "integer",
        "null"
      ],
      "minimum": 1,
      "maximum": 86400
    },
    "claudeJsonConfig": {
      "type": [
        "string",
        "null"
      ]
    },
    "systemPrompt": {
      "type": [
        "string",
        "null"
      ]
    },
    "inheritSystemPrompt": {
      "type": "boolean",
      "default": false
    },
    "mcpServersConfig": {
      "oneOf": [
        {
          "type": "object"
        },
        {
          "type": "string"
        },
        {
          "type": "null"
        }
      ]
    },
    "skills": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "skillKey",
          "semanticVersion"
        ],
        "additionalProperties": false,
        "properties": {
          "skillKey": {
            "$ref": "#/$defs/resourceKey"
          },
          "semanticVersion": {
            "type": "string",
            "pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[A-Za-z-][0-9A-Za-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\\+([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?$"
          }
        }
      },
      "default": []
    },
    "enabledTools": {
      "anyOf": [
        {
          "type": "null"
        },
        {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      ]
    },
    "toolPromptOverrides": {
      "type": [
        "object",
        "null"
      ]
    },
    "subAgents": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "agentKey"
        ],
        "properties": {
          "agentKey": {
            "$ref": "#/$defs/resourceKey"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "callName": {
            "type": [
              "string",
              "null"
            ],
            "minLength": 1
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "additionalProperties": false
      },
      "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
    },
    "runtimeMethods": {
      "description": "Candidate scope. Omitted or null means all; explicit none and selected remain unchanged. Actual access remains bounded by the Grant and current user permissions.",
      "default": {
        "mode": "all"
      },
      "oneOf": [
        {
          "type": "null"
        },
        {
          "$ref": "#/$defs/runtimeMethodScope"
        }
      ]
    },
    "defaultRuntime": {
      "anyOf": [
        {
          "type": "null"
        },
        {
          "type": "object",
          "required": [
            "runtimeKey"
          ],
          "additionalProperties": false,
          "properties": {
            "runtimeKey": {
              "type": "string",
              "maxLength": 128,
              "pattern": "^[a-z0-9][a-z0-9._-]*$"
            },
            "semanticVersion": {
              "anyOf": [
                {
                  "type": "string",
                  "pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[A-Za-z-][0-9A-Za-z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[A-Za-z-][0-9A-Za-z-]*))*))?(?:\\+([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?$"
                },
                {
                  "type": "null"
                }
              ]
            }
          }
        }
      ]
    },
    "parentAgentKey": {
      "anyOf": [
        {
          "$ref": "#/$defs/resourceKey"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "$defs": {
    "nonEmptyString": {
      "type": "string",
      "minLength": 1,
      "pattern": "\\S"
    },
    "resourceKey": {
      "type": "string",
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
    },
    "runtimeMethod": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "service",
        "method"
      ],
      "properties": {
        "service": {
          "$ref": "#/$defs/nonEmptyString"
        },
        "method": {
          "$ref": "#/$defs/nonEmptyString"
        }
      }
    },
    "runtimeMethodList": {
      "type": "array",
      "maxItems": 1024,
      "uniqueItems": true,
      "items": {
        "$ref": "#/$defs/runtimeMethod"
      }
    },
    "runtimeMethodScope": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "mode"
          ],
          "properties": {
            "mode": {
              "const": "all"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "mode"
          ],
          "properties": {
            "mode": {
              "const": "none"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "mode",
            "methods"
          ],
          "properties": {
            "mode": {
              "const": "selected"
            },
            "methods": {
              "allOf": [
                {
                  "$ref": "#/$defs/runtimeMethodList"
                },
                {
                  "type": "array",
                  "minItems": 1
                }
              ]
            }
          }
        }
      ]
    }
  },
  "$id": "https://docs.baijimu.com/contracts/agent-definition/2.0.0/schema.json"
}
