Yolk SDK
Build guides

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

  1. The model calls a tool requiring approval, the built-in question tool, a typed input tool, or an action-backed interaction.
  2. The loop emits AgentAwaitingInput with pending requests.
  3. Your UI renders the matching controls. Input forms use InputRequest.input.kind; action-backed editors use InteractionRequest.interaction.kind.
  4. Your app validates and resumes with typed HitlResponse values. InteractionResponse requires 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.

  • AgentAwaitingInput from @yolk-sdk/agent/protocol
  • ToolApprovalRequest from @yolk-sdk/agent/protocol
  • QuestionRequest from @yolk-sdk/agent/protocol
  • InputRequest from @yolk-sdk/agent/protocol
  • InputResponse from @yolk-sdk/agent/protocol
  • InteractionRequest, InteractionResponse, InteractionHost from @yolk-sdk/agent/protocol
  • validateInteractionSubmission from @yolk-sdk/agent/protocol
  • makeInteractionTool from @yolk-sdk/agent/tools
  • makePlanReviewTool, previewStoredToolPlan from @yolk-sdk/agent/tools
  • makeInputRequiredToolResult, toolInputRequired from @yolk-sdk/agent/protocol
  • makeInputReviewTool, InputReviewHost, InputPauseResolution, InputReviewOutcome from @yolk-sdk/agent/tools
  • ToolChangePreview, groupToolChangePreviews from @yolk-sdk/agent/tools
  • loadInteractionReceipts from @yolk-sdk/agent/loop
  • plainHitlResponse from @yolk-sdk/agent/protocol
  • questionResponseStructuredContent from @yolk-sdk/agent/protocol
  • inputResponseStructuredContent from @yolk-sdk/agent/protocol
  • toolRunsFromHitlRequests from @yolk-sdk/agent/client

On this page