Viewport HITL
Human approval and policy gates before agent side effects, in Python and TypeScript.
Status: Beta. Install from npm (@viewportai/hitl) or PyPI (viewport-hitl); see the quickstart.
Viewport HITL puts a policy and, when needed, a person between an agent and its side effects. You declare in YAML what an agent may do alone, what needs a human, and what it may never do. The gate enforces it at the tool boundary, asks the right people through the right channel (Slack, a signed webhook, the terminal, your own), keeps the request durable while it waits, binds the answer to the exact arguments that were approved, and writes a hash-chained receipt for every step.
| Python | TypeScript | |
|---|---|---|
| Package | viewport-hitl (import from viewportai import hitl) | @viewportai/hitl |
| Runtime | Python 3.11+ | Node 22+ (from source: 22.18 or later) |
| CLI | viewport-hitl | npx @viewportai/hitl |
30 seconds
A policy file. Refunds run on their own; refunds over $50 need a human; anything no rule mentions is denied.
rules:
refunds: { allow: issue_refund }
negative-refunds:
deny: issue_refund
when: { args: { amount: { lt: 0 } } }
reason: A refund amount cannot be negative
large-refunds:
ask: issue_refund
when: { args: { amount: { gt: 50 } } }
reason: Refunds over $50 need a human
A complete program: gate the function (it keeps its signature) and call it twice. Save it next to the policies/
folder as quickstart.py or quickstart.ts.
from pathlib import Path
from viewportai import hitl
gate = hitl.Gate(Path(__file__).parent / "policies" / "refunds.yaml")
@gate
def issue_refund(order_id: str, amount: float) -> str:
return f"Refunded ${amount:g} on {order_id}"
print(issue_refund("A-1001", 20)) # policy allows it: runs now
try:
print(issue_refund("A-1002", 900)) # asks you in the terminal first
except hitl.ActionDenied as denied:
print(denied.status, denied.message) # your "no", or no terminal to ask: deniedimport { ActionDenied, Gate } from "@viewportai/hitl";
const gate = new Gate(`${import.meta.dirname}/policies/refunds.yaml`);
const issueRefund = gate.tool({
name: "issue_refund",
input_schema: {
type: "object",
properties: { order_id: { type: "string" }, amount: { type: "number" } },
required: ["order_id", "amount"],
},
execute: async ({ order_id, amount }) => `Refunded $${amount} on ${order_id}`,
});
console.log(await issueRefund({ order_id: "A-1001", amount: 20 })); // policy allows it: runs now
try {
console.log(await issueRefund({ order_id: "A-1002", amount: 900 })); // asks you in the terminal first
} catch (e) {
if (!(e instanceof ActionDenied)) throw e;
console.log(e.status, e.message); // your "no", or no terminal to ask: denied
}The $20 refund runs. The $900 refund asks you in the terminal; with no terminal and no channel configured, the ask
fails closed and the call is denied with hitl.no_approver:
Refunded $20 on A-1001
denied No approver or channel is available for "default"This is the repository's examples/*/quickstart program. To run it, or your own copy, from a clone, see
Quickstart and the README's Getting started.
Why
- Policies people can read. Rules are YAML with
allow,askanddeny. The most restrictive matching rule wins, so order never matters and a broad allow can never mask a narrow deny. - Approvals bound to what runs. An approval covers one exact action (a canonical digest of tool, arguments, actor and the context the policy reads). Different arguments need a new approval. Each approval runs once.
- Fails closed. Errors, unknown results, store failures and missing approvers deny; an approval that times out
denies unless a rule opts into
on_timeout: allow. - Native to each agent framework. LangGraph interrupts, Claude Agent SDK hooks, OpenAI Agents SDK interruptions and Vercel AI SDK tool approvals, with an execution-time check behind each.
- Auditable. Every decision, request, answer and execution is a hash-chained receipt you can verify offline.
Where next
- Quickstart: a refund agent with a human on the support desk, end to end.
- Concepts: actions, policies, approvals, channels, receipts, invariants.
- Guides: LangGraph, Claude Agent SDK, OpenAI Agents SDK, Vercel AI SDK, Pydantic AI.
- Reference: the policy schema, the Gate API, errors and the CLI.
Every code sample on these pages is pulled from a runnable example in
examples/. Each runs with no API keys and checks its own
outcome in CI.