Before Your AI Agent Retries, Check This One Thing

AI Agents may lose state when calling tools; query and reconcile before retrying to avoid duplicate side effects.
The article explores the "uncertain tool effect" AI Agents face when calling external tools: a request has been sent but no result has returned, leaving the Agent unable to tell whether the operation was executed. This state is common in distributed systems—network timeouts and process crashes can both cause responses to be lost. Blind retries can cause duplicate orders, duplicate payments, and other side effects. The article proposes the core principle "query first, then decide": before retrying, query the target system to see whether the request's unique identifier already exists; if it does, record the result and continue; otherwise, assess whether to retry. From the ACES security perspective, reconciliation is not only a technical fix but also a compliance requirement for authorization and evidence chains. Implementation recommendations include mandatory idempotency, audit logs, and human intervention for high-risk operations.
When an AI Agent loses state while calling a tool, have you ever wondered: did the operation actually fail, or was it just the response that got lost? This "uncertain tool effect" is an obstacle you must overcome when building reliable Agent systems. This article explores its causes and risks in depth, and offers a practical framework for solving it.
What Is the Uncertain Tool Effect?
The uncertain tool effect refers to an Agent being unable to determine whether an external action has already occurred. For example, an Agent initiates an API call, but the session is interrupted before the result is recorded. At this point, the Agent can neither confirm that the operation succeeded nor assert that it failed—it is in a cognitive "Schrödinger state."

This uncertainty is not an edge case. In distributed systems, network timeouts, process crashes, and lost messages can all cause a response to fail to return, while the request itself may already have been processed by the target system. For an autonomously operating Agent, this ambiguity translates directly into business risk.
Uncertainty in distributed systems is the key background for understanding this problem. In distributed computing, nodes communicate over a network, and the network itself is unreliable: messages can be delayed, lost, duplicated, or arrive out of order. The classic "Two Generals' Problem" shows that deterministic consensus is impossible over an unreliable channel. When an Agent calls a remote API, the request may have reached the server and been executed, but the response was lost on the way back—the Agent can only observe the local phenomenon of a "timeout" and cannot infer the remote state. This is fundamentally different from a local function call: a local call either returns successfully or throws an exception, so the state is determinate; a remote call introduces a third state—unknown. The "at-least-once" and "at-most-once" semantics of distributed systems are responses to this, and "exactly-once" can usually only be approximated through idempotency combined with deduplication.
The Risk of Duplicate Execution and Real-World Cases
Suppose you ask an Agent to submit a purchase request, but the session unexpectedly terminates after the request is sent and before the result returns. If the Agent simply retries, it may submit the order to the supplier twice, causing duplicate purchases and financial loss.

This is not a theoretical exercise. Any operation with side effects—such as payments, order creation, or sending emails—can cause problems when retried blindly. OpenAI's Agent SDK alpha version explicitly recommends reconciling uncertain tool effects before resuming execution.

Core Principle: Query First, Then Decide
When facing an uncertain tool effect, the practical rule is: before retrying, first check whether the original request already exists in the target system.
The specific steps are as follows:
- Query the target system: Ask the external service whether the request's unique identifier (such as an idempotency key or transaction ID) already exists.
- Branch based on the query result:
- If the request already exists, record its result and continue the subsequent workflow, avoiding duplicate execution.
- If the request does not exist, then decide whether to retry. At this point you still need to assess the necessity and safety of the retry.
- Record evidence: Regardless of the outcome, persist the query and decision process for auditing and debugging.

The key to this pattern is leveraging the target system's idempotency design or an external reconciliation mechanism. Not all APIs support idempotency keys, but Agent developers should prioritize services with this capability, or implement compensating logic at the application layer.
Idempotency means that executing the same operation once and executing it multiple times produces the same effect on system state. In HTTP semantics, GET, PUT, and DELETE are defined as idempotent, while POST is usually not. In practice, APIs often implement safe retries through client-generated idempotency keys: the client generates a unique key for each logical operation, the server records the first processing result corresponding to that key, and subsequent requests carrying the same key directly return the cached result without re-executing. Payment APIs such as Stripe are typical examples of this pattern. For legacy systems that do not support idempotency keys, you can implement "query-compare-compensate" logic at the application layer, or introduce transaction IDs and deduplication tables. Agent developers should make idempotency part of the interface contract at the tool design stage, rather than remedying it after the fact.
Security Perspective: Authorization and Evidence
From a security (ACES) perspective, every Agent action requires explicit authorization and an evidence chain. The uncertain tool effect exposes not only a reliability problem but also a governance gap: you cannot prove what the Agent executed or whether it was authorized. Therefore, reconciliation is not only a technical fix but also a compliance requirement.
In real systems, this means:
- Generate a tamper-proof audit log for every tool call;
- Embed authorization checks in the retry logic;
- Treat the "uncertain state" as a first-class citizen rather than a hidden exception.
Implementation Recommendations and Conclusion
For teams building Agent applications, it is recommended to start from the following aspects:
- When designing tool interfaces, mandate idempotency or provide a query endpoint;
- Implement detection and reconciliation processes for "uncertain effects" at the Agent orchestration layer;
- Tie retry policies to business risk levels; high-risk operations must involve human intervention or strict reconciliation.
The stronger the autonomy of an AI Agent, the more important the management of uncertainty becomes. Rather than remedying things after an incident, perform a simple check before retrying.
Related articles

AI Coding Agent Leaks User Email: Inside the Claude Code Privacy Controversy
Claude Code was caught writing user emails into web request headers, sparking privacy concerns. We break down the technical root cause, Anthropic's fix, developer pushback, and tips for protecting yourself as an AI agent user.

Claude Code Allegedly Leaks User Emails: A Privacy Storm Triggered by a Fix
Claude Code was reported to potentially send user emails to visited websites, caused by a change introduced to fix another bug. This article covers the timeline, technical causes, team response, and data boundary issues for AI coding tools.

Claude Personal Email Leak Vulnerability Explored: Risks, Mechanism, and Temporary Fixes
Claude's personal email leak exposed: ClaudeCode writes real user emails into request headers when visiting sites requiring contact emails, causing scam email floods. This article explains the vulnerability, timeline, and temporary fixes like upgrading to 2.1.3.1.7+ and enabling the ccplugin-privacy plugin, while warning against using the skip permissions flag.