Deadlines and Outboxes for Agent Work

Lesson 2 of 4

Stop When the Budget Is Gone

Estimated time: 10 minutes

Stop when the budget is gone

A budget only helps if a spent budget changes behaviour. At zero remaining, cancel the calls that are still open, keep the results that already arrived, and report the run as partial.

Waiting anyway is the common mistake. The caller has already stopped listening for the answer, so the work continues for nobody, and the record of the run says nothing about why it took so long.

def finish(results, expired_hops):
    return {
        "status": "partial" if expired_hops else "ok",
        "returned": len(results),
        "expired": expired_hops,
    }

Name the hop that expired. A reader can act on the search hop expiring with four seconds left, and cannot act on a general request failure.

Report partial results rather than a single failure word. Cancelling three calls does not undo the results the other calls already returned.