ADR-0015: Reply options and tool UI payloads
- Status: Accepted. Extended by ADR-0017: tool results as React components, on the path set here.
- Date: 2026-11-11
Context
Site owners want clickable answers under a bot's reply ("Yes, book it", "Show prices", "Talk to a person"), as Intercom and Drift have. Two sources make sense:
- The model suggests them from the conversation: likely next questions.
- A tool defines them from its result: the open slots a booking tool found, the plans a pricing tool returned.
The second is the first, smallest case of a wider need: a tool's result shown as UI, not as text. ADR-0008 and ADR-0011 planned toolRenderers (React components for tool results) for 0.3. Today the client sees only a tool's name and state (tool.status); its result never leaves the server.
The rules that bound the design:
- ADR-0004: the client never chooses tools, flows, instructions or models. A button can't trigger anything a typed message couldn't.
- ADR-0003: no database. Whatever the chat shows after a reload must come back from the OpenAI conversation.
- ADR-0011: answers render through the sanitized Markdown renderer; everything else renders as plain text.
- ADR-0013: browser events carry metadata only.
Decision
Common foundation
Both sources produce the same thing and share everything after it.
- Protocol: a new event
replies { messageId, items: string[] }, sent beforemessage.end. It is additive in protocol version 1: older clients ignore unknown events. At most one per answer. - Limits, enforced on the server and checked again in the client: at most 4 items of at most 80 characters, trimmed, non-empty and without duplicates. An item that contains a URL is dropped. If nothing is left, no event is sent.
- State:
ChatMessage.replies?: readonly string[]in the browser core, set by the reducer. - UI: a headless primitive
QuickReplieswith the partsreplies(the group) andreply(each button), plus the default look in the skin. It is shown only under the latest assistant answer, and disappears once the visitor sends anything.- Placement (added during implementation, #41): the theme variant
repliesputs the options under the answer (answer, the default) or in one row above the message field (composer). Placed outsideMessageList,QuickRepliesshows the latest answer's options. Every other rule here holds in both places.
- Placement (added during implementation, #41): the theme variant
- Rendering: each item is rendered as plain text, never as Markdown, so a reply can't carry links, images or formatting.
- A click is a visitor message. It calls
actions.send(text)with the item's text, exactly as if the visitor had typed it. The server can't tell the difference and doesn't need to: the message goes through the same limits and budgets as any other, and no tool, flow or instruction is selected by the click. - Events (ADR-0013, additive):
message.sentgetssource: 'reply'. - History after a reload:
openai/history.tsrebuilds the replies of the last answer from the storedfunction_callitems (and, for tool-defined replies, theirfunction_call_output), which it skips today. The history response gets an optionalreplieson that message. - Precedence: if a tool defined replies in a turn, the model's suggestion for that turn is ignored.
Variant A: model-suggested replies
- Opt-in per bot:
widget.replies: 'suggest'. The default is off. - A built-in, reserved tool
suggest_replieswith one argument,items: string[]. Its description tells the model to call it, at most once, when a few short next steps would help the visitor.defineBotrejects a bot tool with that name. - The server answers the call itself with a fixed output, because a call without an output breaks the next turn (spike S1, ADR-0003). It runs no bot code.
- Cost: the tool's definition adds input tokens to every step (inside the cached prefix), and when the model calls it before it has written its answer, the turn takes one more model step. The cost guide documents this.
- The last step:
toolChoice()inopenai/tools.tsforbids function tools on the turn's last step (onlyfile_searchstays), so a call there could not be answered. On that step the model can't suggest replies, and a bot withmaxSteps: 1never does. - A call after the answer (checked against the OpenAI docs during implementation, #46): the Conversations API accepts a
function_call_outputadded withconversations.items.create, so the server stores the fixed output there and the turn ends without another model call. If storing fails, the next turn's repair of a call left without output answers it. GPT-5.4 and later can mark text written before a tool call asphase: "commentary", which history doesn't show; then, as when the call comes before the answer, the server answers the call in one more step, in whichsuggest_repliesis no longer allowed, so the turn ends with a visible answer. The live smoke test (suggest_repliescase) shows which path a model takes. Once a tool has defined options in a turn,suggest_repliesisn't offered again in it, since the tool's options win; history reads a suggestion only from an answered call, as only then did the turn send it.
Variant B: tool-defined replies
-
A tool derives replies from its own result on the server, in the developer's code, not the model's. Two shapes are on the table:
defineTool({ ..., replies: (output) => string[] }), a function of the tool's result;executereturning{ result, replies }, where onlyresultgoes to the model.
The implementation picks one (or both); the protocol, the limits and the UI don't depend on it. The second shape is ambiguous for a tool whose real result has those keys, which favors the first.
- Chosen (during implementation, #47): only
replies: (output) => string[] | undefined. One option is a smaller public surface than two, and it leavesexecute's return value meaning one thing.repliesgets the output as stored, parsed back from JSON, so a live turn and a reload derive the same options; it runs only for a successful call, and when several calls of a turn define options, the last one wins.
-
The tool's result still never reaches the client. Only the replies do, after the same limits.
-
This is the first slice of tool UI payloads.
toolRendererswill follow the same path: the tool's code turns its result into a small, typed, size-capped payload; the server validates it and sends it as its own protocol event; the client renders it with known components, never with HTML from the server or the model. Each new payload kind gets its own event schema and limits.
Consequences
- New public API (ADR-0006):
- the
repliesprotocol event and therepliesfield in the history response (additive in protocol version 1); QuickRepliesand therepliesandreplyparts, and the theme variantreplies(answerorcomposer);widget.repliesand the reserved tool namesuggest_replies;- the
repliesoption ofdefineTool(the{ result, replies }shape was not taken, #47); source: 'reply'in the event catalog.
- the
- Security holds without new rules. A reply is model or tool output shown as text and sent back as the visitor's own words. A prompt injection (for instance in a knowledge-base document) can at worst suggest misleading text the visitor then chooses to send, which they could also have typed.
- The visitor's message is the reply's text, so the transcript,
onUsageand analytics stay simple. - Variant A costs tokens, and sometimes a step. That is why it's opt-in.
- Model-suggested replies are in the answer's language, so they follow a language switch from the next answer on (ADR-0014).
- History has to understand function calls for the first time. The mapper still shows only user and assistant messages; replies attach to the last answer only, so older turns aren't parsed.
Alternatives considered
- Structured output (
text.formatwith a JSON schema) holding the answer and the replies. Rejected:- it fights tools: every step's final text must match the schema, including the step after a tool call;
- it breaks citations:
file_searchannotations point into the output text, which would then be JSON; - it breaks streaming: the visitor would see JSON fragments, or the client would need a partial JSON parser to stream the answer field.
- Parsing a marker out of the answer text (for example a list after
---). Fragile, visible while streaming, and easy for a prompt injection to imitate. - Buttons that carry an action ID the server acts on (a flow or tool selected by the click). It lets the client choose server behavior, against ADR-0004. If a flow ever needs it, it gets its own ADR.
- Replies under every answer. Old suggestions go stale and invite clicks that make no sense later in the conversation.
- Markdown in replies. A button needs no formatting, and plain text removes a whole class of injection.
- Full
toolRenderersfirst. A typed, sanitized payload path is easier to get right with one small payload (a list of strings) than with arbitrary components.