DEV Community

Haley
Haley

Posted on

How Should an AI Agent Recover When a Tool Call Times Out?

A refund tool returns a timeout. The agent knows it sent the request, but the payment system may have processed it before the response was lost. A retry could issue a duplicate refund. A confirmation could tell the customer that money is on the way before the system has verified it.

In Beyond LLMs: Building Reliable AI Agents, Madhumitha Kolkar, a senior machine learning engineer at SolarWinds, uses a hypothetical food-delivery refund to explain how an agent checks eligibility, acts within policy, and seeks human approval when required. The example makes a useful test for the agent harness, the software that controls which tools the model can use and how the workflow handles errors.

Three cases worth adding to the test suite

Scenario Expected behavior Evidence to check
The order ID is missing Ask for the order ID and pause the refund workflow. The agent never calls the refund tool.
A reviewer rejects the refund Record the decision and end or escalate the request according to policy. No refund was issued.
The payment provider times out after receiving the request Mark the result as unknown and check the payment system before deciding whether to retry. The payment system records at most one refund, and the customer sees a status supported by that record.

When the payment provider supports idempotency keys, reuse the same key when retrying the same refund request within the provider’s supported window. A workflow checkpoint can preserve where the agent stopped. The payment system is still the source of truth for whether the refund went through. If the outcome remains unknown, the workflow can escalate the case and give support the original request ID.

Five companies with examples developers can compare

  • GeekyAnts describes testing whether an internal engineering assistant chooses the right workflow and whether the work it produces meets the request.

  • SolarWinds is where Kolkar describes leading work on evaluations that examine the sequence of actions an agent takes.

  • Anthropic describes grading both the transcript of an agent run and the final state of the environment.

  • OpenAI documents how its Agents SDK can pause a run before a designated tool call and resume after a reviewer approves or rejects it.

  • Microsoft documents how Agent Framework can save workflow state and resume from a checkpoint.

Where should recovery logic live?

Should a tool wrapper resolve uncertain outcomes before returning control to the agent? Should the workflow orchestrator own that decision? Or should a separate reconciliation job handle operations that may take longer to confirm?

For teams that have shipped agents with write access, which approach has made retries and production incidents easier to reason about?

Top comments (1)

Collapse
 
rudratosh profile image
Rudratosh Shastri •

The key move is to stop treating the timeout as a failure. A timeout tells you what the caller observed, not what the server committed — the refund may well have gone through. So the agent shouldn't retry; it should resolve the uncertainty first. Put the operation in an explicit UNKNOWN state, then reconcile: query the provider by a stable reference you set at dispatch, and only re-send if that comes back empty. Never let an ambiguous outcome turn into an automatic second refund. I wrote the full recovery path out — state machine, reconciliation, the no-lookup-provider case — here: dev.to/rudratosh/your-ai-agent-ret...