← Back to Dashboard
1. Function and API Tool Patterns2. Retries, Idempotency, and Timeouts3. Web Search: Built-In Server-Side Grounding

Retries, Idempotency, and Timeouts

📚 Tool Use and Orchestration10 min85 XP⌨ Hands-on lab

Operational Discipline for Agent Tools

Most production failures are orchestration failures: duplicate actions, runaway retries, or hung calls. An agent that creates three identical P1 tickets because a timeout retried is an agent nobody trusts again.

Idempotency: Same Intent, One Effect

# Deterministic key: same logical action always produces the same key
idempotency_key = hash(service + incident_signature + minute_bucket)

POST /tickets
Idempotency-Key: chk-7f3a2b-202607161430
→ first call:  201 Created (ticket #4402)
→ retry call:  200 OK (returns existing #4402, no duplicate)

The receiving service stores processed keys and returns the original result on replay. Without this, every retry of a side-effect operation is a potential duplicate write.

Retry Policy That Doesn't Melt Downstream Systems

Failure typeRetry?Pattern
Transient (timeout, 429, 503)YesExponential backoff + jitter, budget of 2-3 attempts
Permanent (400 validation, 403 authz)NoReturn typed error to the agent - retrying cannot help
Ambiguous (connection dropped mid-call)Only with idempotency keyOtherwise you risk duplicate side effects

Timeout Budgets

Set a per-tool timeout (e.g. 5s) and a whole-plan budget (e.g. 60s). A 10-step agent where each step can hang for 30s is a 5-minute user wait hiding behind a spinner. When budget is exhausted: degrade gracefully - partial results plus an explicit "steps not completed" summary beats a silent hang.

  • Use idempotency keys for every side-effect operation.
  • Set timeout budgets and bounded retries with backoff + jitter.
  • Emit structured logs for every tool decision - attempted, validated, executed, outcome, latency.
Circuit breaker: if a tool fails repeatedly across requests, stop calling it for a cool-down window and route to fallback. Hammering a struggling dependency turns one failure into an outage.
⌨ HANDS-ON LABHarden a Tool Call Policy
⭐ +150 XP

Define retry and idempotency rules for ticket creation and notification actions.

1Draft idempotency key strategy.
2Set retry budget and timeout targets.
lab-sandbox — simulated environment
INFINITY LAB SANDBOX v2.6 — simulated shell
Type the command for the current objective. Helpers: "hint", "solution", "clear".
$
OBJECTIVE 1 / 2 — type "hint" if stuck
🧪 Knowledge Check
Press 1-4 to select1 of 2
Idempotency keys mainly prevent:
Model latency
Duplicate side effects
IAM policy drift
CloudTrail entries