Reporting and Observing Agent Runs Honestly
Lesson 1 of 4
Report Three Counts
Estimated time: 10 minutes
A batch is rarely all or nothing
The most misleading word in a status report is done. A batch that processed ninety of a hundred items is partly done, and a caller that reads done as everything is done will skip the remaining ten.
Report three counts, not one: succeeded, failed and skipped. Skipped separates the items the run chose not to touch from the items that broke, and those two groups need different follow up.
def summarize(total, results):
ok = [r for r in results if r["status"] == "ok"]
bad = [r for r in results if r["status"] == "error"]
return {
"succeeded": len(ok),
"failed": len(bad),
"skipped": total - len(results),
"failed_ids": [r["id"] for r in bad],
}
Name the failures, not just their number. A count says how bad it is, the identifiers say where to look.