An agent that works perfectly in a demo can fail quietly in production. The usual cause is not the model’s reasoning — it is a tool that times out, returns half the data, or returns data that looks fine but is wrong. This worked example shows how a reliable agent handles each case.

Why are tool failures the hard part of agentic AI?

Language models are good at continuing confidently. If a tool returns incomplete data, a naive agent will often summarise whatever it received and present it as the full answer. Nothing crashes, so nobody notices. Reliability therefore depends on the agent checking results before it uses them, and responding differently to different kinds of failure.

The scenario

An operations team asks an agent: “Summarise last week’s failed payments by region.” The agent has one tool, query_payments, which accepts a status, a date range and a pagination cursor. It returns rows, an optional error, and a has_more flag when results are truncated.

Step 1: Define what a good result looks like

Before calling the tool, the agent needs a contract for a usable result. For this task, a good result:

  • has no error;
  • includes every page of results, not just the first;
  • has a region on every row, because the summary is grouped by region;
  • contains only rows inside the requested date range.

Step 2: Classify the failure

Different failures need different responses. Treating them all the same — usually by retrying — wastes time on permanent errors and hides data problems.

Failure types and the right response
Failure typeExampleRight response
TransientTimeout, rate limitRetry with backoff, up to a fixed limit
RepairableTruncated results (has_more)Fix the request — fetch the next page
IncompleteRows missing a required fieldDo not fill the gap; report it
WrongRows outside the requested datesDo not use the data; escalate
PermanentUnauthorised, unknown toolStop immediately and escalate

Here is the check, written as a small, testable function that runs on every tool result:

def check_payments_result(result, start, end):
    """Classify a tool result before the agent is allowed to use it."""
    if result.error in {"timeout", "rate_limited"}:
        return Check(ok=False, kind="transient", reason=result.error)
    if result.error in {"unauthorised", "unknown_tool"}:
        return Check(ok=False, kind="permanent", reason=result.error)
    if any(row.get("region") is None for row in result.rows):
        return Check(ok=False, kind="incomplete", reason="rows missing region")
    if any(not (start <= row["date"] <= end) for row in result.rows):
        return Check(ok=False, kind="wrong", reason="rows outside requested dates")
    return Check(ok=True, kind="ok")

Step 3: Bound the recovery

Recovery must have limits, or a failing agent becomes an expensive loop. The agent below retries transient errors a fixed number of times, follows pagination up to a page limit, and returns an explicit escalation instead of guessing when anything else goes wrong.

def fetch_failed_payments(tool, start, end, max_attempts=3, max_pages=20):
    rows, cursor = [], None
    for _ in range(max_pages):
        for attempt in range(1, max_attempts + 1):
            result = tool.query_payments(status="failed", start=start, end=end, cursor=cursor)
            check = check_payments_result(result, start, end)
            if check.kind != "transient":
                break
            wait_with_backoff(attempt)
        if not check.ok:
            # Still transient after retries, permanent, incomplete or wrong: never guess.
            return Escalation(reason=check.reason, partial_rows=rows)
        rows.extend(result.rows)
        if not result.has_more:
            return rows                    # complete, validated data
        cursor = result.next_cursor        # truncated result: repair by fetching the next page
    return Escalation(reason="page limit reached", partial_rows=rows)

Two details matter. First, the retry limit and page limit are explicit, so the worst case is known in advance. Second, the escalation carries the partial rows and the reason, so a person can decide quickly without repeating the work.

Step 4: Escalate honestly

When the agent cannot complete the task, its final message should say exactly what it knows and what it does not. Compare these two endings:

  • Unreliable: “Failed payments last week: North 42, South 17.” (Silently based on the first page only.)
  • Reliable: “I retrieved 3 of an expected 5 pages before the payments service returned an authorisation error. The partial totals are below; please check access for the reporting account before relying on them.”

The second answer is less satisfying in the moment and far more useful. Honest uncertainty is a feature of a well-designed agent, not a weakness.

How can you practise this skill?

Take an agent you have built and deliberately break its tools: return timeouts, truncate results, drop a field, or shift dates. Watch what the agent does, then add checks and limits until every failure ends in either a correct answer or a clear escalation. This “recover” stage is central to the BrihatLabs Agentic AI learning path. If you are new to agents, start with what agentic AI is and how it differs from a chatbot.

Key takeaways

  • Validate every tool result against an explicit contract before the agent uses it.
  • Classify failures — transient, repairable, incomplete, wrong, permanent — and respond to each differently.
  • Bound retries and steps so the worst case is known in advance.
  • When in doubt, escalate with what is known and unknown, rather than guessing.