Generative AI & Agentic AIAgent workflows and state

Idempotency keys for agent tool calls

PK
Pankit Kumar
Sr. Data Scientist at Parexel (a Goldman Sachs–backed company) · 20 September 2026 · 2 min read
Technically reviewed by Ishaan Sharma
In this article (5 sections)

Networks fail at ambiguous moments. A client may time out after the server creates a ticket, then retry. Without idempotency, one intended action becomes two records.

Execute the same call twice

The agent controls lab uses an in-memory tool.

python
from agent_cases import idempotency_case

result = idempotency_case()
assert result["first"]["created"] is True
assert result["second"]["created"] is False
assert result["records"] == 1
assert result["same_result"] is True

Both calls use RUN-3:create-ticket and return ticket T-100; only the first creates it. No external ticket system runs.

Derive keys from intent

Use a stable run or business operation ID plus action identity. Store the key, normalized request digest, status and response atomically with the side effect. A repeated key with different material arguments must fail rather than reuse an unrelated receipt.

Set retention long enough for the retry window and workflow recovery. Downstream services should support the same boundary where possible; client-only deduplication cannot protect a server that processes duplicates concurrently.

Handle uncertain outcomes

After timeout, query the operation by key before retrying. Distinguish not-started, processing, succeeded and failed-safe states. Preserve receipts in checkpoints and audit logs.

The Generative & Agentic AI course applies idempotency to messages, tickets and other consequential tools.

Exercise

Implement a concurrent idempotent tool with request-digest checks. Send ten identical calls and one conflicting call under the same key; prove one side effect and a clear conflict error.

Continue learning

This article is part of the Agent workflows and state sequence. Use the neighbouring tasks when you need the prerequisite or the next application.

Reference: Stripe idempotent request documentation.

PK
Pankit Kumar
Lead Instructor, NeuraPath Academy

Pankit Kumar has 10 years in Data Science & AI, building and shipping production systems in regulated pharma and clinical environments. He is a freelance trainer at Boston Institute of Analytics, AnalytixLabs and Scaler, and has taught this material to thousands of working professionals.

This article is part of our Generative & Agentic AI programme — 3 months. Add practical GenAI, retrieval and agent-building skills to your existing toolkit.

Explore Generative & Agentic AI
Counselling is free · no obligation

Not sure which programme fits?

Tell us your background and we will map it to the right entry point — including saying so when a cheaper programme is the better fit. A counsellor replies within one working day.