Human in the loop
Example OrchaJS human-in-the-loop agent that pauses for approval, then resumes.
01import "./orcha/index.js";02import { orcha } from "orchajs";03 04let response = await orcha.approvalAgent.run({05 content: "Approve a $750 laptop for a new engineer.",06 clientCapabilities: ["request_human_approval"],07}).result;08 09if (response.status === "waiting_for_client_action") {10 // Collect this decision from your UI or approval system.11 const toolResults = response.clientToolCalls.map((call) => ({12 callId: call.callId,13 output: {14 approved: true,15 note: "Approved by the engineering manager.",16 },17 }));18 19 response = await orcha.approvalAgent.resume(20 response.sessionId,21 { toolResults },22 ).result;23}24 25if (response.status === "completed") {26 console.log(response.output);27}Move work into the caller
This example is a complete purchase approval agent. It can prepare the request,
but it cannot approve a purchase itself. The request_human_approval action
has execution: "client", so Orcha describes the action to the model without
providing executable server code.
When the model requests approval, Orcha stores the request and pauses safely.
The application receives the action name, validated arguments, and a callId.
After the human decides, the application resumes that same session with the
result. The process can restart or the decision can happen much later; the
model context is already durable.
Human approval is only one client-action pattern. The same boundary can ask a browser to upload a document, request a device location, open a confirmation screen, collect a signature, or use any capability owned by the caller.
Select any file in the editor to inspect the complete standalone project.
Understand each file
orcha/approvalAgent/actions/requestHumanApproval/index.json
Defines work that the application, not Orcha, must perform.
- execution: client means there is no index.js implementation.
- The parameters describe what the application receives.
- The output schema validates the human decision submitted on resume.
orcha/approvalAgent/index.json
Configures the purchase approval agent.
orcha/approvalAgent/instructions.md
Requires the model to request a human decision rather than approving a purchase itself.
orcha/index.ts
Configures Anthropic and registers approvalAgent.
app.ts
Advertises the client capability, handles the durable pause, and resumes with the human decision.
- A client action can also open a document picker, request a device location, show UI, or use another caller-owned capability.
- Use every callId returned by clientToolCalls exactly once.