Skip to content

Commit e24c4f5

Browse files
committed
cover tool approvals in the client protocol
1 parent 31a17c3 commit e24c4f5

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

docs/ai-chat/client-protocol.mdx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,45 @@ After sending, subscribe to the output stream again (same URL, same auth) to rec
251251
On turn 2+, only send the **new** message(s) in the `messages` array — not the full history. The agent accumulates the conversation internally. On turn 1 (or after a continuation), send the **full** message history.
252252
</Warning>
253253
254+
### Tool approval responses
255+
256+
When a tool requires approval (`needsApproval: true`), the agent streams the tool call with an `approval-requested` state and completes the turn. After the user approves or denies, send the **updated assistant message** (with `approval-responded` tool parts) back via the same input stream:
257+
258+
```bash
259+
POST /realtime/v1/streams/{runId}/input/chat-messages
260+
Authorization: Bearer <publicAccessToken>
261+
Content-Type: application/json
262+
263+
{
264+
"data": {
265+
"messages": [
266+
{
267+
"id": "asst-msg-1",
268+
"role": "assistant",
269+
"parts": [
270+
{ "type": "text", "text": "I'll send that email for you." },
271+
{
272+
"type": "tool-sendEmail",
273+
"toolCallId": "call-1",
274+
"state": "approval-responded",
275+
"input": { "to": "user@example.com", "subject": "Hello" },
276+
"approval": { "id": "approval-1", "approved": true }
277+
}
278+
]
279+
}
280+
],
281+
"chatId": "conversation-123",
282+
"trigger": "submit-message"
283+
}
284+
}
285+
```
286+
287+
The agent matches the incoming message by its `id` against the accumulated conversation. If a match is found, it **replaces** the existing message (instead of appending). This updates the tool approval state, and `streamText` executes the approved tool on the next step.
288+
289+
<Note>
290+
The message `id` must match the one the agent assigned during streaming. If you're using `TriggerChatTransport`, IDs are kept in sync automatically. Custom transports should use the `messageId` from the stream's `start` chunk.
291+
</Note>
292+
254293
## Pending and steering messages
255294
256295
You can send messages to the agent **while it's still streaming a response**. These are called pending messages — the agent receives them mid-turn and can inject them between tool-call steps.

0 commit comments

Comments
 (0)