$ lexprog.com

// notes from an old coder -- php, databases, and the occasional rant

[November 08, 2026] AI

Prefer Idempotent Tools

Design every mutating tool as idempotent. Agents retry, users double-click, and proxies replay POSTs.

────────────────────────────────────────────────────────

Prefer Idempotent Tools

Tip: The network will retry you

Design every mutating tool as idempotent. Agents retry, users double-click, and proxies replay POSTs.

def upsert_comment(pr_id, marker, body):
    existing = find_comment(pr_id, marker)
    return update(existing, body) if existing else create(pr_id, marker, body)

Gotcha: create_comment on retry spam

Without a marker, every retry adds another bot comment. Key the write.

gh.pr.comment(pr_id, body)  # not idempotent

Source: https://docs.anthropic.com/en/docs/agents-and-tools/tool-use/overview

────────────────────────────────────────────────────────
<-- back to posts