{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://contextosai.com/schemas/agent-delegation.v1.schema.json",
  "title": "AgentDelegationEnvelope v1",
  "type": "object",
  "required": [
    "envelope_version", "delegation_id", "parent_run_id", "child_run_id", "trace_id",
    "tenant_id", "issuer", "subject", "principal_chain", "scope", "sub_budget",
    "effect_policy", "issued_at", "expires_at", "parent_claim_hash"
  ],
  "properties": {
    "envelope_version": { "const": "contextos.agent_delegation.v1" },
    "delegation_id": { "type": "string" },
    "parent_run_id": { "type": "string" },
    "child_run_id": { "type": "string" },
    "trace_id": { "type": "string" },
    "tenant_id": { "type": "string" },
    "issuer": { "type": "string" },
    "subject": { "type": "string" },
    "principal_chain": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "https://contextosai.com/schemas/run-context.v1.schema.json#/$defs/Principal" }
    },
    "scope": {
      "type": "object",
      "required": ["allowed_intents", "allowed_capabilities", "data_classification_ceiling", "output_schema_ref"],
      "properties": {
        "allowed_intents": { "type": "array", "minItems": 1, "items": { "type": "string" }, "uniqueItems": true },
        "allowed_capabilities": { "type": "array", "items": { "type": "string" }, "uniqueItems": true },
        "data_classification_ceiling": { "type": "string", "enum": ["PUBLIC", "INTERNAL", "CONFIDENTIAL", "RESTRICTED"] },
        "output_schema_ref": { "type": "string" }
      },
      "additionalProperties": false
    },
    "sub_budget": { "$ref": "https://contextosai.com/schemas/run-context.v1.schema.json#/$defs/RunBudget" },
    "effect_policy": { "type": "string", "enum": ["isolate_until_accepted", "read_only"] },
    "issued_at": { "type": "string", "format": "date-time" },
    "expires_at": { "type": "string", "format": "date-time" },
    "cancellation_ref": { "type": "string" },
    "parent_claim_hash": { "type": "string" }
  },
  "additionalProperties": false
}
