Agent Harness Tutorial · End to end · Zoom level 3
How we take care of it: approval covers it
approval covers it catches a payout without a matching, recorded approval.
How we took care of it.
- Before paying above the limit, the claims system checks the approval itself: granted, not expired, same arguments, decided by someone other than the customer.
| It reads | the agent_state.approvals row for this payout |
| Kind | rule |
| Provided by | claims system |
| If it fails | refused |
| Where in the code | covers() · claims_system/server.py |
| Runs at | 5 · The tool itself |
Real exampleFlow 8: paid only after Asha's decision was recorded.
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.
def covers(
approval: ApprovalRecord | None,
*,
holder: str,
claim: Row,
key: str | None,
now: float,
limit: Decimal = AOAS_LIMIT,
) -> str | None:
"""Why this approval record does not cover paying this claim now, or `None`.
The call is rebuilt as this system received it — the claim, the amount this
system holds for it, the policyholder it verified, the key on the call — and
its digest must be the record's (`agent_harness.contracts.records.refusals`).
`limit` is the automatic limit read for this payout."""
if approval is None:
return "issue_payout needs an approval, and none this system can read was named"
amount = Decimal(str(claim.get("approved_amount", 0)))
failed = refusals(
approval,
action="issue_payout",
args={"claim_id": str(claim["id"]), "amount": str(amount)},
requested_for=holder,
idempotency_key=key or "",
now=now,
)
if approval.decided_by in (None, holder):
failed.append("nobody but the policyholder approved it")
if amount > limit and approval.decided_by == AUTOMATIC_APPROVER:
failed.append(f"{amount} is above the {limit} automatic limit, and no person decided it")
if not failed:
return None
return f"approval {approval.id} does not cover this payout: {'; '.join(failed)}"