Skip to Content
Recodocs

Operator chat

Console APIs for chatting with the operator agent, managing conversations, workspaces, UI tool handoffs, steering, and related reads.

8 min read

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

MethodPathPermissionHandlerWhat it does
POST/api/operator-chat/chatagents.operatechatStreams 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}/revealagents.operatereveal_valueReveals 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}/cancelagents.operatecancel_runRequests cancellation and polls until the run is no longer running (up to five seconds).
GET/api/operator-chat/ui/nextagents.operateui_nextLong-polls for the next ui tool request for a conversation (wait clamped 0–25s, default 20).
POST/api/operator-chat/ui/{call_id}agents.operateui_resultSubmits the panel result for a UI call; 404 JSON when resolve fails.
POST/api/operator-chat/runs/{run_id}/feedbackagents.operaterate_runRecords thumbs up/down feedback with optional reason and note on a run.
GET/api/operator-chat/modelsagents.operatemodelsReturns operator_chat.model_catalog for the application database and secrets.
GET/api/operator-chat/conversationsagents.operateconversationsLists conversations for the viewer with optional cursor and archived (active default).
POST/api/operator-chat/conversations/archive-allagents.operatearchive_all_conversationsArchives many conversations, optionally limited to conversation_ids.
GET/api/operator-chat/conversations/{conversation_id}agents.operateconversationLoads one saved conversation for the viewer.
POST/api/operator-chat/conversations/{conversation_id}/titleagents.operaterename_conversationRenames a conversation the caller owns.
POST/api/operator-chat/conversations/{conversation_id}/archiveagents.operatearchive_conversationSets archived flag on an owned conversation.
POST/api/operator-chat/conversations/{conversation_id}/resetagents.operatereset_conversationArchives the conversation (leaves list; runs and decisions stay on record).
GET/api/operator-chat/workspacesagents.operateworkspacesLists workspace folder state for the principal.
POST/api/operator-chat/workspacesagents.operatecreate_workspaceCreates a named workspace folder.
PATCH/api/operator-chat/workspaces/{folder_id}agents.operateupdate_workspaceUpdates folder name and/or expanded state.
DELETE/api/operator-chat/workspaces/{folder_id}agents.operatedelete_workspaceDeletes a workspace folder.
POST/api/operator-chat/conversations/{conversation_id}/workspaceagents.operateassign_workspaceAssigns an owned conversation to a folder; folder_id may be null.
GET/api/operator-chat/page-insightsagents.operatepage_insightsReturns host-counted chips for the open page from path, JSON reads, and optional record_id.
GET/api/operator-chat/journalagents.operatejournalReturns masked journal entries by record, asker, or self; limit 1–200 (default 50).
GET/api/operator-chat/conversations/{conversation_id}/filessandbox.runlist_filesMetadata for conversation working files on the latest run.
GET/api/operator-chat/conversations/{conversation_id}/files/contentsandbox.runfile_contentRaw 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/cleanupsandbox.runcleanup_filesCleans up files for a given request_id on the conversation file run.
POST/api/operator-chat/conversations/{conversation_id}/steeragents.operatesteer_answerInjects steering text into the running answer, or returns {"state": "next"} when none is running.
POST/api/operator-chat/runs/{run_ref}/steering/leftoversagents.operatesteering_leftoversReturns steering messages the finished or stopped run never consumed.
POST/api/operator-chat/steering/staleagents.operatesteering_staleMaps each approval_id to a stale reason or null after latest changes.

Request and response models

PageContextBody

FieldType
pathstr
readslist[dict[str, Any]] (default empty)
record_idstr | None
uidict[str, Any] | None

DecisionBody

FieldType
approval_idstr (length 1–64)
outcome"allow" | "deny" | "answer"
preview_fingerprintstr | None (max 128)

Extra fields are forbidden.

ChatRequest

FieldType
messageslist[dict[str, Any]] (min length 1)
conversation_idstr | None
run_idstr | None
surface"console" | "panel" (default "console")
page_contextPageContextBody | None
invoice_sourceInvoiceSourceRequest | None
modelstr | None
reasoning_enabledbool | None
reasoning_effortstr | None
fast_modebool (default false)
attachment_idslist[str] (max length 5)
decisionDecisionBody | 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

FieldType
refstr (length 1–64)

Response: dict from operator_chat.reveal.

FeedbackBody

FieldType
rating"up" | "down"
reasonstr | None
notestr | None (max 1000)

Response: dict from operator_chat.rate.

TitleBody

FieldType
titlestr (length 1–200)

Response: {"conversation_id", "title"}.

ArchiveBody

FieldType
archivedbool (default true)

Response: {"conversation_id", "archived"}.

ArchiveAllBody

FieldType
conversation_idslist[str] | None (max length 500)

Response: {"archived_count": count}.

WorkspaceFolderCreateBody

FieldType
namestr (length 1–60)

Response: {"folder": folder.to_dict()}.

WorkspaceFolderUpdateBody

FieldType
namestr | None (length 1–60 when set)
expandedbool | None

Response: {"folder": folder.to_dict()}.

ConversationWorkspaceBody

FieldType
folder_idstr | None

Response: {"conversation_id", "folder_id"}.

UiResultBody

FieldType
conversation_idstr
resultdict[str, Any]

Response: JSONResponse {"ok": true} on success, or {"ok": false} with status 404 when resolve fails.

FileCleanupBody

FieldType
request_idstr (length 1–256)

Response: return value of operator_files.cleanup.

SteerBody

FieldType
textstr (length 1–4000)

Response: steering result dict, or {"state": "next"} when operator_steering.NotRunning.

StaleBody

FieldType
approval_idslist[str] (max length 50)

Response: {"stale": {approval_id: reason or null}}.

Query and simple JSON responses

RouteNotable query/bodyResponse shape
ui_nextconversation_id, wait{"request": pending | null}
cancel_runpath run_ref{"run_id", "status"}
modelsnoneoperator_chat.model_catalog(...) dict
conversationscursor, archivedlisting dict
conversationpath idsaved conversation dict
workspaces GETnonelist_state dict
delete_workspacepath folder_id{"folder_id", "deleted": true}
page_insightspath, reads JSON string, record_idinsights dict
journalrecord, asker, limit{"record", "asker", "entries"}
list_filespath conversation_idfile metadata
file_contentpath, expected_hash, operation_id, result_kindraw bytes + ETag headers
steering_leftoverspath 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