Agent skill · Content & Marketing

agentsop-llm-tool-idempotency

Decision protocol for making side-effectful agent tools idempotent — so when an LLM tool call is retried (timeout, framework resume, user re-run, model duplicate emit), the second call is a no-op instead of a double-send. The load-bearing premise: the LM cannot promise it'll call exactly once; the tool must promise the second call is safe. Framework-agnostic — applies to LangGraph node bodies that re-run on resume, MCP tools, OpenAI tool-calling retries, CrewAI delegated tool invocations, and direct HTTP wrappers. Search keywords: duplicate email sent, charged twice, exactly-once, idempotency

agentsopegithub.com/agentsopeGitHub ↗
claude-codeMIT
Install
npx skills add agentsope/SkillAlchemy --skill agentsop-llm-tool-idempotency --agent claude-code

Same command for any agent — swap --agent for codex, cursor, copilot.

Facts
Files in the skill folder: 5
SKILL.md size: 33 KB
Bundled scripts: none
Version: 0.1.0
Path: skills/agentsop-llm-tool-idempotency/SKILL.md
Open the folder on GitHub →
Where it comes from
Stars: 255
Language: Python

Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.

Review
written from the skill's own SKILL.md · Aug 5, 2026

What it does

Decision protocol to ensure side-effectful agent tools are idempotent when an LLM tool call is retried. It prescribes mechanisms so a second call is a no-op, focusing on idempotency keys, dedup tables, content-addressed writes, and saga-based compensation. Targets engineers wiring tools whose actions include emails, payments, DB writes, and API calls. Triggers include tool names with send_, create_, charge_, post_, write_, publish_, transfer_, delete_, update_, or notify_, as well as retries via various layers. It outlines a taxonomy of idempotency strategies (OP-1 to OP-5) and operational steps for classifying, selecting mechanisms, key generation, propagation through layers, conflict handling, and dedup record persistence. It also details how to expose a replay indicator was_replay in results.

How it works

Activation rules specify when to apply the protocol (e.g., idempotency-key capable APIs, internal writes, compensatable operations). Core mental model contrasts: LM at-least-once vs tool at-most-once, using an idempotency key generated by the agent and persisted before the tool call. The protocol describes four retry sources and the idempotency key guidance: origin in agent state, persistence before call, and reuse on resume. It presents three practical mechanisms: OP-1 Idempotency-key HTTP header (Stripe pattern), OP-2 Dedup table at tool-call layer, OP-3 Content-addressed write, OP-4 Database INSERT … ON CONFLICT DO NOTHING, OP-5 Saga/compensation for non-idempotent external calls. Step-by-step guidance covers classification, mechanism choice, key naming, key propagation, conflict responses, and recording was_replay in results. It also includes concrete action templates for each pattern (e.g., HTTP headers, dedup table schema, content-addressed write, and SQL constructs).

When to use it

Use when any tool performs a side effect (send_email, create_record, charge_card, post_message, write_file, publish_event, transfer_funds) or when a LangGraph node with an interrupt and side effect may resume, or when a transport timeout or model duplicate emission could trigger a retry. It also applies when a server or client layer may re-invoke tools after timeouts or retries. Do not activate for read-only tools or when the side effect is inherently commutative and safe under duplication.

What it can touch

Tool wrappers and state management must store and propagate the idempotency key through: agent state, tool wrapper, HTTP client, and external API. It prescribes using headers like Idempotency-Key and maintaining state-persisted keys before the call. It covers including the key in retries and caching responses server-side (TTL specifics referenced for Stripe).

Caveats

References Stripe idempotency patterns and related patterns in AWS and databases; notes that same key with same args may return cached response, while same key with different args indicates a caller bug. It emphasizes persisting dedup records atomically with commits in transactional patterns and warns about potential conflicts if keys collide or if key generation is not persisted before the call. License: MIT (from frontmatter).

From the SKILL.md

# LLM Tool Idempotency · SOP > One-liner: **The LM is at-least-once; the tool must be at-most-once.** > Every framework that promises "durable execution" still re-runs node bodies > on resume. Every HTTP client retries on timeout. Every model occasionally > emits the same tool_call twice. Idempotency belongs in the tool, not in a > wish. --- ## 1. 何时激活 (Activation Rules) Activate this skill when **any** of the following triggers fire: - You're defining a tool whose name contains `send_`, `create_`, `charge_`, `post_`, `write_`, `publish_`, `transfer_`, `delete_`, `update_`, or `notify_`. - The tool wraps a third-party API call (Stripe, SendGrid, Twilio, Slack, Discord webhook, S3 PUT, payment gateway, internal write API). - You're inside a LangGraph node that contains an `interrupt(...)` call AND a side effect in the same function body — the resume re-runs the body from the top `[langgraph/gotchas]`. - The tool is invoked through MCP, OpenAI tool-calling, Anthropic tool use, CrewAI delegation, or any layer where a transport timeout could be interpreted as "retry" even though the operation succeeded server-side. - The user reports "the agent sent it twice" / "charge appeared twice"

What's inside
Steps it walks through
  1. 1. 何时激活 (Activation Rules)
  2. 2. 核心心智模型 (Core Mental Model)
  3. 2.1 The fundamental asymmetry
  4. 2.2 The promise inversion
  5. 2.3 The idempotency key has to come from the agent, not the tool
  6. 2.4 Three classes of side effect, three idempotency strategies
  7. 3. SOP 工作流 (Agentic Protocol)
  8. Step 1 · Classify the side effect
  9. Step 2 · Choose the idempotency mechanism
  10. Step 3 · Decide where the key is generated and how it's named
  11. Step 4 · Pass the key through every layer
  12. Step 5 · Handle the conflict response
  13. Step 6 · Persist the dedup record on the commit side, atomically
  14. Step 7 · Expose wasreplay in the tool result
Ships with 4 files
  • README.md
  • intermediate/operation_candidates.json
  • references/R1-source-evidence.md
  • references/R2-pattern-library.md
More from SkillAlchemy
All skills →
About this skill
What does the agentsop-llm-tool-idempotency skill do?

Decision protocol for making side-effectful agent tools idempotent — so when an LLM tool call is retried (timeout, framework resume, user re-run, model duplicate emit), the second call is a no-op instead of a double-send. The load-bearing premise: the LM cannot promise it'll call exactly once; the tool must promise the second call is safe. Framework-agnostic — applies to LangGraph node bodies that re-run on resume, MCP tools, OpenAI tool-calling retries, CrewAI delegated tool invocations, and direct HTTP wrappers. Search keywords: duplicate email sent, charged twice, exactly-once, idempotency

How do I install it?

Run `npx skills add agentsope/SkillAlchemy --skill agentsop-llm-tool-idempotency --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.

Where does this skill come from?

From agentsope/SkillAlchemy, a repository with 255 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.

Is a popular skill a good skill?

Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.

Keep going