Gate API
The Gate in Python and TypeScript, its options, its methods, and the values they return.
Same behavior and verdicts, names idiomatic to each language: Python keyword arguments are snake_case, TypeScript options are
camelCase, and wire data (approvals, reviews, receipts) is snake_case in both.
Building a gate
hitl.Gate(policy=None, /, **options) and new Gate(policy?, options?). With no policy the gate loads
policies/*.yaml. A policy is a path, a folder, a list of either, an inline document (a dict or object, still
snake_case), shorthand, or a Policy.
| Python | TypeScript | Default | Meaning |
|---|---|---|---|
policy_resolver | policyResolver | none | fn(tenant) returns the tenant's policy; instead of a fixed policy (Tenants) |
policy_resolver_timeout_ms | policyResolverTimeoutMs | 5000 | A slow resolver denies that tenant (hitl.policy_unavailable) |
store | store | memory | Approvals, limits, grants, history, executions (Stores) |
channels | channels | none | Channels referenced by name from approvers |
approvers | approvers | none | Code approvers by the name YAML uses (auto(...), chain(...), quorum(...)) |
default_channel | defaultChannel | terminal, else the only channel | Channel of the implicit default approver |
receipts | receipts | off | A JSONL path, a receipt store, or True / true for the store's own |
receipts_required | receiptsRequired | True | Deny when a pre-execution receipt cannot be written |
mode | mode | "wait" | "wait" or "suspend"; adapters pick per call |
default | default | policy's | Overrides the effect when no rule matches |
identities | identities | none | Maps reviewer and actor ids to people, for the self-approval check |
reviewer | reviewer | none | fn(approver, identity, approval): may this identity answer? Required by members: { permission } |
reviewer_timeout_ms | reviewerTimeoutMs | 5000 | A reviewer that times out rejects the review |
scorers | scorers | none | Named risk scorers; passing them makes unknown names a load error |
scorer_timeout_ms | scorerTimeoutMs | 1000 | Per scorer. A timeout scores 100 |
redact | redact | none | Runs before args are stored or shown. Digests cover the unredacted args |
deny_message | denyMessage | built in | What to tell the model on refusal |
on_decided | onDecided | none | Called after every terminal transition (also gate.on_decided(fn) / gate.onDecided(fn)) |
hook_retry | hookRetry | 5 attempts, doubling from 1s | Retries for a failing on_decided hook, on the gate's clock |
on_error | onError | none | Errors that cannot fail the call, such as hitl.receipt_lost |
logger | logger | silent | Structured logs. Args and results are never logged at info level |
sink | sink | ambient | Where approval events go |
clock | clock | system | Every timed wait sleeps on it; pass a FakeClock in tests |
ids | ids | ULIDs | Id generator |
context | context | none | Merged under every action's context |
tenant | tenant | none | Tenant for every action |
default_timeout | defaultTimeout | "1h" | Approval timeout when no rule or approver sets one |
reservation_ttl | reservationTtl | "15m" | How long a limit reservation lives if the process dies |
invariants | invariants | 10,000 events per scope | History bounds (InvariantOptions in Python) |
poll_ms | pollMs | 50 to 2000 ms | Wait-mode polling when the store cannot push |
Methods
All IO methods are async. Python also has blocking forms under gate.sync (gate.sync.respond(...)).
| Method | Returns | Does |
|---|---|---|
evaluate(action) | Decision | Policy only, with facts loaded from the store |
authorize(action, wait=, key=, consume=, ...) | Authorization | The full lifecycle. Never raises for denied, expired or pending |
redeem(action, ...) | Authorization | Execution wrappers: consume an existing approval, never create one (hitl.not_approved) |
consume(approval_id, execution_key=, tenant=) / consume(approvalId, { executionKey, tenant }) | Authorization | Consume an approved approval by id, from a process that has only the id (Durable execution) |
execution(key, tenant=) / execution(key, { tenant }) | execution or none | Read an execution record, tenant-checked: how a key ended, for an idempotent verify after settle |
settle(key, ok=, error_type=) / settle(key, { ok, errorType }) | execution, changed | Commit or release an execution's reservations and write executed, once, from any process (Durable execution) |
idle() | Waits for background work (hook retries) before shutdown. Python sync code: gate.sync.idle(timeout) | |
policy_for(tenant) / policyFor(tenant) | Policy | The policy a tenant's actions are evaluated with |
respond(approval_id, review) | RespondResult | Record one answer: accepted, duplicate, conflict, rejected, not_found |
cancel(approval_id, reason) | Approval | Cancel a pending approval |
get(approval_id) | Approval or none | Read one approval (applies expiry) |
pending(tenant=, tool=) | async iterator | Pending approvals, optionally for one tenant or a list |
sweep(limit=500) | count | Expire overdue approvals, pull missed answers from channels with status, release unsettled executions |
reload() | PolicyInfo | Reload policies; a failed reload keeps the old policy |
scorer(name, fn) | the gate | Register a risk scorer (a decorator in Python) |
webhooks(base_path=) | ASGI app / Fetch handler | Inbound handler for every channel (Channels) |
wrap(tool) | Tool | Gate a core Tool (a ToolMiddleware) |
@gate / gate.tool({...}) | gated callable | Gate a function (Python) or define a gated tool (TypeScript). .tool is the core Tool for adapters |
grants.list(action), grants.revoke(id) | Remembered approvals |
authorize options: wait (default: the gate's mode), key (idempotency key; required in suspend mode without a
call_id), adapter and scope (for the default key), consume (default true; native hooks pass false and the
execution wrapper consumes), create (false only redeems), resume (what an adapter needs to resume, stored on the
approval), input_schema / inputSchema (args that fail it are denied with hitl.invalid_args), execution_key /
executionKey (the durable key a consume is recorded under; "call_id" uses the action's call id and binds the
approval to it), bind_execution_key / bindExecutionKey (the only execution key that may consume the approval this
call creates). A stored idempotency_key passed back as key finds its approval (the gate's digest suffix is not
appended twice).
Authorization
| Field | Meaning |
|---|---|
granted | True only for allowed, or approved and consumed |
status | allowed, approved, denied, expired, cancelled, pending |
args | What to execute with: the frozen args, or the approver's edit |
decision, approval | The policy Decision, and the Approval when one was needed |
message, code | What to tell the model on refusal, and the machine reason (hitl.no_approver, ...) |
raise_for_status() / raiseForStatus() | Raises ActionDenied or ApprovalPending when not granted |
consumed, execution_key / executionKey | Whether this call consumed (or re-entered) an execution, and its key for settle |
succeeded(), failed(error) | After executing: settle the execution (commit or release reservations, write executed) |
Gated functions, tools and adapters call succeeded / failed for you.
Reviews
approve(by=, reason=, edited_args=, remember=, id=, digest=), deny(by=, message=, reason=, id=, digest=) and
escalate(by=, reason=) build reviews (hitl.approve(...) in Python, approve({...}) in TypeScript). digest is
the digest the reviewer saw; a mismatch is rejected. remember is a grant spec: { scope: session | thread | actor, match: exact | tool, ttl }.
Approvers in code
| Python | TypeScript | Meaning |
|---|---|---|
human(channel, name=) | human(channel, { to, name }) | A person answering through a channel (what YAML approvers build) |
auto(name, fn), or @hitl.auto(name) | auto(fn) or auto(name, fn) | Code that returns a review |
chain(name, *approvers) | chain(name, ...approvers) | Ask in order; an escalate answer passes to the next |
quorum(name, n, *approvers) | quorum(name, n, ...approvers) | n code approvers must approve. A quorum of people is YAML quorum: with members |
Register them in approvers= and refer to them from YAML by name (approver: kyc).