LuAITools.com
提交工具
🧮AI
Repeat it, but don't double-count it

Idempotency

Idempotency means doing the same operation once or ten times gives the same result — the foundation for an agent's tool calls to be safely retried.

What is idempotency?

You can jab an elevator button ten times and it only registers once. When you mash "pay" while shopping online, ideally you're only charged once. That property — doing something many times gives the same result as doing it once — is idempotency.

Why agents need it badly

Agents retry
Network hiccups, timeouts, errors — an agent often needs "one more try". If each retry charged you again, you'd be in trouble.
Multiple agents can do the same job twice
When agents split work, two of them might fire the same action. Idempotency makes a duplicate execution harmless.

Idempotent vs not

Idempotent operations
Reading data, setting a fixed value (PUT), deleting a specific resource — doing it more times changes nothing.
Non-idempotent operations
Something like "add $100 to the account" accumulates: each run changes the state, so it needs an idempotency key to protect it.

How to make things idempotent

Give requests a unique ID
The client generates an idempotency key per operation; the server records "already handled" and ignores duplicates.
Prefer "set to X" over "add one"
Design operations to assign a fixed value rather than increment.
Back it up at the database
Unique indexes and transactions block duplicate writes at the storage layer.

Bottom line: idempotent means "repeat it, but don't double-count it."

Comments