HITLReference

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.

PythonTypeScriptDefaultMeaning
policy_resolverpolicyResolvernonefn(tenant) returns the tenant's policy; instead of a fixed policy (Tenants)
policy_resolver_timeout_mspolicyResolverTimeoutMs5000A slow resolver denies that tenant (hitl.policy_unavailable)
storestorememoryApprovals, limits, grants, history, executions (Stores)
channelschannelsnoneChannels referenced by name from approvers
approversapproversnoneCode approvers by the name YAML uses (auto(...), chain(...), quorum(...))
default_channeldefaultChannelterminal, else the only channelChannel of the implicit default approver
receiptsreceiptsoffA JSONL path, a receipt store, or True / true for the store's own
receipts_requiredreceiptsRequiredTrueDeny when a pre-execution receipt cannot be written
modemode"wait""wait" or "suspend"; adapters pick per call
defaultdefaultpolicy'sOverrides the effect when no rule matches
identitiesidentitiesnoneMaps reviewer and actor ids to people, for the self-approval check
reviewerreviewernonefn(approver, identity, approval): may this identity answer? Required by members: { permission }
reviewer_timeout_msreviewerTimeoutMs5000A reviewer that times out rejects the review
scorersscorersnoneNamed risk scorers; passing them makes unknown names a load error
scorer_timeout_msscorerTimeoutMs1000Per scorer. A timeout scores 100
redactredactnoneRuns before args are stored or shown. Digests cover the unredacted args
deny_messagedenyMessagebuilt inWhat to tell the model on refusal
on_decidedonDecidednoneCalled after every terminal transition (also gate.on_decided(fn) / gate.onDecided(fn))
hook_retryhookRetry5 attempts, doubling from 1sRetries for a failing on_decided hook, on the gate's clock
on_erroronErrornoneErrors that cannot fail the call, such as hitl.receipt_lost
loggerloggersilentStructured logs. Args and results are never logged at info level
sinksinkambientWhere approval events go
clockclocksystemEvery timed wait sleeps on it; pass a FakeClock in tests
idsidsULIDsId generator
contextcontextnoneMerged under every action's context
tenanttenantnoneTenant for every action
default_timeoutdefaultTimeout"1h"Approval timeout when no rule or approver sets one
reservation_ttlreservationTtl"15m"How long a limit reservation lives if the process dies
invariantsinvariants10,000 events per scopeHistory bounds (InvariantOptions in Python)
poll_mspollMs50 to 2000 msWait-mode polling when the store cannot push

Methods

All IO methods are async. Python also has blocking forms under gate.sync (gate.sync.respond(...)).

MethodReturnsDoes
evaluate(action)DecisionPolicy only, with facts loaded from the store
authorize(action, wait=, key=, consume=, ...)AuthorizationThe full lifecycle. Never raises for denied, expired or pending
redeem(action, ...)AuthorizationExecution wrappers: consume an existing approval, never create one (hitl.not_approved)
consume(approval_id, execution_key=, tenant=) / consume(approvalId, { executionKey, tenant })AuthorizationConsume an approved approval by id, from a process that has only the id (Durable execution)
execution(key, tenant=) / execution(key, { tenant })execution or noneRead 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, changedCommit 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)PolicyThe policy a tenant's actions are evaluated with
respond(approval_id, review)RespondResultRecord one answer: accepted, duplicate, conflict, rejected, not_found
cancel(approval_id, reason)ApprovalCancel a pending approval
get(approval_id)Approval or noneRead one approval (applies expiry)
pending(tenant=, tool=)async iteratorPending approvals, optionally for one tenant or a list
sweep(limit=500)countExpire overdue approvals, pull missed answers from channels with status, release unsettled executions
reload()PolicyInfoReload policies; a failed reload keeps the old policy
scorer(name, fn)the gateRegister a risk scorer (a decorator in Python)
webhooks(base_path=)ASGI app / Fetch handlerInbound handler for every channel (Channels)
wrap(tool)ToolGate a core Tool (a ToolMiddleware)
@gate / gate.tool({...})gated callableGate 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

FieldMeaning
grantedTrue only for allowed, or approved and consumed
statusallowed, approved, denied, expired, cancelled, pending
argsWhat to execute with: the frozen args, or the approver's edit
decision, approvalThe policy Decision, and the Approval when one was needed
message, codeWhat 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 / executionKeyWhether 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

PythonTypeScriptMeaning
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).

On this page