Human-in-the-loop in AI Transport uses the tool calling primitives to create approval gates. The agent requests approval, the turn pauses, and any connected client can approve or reject. Because the session is durable, the approval request reaches the user even after reconnecting or switching devices.
How it works
The pattern builds on tool calling. The agent defines a tool that requires human approval. When the LLM invokes that tool, the turn ends with a pending tool call. The client presents the approval request to the user. When the user approves or rejects, the client submits the result via view.update(), which triggers a continuation turn.
The flow:
- The agent streams a response that includes a tool call requiring approval.
- The turn ends. The pending tool call is published to the channel.
- Any connected client sees the pending approval and presents it to the user.
- The user approves or rejects. The client calls
view.update()with the result. - A continuation turn starts. The agent receives the approval result and proceeds.
Define an approval tool
On the server, define a tool without an execute function. The tool's description tells the LLM when to request approval:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const result = streamText({
model: anthropic('claude-sonnet-4-20250514'),
messages: conversationHistory,
tools: {
requestApproval: {
description: 'Request user approval before executing a sensitive action',
inputSchema: z.object({
action: z.string().describe('Description of the action to approve'),
details: z.string().describe('Additional context for the user'),
}),
// No execute function - requires client-side approval
},
// Other tools that the agent can use after approval
executeTransfer: {
description: 'Execute a bank transfer',
inputSchema: z.object({ amount: z.number(), recipient: z.string() }),
execute: async ({ amount, recipient }) => {
return await processTransfer(amount, recipient)
},
},
},
abortSignal: turn.abortSignal,
})
const { reason } = await turn.streamResponse(result.toUIMessageStream())
await turn.end(reason)When the LLM decides an action needs approval, it invokes requestApproval. The turn ends with the tool call pending.
Handle approval on the client
On the client, detect pending approval requests and present them to the user:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const { nodes } = useView(transport)
// Find the node containing a pending approval request
const pendingNode = nodes
.find(n => n.message.parts?.some(p =>
p.type === 'dynamic-tool' &&
p.toolName === 'requestApproval' &&
p.state === 'input-available'
))
const pendingApproval = pendingNode?.message.parts
?.find(p => p.type === 'dynamic-tool' && p.state === 'input-available')
if (pendingNode && pendingApproval) {
const { action, details } = pendingApproval.args
// Render an approval UI
// First argument to view.update() is the Ably message ID of the node containing the tool invocation
return (
<ApprovalDialog
action={action}
details={details}
onApprove={() =>
view.update(pendingNode.id, [{
type: 'tool-output-available',
toolCallId: pendingApproval.toolCallId,
output: { approved: true },
}])
}
onReject={() =>
view.update(pendingNode.id, [{
type: 'tool-output-available',
toolCallId: pendingApproval.toolCallId,
output: { approved: false, reason: 'User declined' },
}])
}
/>
)
}When the user approves, view.update() submits the result and triggers a continuation turn. The agent receives { approved: true } as the tool result and proceeds with the action. If the user rejects, the agent receives the rejection and can adjust its behavior.
Multi-device approval
Because the session is a shared Ably channel, the approval request is visible on every connected device. Any device can submit the approval - the first response wins.
A user might start a conversation on their laptop, step away, and approve the request on their phone. The agent doesn't know or care which device approved it. The continuation turn starts as soon as any client submits the result.
1
2
3
// Device A (laptop) - sees the approval request
// Device B (phone) - also sees the same approval request
// Either device can call view.update() to approve or rejectThis is particularly useful for asynchronous workflows where the agent works on a task, hits a point requiring human judgment, and the user responds whenever they're available - from whichever device is convenient.
Durable approval requests
Approval requests survive disconnections. If the user is offline when the agent requests approval, the pending tool call persists in the channel history. When the user reconnects, the view loads the conversation including the pending request, and the approval UI appears.
The agent's turn has already ended, so there's no connection or timeout to worry about. The continuation turn starts only when the user submits their response - minutes, hours, or days later.
Related features
- Tool calling - the underlying mechanism for human-in-the-loop
- Multi-device sessions - approval from any connected device
- Reconnection and recovery - approval requests survive disconnections
- History and replay - pending approvals persist in history
- Client transport API - reference for
view.updateand other client methods. - Sessions and turns - how approval pauses and resumes turns.
- Get started - build your first AI Transport application.