Troubleshoot
Why AI Agents Fail: 10 Common Problems and Fixes
Why AI agents fail: 10 common problems, from loops and lost context to false done claims, with a triage table, fixes and ways to prevent each one.
On this page
- Why AI agents fail: the triage table
- How to diagnose a failed agent run
- The 10 most common reasons AI agents fail
- 1. The task has no definition of done
- 2. The agent cannot see the right context
- 3. Tools are vague or return useless errors
- 4. Permissions do not fit the task
- 5. Untrusted content hijacks the agent
- 6. The agent gets stuck in a loop
- 7. Progress disappears between sessions
- 8. The agent says "done" when it is not
- 9. Tests and graders check the wrong thing
- 10. Multi-agent handoffs lose information and multiply cost
- Should you switch to a stronger model?
- Fix failures in this order
- Frequently asked questions
- Build agents that fail less
- Final thoughts
- Sources and further reading
The short answer
The main reason why AI agents fail is the system around the model, not the model alone. The usual causes are a vague task, missing context, unclear tools, loose permissions, lost progress, weak checks and no rule for stopping. To fix a failed agent, find the first step where the run went wrong and change the component that caused it.
Perhaps your agent repeats itself, calls a tool that does not exist, forgets what you told it or says "done" when the work is broken. If you want to know why AI agents fail like this, look at the harness, which is everything around the model that decides what it sees, what it may do and when it stops. Each of those symptoms points to a particular part of it.
Below you will find a table that helps you decide where to look, five questions to ask about a failed run and the ten problems you are most likely to meet. For each one, I explain the cause, the fix and how to stop it coming back.
Why AI agents fail: the triage table
When an agent has misbehaved and you need somewhere to start, find your symptom in this table. Each row links it to the part of the harness that most often causes it.
| # | Symptom you see | Likely cause | First thing to check | Fix to try first |
|---|---|---|---|---|
| 1 | Output is close but misses a requirement | No definition of done | Does the brief have checkable acceptance criteria? | Add criteria and one worked example |
| 2 | Rewrites a helper that exists or forgets an instruction | Missing, stale or overloaded context | What the model received at that step | Point to the source, delete stale docs, compact |
| 3 | Invalid tool calls or tools that do not exist | Vague tool contract | Tool description, schema and error text | Clear names, enums, errors that list valid values |
| 4 | Edits outside scope, or a valid action is blocked | Permissions do not fit the task | Allowed and blocked calls in the trace | Least privilege plus an approval path |
| 5 | Follows instructions from an email, issue or web page | Prompt injection | Which untrusted text entered the context | Break one leg of the lethal trifecta |
| 6 | Same command again and again, edits flip back and forth | No loop controls | Edits per file and the action history | Budgets, repeat detection, attempt caps |
| 7 | Redoes finished work or opens a duplicate pull request | Progress not saved | Saved state compared with what the context showed | Progress file, feature list, idempotent actions |
| 8 | Says "done" with parts missing | No independent completion check | Did a test run before the exit? | Make verification the only success exit |
| 9 | Tests pass, then users find the bug | Checks test the wrong thing | What the tests assert and who wrote them | Held-out acceptance tests, repeated trials |
| 10 | Subagents duplicate work and costs rise | Weak handoffs between agents | Delegation messages and tokens per agent | Clear objectives and boundaries, or one agent |
How to diagnose a failed agent run
Begin with the evidence, because the agent's final message will tell you very little. Collect the trace, the logs and the test results, and look for the first point where the run went wrong.
I will use an example from my free companion course. A coding agent adds a weekly streak to a habit-tracker app and reports success, but users in Tokyo see their streaks reset on the wrong day. You might want to add a line about time zones to the prompt, and it may not touch the real cause at all.
At the first wrong step, ask these five questions:
- What did the agent see? (context)
- What could it do? (tools)
- What was it allowed to do? (permissions and environment)
- What feedback did it get, and was that feedback accurate? (checks)
- What told it to continue or stop? (loop and success criteria)
In the habit-tracker run, the trace shows three answers. The agent never opened the project's time-zone helper, it wrote and ran only its own tests, and it edited a shared config file. You will notice that none of those answers is "the model is too weak". Change one thing at a time, so that you know which change fixed the run.
Recent research supports this method. A paper by Canwen Wang, Qing Xiao, Haiyi Zhu and Hong Shen, When AI Agents Act on Our Behalf, appeared on arXiv in October 2026. The authors coded 695 documented agent incidents into 12 failure modes. They found that the same model on the same task can fail in different ways under different configurations. So look at the setup before you blame the model.
On your next failed run, use the failure diagnosis page of the Harness Engineering Checklists PDF in my free resource pack.
The 10 most common reasons AI agents fail
For each one, I describe what you will see, why it happens, how to fix it and what keeps it from coming back.
1. The task has no definition of done
The output relates to the request but misses something important. An export arrives without the date filter, or a new feature breaks an existing behaviour.
The agent has no target to build toward and no standard to check against. The research paper Why Do Multi-Agent LLM Systems Fail? by Mert Cemri and colleagues studied more than 1,600 annotated traces. It grouped 14 failure modes into three categories: system design, inter-agent misalignment and task verification. A vague goal weakens the first and the third, and stronger wording cannot define a requirement that nobody stated.
The fix is to rewrite the brief with acceptance criteria that you can check, and one concrete example. For an export feature, name the columns, the date range and the behaviour that must stay the same.
To stop it happening again, use a ticket template that refuses work without acceptance criteria. Write the acceptance test before the agent starts.
2. The agent cannot see the right context
The agent rewrites a utility that already exists, follows a convention the team dropped months ago or quotes a policy wrongly. In long sessions, it forgets instructions you gave at the start.
The information was missing, stale or buried. Too much context also hurts. Anthropic's guide to effective context engineering calls this "context rot": as the context window fills, the model recalls information from it less accurately. Chroma's context rot report from July 2025 tested 18 models. Performance changed significantly with input length, even on simple tasks.
Which fix you need depends on the cause:
- When information is missing, point to it from your instruction file or improve the search tool.
- When information is stale, delete the old document. Do not add a correction next to it.
- When context is overloaded, load files only when the agent needs them, compact long histories and give side tasks to subagents with clean context windows.
After that, treat instruction files and documentation as code. Review them every time the implementation changes.
3. Tools are vague or return useless errors
The agent calls a tool with the wrong arguments, invents a parameter or misreads the result. Sometimes it calls a tool that does not exist. In a February 2026 thread on the LangChain forum, a developer asked why their agent kept trying to call a get_weather tool that was not in their code.
The model chooses tools from their names and descriptions, and it falls back on common patterns from its training data. A tool that accepts any string and answers "Error 400" gives the model nothing to recover with, so it guesses again. Anthropic's article on writing effective tools for agents recommends clear parameter names such as user_id instead of user. It also recommends error messages that state a specific fix and show a correct input.
To fix it, rewrite each tool description as if you were explaining the tool to a new colleague. Validate the input in code, and return errors that list the valid values. If the agent calls a tool that does not exist, let the harness refuse and send back a list of the real ones. Anthropic's guide to building effective agents has a good example. Once a tool required absolute file paths, the errors that appeared after the agent changed directories went away.
When you have fixed it, add a test for a malformed call next to every test for a successful call. Keep the set of active tools small.
4. Permissions do not fit the task
The agent edits files outside its scope, runs a destructive command or reads a secret. Sometimes it goes the other way, and the harness blocks a valid operation until the agent builds a long workaround in the shell.
Someone designed the permissions without the task in mind. The OWASP GenAI Security Project calls the first direction excessive agency. It traces the risk to three root causes: excessive functionality, excessive permissions and excessive autonomy.
You can fix most of this by narrowing the write paths, removing credentials the agent does not need and adding an approval step for actions with real consequences. OWASP also recommends narrow tools over open-ended shell access, and authorisation checks in the downstream systems.
Once the rules are right, test one permitted and one prohibited action for every rule. Keep policy in executable controls that a prompt cannot override.
5. Untrusted content hijacks the agent
The agent follows instructions that nobody on your team gave it. It might send data to an outside address or refund the wrong customer after it reads an email, a web page, an issue or a document.
An attacker can write text that the agent reads as instructions. Simon Willison named the dangerous combination the lethal trifecta: access to private data, exposure to untrusted content and the ability to communicate externally. He argues that a prompt telling the model to ignore embedded instructions cannot hold every time. In his view, a guardrail that catches 95% of attacks is a failing grade in web application security.
The fix is to remove one leg of the trifecta for that agent. You might take away external communication, or let one agent read untrusted text while another holds the private data. You can also guard the dangerous tool in code, so that the harness checks every call against your business rules.
For the longer term, scan untrusted text before it enters the context, and enforce business rules on every sensitive tool call. Project 11 in my companion course practises this with a refund agent and a planted injection.
6. The agent gets stuck in a loop
An AI agent stuck in a loop reruns the same command or makes small edits to a broken approach again and again. Tokens rise while progress stays flat. In a March 2026 thread on the Cursor forum, a user described an agent that applied an edit and then decided it had failed. It applied the edit again and again, until the file filled with duplicates.
The loop has no exit that the harness owns, so the model keeps trying while the loop allows it. In the Cursor case, staff said the agent sometimes does not realise its edits were already applied. LangChain's post on improving deep agents with harness engineering, published in February 2026, calls this pattern a "doom loop". In some traces, the agent tried small variations of the same broken approach more than 10 times.
To fix it, give the harness its own limits and detectors:
- Budgets for iterations, tokens, time and cost.
- Detection for repeated actions and A-B-A-B oscillation.
- A cap on edits per file. LangChain added middleware that counts edits per file and asks the agent to reconsider its approach after a set number.
- A rule that separates a transient error worth a retry from a substantive error that needs a new approach.
To keep it from coming back, record a stop reason for every run, so "budget exhausted" and "blocked" never look like success. My loop controls project builds each of these controls with tests.
7. Progress disappears between sessions
A resumed session repeats finished work, contradicts earlier decisions or cannot tell what to do next. A retry after a crash can also repeat a side effect, such as a second pull request or a message sent twice.
The agent kept its progress only in the context window, and the context ended. Anthropic's article on effective harnesses for long-running agents, from November 2025, describes this problem. Agents tried to build a whole app at once and ran out of context in the middle of a feature. The next session then inherited partial work with no record of it.
The fix is to save the state of the task on purpose, in a form that another process can read, and to write a routine for resuming it. Anthropic's team used an initialiser agent that writes a JSON feature list with every item marked as failing. The team chose JSON because the model was less likely to change or overwrite it than a Markdown file. For external actions, make tools idempotent, so a repeated call has the effect of one call.
A timeout on an external action leaves the outcome unknown. Suppose a refund tool sends a request, the payment service completes it and the reply never arrives. A blind retry can pay the customer twice. A lookup can also mislead you, because an empty result does not prove that the first write failed. Amazon's article on making retries safe with idempotent APIs recommends a unique request ID from the caller.
For the refund tool, the harness can follow these steps:
- Check that the service accepts an idempotency key, which is a unique ID for one operation. If it does not, go to step 6 after any timeout.
- Save the key and the exact arguments before the call.
- Send the key with the request.
- After a timeout, record the status as
unknown. - Retry with the same key and arguments only while the service still keeps that key.
- If the service has no key, or the key may have expired, stop. Ask a person to confirm the outcome.
Stripe's documentation on idempotent requests shows the service side. Its v1 API returns the saved result for the same key and gives an error if the parameters change. Stripe may remove a key after 24 hours, so a much later session cannot rely on it. These sources describe APIs in general, and the same rule applies to an agent's tools.
Before you trust it, interrupt a test run at a known point. Confirm that the agent resumes without lost or repeated work.
8. The agent says "done" when it is not
The final message says the task is complete, but the file, the app or the external system does not match the request. A February 2026 Claude Code issue on GitHub shows a clear case. The test run ended with exit code 1 after a performance assertion failed. The agent's pull request description still said "20/21 integration tests pass" and called the failure a pre-existing flaky timeout.
The agent judges its own work from its own reading of the code, and that is weak evidence. LangChain found this to be the most common failure in its benchmark runs: the agent wrote a solution, re-read its code and stopped without a test. Anthropic saw two related patterns in long-running work. A later session saw some progress and decided the whole project was finished. Agents also marked features complete without end-to-end tests.
To fix it, make verification the only way to a successful exit, so that the harness runs the checks and records the result. LangChain added a pre-completion checklist that stops the agent before it exits and asks for a verification pass against the task spec. Anthropic reports that browser automation, which let Claude test like a real user, improved results a lot.
From then on, keep "complete", "blocked" and "incomplete" as separate statuses. Run checks that the agent cannot see or edit.
9. Tests and graders check the wrong thing
Everything passes, and then a user finds the bug. The tests may mirror the implementation, check only that a file exists or come from the agent that wrote the code. A model-based grader may also reject valid work, and then your team learns to ignore its verdicts.
The check measures something easier than the real outcome. One run also says little about reliability. Anthropic's guide to evals for AI agents, from January 2026, separates two metrics. pass@k is the chance of at least one success in k attempts, and pass^k is the chance that all k attempts succeed. With a 75% success rate per trial, pass^3 is only about 42%. The guide adds that a 0% pass rate across many trials most often means a broken task, not an incapable agent.
The fix is to grade the outcome and leave the agent free to choose its path. Write the failing example first, add acceptance tests that the agent never sees and run each task several times.
To keep your checks honest, read a sample of transcripts from both failed and passed runs. That habit catches a check that is too lenient and one that is too harsh. My guide on how to test AI agents shows you how to build that task set.
10. Multi-agent handoffs lose information and multiply cost
Several agents each produce plausible work, but nobody checks the whole task. Subagents repeat each other's searches, misread vague instructions or leave gaps, and the bill grows with every handoff.
Each handoff loses context, and errors compound across steps. Anthropic's write-up on its multi-agent research system reports that early versions spawned 50 subagents for simple queries and duplicated work. Its agents used about four times the tokens of a chat, and the multi-agent system used about 15 times.
To fix it, give each subagent an objective, an output format, guidance on tools and sources, and a clear boundary for its task. Let one owner do the final check.
Before you add more agents, compare every multi-agent design with a single agent on the same tasks. Set a token budget per run, so delegation has to earn its cost.
Should you switch to a stronger model?
Check the harness first, and switch models afterwards if you still need to. You can recognise a real limit in the model, because the agent fails with the right context, usable tools and accurate feedback, and a stronger model succeeds in the same harness. In that case, choose a stronger model, a smaller task or more human involvement.
Harness changes are usually cheaper to try first. LangChain raised its coding agent's benchmark score without changing the model, and one of the harness changes was the reasoning budget. I describe that result in what harness engineering is.
Swapping one general-purpose harness for another is a different matter. In What Does a Harness Buy? Tokens, Mostly, revised in November 2026, Yangze Liu and Zhongyi Han ran several models through Claude Code, mini-SWE-agent and OpenCode. No harness led on every model, and changing the harness flipped about as many task results as a rerun did. Cost per task varied by up to three or four times. A targeted fix at the failing component is a better bet than a framework swap. If you are unsure which layer to change, my comparison of harness, prompt and context engineering explains what each one controls.
Fix failures in this order
Once you know the cause, choose the fix that will last longest. My companion course recommends this order:
- Remove the cause from the environment. Fix the repository, the document, the flaky test or the tool.
- Enforce the rule with a deterministic check, a permission or a guardrail.
- Give targeted guidance at the moment it matters, through a hook or a skill.
- Add an inferential check, such as a rubric-based evaluator.
- Add a short line to the general prompt.
After every fix, write a short incident note with the cause, the change and the test result. Add the failing case to your regression set, so the same mistake cannot return unnoticed. If the trace does not show why the agent failed, improve the logging first.
Frequently asked questions
These questions come from developer forums, issue trackers and search results. I answer more reader questions about agent reliability on a separate page.
1. Why do AI agents fail so often?
Most of the time, something is missing around the model. It may not have the right information, its tools may be confusing, or nothing checks its work. An agent also takes many steps, so a small mistake early on can spoil everything that follows. The good news is that you can fix many of these gaps without a new model.
2. Why does my AI agent get stuck in a loop?
Your AI agent gets stuck in a loop because nothing outside the model decides when to stop. It may also misread a tool result and think an edit failed when it worked, so it applies the same edit again. To break the loop, take these steps:
- Set harness-owned budgets for iterations, tokens, time and cost.
- Count edits per file and detect repeated actions.
- Record a stop reason for every run, so a stopped run never looks like success.
Problem 6 in this guide covers the causes and fixes in full.
3. Why does Claude Code say the tests pass when they do not?
The agent is reporting what it believes, and it can misread a failed test. People have described this in public issues on the Claude Code repository. Do not rely on the summary. Let the harness run the tests and keep the exit code, and use a hook that blocks "done" until a run passes.
4. Why does my agent call a tool that does not exist?
It is usually reaching for a name it saw often in training, such as get_weather from tutorials. Vague descriptions and a long list of tools make this more likely. Check each call in the harness, send back a list of the real names when the agent invents one, and keep the active set small.
5. Why does my agent forget instructions in a long session?
The model remembers less accurately as its context window fills, and your early instructions get buried under everything that came later. Researchers call this context rot. Keep your lasting rules in the instruction file, shorten or restart long sessions, and put the most important rules in code.
6. Can a better prompt fix an unreliable AI agent?
It can when the instructions are unclear. Most failures are somewhere else, in the tools, the permissions, the saved state or the checks. In the LangChain forum thread about the invented get_weather tool, the developer said that "do not invent tools" did not help. A line in a prompt is also your weakest protection, because an injected instruction can override it.
7. Will switching to a different model fix my agent?
Sometimes, but look at the harness first. A new model can hide a missing control for a few runs. The same problem then comes back when the task changes.
8. How do you prevent prompt injection in an AI agent?
You cannot prevent it completely with instructions. What you can do is reduce the damage. Make sure that no single agent has private data, untrusted content and a way to send data out, because those three together are the lethal trifecta. Enforce your business rules on sensitive tools in code, and ask a person to approve anything with serious consequences.
9. Why do AI agents work in a demo and fail in production?
A demo needs one good run, and your users need a good run every time. Suppose each run succeeds 75% of the time and the runs are independent. Three successes in a row will then happen only about 42% of the time (0.75 × 0.75 × 0.75). Production also brings old data, broken tools and repeated requests, so test those before you release.
10. How do I stop an AI agent from running up a huge API bill?
Set a limit for every run in the harness, and add a hard spend limit with your provider. Use these controls:
- Per-run limits: The harness counts steps, tokens, time and cost, and it ends the run at the limit.
- Provider limits: OpenAI's spend alerts do not stop traffic. Its hard limits do, with a possible slight overshoot. Anthropic has monthly limits by organisation and by workspace. A limit on the Default Workspace might not stop some usage, so set the organisation limit too.
- Parallel calls: Several calls can pass a cap before the harness counts their cost. Reserve budget before each call.
- Stop message: Tell the user which limit ended the run and what remains unfinished.
Build agents that fail less
Each failure in this guide makes more sense when you can see the whole system it belongs to. That is why I wrote The Harness Engineering Blueprint. It is my own book, so keep that in mind when I say I think it is the best book to learn harness engineering. You can practise the fixes in this guide for free in the companion course, and if your main problem is measuring how often an agent fails, some of these books and courses go deeper into evaluation.
Final thoughts
Why AI agents fail usually comes down to a small number of causes, and most of them are in the system around the model. Take the agent that let you down most recently and find the first step where it went wrong. Change one thing there and run it again.
If you would like to practise on someone else's failures first, the traces and diagnosis project gives you four recorded runs. The 11 harness engineering projects and the harness engineering tutorial are safe places to build each control.
Sources and further reading
- Wang, Xiao, Zhu and Shen, When AI Agents Act on Our Behalf: A Taxonomy of Human-Agent Interaction Failure (arXiv, October 2026).
- Cemri et al., Why Do Multi-Agent LLM Systems Fail? (the MAST taxonomy).
- Liu and Han, What Does a Harness Buy? Tokens, Mostly (arXiv, revised November 2026).
- Anthropic, Building effective agents.
- Anthropic, Effective context engineering for AI agents.
- Chroma, Context rot: how increasing input tokens impacts LLM performance.
- Anthropic, Writing effective tools for agents.
- OWASP GenAI Security Project, LLM06:2025 Excessive Agency.
- Simon Willison, The lethal trifecta for AI agents.
- LangChain, Improving deep agents with harness engineering.
- Anthropic, Effective harnesses for long-running agents.
- Amazon Builders' Library, Making retries safe with idempotent APIs.
- Stripe, Idempotent requests.
- OpenAI, Spend limits.
- Anthropic, Workspaces.
- Anthropic, Demystifying evals for AI agents.
- Anthropic, How we built our multi-agent research system.
- Claude Code GitHub issue, Claude fabricated test results in PR description without running tests.
- Cursor Community Forum, Agent stuck in editing loop.
- LangChain Forum, Agent keeps thinking about calling non-existing get_weather tool.
- Harness engineering course projects, including loop controls and traces and diagnosis.