You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 7e92a02
Browse filesBrowse the repository at this point in the historyBrowse files
docs(ai-chat): clarify user selection and tool approval
Explain when to collect a tool result with `addToolOutput` and when to
combine `needsApproval` with `execute`. Cover choosing from search
results in the human-in-the-loop guide, including server-side selection
checks and stable operation IDs for retries.
Clarify transcript restoration and the limits of tool-result filtering
for external side effects. Update the frontend approval examples and
link them to the selection guidance.
Mono-RevId: 6c6be1ef71ea4846ba9929179edf48eee77a2af7
Copy file name to clipboardExpand all lines: docs/ai-chat/frontend.mdx
+12-5Lines changed: 12 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -354,7 +354,9 @@ See [Stop generation](/ai-chat/backend#stop-generation) in the backend docs for
354
354
355
355
## Tool approvals
356
356
357
-
The AI SDK supports tools that require human approval before execution. To use this with `chat.agent`, define a tool with `needsApproval: true` on the backend, then handle the approval UI and configure `sendAutomaticallyWhen` on the frontend.
357
+
AI SDK 6 and later support `needsApproval: true` on tools with an `execute` function. The approval request appears before `execute` runs. Approving the call runs it on the next turn; denying it skips execution.
358
+
359
+
To collect a selection from search results, use a tool without `execute` and supply its result with `addToolOutput`. See [Choose from tool results](/ai-chat/patterns/human-in-the-loop#choose-from-tool-results).
358
360
359
361
### Backend: define an approval-required tool
360
362
@@ -377,7 +379,7 @@ const sendEmail = tool({
377
379
});
378
380
```
379
381
380
-
Pass the tool to `streamText`in your `run` function as usual. When the model calls the tool, `chat.agent` streams a `tool-approval-request` chunk. The turn completes and the run waits for the next message.
382
+
Declare the tool on the agent and pass it to the `streamText`supplied to your `run` function. When the model calls the tool, `chat.agent` streams a `tool-approval-request` chunk. The turn completes and the run waits for the next message.
381
383
382
384
### Frontend: approval UI
383
385
@@ -387,9 +389,14 @@ Destructure `addToolApprovalResponse` from `useChat` and wire it to your approva
0 commit comments