{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://adam.system/schemas/v20.0/agent_proposal.schema.json",
  "title": "Agent Proposal Standard (APS/1.0)",
  "description": "A formal JSON Schema for system-generated agent proposals.",
  "type": "object",
  "properties": {
    "proposalMetadata": {
      "type": "object",
      "properties": {
        "proposalID": {
          "type": "string",
          "format": "uuid"
        },
        "timestamp": {
          "type": "string",
          "format": "date-time"
        },
        "originatingAgent": {
          "type": "string"
        },
        "triggeringEvent": {
          "type": "object",
          "properties": {
            "eventId": {
              "type": "string"
            },
            "eventType": {
              "type": "string"
            }
          },
          "required": ["eventId", "eventType"]
        }
      },
      "required": ["proposalID", "timestamp", "originatingAgent", "triggeringEvent"]
    },
    "agentDefinition": {
      "type": "object",
      "properties": {
        "agentId": {
          "type": "string",
          "pattern": "^[A-Z][a-zA-Z0-9]*Agent$"
        },
        "agentName": {
          "type": "string",
          "maxLength": 100
        },
        "description": {
          "type": "string",
          "maxLength": 1000
        },
        "instructions": {
          "type": "string",
          "maxLength": 8000
        }
      },
      "required": ["agentId", "agentName", "description", "instructions"]
    },
    "capabilityManifest": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "properties": {
          "capabilityName": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "inputSchema": {
            "$ref": "https://json-schema.org/draft/2020-12/schema"
          },
          "outputSchema": {
            "$ref": "https://json-schema.org/draft/2020-12/schema"
          }
        },
        "required": ["capabilityName", "description", "inputSchema", "outputSchema"]
      }
    },
    "collaborationProtocol": {
      "type": "object",
      "properties": {
        "subscribedEvents": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "publishedEvents": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "requiredAPIs": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "apiName": {
                "type": "string"
              },
              "endpoint": {
                "type": "string",
                "format": "uri"
              }
            },
            "required": ["apiName", "endpoint"]
          }
        }
      }
    },
    "dataRequirements": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "sourceName": {
            "type": "string"
          },
          "dataType": {
            "type": "string"
          },
          "accessCredentialsSecretName": {
            "type": "string"
          },
          "updateFrequency": {
            "type": "string"
          }
        },
        "required": ["sourceName", "dataType", "accessCredentialsSecretName"]
      }
    }
  },
  "required": ["proposalMetadata", "agentDefinition", "capabilityManifest", "collaborationProtocol"]
}
