cleandataengineering.aiAgent Harness, drawn simply
You are here: End to end › Checks › 4 · Before the tool › approval gate

Agent Harness Tutorial · End to end · Zoom level 3

How we take care of it: approval gate

approval gate catches a payout over ₹25,000.

Open: 11before loopopen ›Open: 22before modelopen ›Open: 33after modelopen ›Open: 44before toolopen ›Open: 55the toolopen ›Open: 66after toolopen ›Open: 77after loopopen ›Open: 88before replyopen ›It readsthe payout amount and theautomatic limit (₹25,000, in Appapproval gateworkflow · harness + DBOSpassCarries onfailIf it failswait for a personWHERE IN THE CODE: F approvals/payout.py · H approvals/dbos.py
The strip at the top shows every check point where this check runs, in dark.

How we took care of it.

  1. request_payout starts a DBOS approval workflow.
  2. ₹25,000 or less: granted by policy:automatic-limit and paid in the same turn.
  3. More: it waits for a claims handler; Rohan is told nothing has been paid yet.
It readsthe payout amount and the automatic limit (₹25,000, in App Configuration)
Kindworkflow
Provided byharness + DBOS
If it failswait for a person
Where in the codeF approvals/payout.py · H approvals/dbos.py
Runs at4 · Before the tool
Real exampleFlow 7: ₹25,000 paid in 3.2 s. Flows 8 and 9: ₹25,001 waited for Asha.

More on this: Payout flow.

How it is done: the real code

Cut from the live repositories each time the site is built, so it always matches what runs.

    async def handle(arguments: dict[str, object]) -> ToolResult:
        claim_id = arguments.get("id")
        if not isinstance(claim_id, str) or not claim_id:
            return _error(REQUEST_PAYOUT, "a claim reference is required")
        approval = await approvals.request(
            action=PAYOUT_ACTION,
            args={"claim_id": claim_id},
            identity=identity,
            idempotency_key=idempotency_key,
            conversation_id=conversation_id,
        )
        if approval.state is ApprovalState.WAITING:
            raise PayoutRequested(approval)
        if approval.state is ApprovalState.DONE:
            # Named by its row, as every claims-system answer is: this answer is
            # the latest word on the claim's status (AOAS `consistency`, F-21).
            done = {
                "id": claim_id,
                "status": "paid",
                "approval_id": approval.id,
                "claim_id": claim_id,
                "amount": str(approval.args.get("amount", "")),
            }
            return ToolResult(name=PAYOUT_ACTION, text=approval.result or "", structured=done)
        if approval.declined:
            raise ActionDeclined(DECLINED_REPLY.format(claim_id=claim_id), approval.result or "")
        return _error(REQUEST_PAYOUT, approval.result or f"the payout is {approval.state.value}")