<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/your-agent-just-learned-to-spend-money-now-make-sure-it-only-spends-it-once--t9pabkxsp" -->

---
title: Your agent just learned to spend money. Now make sure it...
description: Payment tool calls inside AI agent loops create a double-charge risk: if a charge succeeds but the response fails to arrive, a naive retry re-runs the entire...
canonical: https://daily.dev/posts/your-agent-just-learned-to-spend-money-now-make-sure-it-only-spends-it-once--t9pabkxsp
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Your agent just learned to spend money. Now make sure it only spends it once. | daily.dev
og:description: Payment tool calls inside AI agent loops create a double-charge risk: if a charge succeeds but the response fails to arrive, a naive retry re-runs the entire...
og:url: https://daily.dev/posts/your-agent-just-learned-to-spend-money-now-make-sure-it-only-spends-it-once--t9pabkxsp
og:image: https://api.daily.dev/og/posts/T9pAbkXSp.png
og:image:alt: Your agent just learned to spend money. Now make sure it only spends it once.
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Your agent just learned to spend money. Now make sure it only spends it once.

**[Inngest Blog](https://daily.dev/sources/inngest)** · 9 min read · 0 upvotes · 0 comments

## Summary

Payment tool calls inside AI agent loops create a double-charge risk: if a charge succeeds but the response fails to arrive, a naive retry re-runs the entire agent loop, including tools that already succeeded. The fix moves the agent off the request thread into a durable Inngest function, wraps each tool call as its own function with retries and memoization via step.run, and uses step.invoke so tool results return directly without event correlation. Memoization prevents replay of already-completed steps, but a narrow at-least-once execution window remains where a step's completion is never recorded; the remaining fix is threading the model's existing toolCallId through as the payment provider's idempotency key so even a duplicate execution dedupes safely. The pattern applies to any agent framework, not just the raw Anthropic SDK example shown.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.inngest.com/blog/your-agent-just-learned-to-spend-money>

## Questions this post answers

### How do I stop an AI agent from double-charging a customer when a payment tool call times out and the loop retries?

Move the agent out of the HTTP request into a durable function where each tool call runs as its own memoized step with its own retry budget, so replays return the stored result instead of re-executing a completed charge. Because retries still give at-least-once execution of the step body, thread the model's existing tool call id through as the payment provider's idempotency key so even a duplicate execution dedupes safely.

_Track patterns like durable execution and idempotency keys for money-moving agent tools on daily.dev._

### What does Inngest's step.run memoization actually protect against in an agent loop?

It protects against re-executing a step that already finished successfully: once step.run records a result, any later replay of the run returns that stored value instead of running the step body again, which stops the whole-loop retry from re-charging a payment that already succeeded. It does not protect against a step whose completion was never recorded, since that requires an idempotency key instead.

_Developers wiring retries into agent tool calls compare durable-execution patterns like this on daily.dev._

### Why is invoking a tool with step.invoke safer than firing an event and waiting for a completion event in an agent loop?

Step.invoke calls the tool's function and returns the value directly to the calling line, so there is no toolCallId correlation to get wrong and no timing window where a completion event fires before anything is listening. Promise.all can run multiple invoked tool calls in parallel and each result lands where it belongs by construction, without manual event matching.

_Engineers designing multi-tool agent orchestration weigh trade-offs like this on daily.dev._

## Similar posts on daily.dev

- [Your Agent Isn't Dumb. Your Tools Are.](https://daily.dev/posts/your-agent-isn-t-dumb-your-tools-are--grledaace) · The T-Shaped Dev · 3 upvotes · 2 comments
- [Tool Calling, Explained: How AI Agents Decide What to Do Next](https://daily.dev/posts/tool-calling-explained-how-ai-agents-decide-what-to-do-next-ug95msj09) · Towards Data Science · 1 upvotes · 0 comments
- [How we eliminated $1 million a year of wasted AI agent spend in one hour](https://daily.dev/posts/how-we-eliminated-1-million-a-year-of-wasted-ai-agent-spend-in-one-hour-sl4y8p7za) · databricks · 1 upvotes · 0 comments
- [How do I monitor and trace AI agents running in Production](https://daily.dev/posts/how-do-i-monitor-and-trace-ai-agents-running-in-production-wulrtjnmd) · DigitalOcean Community · 0 upvotes · 0 comments
- [Agents don't fail at the starting line](https://daily.dev/posts/agents-don-t-fail-at-the-starting-line-recimt5nh) · Inngest Blog · 1 upvotes · 0 comments

---

Tags: [#ai-agents](https://daily.dev/tags/ai-agents), [#inngest](https://daily.dev/tags/inngest), [#payment-processing](https://daily.dev/tags/payment-processing)

[View this post on daily.dev](https://daily.dev/posts/your-agent-just-learned-to-spend-money-now-make-sure-it-only-spends-it-once--t9pabkxsp)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Your agent just learned to spend money. Now make sure it only spends it once.","url":"https://daily.dev/posts/your-agent-just-learned-to-spend-money-now-make-sure-it-only-spends-it-once--t9pabkxsp","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/your-agent-just-learned-to-spend-money-now-make-sure-it-only-spends-it-once--t9pabkxsp"},"datePublished":"2026-09-13T19:57:23.643Z","dateModified":"2026-10-15T02:22:27.964Z","description":"Payment tool calls inside AI agent loops create a double-charge risk: if a charge succeeds but the response fails to arrive, a naive retry re-runs the entire...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/808a072c3b7de9f5c2d26597a91db604?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/808a072c3b7de9f5c2d26597a91db604?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Inngest Blog","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Inngest Blog","logo":"https://media.daily.dev/image/upload/s--ieZKUa5y--/c_limit,w_256/f_auto,q_auto/v1789329423/logos/inngest?_a=BAMAMicg0","url":"https://daily.dev/sources/inngest"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/your-agent-just-learned-to-spend-money-now-make-sure-it-only-spends-it-once--t9pabkxsp","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"ai-agents,inngest,payment-processing","timeRequired":"PT9M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Inngest Blog","item":"https://daily.dev/sources/inngest"},{"@type":"ListItem","position":3,"name":"Your agent just learned to spend money. Now make sure it only spends it once."}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/your-agent-just-learned-to-spend-money-now-make-sure-it-only-spends-it-once--t9pabkxsp#faq","mainEntity":[{"@type":"Question","name":"How do I stop an AI agent from double-charging a customer when a payment tool call times out and the loop retries?","acceptedAnswer":{"@type":"Answer","text":"Move the agent out of the HTTP request into a durable function where each tool call runs as its own memoized step with its own retry budget, so replays return the stored result instead of re-executing a completed charge. Because retries still give at-least-once execution of the step body, thread the model's existing tool call id through as the payment provider's idempotency key so even a duplicate execution dedupes safely. Track patterns like durable execution and idempotency keys for money-moving agent tools on daily.dev."}},{"@type":"Question","name":"What does Inngest's step.run memoization actually protect against in an agent loop?","acceptedAnswer":{"@type":"Answer","text":"It protects against re-executing a step that already finished successfully: once step.run records a result, any later replay of the run returns that stored value instead of running the step body again, which stops the whole-loop retry from re-charging a payment that already succeeded. It does not protect against a step whose completion was never recorded, since that requires an idempotency key instead. Developers wiring retries into agent tool calls compare durable-execution patterns like this on daily.dev."}},{"@type":"Question","name":"Why is invoking a tool with step.invoke safer than firing an event and waiting for a completion event in an agent loop?","acceptedAnswer":{"@type":"Answer","text":"Step.invoke calls the tool's function and returns the value directly to the calling line, so there is no toolCallId correlation to get wrong and no timing window where a completion event fires before anything is listening. Promise.all can run multiple invoked tool calls in parallel and each result lands where it belongs by construction, without manual event matching. Engineers designing multi-tool agent orchestration weigh trade-offs like this on daily.dev."}}]}
```

