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 framework does with that moment. I wired the OpenAI Agents SDK to the same testbench: a fake refund tool over MCP, a fault injected on purpose, and a local database that counts how many refunds really happened.

What the SDK hands the model

When an MCP tool call fails, for example because the client times out, the OpenAI Agents SDK (0.26.0) does not stop the run. By default it turns the failure into the tool's output, and the model reads this:

An error occurred while running the tool.

That's the whole message. It doesn't say whether the request reached the server, whether the refund was committed, or whether a retry is safe. That's deliberate: the SDK's default leaves the exception out, so internal details don't leak into the model's context. (I checked the SDK's source: default_tool_error_function returns exactly that sentence, and passing failure_error_function=None makes the error raise out of the run instead.)

So the model has to decide what to do with almost no information.

What happens next

I ran the agent with a scripted model, so there was no API key and the result was the same every time. Its rule was simple: if the tool call fails, call it again. The fault let the refund commit, then held the reply until the client timed out.

  • Retry without an idempotency key: two refunds for every order. In an independent tester's run with the SDK's default error handler, 5 orders produced 10 refunds. The agent reported "done" each time.
  • Retry with one stable key per refund (refund-<order_id>, the same on every attempt, enforced by the refund service): one refund per order, every time.

The scripted model chooses to retry, so this shows what that choice leads to. It doesn't measure how often a real model makes it. But "an error occurred, so try again" is a very natural reading of that message.

The SDK isn't doing anything wrong

Hiding exception details from the model is a sensible default, and the SDK can't know whether your tool's side effect happened. The point is where the safety has to live:

  • Not in the error message. The model can't infer the truth from it, and neither could a human. The same failure looks identical whether the refund was made or not.
  • Not in the model's judgement. Whether it retries, gives up or says "done" is a guess in every case.
  • In the operation itself. One idempotency key per intended refund, sent on every attempt and enforced by the system that makes the refund. Then a retry is harmless, whatever the model decides.

A status check before retrying helps, but it's weaker. It can run while the first request is still in flight, and a separate test showed it fails when the agent's own process restarts.

If you use the OpenAI Agents SDK

  • Give your side-effecting tools an idempotency key, and derive it from the operation, not the attempt. A new key per retry did no better than no key at all in my tests.
  • Enforce the key where the effect happens: in the payment provider, the database or the service, not in the agent.
  • If you write your own failure_error_function, decide what the model should see. Pass the exception's type, not its message, since messages can carry URLs or headers. Consider telling the model plainly that the outcome is unknown.
  • Test the failure, not just the happy path. A demo that never loses a reply will never show you the double refund.

Try it

The example and the testbench are open source (MIT) and run locally, with no API key:

pip install "agent-crashtest[local]" crashtest selftest 

If you run it against your own agent, I'd like to hear what it did.