# Exactly Once Agent Actions

> Design retry-safe agent actions using idempotency keys, outcome ledgers, and state reconciliation to prevent double-execution.

Exactly Once Agent Actions is a paid AI agent skill on Agensi by Khristian Kopachelli, in APIs & Backend. It loads into your AI agent through the Agensi MCP server, always in its latest approved version.

- Price: $12 (one-time purchase)
- Creator: [Khristian Kopachelli](https://www.agensi.io/creators/khristian-kopachelli)
- Category: [APIs & Backend](https://www.agensi.io/skills/apis-backend)
- Version: 1.0
- Last updated: 2026-11-29
- Security: scan passed (2026-11-29); every new listing is also reviewed by a person
- Listing: https://www.agensi.io/skills/exactly-once-agent-actions
- Tags: api, idempotency, node-js, distributed-systems, sqlite

## About this skill

Distributed systems are inherently unreliable. When an agent times out on a payment or an API write, you cannot know if the operation failed or if only the response was lost. Retrying blindly leads to double charges and corrupted state.

This skill provides the architectural patterns and implementation guidance to achieve exactly-once semantics for agentic side effects. It focuses on the effect-ledger pattern to ensure every external action is idempotent, verifiable, and recoverable.

### What it does
- **Durable Intent Tracking** saves operation state before execution to prevent orphan actions.
- **Idempotency Enforcement** ensures concurrent or repeated calls with the same ID never execute the side effect twice.
- **State Reconciliation** handles the "unknown" state when providers time out, using lookup adapters to verify remote status.
- **Lease Fencing** prevents stale or slow workers from overwriting newer operation attempts.
- **Fingerprint Validation** detects if the same operation ID is being reused for different inputs, preventing data collisions.

### How it works
1. **Initialize the Ledger** using a durable store like SQLite or Cloudflare D1 to persist intent and outcomes.
2. **Define an Adapter** that implements the `run` and `lookup` methods for your specific external provider.
3. **Execute the Action** by passing a stable `operationId` that persists across agent retries.
4. **Handle Uncertainty** by checking for `unknown` status and triggering a reconciliation flow instead of an automatic retry.

### Frameworks & tools
The implementation references the `effect-ledger` library for Node.js (v22.13+). It supports `SqliteStore` via `node:sqlite`, `D1Store` for Cloudflare, and `MemoryStore` for testing.

### Why this beats prompting it yourself
LLMs often suggest simple try-catch retry loops that ignore the "Two Generals' Problem." This skill enforces a strict state machine that separates intent from outcome, ensuring your agent doesn't double-spend or double-post when the network flinches.

### Use cases
- **Payment Processing** where a timeout could result in double-charging a customer.
- **Email/SMS Dispatch** to ensure notification bursts don't spam users during API instability.
- **Database Writes** across distributed services where standard transactions aren't available.
- **Resource Provisioning** in cloud environments where duplicate requests incur costs.

### Known limitations
Requires Node.js 22.13 or higher for native SQLite support. The `leaseMs` must be manually tuned to exceed the worst-case provider response time to prevent race conditions.

## How to use this skill

1. Connect your AI agent to Agensi once: add the MCP server https://mcp.agensi.io/mcp/auth and sign in with your Agensi account (OAuth, no API key). Steps for Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and other agents: https://www.agensi.io/docs/mcp-setup
2. Ask your agent: "Use the Exactly Once Agent Actions skill from Agensi" and describe your task.
3. Buy it on the listing or let your agent ask you first; your agent then loads it from Agensi when it needs it. Every paid skill has a money-back guarantee: https://www.agensi.io/docs/money-back-guarantee

## Frequently asked questions

### What specific problem does the Exactly Once Agent Actions skill solve?

This skill provides the architectural framework and code patterns to prevent 'double-execution' errors, such as double-charging a customer or sending duplicate emails, which occur when an agent retries an action after a network timeout.

### What assets are included in this purchase?

You will receive a complete implementation guide, the effect-ledger architectural pattern documentation, and pre-built adapters for SQLite and Cloudflare D1 to manage your operation state.

### How does this approach differ from a standard try-catch retry loop?

Unlike a simple retry loop, this skill uses a durable ledger and 'lookup' adapters to verify the actual status of a remote service before deciding whether to re-run an action or recover the existing result.

### Are there any specific infrastructure requirements for this skill to work?

Yes, you will need a durable storage layer like SQLite or Cloudflare D1 to persist the intent and outcome ledgers; a MemoryStore is included for local development and testing.

### How does the skill handle race conditions if multiple agents attempt the same action?

The skill handles high-concurrency via lease fencing, which prevents multiple agent instances or slow workers from processing the same operation ID simultaneously.

---

Source: [Agensi](https://www.agensi.io), the marketplace of skills for AI agents. Any MCP-compatible agent (Claude, ChatGPT, Claude Code, Codex, Cursor, VS Code and more) connects at https://mcp.agensi.io/mcp/auth and signs in with an Agensi account; setup for every agent: https://www.agensi.io/docs/mcp-setup. Append .md to any skill, guide or docs address on agensi.io for its markdown version.
