Skip to main content

viewport-hitl

Human approval and policy gates before agent side effects. Declare in YAML what an agent may do alone, what needs a person, and what it may never do. HITL enforces it at the tool boundary, asks the right people through the right channel, survives restarts while it waits, binds every approval to the exact arguments that were approved, and writes a hash-chained receipt for all of it.

Status: beta (v0.1). Python >= 3.11. The TypeScript twin is @viewportai/hitl; both pass the same conformance vectors.

pip install viewport-hitl   # or: uv add viewport-hitl

To build from source, see https://github.com/viewportai/hitl#from-source.

Extra Adds
slack hitl.slack(...) (httpx)
postgres hitl.postgres(dsn) (psycopg 3)
sign Ed25519 verification for hitl.console(...) reviews (cryptography)
otel OpenTelemetry spans (opentelemetry-api)
langgraph, claude-agent-sdk, openai-agents, pydantic-ai the framework adapter of the same name

hitl.sqlite(path), hitl.webhook(...), hitl.web(...) and hitl.terminal() need no extra.

Quickstart

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: denied
# policies/refunds.yaml
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

The most restrictive matching rule wins (deny > ask > allow), so a broad allow can never mask a narrow deny. Anything no rule mentions is denied. Sync functions stay sync, async functions stay async; issue_refund.tool is a core Tool for any adapter.

Production shape

A durable store shares approvals, limits, grants and receipts across processes (hitl.postgres(dsn) the same way):

def process_start() -> hitl.Gate:
    """One process: a fresh gate on the shared SQLite file, with receipts in the same file."""
    # redact_key="store" keeps a development redaction key in the store; production sets VIEWPORT_REDACT_KEY.
    return hitl.Gate(POLICY, store=hitl.sqlite(DB), receipts=True, clock=clock, redact_key="store")


invoice = {"tool": "send_invoice", "args": {"invoice_id": "INV-7"}, "call_id": "call_1"}
key = "workflow-42:step-3"  # your runtime's stable step identity

Channels are referenced by name from YAML approvers; their answers arrive through one ASGI app:

clock = FakeClock("2026-11-25T10:00:00Z")
gate = hitl.Gate(
    POLICY,
    mode="suspend",  # a web app: never block a request waiting for a human
    clock=clock,
    channels=[
        hitl.slack(token="xox" + "b-your-bot-token", signing_secret=SLACK_SIGNING_SECRET, transport=slack_api),
        hitl.webhook(
            name="compliance",
            url="https://compliance.example/hitl",
            secret=OUTBOUND_SECRET,
            inbound_secret=INBOUND_SECRET,  # a receiver of the requests cannot sign answers
            transport=compliance,
            now=clock.now,
        ),
    ],
)


@gate
async def send_campaign(campaign: str, audience: str) -> str:
    return f"Sent {campaign} to {audience}"


# Mount this at /hitl in your ASGI app: Slack buttons and webhook replies land here.
webhooks = gate.webhooks(base_path="/hitl")

Suspend instead of waiting, so any process can answer later:

action = {"tool": "send_wire", "args": {"to": "ACME-002", "amount": 9_000}, "call_id": "call_2"}
auth = await gate.authorize(action, wait=False)  # returns "pending" at once
assert auth.approval is not None
approval_id = auth.approval.id

clock.advance(FOUR_HOURS)  # nobody answered
swept = await gate.sweep()  # optional: expiry is also applied lazily on every read

late = await gate.respond(approval_id, hitl.approve(by="pager:kim"))  # too late: "conflict", already expired
retry = await gate.authorize(action, wait=False)  # status "expired", never runs

Testing

with hitl.testing.fake_approvals(answer="approve") as approvals:
    assert issue_refund("A-1002", 900) == "Refunded $900 on A-1002"
    assert approvals.asked("issue_refund", args={"amount": {"gt": 50}})

The pytest plugin gives the same thing as the approvals fixture. tests: blocks in policies/*.yaml and policies/*.test.yaml run as pytest items (pytest policies/) and with viewport-hitl test.

CLI

viewport-hitl check | explain | test | receipts verify | pending | approve | deny | init

Docs: https://docs.getviewport.com/hitl

Background

I started Viewport in early 2026. These packages are the v0.1 rebuild: small, composable pieces for agents that act, shaped by what I learned leading an agent platform in production.

License

Apache-2.0.

Metadata

Release files for viewport-hitl 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for viewport-hitl 0.1.0
File Size Uploaded Provenance Actions
viewport_hitl-0.1.0.tar.gz 221.1 kB Without provenance Details for viewport_hitl-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for viewport-hitl 0.1.0
File Interpreter ABI Platform Actions
viewport_hitl-0.1.0-py3-none-any.whl Python 3 none any Details for viewport_hitl-0.1.0-py3-none-any.whl

Total release size: 485.6 kB

Release files / viewport_hitl-0.1.0.tar.gz

Download URL viewport_hitl-0.1.0.tar.gz
Size 221.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3cc58886b7b20c333f3c82ada5b76ef71ab3b42ec4b5a68cf24076896054a8a6
BLAKE2b-256 checksum
How to use checksums
fbf8b00dda68dcde63d94b580c3d7db668b7037b20a42d82961a99178c985f7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / viewport_hitl-0.1.0-py3-none-any.whl

Download URL viewport_hitl-0.1.0-py3-none-any.whl
Size 264.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
06eea2c76926e0ec6ce80f63c60132b5178b34eac22d81270a8c6aef2031417d
BLAKE2b-256 checksum
How to use checksums
8cb71b90ac6b45788fa0fbb93792da418cd0e3656449d39b55be8207d6b2cf38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for viewport-hitl 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page