{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/welkaim/ea-codex/schemas/v1/agent-interaction-contract.json",
  "title": "AgentInteractionContract",
  "description": "Inter-agent communication contract: defines which agent may communicate with which other agent, for which purpose, with which message types, under which data-minimization rule, through which routing boundary, with which evidence obligation, and under which escalation condition. Named in Chapter 13.",
  "type": "object",
  "required": ["apiVersion", "kind", "metadata", "spec"],
  "properties": {
    "apiVersion": { "$ref": "_common.json#/$defs/apiVersion" },
    "kind": { "type": "string", "const": "AgentInteractionContract" },
    "metadata": { "$ref": "_common.json#/$defs/metadata" },
    "spec": {
      "type": "object",
      "required": ["sourceAgent", "targetAgent", "purpose", "messageControls"],
      "properties": {
        "sourceAgent": {
          "type": "object",
          "required": ["agentContractRef"],
          "properties": {
            "agentContractRef": { "type": "string" },
            "providerClass": { "type": "string" }
          },
          "additionalProperties": true
        },
        "targetAgent": {
          "type": "object",
          "required": ["agentContractRef"],
          "properties": {
            "agentContractRef": { "type": "string" },
            "providerClass": { "type": "string" }
          },
          "additionalProperties": true
        },
        "purpose": {
          "type": "string",
          "description": "Purpose statement that bounds the interaction."
        },
        "purposeRef": { "$ref": "_common.json#/$defs/objectiveRef" },
        "allowedMessageTypes": {
          "type": "array",
          "items": { "type": "string" }
        },
        "messageControls": {
          "type": "array",
          "items": {
            "type": "string",
            "examples": [
              "purpose-bound-message",
              "data-minimization",
              "jurisdiction-aware-routing",
              "delegation-evidence-record",
              "patient-identifier-redaction"
            ]
          },
          "minItems": 1
        },
        "routingBoundary": {
          "type": "object",
          "properties": {
            "allowedJurisdictions": {
              "type": "array",
              "items": { "type": "string" }
            },
            "allowedTransport": { "type": "string" }
          },
          "additionalProperties": true
        },
        "evidenceObligation": {
          "type": "object",
          "properties": {
            "store": { "type": "string" },
            "retention": { "type": "string" },
            "fields": {
              "type": "array",
              "items": { "type": "string" }
            }
          },
          "additionalProperties": true
        },
        "escalation": {
          "type": "object",
          "properties": {
            "humanApprovalRequiredWhen": {
              "type": "array",
              "items": { "type": "string" }
            }
          },
          "additionalProperties": true
        }
      },
      "additionalProperties": true
    }
  },
  "additionalProperties": false
}
