Skip to content

Conversations

One exchange with one person, on any channel. The protocol, the transports, the limits and the retention.

Updated

A conversation is one exchange between one person and the agents of a front door. It has an id that starts with cv_. Web chat, phone, email, Slack, Teams and the console are channels of the same model.

A conversation holds the door, the channel, the person, the transcript, the current agent and run, the session values and the guard state. It starts runs for its agents:

  • The first message starts a run of the routed agent (role main).
  • The next messages go to the same run while it waits for a turn.
  • A handoff ends the current run and starts a run of the target agent (role handoff).
  • When the current run has ended or expired, the next message starts a new run of the same agent with the transcript (role continuation).

Runs that an HTTP call, a schedule, an inbound webhook or a delegation starts are not conversations. They have no cv_ id.

Statuses and end reasons

Status Meaning
working A run of the conversation works.
needs_you The agent asked a question.
idle The conversation waits for the next message.
failed The last run failed. The next message starts a new run.
ended The conversation is over. It takes no more messages.
End reason Cause
participant The person ended it (end item, the end of a call).
idle No input for session.idle_ttl.
max_turns The person sent session.max_turns messages.
at_capacity A limit of the door was reached.
maintenance The kill switch of the door is on.
guard The output checks flagged strikes replies in a row.
console A console user ended it.
channel The channel ended it: a call ended, or an embed key was revoked.
error A voice run failed during a call.

Items

The protocol run.cv.v1 carries items. A client sends input items and gets output items. Each durable output item has an integer seq. A client resumes with the last seq it saw.

Input items

Type Fields Rule
text text, client_id? A message of the person. At most 4,000 characters.
file name, content_type, data (base64), client_id? Attaches to the next text of the same batch. A batch with files and no text is one message with empty text.
answer question_id, value, client_id? The answer to an open question. With choices, value must be one of the choice values. A free-text answer is a message and goes through the input checks.
variable name, value Sets a session variable of the door. The value must match its type and range.
cancel Stops the current turn.
typing Resets the idle clock. Never stored.
end Ends the conversation (participant).
audio data Reserved. Refused with unsupported_item.

client_id is free text, at most 64 characters. A repeated text or answer with the same client_id gets the earlier seq and starts no new turn. Use it to retry safely.

One turn is in flight at a time. A text while an agent works answers error with turn_in_flight. Wait for a status item with idle or needs_you, or send cancel.

Output items

Durable items have seq (an integer) and at. Ephemeral items have seq: null, are never stored and never replayed. The seq values rise, but can have gaps: do not expect them to be contiguous.

Type Seq Fields
user durable client_id, text, files (name, content_type). A refused message has blocked: true and empty text.
message durable id, run_id, agent, text (Markdown).
message.delta ephemeral message_id, run_id, agent, attempt, offset, text, reset?.
question durable id, run_id, agent, text, choices (value, label) or null for free text.
activity durable id, run_id, agent, label, status (running, done, failed). One row per tool call: replace by id.
ui durable id, run_id, agent, component, props, fallback.
file durable id, run_id, agent, name, content_type, size, url.
event durable run_id, agent, name, data. Only the names in channels.web.events.
handoff durable from, to, reason (null), run_id.
language durable lang.
blocked durable client_id, kinds, message, reason (flagged or unavailable).
ended durable reason, message.
status ephemeral state (working, idle, needs_you), agent.
error ephemeral code, message, client_id.

Streaming text

The agent text streams as message.delta items, then comes whole as one message with the same id (message_id of the delta, id of the message).

  • Join the deltas of one message_id by offset, the index of the first character of the delta. Drop a delta whose offset is below the length you have.
  • A delta with a higher attempt starts the text of that message again. reset: true clears the text of that message.
  • When the message arrives, show its text and drop later deltas of that id.
  • A door with output checks streams no text before the check (hold: reply), or only checked sentences (hold: sentence).

Error codes

Code When
turn_in_flight A message while an agent works, a check runs or a rewrite runs.
invalid_item A bad item: an answer not in the choices, a variable out of range.
unsupported_item audio, or a file on a door that refuses files.
rate_limited The person is over per_participant.turns_per_minute.
conversation_ended The conversation has ended.
forbidden An observer sent an item.
not_found No such question or conversation.
too_large A text over 4,000 characters, or a file over the limit.
internal A server error. Try again.

Transports

A web client uses the public routes on the org host, https://{org}.cloudraker.run. The web chat does all of this for you. Use these routes to write your own client.

Method and path Auth Answer
GET /_cv/door/{embed_key} None. Origin must be an origin of the door. { door, turnstile: { sitekey, challenge_url } }
GET /_cv/challenge/{embed_key}?origin= None. The Turnstile challenge page for an iframe.
POST /_cv/start/{embed_key} A Turnstile token. 201 { conversation_id, session_token, expires_at, socket_url, items_url, stream_url, door }
POST /_cv/{cv}/ticket Authorization: Bearer cvs_... { ticket, expires_in: 30 }. A one-time socket ticket.
GET /_cv/{cv}/socket?after=&ticket= The socket ticket in ?ticket=. Subprotocol run.cv.v1. 101, a WebSocket.
POST /_cv/{cv}/items Authorization: Bearer cvs_... { seq, items }. Body { items: [...] }, at most 7 MB.
GET /_cv/{cv}/stream?after= Authorization: Bearer cvs_... text/event-stream.
POST /_cv/{cv}/session Authorization: Bearer cvs_... { session_token, expires_at }. A new session token.
DELETE /_cv/{cv} Authorization: Bearer cvs_... { ok: true }. Ends the conversation.

The start body is { turnstile_token, lang?, variables?, gate_accepted? }. A door with a gate needs gate_accepted: true, else 400 invalid_request. Read Web chat.

Session token

The start answers a session token, cvs_.... It is scoped to one conversation, one origin and one embed key.

  • It expires after the door session.idle_ttl with no renewal, and 24 hours after the start at the latest.
  • Every HTTP answer on /_cv/{cv}/* carries a new token in the x-run-session-token header. Use the newest one for the next request.
  • An open socket keeps the expiry of the token it opened with. Only POST /_cv/{cv}/session moves the expiry of an open socket. A header renewal does not.
  • While a socket is open, call POST /_cv/{cv}/session before the expiry of that socket, also after a header renewal. Do this again after each reconnect.
  • Keep the token in memory, or in sessionStorage at most. Never send it in the query string: the gateway refuses it.
  • Never send the token in a socket request. Use a socket ticket.
  • The browser never holds a crk_ key.

WebSocket

A browser socket cannot send the Authorization header. Before each connect and each reconnect, get a socket ticket with POST /_cv/{cv}/ticket and the session token. Then open wss://{org}.cloudraker.run/_cv/{cv}/socket?after={seq}&ticket={ticket} with the subprotocol run.cv.v1 only. The server echoes run.cv.v1.

  • A ticket opens one socket. It expires 30 seconds after the ticket answer.
  • The ticket is for the conversation, the origin and the session of its request. The socket keeps the expiry of the session token in the x-run-session-token header of the ticket answer.
  • The gateway refuses a session token in the subprotocol list with 400.
const res = await fetch(`https://${org}.cloudraker.run/_cv/${cv}/ticket`, {
  method: 'POST',
  headers: { authorization: `Bearer ${sessionToken}` },
})
const { ticket } = await res.json()
const ws = new WebSocket(`wss://${org}.cloudraker.run/_cv/${cv}/socket?after=${lastSeq}&ticket=${ticket}`, 'run.cv.v1')
ws.onmessage = (e) => {
  for (const item of JSON.parse(e.data).items) render(item)
}
ws.send(JSON.stringify({ items: [{ type: 'text', text: 'Hello', client_id: crypto.randomUUID() }] }))
  • Frames are JSON text. A client frame is {"items": [...]}. A server frame is {"items": [...]}.
  • On open, the server replays the durable items after after (default 0), in frames of at most 200 items or 1 MiB, then goes live.
  • The text frame ping gets pong. The server sends no heartbeat.
  • Errors for a sent item come back as error items, not as a close.
Close code Meaning Do this
1000 The conversation ended, after the ended item. Stop.
1011 Server error. Reconnect with the last seq.
4001 The open socket passed the expiry of its session. Stop. Start a new conversation.
4003 Reserved. Stop.
4004 No such conversation. Stop.
4008 More than 10 sockets and streams on this conversation. Close another one.
4029 Reserved. Wait, then reconnect.

The gateway refuses a spent or expired ticket, a ticket of another conversation and a wrong origin with an HTTP status (401 or 403) before the upgrade. A browser then sees close 1006 and no status. After some sockets that do not open, use the HTTP and SSE fallback: its answers carry the status.

HTTP and SSE fallback

When the socket does not open, send items with POST /_cv/{cv}/items and read GET /_cv/{cv}/stream.

  • SSE frames: id: {seq} for durable items (no id for ephemeral items), event: item, data: {item JSON}.
  • A comment : hb comes every 15 seconds.
  • Resume with the Last-Event-ID header or ?after=.
  • EventSource cannot send the Authorization header. Read the stream with fetch and a streamed body.

Limits

Limit Value
Text of one message 4,000 characters. Email, Slack and Teams cut longer text with a notice.
One file over WebSocket 768 KB decoded, per frame.
One file over HTTP 5 MB decoded.
Files per conversation 25 MB in total.
Open sockets and streams 10 per conversation. More get close 4008 or 429 too_many_streams.
Turns in flight 1 per conversation.
Handoffs 3 per message of the person.
Web starts 10 per minute per IP address, per org.
Web item posts 60 per minute per IP address, per org.
Conversation starts 10 per minute per person and door, as a backstop to the door limits.
Session token session.idle_ttl with no renewal, 24 hours in total.

The door limits add to these. Read Front doors.

Retention

The door sets the retention of the conversation and of its runs (session.retention, 1m to 90d, default 30d).

  1. end, the idle time, a cap or the kill switch ends the conversation. The current run is cancelled with by: conversation.
  2. At ended_at plus the retention, the platform deletes the items, the transcript, the files that no run used, and the identity of the person: the id, the display name, the email, the thread key and the embed key.
  3. A stub stays for 90 days. It holds the door, the channel, the status purged, the counts of turns and runs, the credits, model_cost_usd, the guard units and the times. No text.
  4. After the 90 days, the stub goes too.

A refused message is never kept. Its user item has empty text.

Console and CLI

The console shows every conversation of the org: its door, its channel, the current agent, the status and the end reason. A console viewer that does not own a conversation is an observer. It reads, but cannot send. The console also gets the run events of each run, so it can show the work of the agents.

rakerun conversation list --scope agents --door support/support --channel web
rakerun conversation show cv_01K7...
rakerun conversation stream cv_01K7... --after-seq 12
rakerun conversation send cv_01K7... --input "Thanks" --stream
rakerun conversation end cv_01K7...

Billing

A conversation costs what its runs cost: run minutes and AI usage, as for every run. Guard and router calls are not billed in the beta. The conversation reports credits and the guard units it used.

Type to search…

↑↓ navigate↵ selectEsc close