{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://adl-spec.org/0.1/schema.json",
  "title": "ADL Document",
  "description": "Agent Definition Language v0.1.0",
  "$defs": {
    "data_classification": {
      "type": "object",
      "required": ["sensitivity"],
      "properties": {
        "sensitivity": {
          "type": "string",
          "enum": ["public", "internal", "confidential", "restricted"],
          "description": "Information sensitivity level (NIST FIPS 199 / ISO 27001)"
        },
        "categories": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": ["pii", "phi", "financial", "credentials", "intellectual_property", "regulatory"]
          },
          "minItems": 1,
          "description": "Broad information categories handled"
        },
        "retention": {
          "type": "object",
          "properties": {
            "min_days": { "type": "number", "minimum": 0 },
            "max_days": { "type": "number", "minimum": 0 },
            "policy_uri": { "type": "string", "format": "uri" }
          },
          "patternProperties": {
            "^x_[a-z][a-z0-9_]*$": true
          },
          "additionalProperties": false,
          "description": "Data retention requirements"
        },
        "handling": {
          "type": "object",
          "properties": {
            "encryption_required": { "type": "boolean" },
            "anonymization_required": { "type": "boolean" },
            "cross_border_restricted": { "type": "boolean" },
            "logging_required": { "type": "boolean" }
          },
          "patternProperties": {
            "^x_[a-z][a-z0-9_]*$": true
          },
          "additionalProperties": false,
          "description": "Data handling constraints"
        }
      },
      "patternProperties": {
        "^x_[a-z][a-z0-9_]*$": true
      },
      "additionalProperties": false,
      "description": "Data classification (composable; profiles MAY add domain-specific sub-objects via schema composition)"
    }
  },
  "type": "object",
  "required": ["adl_spec", "name", "description", "version", "data_classification"],
  "properties": {
    "adl_spec": {
      "type": "string",
      "pattern": "^\\d+\\.\\d+\\.\\d+$",
      "description": "ADL specification version (semantic versioning)"
    },
    "$schema": {
      "type": "string",
      "format": "uri",
      "description": "URI to this JSON Schema"
    },
    "name": {
      "type": "string",
      "minLength": 1,
      "description": "Human-readable name for the agent"
    },
    "description": {
      "type": "string",
      "minLength": 1,
      "description": "Human-readable description of the agent's purpose and capabilities"
    },
    "version": {
      "type": "string",
      "pattern": "^\\d+\\.\\d+\\.\\d+$",
      "description": "Agent version (semantic versioning)"
    },
    "lifecycle": {
      "type": "object",
      "required": ["status"],
      "properties": {
        "status": {
          "type": "string",
          "enum": ["draft", "active", "deprecated", "retired"],
          "description": "Lifecycle state of the agent"
        },
        "effective_date": {
          "type": "string",
          "format": "date-time",
          "description": "ISO 8601 timestamp when current status took effect"
        },
        "sunset_date": {
          "type": "string",
          "format": "date-time",
          "description": "ISO 8601 timestamp for planned or actual retirement"
        },
        "successor": {
          "type": "string",
          "format": "uri",
          "description": "URI or URN of the replacement agent"
        }
      },
      "patternProperties": {
        "^x_[a-z][a-z0-9_]*$": true
      },
      "additionalProperties": false
    },
    "id": {
      "type": "string",
      "description": "Unique identifier for the agent (URI or URN)"
    },
    "provider": {
      "type": "object",
      "required": ["name"],
      "properties": {
        "name": { "type": "string", "minLength": 1 },
        "url": { "type": "string", "format": "uri" },
        "contact": { "type": "string", "format": "email" }
      },
      "patternProperties": {
        "^x_[a-z][a-z0-9_]*$": true
      },
      "additionalProperties": false,
      "description": "Organization or entity that provides the agent"
    },
    "cryptographic_identity": {
      "type": "object",
      "properties": {
        "did": { "type": "string" },
        "public_key": {
          "type": "object",
          "required": ["algorithm", "value"],
          "properties": {
            "algorithm": { "type": "string" },
            "value": { "type": "string" }
          },
          "patternProperties": {
            "^x_[a-z][a-z0-9_]*$": true
          },
          "additionalProperties": false
        }
      },
      "patternProperties": {
        "^x_[a-z][a-z0-9_]*$": true
      },
      "additionalProperties": false,
      "description": "Cryptographic identification for the agent"
    },
    "model": {
      "type": "object",
      "properties": {
        "provider": { "type": "string" },
        "name": { "type": "string" },
        "version": { "type": "string" },
        "context_window": { "type": "integer", "minimum": 1 },
        "temperature": { "type": "number", "minimum": 0.0, "maximum": 2.0 },
        "max_tokens": { "type": "integer", "minimum": 1 },
        "capabilities": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": ["function_calling", "vision", "code_execution", "streaming"]
          }
        }
      },
      "patternProperties": {
        "^x_[a-z][a-z0-9_]*$": true
      },
      "additionalProperties": false,
      "description": "AI model configuration"
    },
    "system_prompt": {
      "oneOf": [
        { "type": "string", "minLength": 1 },
        {
          "type": "object",
          "required": ["template"],
          "properties": {
            "template": { "type": "string", "minLength": 1 },
            "variables": { "type": "object" }
          },
          "patternProperties": {
            "^x_[a-z][a-z0-9_]*$": true
          },
          "additionalProperties": false
        }
      ],
      "description": "System prompt (string or template object)"
    },
    "tools": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["name", "description"],
        "properties": {
          "name": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_]*$",
            "description": "Unique tool name"
          },
          "description": { "type": "string", "minLength": 1 },
          "parameters": {
            "type": "object",
            "description": "JSON Schema for tool input parameters"
          },
          "returns": {
            "type": "object",
            "description": "JSON Schema for tool return value"
          },
          "examples": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "name": { "type": "string" },
                "input": { "type": "object" },
                "output": {}
              },
              "patternProperties": {
                "^x_[a-z][a-z0-9_]*$": true
              },
              "additionalProperties": false
            },
            "description": "Example invocations"
          },
          "requires_confirmation": { "type": "boolean" },
          "idempotent": { "type": "boolean" },
          "read_only": { "type": "boolean" },
          "annotations": {
            "type": "object",
            "properties": {
              "openapi_ref": { "type": "string", "format": "uri" },
              "operation_id": { "type": "string" }
            },
            "additionalProperties": true,
            "description": "Implementation hints and metadata (open object)"
          },
          "data_classification": {
            "$ref": "#/$defs/data_classification"
          }
        },
        "patternProperties": {
          "^x_[a-z][a-z0-9_]*$": true
        },
        "additionalProperties": false
      },
      "description": "Tools (functions) the agent can invoke"
    },
    "resources": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["name", "type"],
        "properties": {
          "name": { "type": "string", "minLength": 1 },
          "type": {
            "type": "string",
            "enum": ["vector_store", "knowledge_base", "file", "api", "database"]
          },
          "description": { "type": "string" },
          "uri": { "type": "string", "format": "uri" },
          "mime_types": {
            "type": "array",
            "items": { "type": "string" }
          },
          "schema": {
            "type": "object",
            "description": "JSON Schema describing the resource's data structure"
          },
          "annotations": {
            "type": "object",
            "additionalProperties": true,
            "description": "Implementation hints and metadata (open object)"
          },
          "data_classification": {
            "$ref": "#/$defs/data_classification"
          }
        },
        "patternProperties": {
          "^x_[a-z][a-z0-9_]*$": true
        },
        "additionalProperties": false
      },
      "description": "Data sources the agent can access"
    },
    "prompts": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["name", "template"],
        "properties": {
          "name": { "type": "string", "minLength": 1 },
          "template": { "type": "string", "minLength": 1 },
          "description": { "type": "string" },
          "arguments": {
            "type": "object",
            "description": "JSON Schema for template arguments"
          }
        },
        "patternProperties": {
          "^x_[a-z][a-z0-9_]*$": true
        },
        "additionalProperties": false
      },
      "description": "Reusable prompt templates"
    },
    "permissions": {
      "type": "object",
      "properties": {
        "network": {
          "type": "object",
          "properties": {
            "allowed_hosts": {
              "type": "array",
              "items": { "type": "string" },
              "description": "Host patterns (see Section 4.4)"
            },
            "allowed_ports": {
              "type": "array",
              "items": { "type": "integer", "minimum": 1, "maximum": 65535 }
            },
            "allowed_protocols": {
              "type": "array",
              "items": { "type": "string" }
            },
            "deny_private": { "type": "boolean" }
          },
          "patternProperties": {
            "^x_[a-z][a-z0-9_]*$": true
          },
          "additionalProperties": false
        },
        "filesystem": {
          "type": "object",
          "properties": {
            "allowed_paths": {
              "type": "array",
              "items": {
                "type": "object",
                "required": ["path", "access"],
                "properties": {
                  "path": { "type": "string" },
                  "access": {
                    "type": "string",
                    "enum": ["read", "write", "read_write"]
                  }
                },
                "additionalProperties": false
              }
            },
            "denied_paths": {
              "type": "array",
              "items": { "type": "string" },
              "description": "Path patterns to deny (see Section 4.4)"
            }
          },
          "patternProperties": {
            "^x_[a-z][a-z0-9_]*$": true
          },
          "additionalProperties": false
        },
        "environment": {
          "type": "object",
          "properties": {
            "allowed_variables": {
              "type": "array",
              "items": { "type": "string" },
              "description": "Variable name patterns (see Section 4.4)"
            },
            "denied_variables": {
              "type": "array",
              "items": { "type": "string" },
              "description": "Variable name patterns to deny (see Section 4.4)"
            }
          },
          "patternProperties": {
            "^x_[a-z][a-z0-9_]*$": true
          },
          "additionalProperties": false
        },
        "execution": {
          "type": "object",
          "properties": {
            "allowed_commands": {
              "type": "array",
              "items": { "type": "string" }
            },
            "denied_commands": {
              "type": "array",
              "items": { "type": "string" }
            },
            "allow_shell": { "type": "boolean" }
          },
          "patternProperties": {
            "^x_[a-z][a-z0-9_]*$": true
          },
          "additionalProperties": false
        },
        "resource_limits": {
          "type": "object",
          "properties": {
            "max_memory_mb": { "type": "number", "minimum": 0 },
            "max_cpu_percent": { "type": "number", "minimum": 0, "maximum": 100 },
            "max_duration_sec": { "type": "number", "minimum": 0 },
            "max_concurrent": { "type": "integer", "minimum": 1 }
          },
          "patternProperties": {
            "^x_[a-z][a-z0-9_]*$": true
          },
          "additionalProperties": false
        }
      },
      "patternProperties": {
        "^x_[a-z][a-z0-9_]*$": true
      },
      "additionalProperties": false,
      "description": "Agent operational boundaries (deny-by-default)"
    },
    "security": {
      "type": "object",
      "properties": {
        "authentication": {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": ["none", "api_key", "oauth2", "oidc", "mtls"]
            },
            "required": { "type": "boolean" },
            "scopes": { "type": "array", "items": { "type": "string" } },
            "token_endpoint": { "type": "string", "format": "uri" },
            "issuer": { "type": "string" },
            "audience": { "type": "string" }
          },
          "patternProperties": {
            "^x_[a-z][a-z0-9_]*$": true
          },
          "additionalProperties": false
        },
        "encryption": {
          "type": "object",
          "properties": {
            "in_transit": {
              "type": "object",
              "properties": {
                "required": { "type": "boolean" },
                "min_version": { "type": "string" }
              },
              "patternProperties": {
                "^x_[a-z][a-z0-9_]*$": true
              },
              "additionalProperties": false
            },
            "at_rest": {
              "type": "object",
              "properties": {
                "required": { "type": "boolean" },
                "algorithm": { "type": "string" }
              },
              "patternProperties": {
                "^x_[a-z][a-z0-9_]*$": true
              },
              "additionalProperties": false
            }
          },
          "patternProperties": {
            "^x_[a-z][a-z0-9_]*$": true
          },
          "additionalProperties": false
        },
        "attestation": {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": ["self", "third_party", "verifiable_credential"]
            },
            "issuer": { "type": "string" },
            "issued_at": { "type": "string", "format": "date-time" },
            "expires_at": { "type": "string", "format": "date-time" },
            "signature": {
              "type": "object",
              "required": ["algorithm", "value", "signed_content"],
              "properties": {
                "algorithm": { "type": "string" },
                "value": { "type": "string" },
                "signed_content": {
                  "type": "string",
                  "enum": ["canonical", "digest"]
                },
                "digest_algorithm": { "type": "string" },
                "digest_value": { "type": "string" }
              },
              "patternProperties": {
                "^x_[a-z][a-z0-9_]*$": true
              },
              "additionalProperties": false
            }
          },
          "patternProperties": {
            "^x_[a-z][a-z0-9_]*$": true
          },
          "additionalProperties": false
        }
      },
      "patternProperties": {
        "^x_[a-z][a-z0-9_]*$": true
      },
      "additionalProperties": false,
      "description": "Security requirements"
    },
    "data_classification": {
      "$ref": "#/$defs/data_classification"
    },
    "runtime": {
      "type": "object",
      "properties": {
        "input_handling": {
          "type": "object",
          "properties": {
            "max_input_length": { "type": "integer", "minimum": 1 },
            "content_types": {
              "type": "array",
              "items": { "type": "string" },
              "description": "Accepted MIME types (e.g., text/plain, application/json)"
            },
            "sanitization": {
              "type": "object",
              "properties": {
                "enabled": { "type": "boolean" },
                "strip_html": { "type": "boolean" },
                "max_input_length": { "type": "integer", "minimum": 1 }
              },
              "patternProperties": {
                "^x_[a-z][a-z0-9_]*$": true
              },
              "additionalProperties": false
            }
          },
          "patternProperties": {
            "^x_[a-z][a-z0-9_]*$": true
          },
          "additionalProperties": false
        },
        "output_handling": {
          "type": "object",
          "properties": {
            "max_output_length": { "type": "integer", "minimum": 1 },
            "format": {
              "type": "string",
              "enum": ["text", "json", "markdown", "html"]
            },
            "streaming": { "type": "boolean" }
          },
          "patternProperties": {
            "^x_[a-z][a-z0-9_]*$": true
          },
          "additionalProperties": false
        },
        "tool_invocation": {
          "type": "object",
          "properties": {
            "parallel": { "type": "boolean" },
            "max_concurrent": { "type": "integer", "minimum": 1 },
            "timeout_ms": { "type": "integer", "minimum": 0 },
            "retry_policy": {
              "type": "object",
              "properties": {
                "max_retries": { "type": "integer", "minimum": 0 },
                "backoff_strategy": {
                  "type": "string",
                  "enum": ["fixed", "exponential", "linear"]
                },
                "initial_delay_ms": { "type": "integer", "minimum": 0 },
                "max_delay_ms": { "type": "integer", "minimum": 0 }
              },
              "patternProperties": {
                "^x_[a-z][a-z0-9_]*$": true
              },
              "additionalProperties": false
            }
          },
          "patternProperties": {
            "^x_[a-z][a-z0-9_]*$": true
          },
          "additionalProperties": false
        },
        "error_handling": {
          "type": "object",
          "properties": {
            "on_tool_error": {
              "type": "string",
              "enum": ["abort", "continue", "retry"]
            },
            "max_retries": { "type": "integer", "minimum": 0 },
            "fallback_behavior": {
              "type": "object",
              "properties": {
                "action": {
                  "type": "string",
                  "enum": ["return_error", "use_default", "skip"]
                },
                "default": {
                  "description": "Default value when action is use_default"
                },
                "message": { "type": "string" }
              },
              "patternProperties": {
                "^x_[a-z][a-z0-9_]*$": true
              },
              "additionalProperties": false
            }
          },
          "patternProperties": {
            "^x_[a-z][a-z0-9_]*$": true
          },
          "additionalProperties": false
        }
      },
      "patternProperties": {
        "^x_[a-z][a-z0-9_]*$": true
      },
      "additionalProperties": false,
      "description": "Runtime behavior configuration"
    },
    "metadata": {
      "type": "object",
      "properties": {
        "authors": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "name": { "type": "string" },
              "email": { "type": "string", "format": "email" },
              "url": { "type": "string", "format": "uri" }
            },
            "patternProperties": {
              "^x_[a-z][a-z0-9_]*$": true
            },
            "additionalProperties": false
          }
        },
        "license": { "type": "string" },
        "documentation": { "type": "string", "format": "uri" },
        "repository": { "type": "string", "format": "uri" },
        "tags": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9-]*$"
          }
        }
      },
      "patternProperties": {
        "^x_[a-z][a-z0-9_]*$": true
      },
      "additionalProperties": false,
      "description": "Additional metadata"
    },
    "profiles": {
      "type": "array",
      "items": { "type": "string" },
      "description": "Profile identifiers (URIs or registered names)"
    }
  },
  "patternProperties": {
    "^x_[a-z][a-z0-9_]*$": true
  },
  "additionalProperties": false
}
