{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/samva-dev/json-schema/samva-dev-create-agent-payload-schema.json",
  "title": "CreateAgentPayload",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/samva-dev-agents-api-openapi.yml#/components/schemas/CreateAgentPayload",
  "type": "object",
  "properties": {
    "name": {
      "$ref": "#/$defs/AgentName"
    },
    "namespaceId": {
      "anyOf": [
        {
          "$ref": "#/$defs/NamespaceId"
        },
        {
          "type": "null"
        }
      ],
      "description": "The namespace the agent belongs to; it cannot move later. Omit for an organization-level agent. A namespace-scoped key always creates in its own namespace."
    },
    "definition": {
      "anyOf": [
        {
          "$ref": "#/$defs/AgentDefinition"
        },
        {
          "type": "null"
        }
      ],
      "description": "The first draft. Defaults to an agent with no instructions, knowledge, or endpoints, in supervised mode on the standard model.",
      "default": {
        "instructions": "",
        "knowledge": "",
        "endpointIds": [],
        "integrations": [],
        "mode": "supervised",
        "model": "standard",
        "workingHours": null,
        "takeoverTimeoutMinutes": 30
      }
    }
  },
  "required": [
    "name"
  ],
  "additionalProperties": false,
  "$defs": {
    "AgentDefinition": {
      "type": "object",
      "properties": {
        "instructions": {
          "type": "string",
          "maxLength": 20000,
          "x-samva-string-checks": [
            {
              "id": "effect/schema/isMaxLength",
              "payload": {
                "maxLength": 20000
              }
            }
          ]
        },
        "knowledge": {
          "type": "string",
          "maxLength": 100000,
          "x-samva-string-checks": [
            {
              "id": "effect/schema/isMaxLength",
              "payload": {
                "maxLength": 100000
              }
            }
          ]
        },
        "endpointIds": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/MailboxEndpointId"
          },
          "maxItems": 20
        },
        "integrations": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/AgentIntegrationGrant"
          },
          "maxItems": 20
        },
        "mode": {
          "$ref": "#/$defs/AgentMode"
        },
        "model": {
          "$ref": "#/$defs/AgentModel"
        },
        "workingHours": {
          "anyOf": [
            {
              "$ref": "#/$defs/WorkingHours"
            },
            {
              "type": "null"
            }
          ]
        },
        "takeoverTimeoutMinutes": {
          "type": "integer",
          "minimum": 1,
          "maximum": 10080
        }
      },
      "required": [
        "instructions",
        "knowledge",
        "endpointIds",
        "integrations",
        "mode",
        "model",
        "workingHours",
        "takeoverTimeoutMinutes"
      ],
      "additionalProperties": false
    },
    "AgentIntegrationGrant": {
      "type": "object",
      "properties": {
        "integrationId": {
          "$ref": "#/$defs/IntegrationId"
        },
        "tools": {
          "$ref": "#/$defs/AgentToolScope"
        },
        "requireApproval": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[a-z][a-z0-9_.]{0,63}$"
          }
        }
      },
      "required": [
        "integrationId",
        "tools",
        "requireApproval"
      ],
      "additionalProperties": false
    },
    "AgentMode": {
      "type": "string",
      "enum": [
        "live",
        "supervised"
      ]
    },
    "AgentModel": {
      "type": "string",
      "enum": [
        "standard",
        "max"
      ]
    },
    "AgentName": {
      "type": "string",
      "pattern": "^\\S[\\s\\S]*\\S$|^\\S$|^$",
      "minLength": 1,
      "maxLength": 120,
      "x-samva-string-checks": [
        {
          "id": "effect/schema/isMaxLength",
          "payload": {
            "maxLength": 120
          }
        }
      ]
    },
    "AgentToolScope": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "enum": [
                "all"
              ]
            }
          },
          "required": [
            "kind"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "enum": [
                "readOnly"
              ]
            }
          },
          "required": [
            "kind"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "enum": [
                "selected"
              ]
            },
            "names": {
              "type": "array",
              "items": {
                "type": "string",
                "pattern": "^[a-z][a-z0-9_.]{0,63}$"
              },
              "minItems": 1
            }
          },
          "required": [
            "kind",
            "names"
          ],
          "additionalProperties": false
        }
      ]
    },
    "ClockTime": {
      "type": "string",
      "pattern": "^(?:[01]\\d|2[0-3]):[0-5]\\d$"
    },
    "IntegrationId": {
      "type": "string",
      "pattern": "^intg_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "IntegrationId"
    },
    "MailboxEndpointId": {
      "type": "string",
      "pattern": "^mbxep_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "MailboxEndpointId"
    },
    "NamespaceId": {
      "type": "string",
      "pattern": "^ns_[0-9a-hjkmnp-tv-z]{16,24}$",
      "x-samva-brand": "NamespaceId"
    },
    "TimeZone": {
      "type": "string"
    },
    "Weekday": {
      "type": "string",
      "enum": [
        "monday",
        "tuesday",
        "wednesday",
        "thursday",
        "friday",
        "saturday",
        "sunday"
      ]
    },
    "WorkingHours": {
      "type": "object",
      "properties": {
        "timeZone": {
          "$ref": "#/$defs/TimeZone"
        },
        "ranges": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/WorkingHoursRange"
          },
          "minItems": 1,
          "maxItems": 28
        }
      },
      "required": [
        "timeZone",
        "ranges"
      ],
      "additionalProperties": false
    },
    "WorkingHoursRange": {
      "type": "object",
      "properties": {
        "day": {
          "$ref": "#/$defs/Weekday"
        },
        "opens": {
          "$ref": "#/$defs/ClockTime"
        },
        "closes": {
          "$ref": "#/$defs/ClockTime"
        }
      },
      "required": [
        "day",
        "opens",
        "closes"
      ],
      "additionalProperties": false
    }
  }
}