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.
How we took care of it.
- request_payout starts a DBOS approval workflow.
- ₹25,000 or less: granted by policy:automatic-limit and paid in the same turn.
- More: it waits for a claims handler; Rohan is told nothing has been paid yet.
| It reads | the payout amount and the automatic limit (₹25,000, in App Configuration) |
| Kind | workflow |
| Provided by | harness + DBOS |
| If it fails | wait for a person |
| Where in the code | F approvals/payout.py · H approvals/dbos.py |
| Runs at | 4 · 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}")