{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://awooop.platform/contracts/v1/agent",
  "title": "Agent Contract",
  "description": "AwoooP Agent 合約 — 定義一個 agent 的模型、工具、預算與治理規則",
  "type": "object",
  "required": ["agent_id", "agent_name", "model", "provider"],
  "additionalProperties": false,
  "properties": {
    "agent_id": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9_-]{1,127}$",
      "description": "Agent 識別符（project 內唯一）"
    },
    "agent_name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 256,
      "description": "人類可讀 agent 名稱"
    },
    "model": {
      "type": "string",
      "minLength": 1,
      "maxLength": 128,
      "description": "LLM 模型識別符（如 claude-sonnet-4-6, qwen3:8b）"
    },
    "provider": {
      "type": "string",
      "enum": ["anthropic", "openai", "ollama", "gemini", "nvidia", "openrouter"],
      "description": "LLM Provider"
    },
    "max_tokens": {
      "type": "integer",
      "minimum": 1,
      "maximum": 200000,
      "description": "單次 completion 最大 token 數"
    },
    "temperature": {
      "type": "number",
      "minimum": 0.0,
      "maximum": 2.0,
      "description": "Sampling temperature"
    },
    "system_prompt_ref": {
      "type": "object",
      "required": ["artifact_id", "sha256"],
      "additionalProperties": false,
      "properties": {
        "artifact_id": {"type": "string"},
        "sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "System prompt 檔案的 SHA-256 hex digest（ADR-112 artifact integrity）"
        }
      },
      "description": "System prompt artifact reference（必含 sha256）"
    },
    "tools": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["tool_name"],
        "additionalProperties": true,
        "properties": {
          "tool_name": {"type": "string"},
          "mcp_gateway_id": {"type": "string"},
          "sha256": {
            "type": "string",
            "pattern": "^[0-9a-f]{64}$"
          }
        }
      },
      "description": "Agent 可用工具清單"
    },
    "budget_limit_usd_per_run": {
      "type": ["number", "null"],
      "minimum": 0,
      "description": "單次 run 費用上限（USD）；null = 繼承 tenant 預算"
    },
    "require_approval": {
      "type": "boolean",
      "default": false,
      "description": "執行前是否需要人工審核"
    },
    "approval_timeout_seconds": {
      "type": "integer",
      "minimum": 60,
      "maximum": 86400,
      "description": "審核超時秒數（require_approval=true 時有效）"
    },
    "max_parallel_runs": {
      "type": "integer",
      "minimum": 1,
      "maximum": 100,
      "default": 1,
      "description": "最大並行 run 數"
    },
    "tags": {
      "type": "array",
      "items": {"type": "string"},
      "uniqueItems": true,
      "description": "Agent 分類標籤"
    }
  }
}
