{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://rjlsol.com/schemas/agent-product.v1.json",
  "title": "RJL agent product manifest (agent-product.yaml), version 1",
  "description": "Illustrative reference schema from RJL Agent Onboarding. Autonomy levels follow Agent Patterns (L0 to L4), set per action.",
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "schema_version": {
      "const": "rjl.agent-product.v1"
    },
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9._-]*$"
    },
    "version": {
      "type": "string",
      "pattern": "^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)$"
    },
    "lifecycle": {
      "enum": [
        "sandbox",
        "managed_sandbox",
        "certified",
        "degraded",
        "deprecated",
        "retired"
      ]
    },
    "owners": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "business": {
          "type": "string",
          "minLength": 1
        },
        "product": {
          "type": "string",
          "minLength": 1
        },
        "service": {
          "type": "string",
          "minLength": 1
        },
        "control": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "business",
        "product",
        "service",
        "control"
      ]
    },
    "scope": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "purpose": {
          "type": "string",
          "minLength": 1
        },
        "task": {
          "type": "string",
          "minLength": 1
        },
        "users": {
          "type": "string",
          "minLength": 1
        },
        "excluded": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "autonomy": {
          "type": "object",
          "minProperties": 1,
          "additionalProperties": {
            "enum": [
              "L0_assist",
              "L1_approve_each",
              "L2_approve_consequential",
              "L3_monitor",
              "L4_bounded"
            ]
          }
        },
        "interface": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "purpose",
        "task",
        "users",
        "excluded",
        "autonomy",
        "interface"
      ]
    },
    "dependencies": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "data": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "meaning": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "knowledge": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "tools": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        }
      },
      "required": [
        "data",
        "meaning",
        "knowledge",
        "tools"
      ]
    },
    "identity": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "mode": {
          "enum": [
            "delegated_user",
            "service"
          ]
        },
        "workload_ref": {
          "type": "string",
          "minLength": 1
        },
        "delegation": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      },
      "required": [
        "mode",
        "workload_ref"
      ]
    },
    "policy_ref": {
      "type": "string",
      "minLength": 1
    },
    "runtime_ref": {
      "type": "string",
      "minLength": 1
    },
    "memory_policy_ref": {
      "type": "string",
      "minLength": 1
    },
    "limits": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "max_tool_calls": {
          "type": "integer",
          "minimum": 1
        },
        "deadline_seconds": {
          "type": "integer",
          "minimum": 1
        },
        "on_limit": {
          "enum": [
            "stop",
            "escalate"
          ]
        }
      },
      "required": [
        "max_tool_calls",
        "deadline_seconds",
        "on_limit"
      ]
    },
    "evaluation_ref": {
      "type": "string",
      "minLength": 1
    },
    "service_ref": {
      "type": "string",
      "minLength": 1
    },
    "evidence_ref": {
      "type": "string",
      "minLength": 1
    },
    "approval_ref": {
      "type": "string",
      "minLength": 1
    }
  },
  "required": [
    "schema_version",
    "id",
    "version",
    "lifecycle",
    "owners",
    "scope",
    "dependencies",
    "identity",
    "policy_ref",
    "runtime_ref",
    "memory_policy_ref",
    "limits",
    "evaluation_ref",
    "service_ref",
    "evidence_ref",
    "approval_ref"
  ],
  "allOf": [
    {
      "if": {
        "properties": {
          "lifecycle": {
            "const": "certified"
          }
        }
      },
      "then": {
        "properties": {
          "version": {
            "pattern": "^[1-9]\\d*\\.\\d+\\.\\d+$"
          }
        }
      }
    }
  ]
}
