Operator chat
Console APIs for chatting with the operator agent, managing conversations, workspaces, UI tool handoffs, steering, and related reads.
The operator chat API area backs console and panel surfaces that talk to the operator agent. Routes live under the /api/operator-chat prefix. The main chat endpoint streams admission, activity, heartbeats, and either a completed turn or a failure through the kit UI stream media type while the governed run executes on a worker thread.
What this API area is for
A streamed chat result has several stages. Admission tells the caller that work started; activity gives progress; completion or failure tells the caller how the turn ended. Do not treat progress as a completed answer.
Use these routes to ask questions and receive streamed answers, stop runs, rate outcomes, list and organize conversations, assign workspace folders, long-poll so the panel receives the next ui tool request for its conversation, submit UI results, reveal one restricted value the answer stands in for, steer in-flight answers, inspect page chips without calling a model, read the operator action journal, list model choices, and access conversation-scoped working files. Admission takes invoice source context and attachment summaries; a change-card decision is passed to operator_chat.answer, and stand-in mode is the x-recox-standin header when the key matches.
Routes
| Method | Path | Permission | Handler | What it does |
|---|---|---|---|---|
| POST | /api/operator-chat/chat | agents.operate | chat | Streams a governed answer: admits the turn, reports activity and draft text, then data-run or data-failure. |
| POST | /api/operator-chat/conversations/{conversation_id}/runs/{run_id}/reveal | agents.operate | reveal_value | Reveals one restricted value the answer stands in for; the caller needs people.pii.read and owns the conversation. |
| POST | /api/operator-chat/runs/{run_ref}/cancel | agents.operate | cancel_run | Requests cancellation and polls until the run is no longer running (up to five seconds). |
| GET | /api/operator-chat/ui/next | agents.operate | ui_next | Long-polls for the next ui tool request for a conversation (wait clamped 0–25s, default 20). |
| POST | /api/operator-chat/ui/{call_id} | agents.operate | ui_result | Submits the panel result for a UI call; 404 JSON when resolve fails. |
| POST | /api/operator-chat/runs/{run_id}/feedback | agents.operate | rate_run | Records thumbs up/down feedback with optional reason and note on a run. |
| GET | /api/operator-chat/models | agents.operate | models | Returns operator_chat.model_catalog for the application database and secrets. |
| GET | /api/operator-chat/conversations | agents.operate | conversations | Lists conversations for the viewer with optional cursor and archived (active default). |
| POST | /api/operator-chat/conversations/archive-all | agents.operate | archive_all_conversations | Archives many conversations, optionally limited to conversation_ids. |
| GET | /api/operator-chat/conversations/{conversation_id} | agents.operate | conversation | Loads one saved conversation for the viewer. |
| POST | /api/operator-chat/conversations/{conversation_id}/title | agents.operate | rename_conversation | Renames a conversation the caller owns. |
| POST | /api/operator-chat/conversations/{conversation_id}/archive | agents.operate | archive_conversation | Sets archived flag on an owned conversation. |
| POST | /api/operator-chat/conversations/{conversation_id}/reset | agents.operate | reset_conversation | Archives the conversation (leaves list; runs and decisions stay on record). |
| GET | /api/operator-chat/workspaces | agents.operate | workspaces | Lists workspace folder state for the principal. |
| POST | /api/operator-chat/workspaces | agents.operate | create_workspace | Creates a named workspace folder. |
| PATCH | /api/operator-chat/workspaces/{folder_id} | agents.operate | update_workspace | Updates folder name and/or expanded state. |
| DELETE | /api/operator-chat/workspaces/{folder_id} | agents.operate | delete_workspace | Deletes a workspace folder. |
| POST | /api/operator-chat/conversations/{conversation_id}/workspace | agents.operate | assign_workspace | Assigns an owned conversation to a folder; folder_id may be null. |
| GET | /api/operator-chat/page-insights | agents.operate | page_insights | Returns host-counted chips for the open page from path, JSON reads, and optional record_id. |
| GET | /api/operator-chat/journal | agents.operate | journal | Returns masked journal entries by record, asker, or self; limit 1–200 (default 50). |
| GET | /api/operator-chat/conversations/{conversation_id}/files | sandbox.run | list_files | Metadata for conversation working files on the latest run. |
| GET | /api/operator-chat/conversations/{conversation_id}/files/content | sandbox.run | file_content | Raw octet-stream content for a working file; optional query params are path, expected_hash, operation_id, and result_kind. |
| POST | /api/operator-chat/conversations/{conversation_id}/files/cleanup | sandbox.run | cleanup_files | Cleans up files for a given request_id on the conversation file run. |
| POST | /api/operator-chat/conversations/{conversation_id}/steer | agents.operate | steer_answer | Injects steering text into the running answer, or returns {"state": "next"} when none is running. |
| POST | /api/operator-chat/runs/{run_ref}/steering/leftovers | agents.operate | steering_leftovers | Returns steering messages the finished or stopped run never consumed. |
| POST | /api/operator-chat/steering/stale | agents.operate | steering_stale | Maps each approval_id to a stale reason or null after latest changes. |
Request and response models
PageContextBody
| Field | Type |
|---|---|
path | str |
reads | list[dict[str, Any]] (default empty) |
record_id | str | None |
ui | dict[str, Any] | None |
DecisionBody
| Field | Type |
|---|---|
approval_id | str (length 1–64) |
outcome | "allow" | "deny" | "answer" |
preview_fingerprint | str | None (max 128) |
Extra fields are forbidden.
ChatRequest
| Field | Type |
|---|---|
messages | list[dict[str, Any]] (min length 1) |
conversation_id | str | None |
run_id | str | None |
surface | "console" | "panel" (default "console") |
page_context | PageContextBody | None |
invoice_source | InvoiceSourceRequest | None |
model | str | None |
reasoning_enabled | bool | None |
reasoning_effort | str | None |
fast_mode | bool (default false) |
attachment_ids | list[str] (max length 5) |
decision | DecisionBody | None |
Extra fields are ignored on the envelope. The handler reads text only from the last user message’s parts with type "text".
Chat response: StreamingResponse with ui_stream.MEDIA_TYPE and ui_stream.HEADERS. The stream carries admission, activity, optional draft text parts, heartbeats every 10 seconds of silence, then either a run payload from operator_chat.turn with the answer text, or failure/error parts.
RevealBody
| Field | Type |
|---|---|
ref | str (length 1–64) |
Response: dict from operator_chat.reveal.
FeedbackBody
| Field | Type |
|---|---|
rating | "up" | "down" |
reason | str | None |
note | str | None (max 1000) |
Response: dict from operator_chat.rate.
TitleBody
| Field | Type |
|---|---|
title | str (length 1–200) |
Response: {"conversation_id", "title"}.
ArchiveBody
| Field | Type |
|---|---|
archived | bool (default true) |
Response: {"conversation_id", "archived"}.
ArchiveAllBody
| Field | Type |
|---|---|
conversation_ids | list[str] | None (max length 500) |
Response: {"archived_count": count}.
WorkspaceFolderCreateBody
| Field | Type |
|---|---|
name | str (length 1–60) |
Response: {"folder": folder.to_dict()}.
WorkspaceFolderUpdateBody
| Field | Type |
|---|---|
name | str | None (length 1–60 when set) |
expanded | bool | None |
Response: {"folder": folder.to_dict()}.
ConversationWorkspaceBody
| Field | Type |
|---|---|
folder_id | str | None |
Response: {"conversation_id", "folder_id"}.
UiResultBody
| Field | Type |
|---|---|
conversation_id | str |
result | dict[str, Any] |
Response: JSONResponse {"ok": true} on success, or {"ok": false} with status 404 when resolve fails.
FileCleanupBody
| Field | Type |
|---|---|
request_id | str (length 1–256) |
Response: return value of operator_files.cleanup.
SteerBody
| Field | Type |
|---|---|
text | str (length 1–4000) |
Response: steering result dict, or {"state": "next"} when operator_steering.NotRunning.
StaleBody
| Field | Type |
|---|---|
approval_ids | list[str] (max length 50) |
Response: {"stale": {approval_id: reason or null}}.
Query and simple JSON responses
| Route | Notable query/body | Response shape |
|---|---|---|
ui_next | conversation_id, wait | {"request": pending | null} |
cancel_run | path run_ref | {"run_id", "status"} |
models | none | operator_chat.model_catalog(...) dict |
conversations | cursor, archived | listing dict |
conversation | path id | saved conversation dict |
workspaces GET | none | list_state dict |
delete_workspace | path folder_id | {"folder_id", "deleted": true} |
page_insights | path, reads JSON string, record_id | insights dict |
journal | record, asker, limit | {"record", "asker", "entries"} |
list_files | path conversation_id | file metadata |
file_content | path, expected_hash, operation_id, result_kind | raw bytes + ETag headers |
steering_leftovers | path run_ref | {"run_id", "messages"} |
Behaviour and errors
Validation (422): Empty question text (invalid, “Ask a question”). Both invoice_source and decision together (source_context_mismatch). Invalid page_context (ValueError from operator_agent.page_context). Invalid chat model choice (ValueError from operator_chat.chat_choice). InvoiceValidationError with error code in the body. Attachment errors (AttachmentError code). Decision without conversation_id. Invalid reads JSON for page insights. Invalid archive listing parameters. Invalid workspace folder input (ValueError). Invalid feedback (ValueError). Invalid steering text (ValueError). Journal limit outside 1–200.
Refusals and conflicts: Stand-in header present but key mismatch → 403 forbidden. Decision allow may trigger ui_guard.refuse_if_agent_driving before admission. Rate limit on chat reserve → 429 rate_limited with Retry-After. Run refused → 409 run_refused. Store conflicts → 409 conflict. Stale confirmation after change → 409 stale_after_change. Workspace folder create or update Conflict returns 409 conflict.
Not found (404): Missing conversation or run where the store raises NotFound. UI result when resolve fails returns 404 JSON without raising HTTPException. RevealRefused raises HTTPException(error.status), code forbidden when status is 403 and not_found otherwise. Workspace folder not found. File routes report denied and not_found alike as not_found; other file errors use the status from operator_files.http_status.
Chat stream failures: Worker exceptions surface as guarded stream error text; ChatUnavailable emits unavailable failure parts; non-completed run states emit run_{state} failures. Trace URL is included in failure parts only when the viewer can_inspect.
Ownership: Mutations that call _owned require the conversation to belong to the viewer’s principal in the chat store.
Journal masking: When the viewer cannot inspect, run_id and digest are stripped from each entry.
File routes: _file_access requires at least one run on the conversation; otherwise NotFound('Conversation files unavailable').
How the permission model applies
Console routing uses route_roles.py: each handler is keyed as operator_chat_routes.<handler_name> and mapped to a permission string. The app-wide gate dependency refuses signed-in users whose role lacks that permission (403 denied). Unlisted handlers would block console startup via require_complete; this module’s handlers are all declared.
Most routes require agents.operate. Conversation file list, content, and cleanup require sandbox.run instead. Of the file handlers, only cleanup_files calls require_console_write_trust. Every POST, PATCH, and DELETE, and the ui_next poll, call it. Other GET reads do not.
With sign-in off, the caller is Recohut's OS admin on this computer; a bearer-authenticated machine call carries its own grants. The permission table is a ceiling: capabilities, the document kernel, and handler checks (for example reveal PII, journal inspect rights, conversation ownership) may narrow access further but do not widen it.
How is this page?
Last updated on