{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://rodgui.github.io/ai-agent-governance-framework/schemas/agent-blueprint.schema.json",
  "title": "AI Agent Blueprint 2.0",
  "description": "Descrição técnica versionada de arquitetura, dados, identidade, tools, runtime e governança.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "agentId",
    "version",
    "architecture",
    "models",
    "data",
    "identity",
    "tools",
    "runtime",
    "governance"
  ],
  "properties": {
    "schemaVersion": {
      "const": "2.0"
    },
    "agentId": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9._-]{2,63}$"
    },
    "version": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+(?:\\.[0-9]+)?$"
    },
    "architecture": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "pattern",
        "description",
        "trustBoundaries",
        "dependencies"
      ],
      "properties": {
        "pattern": {
          "enum": [
            "assistant",
            "workflow-agent",
            "tool-using-agent",
            "multi-agent",
            "embedded-ai",
            "other"
          ]
        },
        "description": {
          "type": "string",
          "minLength": 20
        },
        "diagramRef": {
          "type": "string",
          "minLength": 3
        },
        "trustBoundaries": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 3
          }
        },
        "dependencies": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "name",
              "type",
              "criticality"
            ],
            "properties": {
              "name": {
                "type": "string"
              },
              "type": {
                "enum": [
                  "platform",
                  "model",
                  "data",
                  "tool",
                  "identity",
                  "network",
                  "human-process",
                  "other"
                ]
              },
              "criticality": {
                "enum": [
                  "low",
                  "moderate",
                  "high",
                  "critical"
                ]
              },
              "owner": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    "models": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "modelId",
          "provider",
          "modelVersion",
          "catalogEntryId",
          "evaluationRef",
          "role",
          "purpose",
          "hosting",
          "versionPinned",
          "dataUse",
          "allowedDataClasses",
          "allowedRegions",
          "fallback"
        ],
        "properties": {
          "modelId": {
            "type": "string"
          },
          "provider": {
            "type": "string"
          },
          "purpose": {
            "type": "string"
          },
          "hosting": {
            "enum": [
              "saas",
              "managed",
              "self-hosted",
              "on-device"
            ]
          },
          "versionPinned": {
            "type": "boolean"
          },
          "dataUse": {
            "enum": [
              "no-training",
              "contract-defined",
              "unknown"
            ]
          },
          "limitations": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "modelVersion": {
            "type": "string",
            "minLength": 1
          },
          "catalogEntryId": {
            "type": "string",
            "pattern": "^MPC-[A-Z0-9-]{3,80}$"
          },
          "evaluationRef": {
            "type": "string",
            "minLength": 3
          },
          "role": {
            "enum": [
              "primary",
              "fallback",
              "specialized"
            ]
          },
          "allowedDataClasses": {
            "type": "array",
            "minItems": 1,
            "uniqueItems": true,
            "items": {
              "enum": [
                "public",
                "internal",
                "confidential",
                "restricted",
                "regulated"
              ]
            }
          },
          "allowedRegions": {
            "type": "array",
            "minItems": 1,
            "uniqueItems": true,
            "items": {
              "type": "string",
              "minLength": 2
            }
          },
          "changeDetectionRef": {
            "type": "string",
            "minLength": 3
          },
          "serviceChangePolicyRef": {
            "type": "string",
            "minLength": 3
          },
          "fallback": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "mode",
              "rationale"
            ],
            "properties": {
              "mode": {
                "enum": [
                  "approved-alternative",
                  "fail-closed",
                  "not-required"
                ]
              },
              "catalogEntryId": {
                "type": "string",
                "pattern": "^MPC-[A-Z0-9-]{3,80}$"
              },
              "equivalenceEvaluationRef": {
                "type": "string",
                "minLength": 3
              },
              "rationale": {
                "type": "string",
                "minLength": 10
              }
            },
            "allOf": [
              {
                "if": {
                  "properties": {
                    "mode": {
                      "const": "approved-alternative"
                    }
                  },
                  "required": [
                    "mode"
                  ]
                },
                "then": {
                  "required": [
                    "catalogEntryId",
                    "equivalenceEvaluationRef"
                  ]
                }
              }
            ]
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "versionPinned": {
                  "const": false
                }
              },
              "required": [
                "versionPinned"
              ]
            },
            "then": {
              "required": [
                "changeDetectionRef",
                "serviceChangePolicyRef"
              ]
            }
          }
        ]
      }
    },
    "data": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "sources",
        "memory"
      ],
      "properties": {
        "sources": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "sourceId",
              "catalogEntryId",
              "classification",
              "purpose",
              "owner",
              "connectorRef"
            ],
            "properties": {
              "sourceId": {
                "type": "string"
              },
              "classification": {
                "enum": [
                  "public",
                  "internal",
                  "confidential",
                  "restricted",
                  "regulated"
                ]
              },
              "purpose": {
                "type": "string"
              },
              "owner": {
                "type": "string"
              },
              "connectorRef": {
                "type": "string"
              },
              "authorizationMode": {
                "enum": [
                  "pre-retrieval",
                  "source-enforced",
                  "post-retrieval",
                  "none"
                ]
              },
              "retention": {
                "type": "string"
              },
              "region": {
                "type": "string"
              },
              "catalogEntryId": {
                "type": "string",
                "pattern": "^SRC-[A-Z0-9-]{3,80}$"
              }
            }
          }
        },
        "memory": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "mode",
            "retention"
          ],
          "properties": {
            "mode": {
              "enum": [
                "none",
                "session",
                "user",
                "team",
                "organization"
              ]
            },
            "retention": {
              "type": "string"
            },
            "deletionMechanism": {
              "type": "string"
            },
            "sensitiveDataAllowed": {
              "type": "boolean"
            }
          }
        }
      }
    },
    "identity": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "model",
        "principal",
        "scopes",
        "secretManagement"
      ],
      "properties": {
        "model": {
          "enum": [
            "workload",
            "delegated-user",
            "per-execution",
            "hybrid"
          ]
        },
        "principal": {
          "type": "string",
          "minLength": 3
        },
        "scopes": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true
        },
        "expiry": {
          "type": "string"
        },
        "secretManagement": {
          "type": "string",
          "minLength": 3
        },
        "breakGlass": {
          "type": "string"
        }
      }
    },
    "tools": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "toolId",
          "catalogEntryId",
          "name",
          "class",
          "protocol",
          "stateChanging",
          "reversible",
          "approvalMode",
          "owner"
        ],
        "properties": {
          "toolId": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9._-]{2,80}$"
          },
          "name": {
            "type": "string"
          },
          "class": {
            "enum": [
              "observe",
              "create",
              "modify",
              "execute",
              "approve",
              "delete",
              "delegate"
            ]
          },
          "protocol": {
            "enum": [
              "api",
              "mcp",
              "browser",
              "code",
              "queue",
              "other"
            ]
          },
          "stateChanging": {
            "type": "boolean"
          },
          "reversible": {
            "type": "boolean"
          },
          "approvalMode": {
            "enum": [
              "automated",
              "human",
              "dual-control",
              "prohibited"
            ]
          },
          "owner": {
            "type": "string"
          },
          "scopes": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            },
            "uniqueItems": true
          },
          "gatewayRef": {
            "type": "string",
            "minLength": 3
          },
          "killSwitchRef": {
            "type": "string",
            "minLength": 3
          },
          "version": {
            "type": "string"
          },
          "catalogEntryId": {
            "type": "string",
            "pattern": "^TLR-[A-Z0-9-]{3,80}$"
          }
        },
        "allOf": [
          {
            "if": {
              "properties": {
                "stateChanging": {
                  "const": true
                }
              },
              "required": [
                "stateChanging"
              ]
            },
            "then": {
              "required": [
                "gatewayRef",
                "killSwitchRef",
                "scopes"
              ],
              "properties": {
                "scopes": {
                  "minItems": 1
                }
              }
            }
          },
          {
            "if": {
              "properties": {
                "stateChanging": {
                  "const": true
                },
                "reversible": {
                  "const": false
                }
              },
              "required": [
                "stateChanging",
                "reversible"
              ]
            },
            "then": {
              "properties": {
                "approvalMode": {
                  "enum": [
                    "human",
                    "dual-control",
                    "prohibited"
                  ]
                }
              }
            }
          },
          {
            "if": {
              "properties": {
                "class": {
                  "const": "observe"
                }
              },
              "required": [
                "class"
              ]
            },
            "then": {
              "properties": {
                "stateChanging": {
                  "const": false
                }
              }
            }
          },
          {
            "if": {
              "properties": {
                "class": {
                  "enum": [
                    "create",
                    "modify",
                    "execute",
                    "approve",
                    "delete",
                    "delegate"
                  ]
                }
              },
              "required": [
                "class"
              ]
            },
            "then": {
              "properties": {
                "stateChanging": {
                  "const": true
                }
              }
            }
          }
        ]
      }
    },
    "runtime": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "environments",
        "observability",
        "quarantine",
        "rollback",
        "killSwitch"
      ],
      "properties": {
        "environments": {
          "type": "array",
          "minItems": 1,
          "items": {
            "enum": [
              "development",
              "test",
              "staging",
              "production"
            ]
          },
          "uniqueItems": true
        },
        "regions": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        },
        "observability": {
          "type": "string",
          "minLength": 3
        },
        "quarantine": {
          "type": "string",
          "minLength": 3
        },
        "rollback": {
          "type": "string",
          "minLength": 3
        },
        "killSwitch": {
          "type": "string",
          "minLength": 3
        },
        "supportRef": {
          "type": "string",
          "minLength": 3
        },
        "sloRef": {
          "type": "string",
          "minLength": 3
        }
      }
    },
    "governance": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "riskTier",
        "admissibility",
        "admissibilityRationale",
        "controlIds",
        "assessmentRefs",
        "prohibitedUses",
        "materialChangeTriggers"
      ],
      "properties": {
        "riskTier": {
          "enum": [
            "T1",
            "T2",
            "T3",
            "T4"
          ]
        },
        "controlIds": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "pattern": "^AGF-[A-Z]{3,5}-[0-9]{3}$"
          },
          "uniqueItems": true
        },
        "assessmentRefs": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 3
          },
          "uniqueItems": true
        },
        "prohibitedUses": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        },
        "materialChangeTriggers": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string"
          },
          "uniqueItems": true
        },
        "releaseEvidenceRef": {
          "type": "string",
          "minLength": 3
        },
        "attestationExpiresAt": {
          "type": "string",
          "format": "date"
        },
        "admissibility": {
          "enum": [
            "permitted",
            "conditional",
            "restricted",
            "prohibited"
          ]
        },
        "admissibilityRationale": {
          "type": "string",
          "minLength": 10,
          "maxLength": 1000
        },
        "conditionRefs": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 3
          }
        },
        "exceptionRef": {
          "type": "string",
          "minLength": 3
        },
        "exceptionExpiresAt": {
          "type": "string",
          "format": "date"
        }
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "runtime": {
            "properties": {
              "environments": {
                "contains": {
                  "const": "production"
                }
              }
            },
            "required": [
              "environments"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "governance": {
            "required": [
              "releaseEvidenceRef",
              "attestationExpiresAt"
            ],
            "properties": {
              "admissibility": {
                "enum": [
                  "permitted",
                  "conditional",
                  "restricted"
                ]
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "governance": {
            "properties": {
              "admissibility": {
                "const": "conditional"
              }
            },
            "required": [
              "admissibility"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "governance": {
            "required": [
              "conditionRefs"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "governance": {
            "properties": {
              "admissibility": {
                "const": "restricted"
              }
            },
            "required": [
              "admissibility"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "governance": {
            "required": [
              "exceptionRef",
              "exceptionExpiresAt"
            ]
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "governance": {
            "properties": {
              "riskTier": {
                "enum": [
                  "T3",
                  "T4"
                ]
              }
            },
            "required": [
              "riskTier"
            ]
          }
        }
      },
      "then": {
        "properties": {
          "tools": {
            "items": {
              "if": {
                "properties": {
                  "stateChanging": {
                    "const": true
                  }
                },
                "required": [
                  "stateChanging"
                ]
              },
              "then": {
                "properties": {
                  "approvalMode": {
                    "enum": [
                      "human",
                      "dual-control",
                      "prohibited"
                    ]
                  }
                }
              }
            }
          }
        }
      }
    }
  ]
}
