AI-assisted engineering/Debug the agent trace

The invoice agent retried a file the OCR service would never accept

Debug the agent traceMedium30 min

An invoice extraction agent ran out of retries on one file. It retried two different files, and only one of them deserved it.

Your task

Name the span where the agent first went wrong, then fix the error handling so the replay passes.

  • root_cause_span() returns the FIRST span whose plan contradicted what the agent already knew
  • on_error(code) returns "retry", "split", or "escalate"; code is the HTTP status, or None when there was none
  • 429 (rate limited) and 500, 502, 503, 504 (server faults) are worth another try
  • 413, a file over the size limit, is split into smaller files and sent again
  • any other code, and no code at all, goes to a person
  • leave call_tool() and check() alone; the OCR service is not the bug

The replay runs your on_error() across status codes at submit, and your named span is checked against the key.