Add human-in-the-loop
Pause for approvals, questions, typed inputs, or action-backed interactions.
Yolk models HITL in protocol, not UI. That means the same loop can pause in Next.js, Workers, WebSockets, or Vercel Workflows.
How it works
- The model calls a tool requiring approval, the built-in question tool, a typed input tool, or an action-backed interaction.
- The loop emits
AgentAwaitingInputwith pending requests. - Your UI renders the matching controls. Input forms use
InputRequest.input.kind; action-backed editors useInteractionRequest.interaction.kind. - Your app validates and resumes with typed
HitlResponsevalues.InteractionResponserequires an additional host-owned atomic acceptance step before resume; raw responses never authorize actions.
What the host owns
- matching pending request ids (Workflow hosts: match the named pause; see HITL resume)
- route auth
- UI copy and controls
- audit logs
- approval policy
- timeout/cancel UX
Runtime modes
For stateless routes, pass toolSet.inputs into the server's loop/runtime configuration and
include hitlResponses in the next runRuntime config. For durable sessions, use _tag: 'AppendHitlResponse' so the response is appended to the session event log.
For schema-backed forms, follow Collect typed input.
Pass toolSet.inputs alongside toolSet.tools into loop/runtime configuration; serializable tool
definitions alone cannot validate responses. Keep input forms pending until server acceptance.
Show what an approval changes
Give approval-gated tools a changePreview hook (makeTool({ approval, changePreview })) and pass
approvalPreviews: toolSet.approvalPreviews to loop/runtime configuration. Pending approval
requests then carry a tool-agnostic before → after preview; render it, or fall back to the raw
arguments when previewError is set. The same hook previews staged plan reviews. Follow
Preview the change.
Execute a reviewed action
Use makeInteractionTool, not makeInputTool, when the user edits values and chooses a
server-defined action that should execute without another model turn or approval. Follow
Authorize one action for the complete host contract.
Authenticate and validate before atomically accepting one immutable submission/cancellation.
Resolve with the scoped interactionHost, and pass both toolSet.interactions and
toolSet.interactionHost to loop/runtime config. Durable preflight first calls
loadInteractionReceipts and passes the snapshots to prepareToolBatch. All pending siblings
still fence dispatch. AppendHitlResponse only logs a response; it is not acceptance authority.
Keep submission pending until server acceptance, and acceptance active until a real outcome. An unknown outcome is not definite failure or permission to retry. Hosts own reconciliation. Voice and background execution do not support action-backed interactions.
A plan review (makePlanReviewTool) is an action-backed interaction too: a person reviews a code
mode script's staged approval-gated calls once and selects the calls to apply. Follow
Review a staged plan.
Finish calls that paused for input
Some calls pause after they were made: a remote MCP server asks a form before it finishes. The
tool stores the pause host-side and returns makeInputRequiredToolResult, an error result marked
{ code: 'input_required', inputRequired: { reviewToolName, pauseIds } }. The model then calls the
input review interaction (makeInputReviewTool, default review_input({ pauseIds }), renderer
input_review): your host loads the stored pauses through InputReviewHost, a person answers each
form (action submit with { answers }, one per pause), and the action resumes each pause once,
reporting it completed, input_required (asked again), not_sent, or unknown
(InputReviewOutcome). Follow
Finish calls that paused for input.
Related APIs
AgentAwaitingInputfrom@yolk-sdk/agent/protocolToolApprovalRequestfrom@yolk-sdk/agent/protocolQuestionRequestfrom@yolk-sdk/agent/protocolInputRequestfrom@yolk-sdk/agent/protocolInputResponsefrom@yolk-sdk/agent/protocolInteractionRequest,InteractionResponse,InteractionHostfrom@yolk-sdk/agent/protocolvalidateInteractionSubmissionfrom@yolk-sdk/agent/protocolmakeInteractionToolfrom@yolk-sdk/agent/toolsmakePlanReviewTool,previewStoredToolPlanfrom@yolk-sdk/agent/toolsmakeInputRequiredToolResult,toolInputRequiredfrom@yolk-sdk/agent/protocolmakeInputReviewTool,InputReviewHost,InputPauseResolution,InputReviewOutcomefrom@yolk-sdk/agent/toolsToolChangePreview,groupToolChangePreviewsfrom@yolk-sdk/agent/toolsloadInteractionReceiptsfrom@yolk-sdk/agent/loopplainHitlResponsefrom@yolk-sdk/agent/protocolquestionResponseStructuredContentfrom@yolk-sdk/agent/protocolinputResponseStructuredContentfrom@yolk-sdk/agent/protocoltoolRunsFromHitlRequestsfrom@yolk-sdk/agent/client