Field note: what your OpenAI agent sees when a tool call fails
A refund tool times out after the refund went through. Here's what the OpenAI Agents SDK tells the model, and why that decides whether your customer is refunded twice. In my last field note I showed that when a tool call breaks, the agent often can't tell whether the action happened: the same error comes back whether the refund went through or not. This time I wanted to know what one popular…
When a tool call fails during an OpenAI agent's operation, the OpenAI Agents SDK (version 0.26.0) does not immediately stop the run. Instead, it turns the failure into the tool's output, and the model receives a message stating, "An error occurred while running the tool." This message does not indicate whether the request reached the server or if the refund was committed.
The SDK's default behavior leaves the exception out of the model's context, preventing internal details from leaking into the model's decision-making process.
To illustrate this, the author set up a testbench with a fake refund tool over MCP, a fault injected on purpose, and a local database that tracks the actual number of refunds. When the OpenAI Agents SDK's default error handler is used, the agent retries the tool call even after a failure, leading to two refunds for every order in the author's test run.
This occurs because the agent has limited information to decide whether to retry or not, as the error message is generic and does not reveal whether the refund was successfully completed.
However, when an idempotency key specific to each refund and order is used, the agent only performs one refund per order, regardless of the number of retries. This demonstrates that the key factor in avoiding double refunds is the usage of an idempotency key, which must be derived from the intended operation, not the attempt number. Additionally, enforcing the key at the service level (payment provider, database, or system making the refund) is crucial, rather than relying on the agent's failure_error_function.
The author concludes by emphasizing that hiding exception details from the model is a sensible default, and the SDK cannot determine the truth from the error message. The agent's decision to retry, give up, or report "done" is an educated guess in every case, and the responsibility of ensuring safe retries should lie with the system enforcing the idempotency key.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to