Aulafy
Courses/Agents and automation/Retries, idempotency, and exactly-once

Retries, idempotency, and exactly-once

Retrying an LLM call can change the reasoning, choose a different tool, or execute a critical action twice. In agents, blind retry is production debt.

  • Distinguish model retry, tool retry, and workflow retry.
  • Design idempotent actions for payments, emails, tickets, and data changes.
  • Create an execution table that blocks duplicates.
TerminalCode
tabla_tool_executions:
  idempotency_key: "invoice-email:cliente-42:2026-07"
  tool: "send_email"
  status: "completed"
  result_id: "msg_abc123"

regla:
  si existe completed con misma key:
    devolver result_id anterior
    no ejecutar tool otra vez
  si existe running:
    esperar o marcar conflicto
  si falla:
    guardar error y decidir retry con humano

Safe pattern

  • Generate an `idempotency_key` before calling the tool.
  • Record `running` before the external effect.
  • Mark `completed` only when the provider confirms.
  • On retry, check the table before acting.
  • For irreversible actions, add human approval.