# Guides for long-running AI agents: retries, crashes, resumes and cost

> Ten guides on the failures long-running AI agents hit: actions that happen twice, runs that die halfway, two workers on one job, spending without a person's say-so, and bills that grow with the session. Each has code you can run.

Source: https://getargentic.com/docs/guides/

Each guide starts from a failure we or other developers have hit, shows the cause, and ends with code that runs without Argentic. Where Argentic is one way to fix it, it says so once, near the end.

## When something happens twice

The refund, the email or the ticket goes out more than once. The cause is usually a retry, a resume or a model asking twice.

- [Test an agent for repeated actions](https://getargentic.com/docs/guides/test-an-agent-for-repeated-actions/). Kill it at every tool call, restart it, count what landed twice. No model or keys needed.
- [Make agent tool calls safe to retry](https://getargentic.com/docs/guides/make-agent-tools-safe-to-retry/). Stable idempotency keys and your own record of what ran, so a timeout doesn't mean a second refund.
- [Why a tool runs twice after a resume](https://getargentic.com/docs/guides/tool-runs-twice-after-resume/). LangGraph re-runs the step that held the interrupt. Three ways to keep the effect to one.
- [Why your agent calls the same tool twice](https://getargentic.com/docs/guides/agent-calls-the-same-tool-twice/). The model asks twice and both run. A call id is the wrong key; claim the action instead.

## When a run dies halfway

A deploy, a time limit or a crash stops the process. These cover getting back to where you were without redoing finished work.

- [Resume an agent after a crash](https://getargentic.com/docs/guides/resume-an-agent-after-a-crash/). What to save, in what order, and a 30-line durable loop you can kill and restart.
- [When a run outlives its serverless function](https://getargentic.com/docs/guides/agent-run-times-out-on-serverless/). Split the run into short invocations that each pick up where the last one stopped.
- [Stop an agent running twice](https://getargentic.com/docs/guides/stop-an-agent-running-twice/). Two workers pick up the same job after a deploy or a retry. A lease and a fencing token keep one out.

## Trust, approval and cost

Letting an agent run for hours raises questions about who approved what, whether the record can be trusted, and what the session costs.

- [Require approval before an agent spends money](https://getargentic.com/docs/guides/human-approval-before-an-agent-spends-money/). A hard ceiling, a signed standing permission, and a one-time approval above it.
- [Prove what your agent did](https://getargentic.com/docs/guides/prove-what-an-agent-did/). A hash-chained log in 60 lines, and what it can and can't show.
- [Run a long session without the bill exploding](https://getargentic.com/docs/guides/long-agent-sessions-without-a-huge-context-bill/). Why cost grows faster than the session, and what rebuilding context from saved state did on our benchmarks.

## By framework

If you already use one, start with its guide: [Vercel AI SDK](https://getargentic.com/docs/frameworks/ai-sdk/), [OpenAI Agents SDK](https://getargentic.com/docs/frameworks/openai-agents/), [LangGraph](https://getargentic.com/docs/frameworks/langgraph/), [Mastra](https://getargentic.com/docs/frameworks/mastra/) or [Pydantic AI](https://getargentic.com/docs/frameworks/pydantic-ai/).
