Error Propagation Across Subagents: Retry Locally, Then Report the Failure, the Attempts and What You Found
A research system asks whether customers prefer chat or email support, and the email search times out on page 3. The subagent retries once, then sends the coordinator the failure type, four logged attempts and two kept results, and the final report marks email as THIN instead of going quiet.
What you will learn
- Retry a transient failure inside the subagent before telling the coordinator
- Return a failure report with failure_type, attempted, partial_results and alternatives
- Tell an empty search (status ok, no matches) from a failed one (status partial, timeout)
- Write coverage notes so the final report shows where each answer is thin
Before you start
- How a coordinator hands work to subagents
- Basic Python dicts and exceptions
A research system is answering one question: Do customers prefer chat or email support? A coordinator hands the searching to subagents. Sooner or later one search fails. Here, the email search comes back with two words: search unavailable.
What can the coordinator do with that? Not much. It doesn't know what failed, what was tried, or whether anything was found before the failure. This article builds a subagent that reports a failure properly, and a coordinator that turns the report into an honest final answer.
One search fails, two bad endings
The coordinator sends a search subagent to the email support data. The subagent searches, and the answer is a timeout. Now a badly built system has two choices, and both are wrong:
- The whole run stops. The chat and phone searches already finished, and their results are thrown away.
- The gap just vanishes. The final report never mentions email, and nobody can tell that half of the question was never answered.
Two field reporters
Picture two reporters phoning the editor from a match. Reporter A says: no story. Why? What happened? What do I tell the readers? The editor can only guess.
Reporter B says: the stadium is closed (the failure type). I tried the gate twice (what was tried). I got two interviews (the partial results). I can try the press office (an alternative). Now the editor can decide. A subagent's failure report should sound like reporter B.
What travels back to the coordinator
Two anti-patterns
The silent empty. The email search times out, but the subagent returns an empty list as if it had succeeded. The coordinator reads that as "nobody wrote about email". The timeout is gone, and the gap is invisible.
Killing the run. One timeout and everything stops. Two finished searches are thrown away, and there's no report at all.
A generic status like "search unavailable" is no better than either. It says nothing about what failed, what was tried, or what was found. All three lose information the coordinator needs to recover.
subagent_report.py: retry once, then report
The project runs on stand-in data, so there's no model and no API key. The pages are a small dictionary, and fetch raises a TimeoutError for whichever page you tell it to fail.
"""A search subagent: retry once locally, then report what it knows.
Stand-in data, no key."""
PAGES = {"email_support": ["Email: fine for billing questions",
"Email: slow when the issue is urgent"],
"chat_support": ["Chat: quick answers",
"Chat: easy to ask more",
"Chat: good for short fixes"],
"phone_support": [],
"survey_archive": ["Survey: email wins for detailed issues"]}
def fetch(source, page, fail=None):
if fail == (source, page):
raise TimeoutError(f"{source} page {page} timed out")
return PAGES[source][page - 1:page]
def search(source, pages=1, fail=None, alternatives=()):
found, attempted = [], []
for page in range(1, pages + 1):
for attempt in (1, 2):
attempted.append(f"{source} page {page}, try {attempt}")
try:
found += fetch(source, page, fail)
break
except TimeoutError:
if attempt == 2:
return {"status": "partial",
"failure_type": "timeout",
"attempted": attempted,
"partial_results": found,
"alternatives": list(alternatives)}
return {"status": "ok", "source": source, "results": found}
Read search from the inside out:
- Retry once, locally. A timeout may pass, so each page gets a second try right here, before anyone else hears about it. The subagent is closest to the problem, so it handles the transient case itself.
- status partial and failure_type. If the second try also fails, the report says what kind of failure it was.
- attempted. Every page and try is logged, so the coordinator knows what not to repeat.
- partial_results. Whatever was found before the failure is kept, so nothing is thrown away.
- alternatives. Another source to try. The coordinator passes in the survey archive.
A search that works and finds nothing takes the last line: status is "ok" and results is an empty list. That's a real answer, and it looks different from a failure on purpose.
The report keys here are the project's own convention, not part of any SDK. What matters is that the four pieces of information are there.
coordinator.py: one decision per report
"""The stand-in coordinator: reads each report, decides, annotates."""
from subagent_report import search
def decide(report):
if report["status"] == "ok" and report["results"]:
return "USE the results"
if report["status"] == "ok":
return "RECORD: searched, found nothing"
if report["alternatives"]:
return "KEEP partial, TRY " + report["alternatives"][0]
return "KEEP partial, mark the gap"
reports = [search("chat_support", 3),
search("email_support", 3, ("email_support", 3),
["survey_archive"]),
search("phone_support", 1)]
notes = []
for r in reports:
print(decide(r))
if r["status"] == "partial":
kept = len(r["partial_results"])
print(" failure:", r["failure_type"], "| tried",
len(r["attempted"]), "| kept", kept)
extra = search("survey_archive", 1)
notes.append("email support: THIN, page 3 unavailable, "
f"survey archive added {len(extra['results'])}")
elif r["results"]:
notes.append("chat support: WELL SUPPORTED, all pages")
else:
notes.append("phone support: NO MATCHES, searched ok")
print("REPORT NOTES")
for n in notes:
print(" -", n)
decide has four outcomes. Results: use them. Status ok but empty: record it, because it is a valid answer. Partial with an alternative: keep what was found and try the alternative. Partial with nothing else to try: keep it and mark the gap. In every branch the gap ends up in notes, so it reaches the final answer. In a real system a model makes these decisions; here simple rules stand in for it.
The run sets up the failure on purpose: the email search is told to time out on page 3, with the survey archive as its alternative.
Run it
Running python coordinator.py:
USE the results
KEEP partial, TRY survey_archive
failure: timeout | tried 4 | kept 2
RECORD: searched, found nothing
REPORT NOTES
- chat support: WELL SUPPORTED, all pages
- email support: THIN, page 3 unavailable, survey archive added 1
- phone support: NO MATCHES, searched ok
- Chat came back complete, so the coordinator uses the results.
- Email timed out. "tried 4" is page 1 try 1, page 2 try 1, then page 3 twice. "kept 2" is the two email pages it read before page 3. The coordinator keeps them and tries the survey archive, which adds one more result.
- Phone searched fine and found nothing. That's recorded, not retried.
- REPORT NOTES has one coverage line for each area.
Empty is not failed
Be careful with one case. An empty list can mean two opposite things.
The phone search worked and there was nothing there. That is information: zero matches. The email search stopped before it could finish. That isn't an answer at all. If both come back as [], the coordinator has to guess, and it will usually guess "nothing there".
Coverage annotations in the final report
The last step is the final report. The coordinator writes the answer and marks how well each part is supported, straight from the notes above:
| Area | What was found (stand-in data) | Coverage |
|---|---|---|
| Chat | Quick answers, easy to ask more | WELL SUPPORTED: every page was read |
| Fine for billing, slow when urgent | THIN: page 3 unavailable, survey archive added | |
| Phone | No matches found | NO MATCHES: searched fine, nothing there |
Now a reader can see what to trust and exactly where the gap is. The email answer is still useful; it just says how thin it is.
Common mistakes
- Returning
[]on a timeout. The failure becomes a fake "no matches", and the gap disappears. - Raising all the way up. One timeout kills the run and throws away the searches that worked.
- A bare "search unavailable". No type, no attempts, no partial results, no next step.
- Sending every transient error up. A timeout that a second try would fix should be retried where it happened.
- Retrying an empty result. Status ok with no matches is an answer. Record it and move on.
- A final report with no coverage notes. The reader can't tell a well-supported answer from a thin one.
Recap
| Report | Meaning | Coordinator does |
|---|---|---|
| status ok, results | Search worked | Use the results |
status ok, [] | Searched, zero matches | Record it, don't retry |
| status partial, alternatives | Failed after a local retry | Keep partial, try the alternative |
| status partial, no alternatives | Failed, nowhere else to look | Keep partial, mark the gap |
On the exam, when a subagent times out, pick the answer that retries locally and then sends the coordinator the failure type, the attempts, the partial results and the alternatives. Reject a bare "unavailable", an empty success and stopping the whole run.
Try it yourself
Call search("email_support", 3, ("email_support", 3)) with no alternatives and check that decide returns "KEEP partial, mark the gap". Then make page 1 fail instead of page 3 and see what partial_results holds and how many attempts are logged.
Related course on Udemy
Claude Certified Architect - Foundations (CCAR-F) Exam Prep
Agentic loops, tools, MCP, Claude Code, prompts, structured output and context.View on Udemy ↗: Claude Certified Architect - Foundations (CCAR-F) Exam Prep (paid course, opens in a new tab)Related posts
The Claude Messages API: Your First Call, Field by Field
One request in, one Message out. The four fields of a Messages API call (model, max_tokens, system, messages), how to read content blocks, stop_reason and usage, and why every turn resends the history.
Claude Tool Use: How tool_use and tool_result Work in the Messages API
Follow one order question through Claude's tool round trip: define a tool, read the tool_use block, run your own function and send a matching tool_result back, including parallel calls and is_error.
Claude Client SDKs Wrap One REST API: Raw HTTP, Python, TypeScript and Async Calls Compared
Every Claude client SDK wraps the same REST request: a POST to /v1/messages with a JSON body. See it built by hand, through the Python and TypeScript SDKs, as typed errors, and as async calls that wait together.
Anthropic SDK Timeouts, Retries and Error Classes: Configure the Client Once, Then Give 429, 529, 400 and Timeouts Their Own Move
Configure the Anthropic SDK client (timeout, max_retries, with_options, async, pagination), see which errors it retries by itself, then repair a retry wrapper so a 429, a 529, a 400 and a timeout each get the move the docs support.
