{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://contextosai.com/schemas/invoke-agent.v1.schema.json",
  "title": "invokeAgent request envelope v1",
  "type": "object",
  "required": ["request_id", "tenant_id", "user", "agent", "context_pack_refs", "input", "mode", "runtime", "trace"],
  "$defs": {
    "InvokeMode": { "type": "string", "enum": ["stream", "batch", "long_running"] },
    "InvokeTrace": {
      "type": "object",
      "required": ["trace_id", "span_id"],
      "properties": {
        "trace_id": { "type": "string" },
        "span_id": { "type": "string" },
        "trace_flags": { "type": "string" },
        "tracestate": { "type": "string" },
        "baggage": { "type": "string" }
      },
      "additionalProperties": false
    },
    "Attachment": {
      "type": "object",
      "required": ["artifact_id", "media_type", "sha256", "uri"],
      "properties": {
        "artifact_id": { "type": "string" },
        "media_type": { "type": "string" },
        "sha256": { "type": "string" },
        "uri": { "type": "string" }
      },
      "additionalProperties": false
    }
  },
  "properties": {
    "request_id": { "type": "string" },
    "session_id": { "type": "string" },
    "tenant_id": { "type": "string" },
    "user": { "$ref": "https://contextosai.com/schemas/run-context.v1.schema.json#/$defs/UserClaims" },
    "agent": { "$ref": "https://contextosai.com/schemas/run-context.v1.schema.json#/$defs/AgentIdentity" },
    "context_pack_refs": {
      "type": "array",
      "minItems": 1,
      "items": { "type": "string", "pattern": "^[A-Za-z0-9_.:-]+@[0-9]+\\.[0-9]+\\.[0-9]+$" }
    },
    "input": {
      "type": "object",
      "required": ["intent", "message"],
      "properties": {
        "intent": { "type": "string" },
        "message": { "type": "string" },
        "channel": { "type": "string" },
        "locale": { "type": "string" },
        "context": { "type": "object", "additionalProperties": true }
      },
      "additionalProperties": false
    },
    "mode": { "$ref": "#/$defs/InvokeMode" },
    "runtime": {
      "type": "object",
      "properties": {
        "plan_timeout_ms": { "type": "integer", "minimum": 1 },
        "max_session_duration_ms": { "type": "integer", "minimum": 1 },
        "max_tool_calls": { "type": "integer", "minimum": 0 },
        "max_payload_bytes": { "type": "integer", "minimum": 1 },
        "max_cost_cents": { "type": "number", "minimum": 0 }
      },
      "additionalProperties": false
    },
    "attachments": { "type": "array", "items": { "$ref": "#/$defs/Attachment" } },
    "trace": { "$ref": "#/$defs/InvokeTrace" }
  },
  "additionalProperties": false
}
