A tool times out while sending a message. The agent tries again. Two copies arrive because the first request succeeded and only its response was lost.

The mistake is treating a missing response as proof that no effect occurred. An agent’s ability to persist through errors makes this especially relevant: retry behavior needs to be part of the application’s contract, not something improvised in the conversation.

Classify the outcome before retrying

Separate failures known to occur before execution from failures whose effects are uncertain. A rejected argument normally has no delivery effect. A connection failure after a request was accepted may leave the outcome unknown.

Observation Useful state Next decision
Validation rejected the action Rejected Correct the proposal; do not execute it
Work is queued or running Pending Check the existing operation
Provider confirms acceptance Accepted Preserve the reference and track completion if needed
Response is lost after submission Unknown Reconcile before issuing a new operation

Acceptance is not always final completion. Keep the states appropriate to the service, such as accepted, delivered, or failed, without inventing a stronger guarantee than the provider offers.

Give one logical action a stable identity

Generate an operation ID when the trusted application accepts a specific authorized action. Reuse that identity across retries of the same action. A fresh random key on every attempt cannot connect the attempts.

Bind the key to the actor or tenant, operation type, and normalized payload. If a repeated key arrives with different content, reject the conflict instead of returning a result for another action. Define which fields participate in the comparison and avoid relying on arbitrary JSON property order.

Do not derive the identity solely from message text. Two intentionally separate messages may have identical bodies. The application needs to distinguish a retry from a new authorized request.

Make the state durable and the claim atomic

Workers must coordinate through storage that survives a process restart. A unique constraint on the scoped operation key, together with an atomic state transition, can prevent simultaneous workers from claiming the same work independently.

An in-memory map is useful for a local exercise but does not coordinate multiple processes. A short cache TTL is not automatically safe either: expiration can make an old retry look new while a remote operation still exists.

Persist the intended action and enough state to reconcile it. Avoid storing unnecessary private content, and apply the same authorization and retention controls used for other sensitive job records.

Coordinate with the receiving service

Use the provider’s supported idempotency mechanism when available. Verify its scope, retention window, payload-conflict behavior, and treatment of failed requests. Your local database cannot atomically commit an arbitrary third-party effect by itself.

If the provider has no suitable mechanism, define how an uncertain result is investigated before another attempt. A status lookup or human review may be safer than retrying an irreversible operation. Do not claim exactly-once delivery from a local flag alone.

Retries also need current authorization. If access is revoked while an operation is pending, a later attempt must not treat its historical approval as unlimited permission. The least-privilege guide covers that execution-time boundary.

Test the ambiguous cases deliberately

In a controlled environment, make the receiving fixture record the action and then lose its acknowledgement. Verify that the application marks the result uncertain and does not produce a second independent effect when the agent retries.

Run two workers against the same operation, restart a worker between state changes, and reuse a key with modified content. Include a successful retry or lookup so the test does not pass simply because all work is blocked.

Record the operation key, trusted scope, state transitions, provider reference, and observed effect count. Keep raw message contents out of routine logs where possible. A useful audit trail should let an operator distinguish a delayed response from a duplicate action.

Begin with the one tool whose duplicate effect would be most expensive to reverse. Write down how that tool handles an unknown outcome before giving the agent permission to recover from it automatically.