{
  "openapi": "3.1.0",
  "info": {
    "title": "Telos Brain Execution API",
    "version": "1.0.0",
    "summary": "Runtime API for a deployed Telos Brain",
    "description": "The Execution API is the runtime surface of a Telos Brain. Authenticate with the per-brain API key issued at first deploy. Tenancy is implicit from the key — never send a `brain_id`.\n\nThis is a different plane from the Management API used by the CLI (`tbk_` org keys, `/brains/...`). Details: https://www.telosbrain.com/skills/BRA401\n\nAuthoritative skill docs: BRA401 (auth), BRA402 (entities / units of work), BRA403 (runs), BRA404 (inbox), BRA409 (run variables), BRA410 (transcription).",
    "contact": {
      "name": "Telos Brain",
      "url": "https://www.telosbrain.com"
    }
  },
  "externalDocs": {
    "description": "Public skill directory",
    "url": "https://www.telosbrain.com/skills"
  },
  "servers": [
    {
      "url": "https://go.telosbrain.com",
      "description": "Hosted Execution API"
    }
  ],
  "security": [
    {
      "brainApiKey": []
    }
  ],
  "tags": [
    {
      "name": "Brain",
      "description": "Identity for the brain resolved from the API key."
    },
    {
      "name": "Entities",
      "description": "Business records scoped to the brain (BRA402)."
    },
    {
      "name": "Units of Work",
      "description": "Jobs against an entity, plus context/data logs (BRA402)."
    },
    {
      "name": "Workflows",
      "description": "List and run workflows (BRA403)."
    },
    {
      "name": "Runs",
      "description": "Chat sessions, stop/complete, telemetry (BRA403)."
    },
    {
      "name": "Inbox",
      "description": "Learning signals and tasks (BRA404)."
    },
    {
      "name": "Transcription",
      "description": "Extract text from an uploaded file (BRA410)."
    }
  ],
  "paths": {
    "/brain": {
      "get": {
        "tags": [
          "Brain"
        ],
        "operationId": "getBrain",
        "summary": "Brain identity",
        "description": "Public header metadata for the brain resolved from the API key. Does not return the API key or organisation id.",
        "responses": {
          "200": {
            "description": "Brain header",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Brain"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/entities": {
      "get": {
        "tags": [
          "Entities"
        ],
        "operationId": "listEntities",
        "summary": "List entities",
        "parameters": [
          {
            "name": "entity_type_code",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Narrow to one entity type. Unknown codes yield an empty list."
          }
        ],
        "responses": {
          "200": {
            "description": "Flat array; no pagination",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Entity"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "tags": [
          "Entities"
        ],
        "operationId": "createEntity",
        "summary": "Create an entity",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateEntityRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created entity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Entity"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/entities/{id}": {
      "put": {
        "tags": [
          "Entities"
        ],
        "operationId": "updateEntity",
        "summary": "Update entity name and description",
        "description": "Entity type is immutable.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateEntityRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated entity",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Entity"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/entities/{id}/variables": {
      "get": {
        "tags": [
          "Entities"
        ],
        "operationId": "getEntityVariables",
        "summary": "Read entity variables",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Key/value pairs",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Variable"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "put": {
        "tags": [
          "Entities"
        ],
        "operationId": "setEntityVariables",
        "summary": "Upsert entity variables",
        "description": "Creates or updates supplied keys; omitted keys are left untouched.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SetVariablesRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Full variable set after update",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Variable"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/units-of-work": {
      "post": {
        "tags": [
          "Units of Work"
        ],
        "operationId": "createUnitOfWork",
        "summary": "Create a unit of work",
        "description": "Initial status is Open.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateUnitOfWorkRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created unit of work",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnitOfWork"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/units-of-work/{id}/variables": {
      "get": {
        "tags": [
          "Units of Work"
        ],
        "operationId": "getUnitOfWorkVariables",
        "summary": "Read unit-of-work variables",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Key/value pairs",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Variable"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "put": {
        "tags": [
          "Units of Work"
        ],
        "operationId": "setUnitOfWorkVariables",
        "summary": "Upsert unit-of-work variables",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SetVariablesRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Full variable set after update",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/Variable"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/units-of-work/{id}/context": {
      "post": {
        "tags": [
          "Units of Work"
        ],
        "operationId": "appendUnitOfWorkContext",
        "summary": "Append a context event",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AppendContextRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created context record",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    }
                  },
                  "required": [
                    "id"
                  ]
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/units-of-work/{id}/data": {
      "post": {
        "tags": [
          "Units of Work"
        ],
        "operationId": "appendUnitOfWorkData",
        "summary": "Append a data/telemetry record",
        "description": "High-frequency write path. Success has no body.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AppendDataRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created (empty body)"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/units-of-work/{id}/complete": {
      "post": {
        "tags": [
          "Units of Work"
        ],
        "operationId": "completeUnitOfWork",
        "summary": "Mark a unit of work complete",
        "description": "Sets status to Complete and enqueues the learning eval. Idempotent if already complete.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Updated unit of work",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/UnitOfWork"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/units-of-work/{id}/telemetry": {
      "get": {
        "tags": [
          "Units of Work"
        ],
        "operationId": "getUnitOfWorkTelemetry",
        "summary": "Merged context and data telemetry",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Ordered telemetry records",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/UnitOfWorkTelemetryRecord"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/workflows": {
      "get": {
        "tags": [
          "Workflows"
        ],
        "operationId": "listWorkflows",
        "summary": "List workflows",
        "responses": {
          "200": {
            "description": "Workflows ordered by name",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/WorkflowSummary"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/workflows/{code}/run/sync": {
      "post": {
        "tags": [
          "Workflows"
        ],
        "operationId": "runWorkflowSync",
        "summary": "Run a workflow synchronously (SSE chat session)",
        "description": "Streams Server-Sent Events. The run is left open at AwaitingInput so you can continue via POST /runs/{runId}/messages. Unknown workflow codes surface as a terminal SSE error event (HTTP 200) because headers are committed before work starts.",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkflowCode"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RunRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "SSE stream (`run_started`, `status`, `thinking`, `tool_call`, `tool_result`, `text`, `error`, `done`)",
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/workflows/{code}/run/async": {
      "post": {
        "tags": [
          "Workflows"
        ],
        "operationId": "runWorkflowAsync",
        "summary": "Queue a workflow run",
        "description": "Honours `callbackUrl` when supplied (https, host on allowed-callback-domains).",
        "parameters": [
          {
            "$ref": "#/components/parameters/WorkflowCode"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RunRequest"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Queued",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AsyncRunAccepted"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/runs/{runId}/messages": {
      "post": {
        "tags": [
          "Runs"
        ],
        "operationId": "continueRun",
        "summary": "Continue an open chat session",
        "description": "Same SSE wire format as /run/sync. Session must be AwaitingInput.",
        "parameters": [
          {
            "$ref": "#/components/parameters/RunId"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ContinueRunRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "SSE stream",
            "content": {
              "text/event-stream": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/runs/{runId}/stop": {
      "post": {
        "tags": [
          "Runs"
        ],
        "operationId": "stopRun",
        "summary": "Stop the in-flight turn and leave the session open",
        "parameters": [
          {
            "$ref": "#/components/parameters/RunId"
          }
        ],
        "responses": {
          "200": {
            "description": "Session remains AwaitingInput",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RunStatusResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/runs/{runId}/complete": {
      "post": {
        "tags": [
          "Runs"
        ],
        "operationId": "completeRun",
        "summary": "Close a chat session",
        "description": "Idempotent if already Completed. 409 if a turn is still in progress — call stop first.",
        "parameters": [
          {
            "$ref": "#/components/parameters/RunId"
          }
        ],
        "responses": {
          "200": {
            "description": "Session closed",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RunStatusResponse"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/runs/{id}/telemetry": {
      "get": {
        "tags": [
          "Runs"
        ],
        "operationId": "getRunTelemetry",
        "summary": "Run telemetry (OpenTelemetry GenAI)",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "OTEL-projected run telemetry",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RunTelemetry"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      }
    },
    "/inbox": {
      "get": {
        "tags": [
          "Inbox"
        ],
        "operationId": "listInboxEntries",
        "summary": "List inbox entries",
        "description": "Most recent first. Body is excluded from the list.",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/InboxEntryStatus"
            }
          },
          {
            "name": "created_since",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date-time"
            },
            "description": "ISO 8601 lower bound on CreatedAt"
          }
        ],
        "responses": {
          "200": {
            "description": "Entry summaries",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/InboxEntrySummary"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      },
      "post": {
        "tags": [
          "Inbox"
        ],
        "operationId": "createInboxEntry",
        "summary": "Add an inbox entry",
        "description": "Also runs inbox trigger matching and may create PENDING tasks.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateInboxEntryRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created entry including generated tasks",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InboxEntry"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/inbox/tasks": {
      "get": {
        "tags": [
          "Inbox"
        ],
        "operationId": "listInboxTasks",
        "summary": "List inbox tasks across entries",
        "parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/InboxTaskStatus"
            }
          },
          {
            "name": "entry_id",
            "in": "query",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Tasks, most recent first",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/InboxTask"
                  }
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    },
    "/inbox/{id}": {
      "get": {
        "tags": [
          "Inbox"
        ],
        "operationId": "getInboxEntry",
        "summary": "Inbox entry detail",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "responses": {
          "200": {
            "description": "Full entry including body and tasks",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InboxEntry"
                }
              }
            }
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          }
        }
      },
      "patch": {
        "tags": [
          "Inbox"
        ],
        "operationId": "updateInboxEntry",
        "summary": "Update entry status and/or content",
        "description": "Supply at least one field. title, source, and date are immutable. Status must move forward.",
        "parameters": [
          {
            "$ref": "#/components/parameters/Id"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateInboxEntryRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated entry",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InboxEntry"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/inbox/{entryId}/tasks/{taskId}": {
      "patch": {
        "tags": [
          "Inbox"
        ],
        "operationId": "updateInboxTask",
        "summary": "Update a task (approve, cancel, or edit action)",
        "description": "Setting status to RUNNING from AWAITING_APPROVAL approves the task and runs the linked workflow. status CANCELLED cancels from any non-terminal state.",
        "parameters": [
          {
            "name": "entryId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "taskId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UpdateInboxTaskRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Updated task",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InboxTask"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          }
        }
      }
    },
    "/transcription": {
      "post": {
        "tags": [
          "Transcription"
        ],
        "operationId": "transcribeFile",
        "summary": "Extract text from one uploaded file",
        "description": "multipart/form-data field `file`. Max 20 MB. File is discarded after extraction. Accepted: png, jpg, jpeg, webp, pdf, docx, xlsx, csv, md, markdown.",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "file"
                ],
                "properties": {
                  "file": {
                    "type": "string",
                    "format": "binary",
                    "description": "The file to extract text from"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Extracted text",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TranscriptionResult"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "brainApiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "Per-brain API key printed once at first deploy (`Authorization: Bearer <key>`). Missing or invalid keys return 401. Cross-tenant resources return 404, never 403."
      }
    },
    "parameters": {
      "Id": {
        "name": "id",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string"
        }
      },
      "RunId": {
        "name": "runId",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string"
        }
      },
      "WorkflowCode": {
        "name": "code",
        "in": "path",
        "required": true,
        "schema": {
          "type": "string",
          "example": "WF-CHAT"
        },
        "description": "Stable workflow deploy code"
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Missing/invalid field, or unknown type code",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Missing or invalid brain API key",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "Resource not found within this brain's scope",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Conflict": {
        "description": "Invalid state transition",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "required": [
          "error"
        ],
        "properties": {
          "error": {
            "type": "string"
          }
        }
      },
      "Variable": {
        "type": "object",
        "required": [
          "key",
          "value"
        ],
        "properties": {
          "key": {
            "type": "string"
          },
          "value": {
            "type": "string"
          }
        }
      },
      "Brain": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "instanceName": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "example": "Active"
          },
          "embeddingModel": {
            "type": [
              "string",
              "null"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "CreateEntityRequest": {
        "type": "object",
        "required": [
          "entityTypeCode",
          "name"
        ],
        "properties": {
          "entityTypeCode": {
            "type": "string",
            "description": "Must match a type in the brain schema"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "variables": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Variable"
            }
          }
        }
      },
      "UpdateEntityRequest": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          }
        }
      },
      "Entity": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "id": {
            "type": "string"
          },
          "entityTypeId": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "variables": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Variable"
            }
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "updatedAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "SetVariablesRequest": {
        "type": "object",
        "required": [
          "variables"
        ],
        "properties": {
          "variables": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Variable"
            }
          }
        }
      },
      "CreateUnitOfWorkRequest": {
        "type": "object",
        "required": [
          "entityId",
          "unitOfWorkTypeCode",
          "title"
        ],
        "properties": {
          "entityId": {
            "type": "string"
          },
          "unitOfWorkTypeCode": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "variables": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Variable"
            }
          }
        }
      },
      "UnitOfWork": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "id": {
            "type": "string"
          },
          "entityId": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "Open",
              "InProgress",
              "Complete",
              "Cancelled",
              "Failed"
            ]
          },
          "variables": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Variable"
            }
          },
          "completedDate": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          }
        }
      },
      "AppendContextRequest": {
        "type": "object",
        "required": [
          "title",
          "source"
        ],
        "properties": {
          "date": {
            "type": "string",
            "format": "date-time"
          },
          "title": {
            "type": "string"
          },
          "message": {
            "type": "string"
          },
          "source": {
            "type": "string",
            "description": "e.g. agent, user, system"
          }
        }
      },
      "AppendDataRequest": {
        "type": "object",
        "required": [
          "source",
          "type",
          "body"
        ],
        "properties": {
          "date": {
            "type": "string",
            "format": "date-time"
          },
          "source": {
            "type": "string"
          },
          "type": {
            "type": "string"
          },
          "body": {
            "type": "string",
            "description": "Unbounded string; typically JSON"
          },
          "tags": {
            "type": "string",
            "description": "Optional comma-separated tags"
          },
          "effort": {
            "type": "integer",
            "description": "Optional effort in seconds"
          }
        }
      },
      "UnitOfWorkTelemetryRecord": {
        "type": "object",
        "properties": {
          "recordType": {
            "type": "string",
            "enum": [
              "Context",
              "Data"
            ]
          },
          "date": {
            "type": "string",
            "format": "date-time"
          },
          "source": {
            "type": "string"
          },
          "title": {
            "type": [
              "string",
              "null"
            ]
          },
          "message": {
            "type": [
              "string",
              "null"
            ]
          },
          "type": {
            "type": [
              "string",
              "null"
            ]
          },
          "body": {
            "type": [
              "string",
              "null"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "WorkflowSummary": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "version": {
            "type": "integer"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          },
          "pendingTasks": {
            "type": "integer"
          }
        }
      },
      "RunRequest": {
        "type": "object",
        "properties": {
          "inputMessage": {
            "type": "string"
          },
          "entityId": {
            "type": "string"
          },
          "unitOfWorkId": {
            "type": "string"
          },
          "variables": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "description": "String→string map exposed to templates as {{input.<key>}} (BRA409)"
          },
          "callbackUrl": {
            "type": "string",
            "format": "uri",
            "description": "Async path only. Must be https (or localhost http in Development)."
          },
          "caller_jwt": {
            "type": "string",
            "description": "Opaque JWT forwarded to caller-jwt connectors. Never logged or echoed."
          }
        }
      },
      "ContinueRunRequest": {
        "type": "object",
        "required": [
          "inputMessage"
        ],
        "properties": {
          "inputMessage": {
            "type": "string"
          }
        }
      },
      "AsyncRunAccepted": {
        "type": "object",
        "properties": {
          "runId": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "example": "queued"
          }
        }
      },
      "RunStatusResponse": {
        "type": "object",
        "properties": {
          "runId": {
            "type": "string"
          },
          "status": {
            "type": "string"
          }
        }
      },
      "RunTelemetry": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "runId": {
            "type": "string"
          },
          "workflowId": {
            "type": "string"
          },
          "entityId": {
            "type": [
              "string",
              "null"
            ]
          },
          "unitOfWorkId": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "completedAt": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "resource": {
            "type": "object",
            "additionalProperties": true
          },
          "totals": {
            "type": "object",
            "additionalProperties": true
          },
          "spans": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": true
            }
          }
        }
      },
      "InboxEntryStatus": {
        "type": "string",
        "enum": [
          "PENDING",
          "REVIEWING",
          "APPLIED",
          "DISMISSED"
        ]
      },
      "InboxTaskStatus": {
        "type": "string",
        "enum": [
          "PENDING",
          "AWAITING_APPROVAL",
          "RUNNING",
          "COMPLETED",
          "FAILED",
          "CANCELLED"
        ]
      },
      "CreateInboxEntryRequest": {
        "type": "object",
        "required": [
          "title",
          "body"
        ],
        "properties": {
          "title": {
            "type": "string"
          },
          "body": {
            "type": "string",
            "description": "Full signal content (markdown)"
          },
          "source": {
            "type": "string"
          },
          "routingType": {
            "type": "string"
          }
        }
      },
      "UpdateInboxEntryRequest": {
        "type": "object",
        "properties": {
          "status": {
            "$ref": "#/components/schemas/InboxEntryStatus"
          },
          "body": {
            "type": "string"
          },
          "routingType": {
            "type": "string"
          }
        }
      },
      "InboxEntrySummary": {
        "type": "object",
        "additionalProperties": true,
        "description": "List row; body is omitted",
        "properties": {
          "id": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "source": {
            "type": [
              "string",
              "null"
            ]
          },
          "routingType": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "$ref": "#/components/schemas/InboxEntryStatus"
          }
        }
      },
      "InboxEntry": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "id": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "body": {
            "type": "string"
          },
          "source": {
            "type": [
              "string",
              "null"
            ]
          },
          "routingType": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "$ref": "#/components/schemas/InboxEntryStatus"
          },
          "tasks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/InboxTask"
            }
          }
        }
      },
      "InboxTask": {
        "type": "object",
        "additionalProperties": true,
        "properties": {
          "id": {
            "type": "string"
          },
          "status": {
            "$ref": "#/components/schemas/InboxTaskStatus"
          },
          "workflowRunId": {
            "type": [
              "string",
              "null"
            ]
          },
          "response": {
            "type": [
              "string",
              "null"
            ]
          }
        }
      },
      "UpdateInboxTaskRequest": {
        "type": "object",
        "properties": {
          "status": {
            "$ref": "#/components/schemas/InboxTaskStatus"
          },
          "action": {
            "type": "string",
            "description": "Instructions-only text passed to the workflow as its input message when the task runs"
          }
        }
      },
      "TranscriptionResult": {
        "type": "object",
        "required": [
          "result"
        ],
        "properties": {
          "result": {
            "type": "string"
          }
        }
      }
    }
  }
}