{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.anguskit.com/schema/anguscopilot/1.0.0/agent.json",
  "title": "AngusCopilot Agent Specification",
  "description": "AngusCopilot Agent 顶层 Spec（specification: anguscopilot/1.0.0）。OpenAPI 风格的根字段：specification + info + spec。W11 增量字段：spec.multiAgent / spec.observability / spec.bulkhead / spec.degradation。",

  "type": "object",
  "required": ["specification", "info", "spec"],

  "properties": {

    "specification": {
      "description": "规范族 / 版本。Agent 必须取 'anguscopilot/<semver>' 形式。 [stable]",
      "$ref": "common.json#/$defs/SpecificationField",
      "pattern": "^anguscopilot\\/(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-(?:alpha|beta|rc)(?:\\.(?:0|[1-9]\\d*))?)?$"
    },

    "info": {
      "$ref": "info.json"
    },

    "spec": {
      "type": "object",
      "required": ["llm", "reasoning"],
      "properties": {
        "type": {
          "description": "Agent 类型 discriminator（W12 新增）。决定可选 capability 集与默认 reasoning，由 spec/AgentTypeRegistry 解析；未识别值会被记录为 INFO 但不阻断 materialize（前向兼容）。 [beta]",
          "type": "string",
          "minLength": 1,
          "maxLength": 64,
          "pattern": "^[a-z][a-z0-9_-]*$",
          "examples": ["general", "coding", "chat", "rag", "workflow"],
          "default": "general"
        },
        "llm": { "$ref": "llm.json" },
        "reasoning": { "$ref": "reasoning.json" },
        "prompt": {
          "description": "Prompt 模板。 [stable]",
          "type": "object",
          "properties": {
            "system": { "type": "string" },
            "user": { "type": "string" },
            "locale": {
              "type": "string",
              "pattern": "^[a-z]{2}(-[A-Z]{2})?$",
              "examples": ["zh-CN", "en-US", "ja-JP"]
            },
            "templateEngine": {
              "type": "string",
              "enum": ["plain", "mustache", "jinja2"],
              "default": "mustache"
            }
          },
          "patternProperties": { "^x-": true },
          "unevaluatedProperties": false
        },
        "capabilities": { "$ref": "capabilities.json" },
        "memory": { "$ref": "memory.json" },
        "safety": { "$ref": "safety.json" },
        "quota": { "$ref": "quota.json" },
        "credentials": { "$ref": "credentials.json" },
        "clarification": { "$ref": "clarification.json" },
        "mcp": { "$ref": "mcp.json" },
        "databases": { "$ref": "databases.json" },
        "events": {
          "description": "事件订阅与发布配置。 [stable]",
          "type": "object",
          "properties": {
            "deliveryMode": {
              "type": "string",
              "enum": ["sync", "async", "hybrid"],
              "default": "hybrid"
            },
            "maxChainDepth": {
              "type": "integer",
              "minimum": 1,
              "maximum": 32,
              "default": 8
            }
          },
          "patternProperties": { "^x-": true },
          "unevaluatedProperties": false
        },

        "multiAgent": {
          "description": "Multi-Agent 拓扑配置（W11 新增；与 §7 对齐）。 [beta]",
          "type": "object",
          "required": ["pattern"],
          "properties": {
            "pattern": {
              "description": "拓扑模式。 [beta]",
              "type": "string",
              "enum": ["standalone", "supervisor", "pipeline", "evaluator-optimizer", "parallelization", "handoff"]
            },
            "workspaceId": {
              "description": "加入或创建的 Workspace 标识。 [beta]",
              "$ref": "common.json#/$defs/Identifier"
            },
            "subContext": {
              "description": "跨 Agent 上下文传递层级（与 §7.4.3 对齐）。 [beta]",
              "type": "object",
              "properties": {
                "mode": {
                  "type": "string",
                  "enum": ["inherit", "scoped", "isolated"],
                  "default": "scoped"
                },
                "whitelist": {
                  "type": "array",
                  "items": { "type": "string", "minLength": 1 },
                  "uniqueItems": true
                }
              },
              "patternProperties": { "^x-": true },
              "unevaluatedProperties": false
            },
            "quota": {
              "description": "跨 Agent 配额策略（与 §7.10.2 对齐）。 [beta]",
              "type": "object",
              "properties": {
                "split": {
                  "type": "string",
                  "enum": ["share", "weighted", "isolated"],
                  "default": "share"
                },
                "weights": {
                  "description": "split=weighted 时各 worker 的权重（C8 约束：每项 ∈ [0,1]，总和约 1）。 [beta]",
                  "type": "object",
                  "additionalProperties": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 1
                  },
                  "minProperties": 1
                }
              },
              "patternProperties": { "^x-": true },
              "$comment": "C8 跨字段约束：split=weighted 时必须 weights。",
              "if": {
                "properties": { "split": { "const": "weighted" } },
                "required": ["split"]
              },
              "then": {
                "required": ["weights"]
              },
              "unevaluatedProperties": false
            },
            "routing": {
              "description": "Supervisor 模式的子 Agent 路由策略（C2 约束：pattern=supervisor 时必填）。 [beta]",
              "type": "object",
              "required": ["strategy"],
              "properties": {
                "strategy": {
                  "type": "string",
                  "enum": ["static", "capability-match", "llm-routing", "load-balance"]
                },
                "fallback": {
                  "description": "无可用 worker 时的兜底策略。 [beta]",
                  "type": "string",
                  "enum": ["wait", "deny", "best-effort"],
                  "default": "wait"
                }
              },
              "patternProperties": { "^x-": true },
              "unevaluatedProperties": false
            },
            "handoff": {
              "description": "Handoff 模式专用（C4 约束：pattern=handoff 时 maxHops ∈ [1,10]）。 [beta]",
              "type": "object",
              "properties": {
                "maxHops": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 10,
                  "default": 5
                },
                "ttl": {
                  "$ref": "common.json#/$defs/Duration",
                  "default": "30m"
                },
                "escalation": {
                  "type": "boolean",
                  "default": false
                }
              },
              "patternProperties": { "^x-": true },
              "unevaluatedProperties": false
            },
            "parallelization": {
              "description": "Parallelization 模式专用（C3 约束：pattern=parallelization 时 waitStrategy 必填）。 [beta]",
              "type": "object",
              "required": ["waitStrategy"],
              "properties": {
                "waitStrategy": {
                  "type": "string",
                  "enum": ["all-required", "k-of-n", "first-good", "best-effort"]
                },
                "k": {
                  "description": "waitStrategy=k-of-n 时必填。 [beta]",
                  "type": "integer",
                  "minimum": 1
                },
                "aggregator": {
                  "type": "string",
                  "enum": ["concat", "fold", "vote", "merge", "top-k"]
                }
              },
              "patternProperties": { "^x-": true },
              "$comment": "waitStrategy=k-of-n 时必须 k。",
              "if": {
                "properties": { "waitStrategy": { "const": "k-of-n" } },
                "required": ["waitStrategy"]
              },
              "then": {
                "required": ["k"]
              },
              "unevaluatedProperties": false
            },
            "pipeline": {
              "description": "Pipeline 模式专用。 [beta]",
              "type": "object",
              "properties": {
                "onError": {
                  "type": "string",
                  "enum": ["continue", "retry", "rollback"],
                  "default": "rollback"
                },
                "stages": {
                  "description": "stage 名称序列（顺序固定）。 [beta]",
                  "type": "array",
                  "items": { "$ref": "common.json#/$defs/Identifier" },
                  "minItems": 2,
                  "uniqueItems": true
                }
              },
              "patternProperties": { "^x-": true },
              "unevaluatedProperties": false
            },
            "evaluatorOptimizer": {
              "description": "Evaluator-Optimizer 模式专用（C5 约束：pattern=evaluator-optimizer 时 threshold 必填）。 [beta]",
              "type": "object",
              "required": ["threshold"],
              "properties": {
                "maxIterations": {
                  "type": "integer",
                  "minimum": 1,
                  "default": 4
                },
                "threshold": {
                  "description": "评估分数阈值，达到则停止迭代。 [beta]",
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1
                },
                "evaluatorRef": {
                  "description": "评估 Agent 引用。 [beta]",
                  "type": "string",
                  "minLength": 1
                }
              },
              "patternProperties": { "^x-": true },
              "unevaluatedProperties": false
            },
            "crossTenant": {
              "description": "跨租户合作开关（与 §7.10.4 对齐）。 [experimental]",
              "type": "object",
              "properties": {
                "enabled": { "type": "boolean", "default": false }
              },
              "patternProperties": { "^x-": true },
              "unevaluatedProperties": false
            },
            "capabilityVisibility": {
              "description": "对兄弟 Agent 暴露 Capability 的控制。 [beta]",
              "type": "object",
              "properties": {
                "exposeToSiblings": { "type": "boolean", "default": false },
                "exposedTags": {
                  "type": "array",
                  "items": { "type": "string" },
                  "uniqueItems": true
                }
              },
              "patternProperties": { "^x-": true },
              "unevaluatedProperties": false
            }
          },
          "patternProperties": { "^x-": true },
          "unevaluatedProperties": false
        },

        "observability": {
          "description": "可观测性配置（W11 新增；与 §13.7 / §6.8 对齐）。 [beta]",
          "type": "object",
          "properties": {
            "tracing": {
              "description": "OpenTelemetry 追踪配置。 [beta]",
              "type": "object",
              "properties": {
                "sampler": {
                  "type": "string",
                  "enum": ["always-on", "always-off", "probability", "tail-based"],
                  "default": "tail-based"
                },
                "probability": {
                  "description": "sampler=probability 时使用。 [beta]",
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1
                },
                "errorSampleRate": {
                  "description": "错误请求强制采样率（D1 约束：sampler=tail-based 时必须 1.0）。 [beta]",
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1,
                  "default": 1.0
                }
              },
              "patternProperties": { "^x-": true },
              "$comment": "D1 跨字段约束：sampler=tail-based 时 errorSampleRate 必须 1.0。",
              "if": {
                "properties": { "sampler": { "const": "tail-based" } },
                "required": ["sampler"]
              },
              "then": {
                "properties": {
                  "errorSampleRate": { "const": 1.0 }
                },
                "required": ["errorSampleRate"]
              },
              "unevaluatedProperties": false
            },
            "recording": {
              "description": "全链路录制（与 §14.3.1 / §6.8.2 对齐）。 [beta]",
              "type": "object",
              "properties": {
                "enabled": { "type": "boolean", "default": false },
                "sampleRate": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 1,
                  "default": 0.01
                },
                "piiRedactor": {
                  "description": "录制启用时必填（D2 约束）。 [beta]",
                  "type": "string",
                  "minLength": 1
                },
                "retentionDays": {
                  "type": "integer",
                  "minimum": 1,
                  "default": 30
                }
              },
              "patternProperties": { "^x-": true },
              "$comment": "D2 跨字段约束：recording.enabled=true 时必须 piiRedactor。",
              "if": {
                "properties": { "enabled": { "const": true } },
                "required": ["enabled"]
              },
              "then": {
                "required": ["piiRedactor"]
              },
              "unevaluatedProperties": false
            },
            "metrics": {
              "description": "指标体系开关。 [beta]",
              "type": "object",
              "properties": {
                "exporter": {
                  "type": "string",
                  "enum": ["prometheus", "otlp", "none"],
                  "default": "prometheus"
                },
                "intervalSeconds": {
                  "type": "integer",
                  "minimum": 5,
                  "maximum": 300,
                  "default": 15
                }
              },
              "patternProperties": { "^x-": true },
              "unevaluatedProperties": false
            }
          },
          "patternProperties": { "^x-": true },
          "unevaluatedProperties": false
        },

        "bulkhead": {
          "description": "Bulkhead 五维隔离配置（W11 新增；与 §13.3 对齐）。 [beta]",
          "type": "object",
          "properties": {
            "byTenant": {
              "type": "object",
              "properties": {
                "maxConcurrent": { "type": "integer", "minimum": 1 },
                "queueCapacity": { "type": "integer", "minimum": 0, "default": 100 }
              },
              "patternProperties": { "^x-": true },
              "unevaluatedProperties": false
            },
            "byAgent": {
              "type": "object",
              "properties": {
                "maxConcurrent": { "type": "integer", "minimum": 1 },
                "queueCapacity": { "type": "integer", "minimum": 0, "default": 50 }
              },
              "patternProperties": { "^x-": true },
              "unevaluatedProperties": false
            },
            "byCapability": {
              "description": "按 Capability ID 单独限流。键为 CapabilityRef。 [beta]",
              "type": "object",
              "additionalProperties": {
                "type": "object",
                "properties": {
                  "maxConcurrent": { "type": "integer", "minimum": 1 }
                },
                "patternProperties": { "^x-": true },
                "unevaluatedProperties": false
              }
            },
            "byModel": {
              "description": "按 LLM 模型隔离。键为模型名。 [beta]",
              "type": "object",
              "additionalProperties": {
                "type": "object",
                "properties": {
                  "maxConcurrent": { "type": "integer", "minimum": 1 },
                  "tokensPerMinute": { "type": "integer", "minimum": 1 }
                },
                "patternProperties": { "^x-": true },
                "unevaluatedProperties": false
              }
            },
            "byHttpHost": {
              "description": "按外部 HTTP 主机连接池隔离（D3 约束：键不能为空字符串）。 [beta]",
              "type": "object",
              "propertyNames": {
                "type": "string",
                "minLength": 1
              },
              "additionalProperties": {
                "type": "object",
                "properties": {
                  "maxConnections": { "type": "integer", "minimum": 1 },
                  "connectTimeout": { "$ref": "common.json#/$defs/Duration" },
                  "readTimeout": { "$ref": "common.json#/$defs/Duration" }
                },
                "patternProperties": { "^x-": true },
                "unevaluatedProperties": false
              }
            }
          },
          "patternProperties": { "^x-": true },
          "unevaluatedProperties": false
        },

        "degradation": {
          "description": "降级策略配置（W11 新增；与 §13.10 对齐）。 [beta]",
          "type": "object",
          "properties": {
            "matrix": {
              "description": "降级规则矩阵（D4 约束：每条必须 trigger + action 同时出现）。 [beta]",
              "type": "array",
              "items": {
                "type": "object",
                "required": ["trigger", "action"],
                "properties": {
                  "trigger": {
                    "description": "触发条件（如 'llm-timeout'、'quota-near-exhausted'、'vector-store-failed'）。 [beta]",
                    "type": "string",
                    "minLength": 1
                  },
                  "action": {
                    "description": "降级动作（如 'fallback-model'、'bm25-fallback'、'reject'）。 [beta]",
                    "type": "string",
                    "minLength": 1
                  },
                  "params": {
                    "type": "object",
                    "additionalProperties": true
                  }
                },
                "dependentRequired": {
                  "trigger": ["action"],
                  "action": ["trigger"]
                },
                "patternProperties": { "^x-": true },
                "unevaluatedProperties": false
              }
            },
            "canary": {
              "description": "降级灰度配置（D5 约束：percent ∈ [1,100]）。 [beta]",
              "type": "object",
              "properties": {
                "enabled": { "type": "boolean", "default": false },
                "percent": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 100
                },
                "tenantWhitelist": {
                  "type": "array",
                  "items": { "$ref": "common.json#/$defs/Identifier" },
                  "uniqueItems": true
                }
              },
              "patternProperties": { "^x-": true },
              "$comment": "canary.enabled=true 时必须 percent。",
              "if": {
                "properties": { "enabled": { "const": true } },
                "required": ["enabled"]
              },
              "then": {
                "required": ["percent"]
              },
              "unevaluatedProperties": false
            }
          },
          "patternProperties": { "^x-": true },
          "unevaluatedProperties": false
        },

        "autonomy": {
          "description": "Agent 自主等级配置（M0 新增，§5.7）。控制推理决策与人工介入边界。 [beta]",
          "type": "object",
          "required": ["level"],
          "properties": {
            "level": {
              "description": "自主等级。AUTONOMOUS=完全自治；ASSISTED=可执行但需上报；HITL=关键步骤需人工审批；WORKFLOW=完全按工作流执行（不允许 Agent 自由推理）。",
              "type": "string",
              "enum": ["AUTONOMOUS", "ASSISTED", "HITL", "WORKFLOW"],
              "default": "AUTONOMOUS"
            },
            "hitl": {
              "description": "HITL 等级专用。timeoutSeconds 与 onTimeout 决定审批超时行为。",
              "type": "object",
              "properties": {
                "approvers": {
                  "type": "array",
                  "items": { "type": "string", "minLength": 1, "maxLength": 256 },
                  "minItems": 1,
                  "uniqueItems": true
                },
                "timeoutSeconds": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 604800,
                  "default": 3600
                },
                "onTimeout": {
                  "type": "string",
                  "enum": ["DENY", "ESCALATE", "AUTO_APPROVE"],
                  "default": "DENY"
                },
                "scope": {
                  "description": "需审批的动作范围。",
                  "type": "array",
                  "items": {
                    "type": "string",
                    "enum": ["destructive", "sensitive", "external-write", "all"]
                  },
                  "uniqueItems": true,
                  "default": ["destructive", "sensitive"]
                }
              },
              "patternProperties": { "^x-": true },
              "unevaluatedProperties": false
            }
          },
          "patternProperties": { "^x-": true },
          "unevaluatedProperties": false
        },

        "workflow": {
          "description": "Agent 关联的工作流（M0 新增，§5.6 + §5.7）。autonomy.level=WORKFLOW 时必填。 [beta]",
          "type": "object",
          "required": ["ref"],
          "properties": {
            "ref": {
              "description": "工作流引用（'workflow://{tenant}/{id}@{version}'，@latest 表最新）。",
              "type": "string",
              "pattern": "^workflow:\\/\\/[^\\s]+$",
              "maxLength": 1024
            },
            "inputMapping": {
              "description": "Agent 入参 → 工作流变量的映射（SpEL 表达式）。",
              "type": "object",
              "additionalProperties": { "type": "string", "maxLength": 4096 }
            },
            "resumeOnApproval": {
              "description": "是否在 HITL 审批通过后自动 resume 工作流。",
              "type": "boolean",
              "default": true
            }
          },
          "patternProperties": { "^x-": true },
          "unevaluatedProperties": false
        }
      },
      "patternProperties": { "^x-": true },
      "unevaluatedProperties": false,

      "$comment": "跨字段约束：模式与配置的一致性、密钥引用合规、Multi-Agent 拓扑约束等。",
      "allOf": [

        {
          "$comment": "ReAct/Plan/Reflect 模式必须声明至少一个 capability；Ask/ToolCall 可选。",
          "if": {
            "properties": {
              "reasoning": {
                "properties": { "mode": { "enum": ["react", "plan", "reflect"] } },
                "required": ["mode"]
              }
            },
            "required": ["reasoning"]
          },
          "then": {
            "required": ["capabilities"],
            "properties": {
              "capabilities": { "minItems": 1 }
            }
          }
        },

        {
          "$comment": "memory.semantic 启用时，必须存在 LLM 配置。",
          "if": {
            "properties": {
              "memory": {
                "properties": {
                  "semantic": {
                    "properties": { "enabled": { "const": true } },
                    "required": ["enabled"]
                  }
                },
                "required": ["semantic"]
              }
            },
            "required": ["memory"]
          },
          "then": {
            "required": ["llm"]
          }
        },

        {
          "$comment": "MCP server 启用时，安全鉴权强制非 'none'（外部入站请求不得无鉴权）。",
          "if": {
            "properties": {
              "mcp": {
                "properties": {
                  "server": {
                    "properties": { "enabled": { "const": true } },
                    "required": ["enabled"]
                  }
                },
                "required": ["server"]
              }
            },
            "required": ["mcp"]
          },
          "then": {
            "properties": {
              "mcp": {
                "properties": {
                  "server": {
                    "properties": {
                      "auth": {
                        "properties": { "mode": { "not": { "const": "none" } } },
                        "required": ["mode"]
                      }
                    },
                    "required": ["auth"]
                  }
                }
              }
            }
          }
        },

        {
          "$comment": "C1: pattern=standalone 时禁止 multiAgent 子段（除 pattern 自身）。",
          "if": {
            "properties": {
              "multiAgent": {
                "properties": { "pattern": { "const": "standalone" } },
                "required": ["pattern"]
              }
            },
            "required": ["multiAgent"]
          },
          "then": {
            "properties": {
              "multiAgent": {
                "not": {
                  "anyOf": [
                    { "required": ["workspaceId"] },
                    { "required": ["subContext"] },
                    { "required": ["routing"] },
                    { "required": ["handoff"] },
                    { "required": ["parallelization"] },
                    { "required": ["pipeline"] },
                    { "required": ["evaluatorOptimizer"] }
                  ]
                }
              }
            }
          }
        },

        {
          "$comment": "C2: pattern=supervisor 时必须 routing 段。",
          "if": {
            "properties": {
              "multiAgent": {
                "properties": { "pattern": { "const": "supervisor" } },
                "required": ["pattern"]
              }
            },
            "required": ["multiAgent"]
          },
          "then": {
            "properties": {
              "multiAgent": {
                "required": ["routing"]
              }
            }
          }
        },

        {
          "$comment": "C3: pattern=parallelization 时必须 parallelization 段。",
          "if": {
            "properties": {
              "multiAgent": {
                "properties": { "pattern": { "const": "parallelization" } },
                "required": ["pattern"]
              }
            },
            "required": ["multiAgent"]
          },
          "then": {
            "properties": {
              "multiAgent": {
                "required": ["parallelization"]
              }
            }
          }
        },

        {
          "$comment": "C4: pattern=handoff 时必须 handoff 段（且 maxHops ∈ [1,10] 由 handoff 子 schema 已约束）。",
          "if": {
            "properties": {
              "multiAgent": {
                "properties": { "pattern": { "const": "handoff" } },
                "required": ["pattern"]
              }
            },
            "required": ["multiAgent"]
          },
          "then": {
            "properties": {
              "multiAgent": {
                "required": ["handoff"]
              }
            }
          }
        },

        {
          "$comment": "C5: pattern=evaluator-optimizer 时必须 evaluatorOptimizer 段（threshold 由该段已 required）。",
          "if": {
            "properties": {
              "multiAgent": {
                "properties": { "pattern": { "const": "evaluator-optimizer" } },
                "required": ["pattern"]
              }
            },
            "required": ["multiAgent"]
          },
          "then": {
            "properties": {
              "multiAgent": {
                "required": ["evaluatorOptimizer"]
              }
            }
          }
        },

        {
          "$comment": "C6: pattern=pipeline + onError=rollback 时必须有 stages 字段（stage 级 compensation 校验由代码层语义校验补充）。",
          "if": {
            "properties": {
              "multiAgent": {
                "properties": {
                  "pattern": { "const": "pipeline" },
                  "pipeline": {
                    "properties": { "onError": { "const": "rollback" } },
                    "required": ["onError"]
                  }
                },
                "required": ["pattern", "pipeline"]
              }
            },
            "required": ["multiAgent"]
          },
          "then": {
            "properties": {
              "multiAgent": {
                "properties": {
                  "pipeline": {
                    "required": ["stages"]
                  }
                }
              }
            }
          }
        },

        {
          "$comment": "C7: crossTenant.enabled=true 时强制 subContext.mode=isolated。",
          "if": {
            "properties": {
              "multiAgent": {
                "properties": {
                  "crossTenant": {
                    "properties": { "enabled": { "const": true } },
                    "required": ["enabled"]
                  }
                },
                "required": ["crossTenant"]
              }
            },
            "required": ["multiAgent"]
          },
          "then": {
            "properties": {
              "multiAgent": {
                "required": ["subContext"],
                "properties": {
                  "subContext": {
                    "properties": {
                      "mode": { "const": "isolated" }
                    },
                    "required": ["mode"]
                  }
                }
              }
            }
          }
        },

        {
          "$comment": "C-AUT-1: autonomy.level=HITL 时必须提供 autonomy.hitl.approvers。",
          "if": {
            "properties": {
              "autonomy": {
                "properties": { "level": { "const": "HITL" } },
                "required": ["level"]
              }
            },
            "required": ["autonomy"]
          },
          "then": {
            "properties": {
              "autonomy": {
                "required": ["hitl"],
                "properties": {
                  "hitl": { "required": ["approvers"] }
                }
              }
            }
          }
        },

        {
          "$comment": "C-AUT-2: autonomy.level=WORKFLOW 时必须提供 spec.workflow。",
          "if": {
            "properties": {
              "autonomy": {
                "properties": { "level": { "const": "WORKFLOW" } },
                "required": ["level"]
              }
            },
            "required": ["autonomy"]
          },
          "then": {
            "required": ["workflow"]
          }
        },

        {
          "$comment": "C-AUT-3: spec.workflow 出现时 reasoning.mode 不能为 react/plan/reflect（避免 Agent 自由推理与工作流冲突；M0 仅允许 ask / toolCall）。",
          "if": {
            "required": ["workflow"]
          },
          "then": {
            "properties": {
              "reasoning": {
                "properties": {
                  "mode": {
                    "enum": ["ask", "toolCall"]
                  }
                }
              }
            }
          }
        }
      ]
    }
  },

  "patternProperties": {
    "^x-": true
  },
  "unevaluatedProperties": false
}
