An AI agent calls a tool to create a support ticket. The ticket service commits the record, but the response never reaches the agent. A timeout appears. The agent tries again, and the customer now has two tickets for the same issue. This is an illustrative failure scenario, not a String AI incident.
Idempotent tool calling addresses that gap between an action and the caller's knowledge of its result. Your application assigns a stable identity to one intended business operation, and the system that performs the action recognizes retries of that operation. A transport timeout alone cannot tell you whether a write happened.
The practical recommendation is to preserve an operation ID across retries, record outcomes durably, and treat uncertain outcomes as a state that needs resolution. This applies to agents using String AI or another model endpoint. It is an application design pattern, not a claim that an API gateway automatically deduplicates your tools.
Separate the model request from the business action
A tool workflow contains several independently fallible steps: ask the model for a next action, validate the proposed arguments, execute a tool, and return its result to the conversation. Our production tool-calling guide covers the interaction loop. This article focuses on what happens when the execution step has an uncertain outcome.
Retrying a model request may produce another proposal. Retrying a business action may create another record. Replaying a completed result into the conversation should require neither a fresh model decision nor another business write. Keep those paths distinguishable in your application.
Consider the ticket example. The application can safely report success when it has a durable receipt identifying the ticket. If it has only a network timeout, the correct state is unresolved. A new ticket creation request would be a decision made without knowing the previous request's outcome.
A tool-call ID and an operation ID have different jobs
In Anthropic's tool-call handling documentation, a tool result refers back to its originating tool use through tool_use_id. That association is part of the conversation protocol. The documentation does not make it a business deduplication contract for an external ticket service.
Use separate identifiers in the execution record:
| Identifier | Scope | What happens on a retry? |
|---|---|---|
| Tool-call ID | One model-proposed call and its result | Preserve the association required by the model API |
| Business operation ID | One accepted user intent, within a tenant and action | Reuse it when retrying that same intent |
| Attempt ID | One delivery or execution attempt | Create a new one to distinguish attempts in logs |
For example, an application could persist an operation ID when a user confirms “create this support ticket.” A later retry reuses that stored ID. If the user deliberately requests a second ticket with identical text, it receives a different operation ID. Identical arguments alone do not prove identical intent.
The application should own the operation ID. Do not ask the model to invent a new one every time an error occurs. A model-provided identifier can be an input to validation, but it should not decide tenant boundaries or permission to replay a stored result.
Put idempotency at the action boundary
AWS's idempotent API design guidance explains why caller-provided request identifiers are useful and why recording the identifier must be coordinated with the mutation. It also discusses rejecting the same identifier when the parameters express a different request.
For an action implemented entirely in your own database, a useful design is to persist the operation record, business mutation and receipt in one transaction. A concurrent retry must encounter a database-enforced uniqueness rule, rather than an application-level “look up, then insert” race.
For example, a PostgreSQL unique constraint can enforce uniqueness across a combination of columns. An illustrative operation key is the combination of tenant ID, action name and operation ID, with each column required to be non-null. The exact transaction and locking behavior still needs to fit your service.
Persist a normalized representation or digest of the validated business arguments alongside that key. Compare meaningful fields consistently: harmless differences in JSON key order should not create a conflict, while a changed customer or destination should. Exclude secrets from stored diagnostics.
On a repeat request, authenticate the caller and check current authorization before looking up or returning a receipt. A remembered operation is not a reusable permission grant. If the key matches but the arguments differ, reject the request clearly. If it already succeeded, return the recorded business result.
An external service creates a second boundary
A transaction in your database cannot atomically commit a ticket in another company's service. There is a failure window between the external write and your local success record. This is the point where a small “processed IDs” table stops being sufficient.
When the downstream API supports idempotency, persist its key before calling it, send the same key on retries, and retain the returned resource ID. Read that API's exact contract: which endpoints support the key, how conflicts behave, and how long deduplication information is retained.
Stripe's idempotency documentation illustrates why these details matter. Its API v1 and API v2 behavior differ, so even a familiar provider name is not enough to infer how a retry will behave. Treat each endpoint and API version as a separate contract.
If the downstream service has no idempotency feature, check whether it supports a client reference or a reliable status lookup. After an ambiguous timeout, query for that operation before considering a new write. A missing lookup result is not conclusive if the service can delay visibility. Without a reliable way to establish the outcome, route the operation to reconciliation or human review.
A transactional outbox can record your business change and delivery intent together, then let a worker send committed work. Delivery can still repeat; the receiving action needs its own deduplication or reconciliation strategy. An outbox alone does not provide end-to-end exactly-once execution.
Open the retry sequence diagram at full size
Make “unknown” visible to the agent and the operator
A useful application-level state model distinguishes work that has not started, work in progress, completed work and an uncertain external outcome. The table below is a proposed design aid, not a provider's required state machine.
| Observed state | Next application action | What to tell the agent |
|---|---|---|
| No execution has started | Validate, authorize and claim the operation | The action is starting |
| Another worker owns the operation | Wait or return a status handle | The same action is already in progress |
| A success receipt exists | Return the authorized stored result | The action completed, with its resource ID |
| External outcome is unknown | Query status or reconcile before another write | Completion has not been confirmed |
| A permanent rejection is confirmed | Stop retrying this request | Explain the actionable failure |
Lease expiration deserves particular care. It may prove that a worker stopped reporting, but it does not prove that the external service did nothing. A replacement worker must reconcile or use the downstream idempotency contract before taking over the write.
The tool's result should preserve that distinction. If a downstream outcome is uncertain, do not return a success message merely to let the conversation continue. Return a status the orchestration code understands, and ensure the agent cannot convert “unknown” into an unbounded sequence of new operations.
Budget retries across the whole workflow
SDK retries, queue redelivery, worker retries and the agent's next turn can all replay related work. A retry budget should account for these layers together. For transient failures, use a deadline, bounded attempts and backoff with jitter; a permanent validation or authorization failure needs correction instead. AWS's timeouts and retries guidance explains the load amplification caused by retries at multiple layers.
Keep the budget attached to the business operation so that a process restart does not reset it. Retain deduplication records for the recovery period your application supports, taking the downstream provider's retention into account. If the provider has forgotten the key, your old request may be treated as a fresh action. Do not silently reopen an expired operation without checking what happened.
For model-call retry policy, refer to our rate-limit and retry-budget guide. Protecting an external write remains a separate requirement.
Test the lost response, not just the failed request
Before enabling a tool that writes, test it against a controlled service or sandbox. These checks exercise different failure windows:
- Commit the action, then drop its response. A retry should resolve to the original resource.
- Send two concurrent requests with one operation ID. The action should produce one business effect.
- Reuse that ID with changed arguments. The service should report a conflict.
- Restart the worker after the external service succeeds but before the local receipt is saved. Recovery should query or replay safely.
- Deliver a delayed retry after the retention window. The application should follow an explicit expired-operation policy.
- Repeat the operation as an unauthorized caller or a different tenant. No stored result should leak across the boundary.
Measure the resulting business objects as well as HTTP statuses. Two 200 responses can legitimately describe one replayed result; one timeout can accompany a successful write. Keep operation ID, attempt ID, outcome and downstream resource reference in your logs, following the data-minimization guidance in what to log from LLM API calls.
String AI's integration documentation covers connecting your model client. The application that executes a ticket, email or database tool must still define the business operation and enforce its execution rules. Start with one write tool, simulate a lost response, and confirm that recovery finds the original result before you add more autonomous actions.
Editorial note: AI assisted drafting. Technical claims were checked against the linked official documentation; the ticket scenario and diagrams are illustrative.