Overview
ntrp uses a persistent SSE connection per session. Connect toGET /chat/events/{session_id} to receive all events (agent responses, tool calls, background task results). Messages are sent via POST /chat/message as fire-and-forget — the response arrives on the SSE stream.
Each event has a type field indicating what happened.
Event envelope
Every chat stream event includes server-owned ordering metadata:id field is the same value as seq. Clients should reconnect with after_seq=<last seen seq> and ignore events whose sequence is not greater than the last applied sequence for that session.
If after_seq is older than the server’s checkpoint watermark (events at or below the watermark are persisted to disk and only available via the history endpoint), or points past the server’s known stream generation, the server emits stream_reset. Desktop responds by reloading session history before applying more events for that session.
A checkpoint advances after every agent step (and at run finish) when the chat service persists messages. The replay buffer itself is not cleared at the checkpoint — it grows up to a fixed size and evicts oldest. Cursors at or above the checkpoint can replay from the buffer alone, no history reload needed; this is the fast path for tab-switch / brief disconnects.
While idle, the SSE keepalive comment frame carries the bus’s latest emitted sequence: : seq=<latest>\n\n. Clients can use this to confirm they are caught up without waiting for a real event.
Event types
thinking
Agent is processing. Includes a status message.
TEXT_MESSAGE_START
Assistant text block started.
TEXT_MESSAGE_CONTENT
Streamed assistant text delta. Only sent when streaming is enabled with ?stream=true.
seq. Accumulate them by message_id.
TEXT_MESSAGE_END
Assistant text block ended. Includes the cumulative content as a convenience.
TOOL_CALL_START
Agent invoked a tool.
TOOL_CALL_ARGS
Tool arguments. NTRP currently emits arguments atomically as a JSON string.
TOOL_CALL_END
Tool call input finished.
TOOL_CALL_RESULT
Tool execution completed.
approval_needed
Tool requires user approval before executing.
POST /tools/result to approve or reject.
RUN_STARTED
Run started.
RUN_FINISHED
Execution complete. Includes token usage.
RUN_ERROR
An error occurred.
background_task
A background task changed state (started, completed, failed, or cancelled).
run_backgrounded
A running agent was moved to background mode.
run_cancelled
Worker acknowledged cancellation and reached the terminal cancelled state.
POST /cancel returns 202 when the run exists and cancellation has been requested. The stream emits run_cancelled when the worker acknowledges cancellation and the run reaches its terminal cancelled state.
task_started, task_progress, task_finished
Sub-agent task lifecycle. These events link child work back to the parent tool row.
stream_reset
The requested after_seq cursor falls below the server’s checkpoint watermark (or is in the future). The client should reload session history and resume from the latest seq.
Approval flow
Whenapproval_needed is received:
- Display the tool call to the user
- Collect their decision (approve/reject)
- Submit via
POST /tools/result: