TypeScript from steps 1 to 3
TypeScript from steps 1 to 3
4. Gate the tool
Replace the body of your tool’sonToolCalled with the gate. approve runs the real side effect and returns the result. block returns a refusal with the gate’s reason in the note. The note goes to the model, which writes the reply to the customer, so if you don’t want check names like right_order=0.01 in the model’s context, send a fixed message and keep reason in your log. review returns null, which pauses the loop exactly as it did under the static rule. The ticket reaches both hooks through the tool’s contextSchema, which the tools reference documents.
A human resolves a paused call by returning a decision, not a payment result. The review surface returns approve or deny. resolveReview in step 5 copies the refund from the pending call in your conversation state into the function_call_output, and onResponseReceived runs the same arithmetic and the same issueRefund as an automatic approval. The SDK passes onResponseReceived only the output it receives and doesn’t expose the original call’s arguments, so resolveReview must be the only code that writes a function_call_output for this tool. A review surface that wrote its own could submit a refund Jev never evaluated, and only the arithmetic check would limit it. The Python tabs in steps 4 and 5 use the Python port of the Agent SDK. Install it with pip install openrouter-agent-sdk and import it as openrouter_agent. Keep every Python import and helper from steps 1 to 3, including os, RefundInput, GateDecision, gate_refund, and refundable_problem, but leave out the step 1 __main__ smoke test and the step 3 loop over cases. The Go tabs call the Responses API directly and run the same hooks in their own loop. If you add the Go code to the first page’s program, replace its main, which only runs the Decisions smoke test, with one that calls handleTicket and then resolveReview in the same process, so resolveReview finds the pending call in the in-memory store.
askJev throws because Decisions is down or returned something the schema rejects, the SDK records the error as that call’s output in the form { error: ... }. The model receives the error instead of a refund result, nothing is issued, and the model may call refund again, which runs the gate again. If you’d rather a human reviewed the calls Jev couldn’t evaluate, catch the error from gateRefund alone and return null. Don’t do the same for the ticket parse, since onResponseReceived parses the same context and a reviewer’s approval would fail on it too. The gate never returns approve without the required evidence.
5. Pass the ticket and handle the pause
Pass the ticket to the tool throughcontext, keyed by tool name, alongside the tools and state you already pass to callModel. After the run, check the state. awaiting_hitl means the gate returned review, and the pending call goes to your review surface as before. The other status values are listed in the Tool Approval & State reference.
Resuming follows the HITL recipe, step 4 with two differences. The function_call_output includes a ReviewDecision whose refund is copied from the pending call in the saved state, so the reviewer only provides a decision and a note. The resumed call passes the same context, because onResponseReceived reads the ticket from it.
handleTicket with the placeholder issueRefund. The model proposed 1200 cents, the gate approved it, and the model told the customer:
8900 cents with its own reason text, which scored policy_covers lower than the step 3 fixture did (0.26 against 0.41) and still landed in the review band. The gate returned review and the run paused:
resolveReview with the pending call’s ID and 'approve'. onResponseReceived issues the refund and the model closes the ticket:
refund.reason is part of the state and the model wrote its own. The agent model didn’t propose the espresso refund in any of our runs, so we exercise the block path by calling gateRefund directly, as in step 3. The gate guarantees the outcome. The model’s judgment doesn’t.
Next steps
- Add Human-in-the-Loop Controls for the review surface and the resume flow that receives this gate’s paused calls
- Tool Approval & State for
requireApprovalwhen a consent gate before execution is the right mechanism - Jev documentation for
scoreandchoicequestions, when a tool has more than one legitimate disposition - Jev SDK for TypeScript and Python to make the same request with the TypeSafe SDK instead of
fetch - Auto-Approve Coding Agent Permission Prompts with Jev for the same gate as a permission hook in Claude Code, Codex, Cursor, or OpenCode
- Cut LLM Cost with a Jev-Verified Cascade for using Jev to verify model answers rather than tool calls
- Jev documentation hub for the Jev tutorial, the other cookbooks, and the TypeSafe docs on choosing thresholds
- Jev model page and Jev Lab for pricing and interactive demos
- Other decision models on OpenRouter from OpenAI, Microsoft, Perplexity, Cloudflare, and others take the same Decisions API request: change
modeland re-check your thresholds on a labeled sample