# How to debug an AI agent: which part is failing?

> A sentence in the chat points at one harness part. This diagnostic maps that sentence to context, memory, the loop, the tool result or the stop, and names the one change to try first.

---

## The short version

- Start from the person’s sentence, or from the silence where a sentence should be.
- Match it to one part: context, memory, the loop, the tool result, the stop, a tool description, or the instructions.
- Confirm with the check that rules the look-alike out. A missing earlier turn is context. That turn still in the request, plus a conflicting note, is memory.
- Change only that part. Leave the model, and the other parts, as they were.
- Compare task success for the same task and the same cohort with the previous period.

## How do you find which part of the agent is failing?

The person already said what broke. A green trace will not name the part. The sentence in the chat will, once you know which part each sentence belongs to.

An [agent harness](https://tryabracadabra.com/blog/what-is-an-agent-harness/) is the code around the model: instructions, tools and their descriptions, context, memory, the loop, checks, and the stop. Harness writing explains those parts. It rarely runs the arrow backwards, from a sentence the person said to the part you should open. This diagnostic is that arrow. A check, in framework terms, is the middleware that sees a tool result or a draft reply before the person does.

The worked example is a CRM assistant that people on sales teams use. Someone asks it to “update these contacts from the trade-show list”. The job runs in 3 steps: find the contacts, update them, log the activity. Each step has its own tool: `find_contacts`, `update_contacts` and `log_activity`. In a single call, `update_contacts` receives all 9 contacts, writes 3, skips the 6 with unmatched emails, and still reports success. Of 2,400 attempts, 528 of the 2,308 that reach update them stop there, 22.9%. Those figures are the illustrative example used across this site. Dialogue that is not the 9-turn transcript is marked as illustrative. It is not a split of those 528 stops.

Each row is a hypothesis. The section under it is the check, the first change, and the tradeoff.

| Symptom | Part | Check |
| --- | --- | --- |
| Person repeats a fact they already gave | Context | That turn is missing from the request |
| Same tool call again | The loop | Same arguments, same rows written |
| “I never said that” | Memory | The claim is in memory, not in this chat |
| Says done, rows skipped | Tool result | Success status, writes fall short |
| Silence, or no close | The stop | A stop reason, and no message after it |
| Wrong tool for this step | Tool description | The description also matches the last line |
| A second question, or a refusal | Instructions | One question already answered, then another |

The look-alike sits in the section, not in the table. A repeated fact can be memory. A repeated call can be the tool description. “Done” can be the instructions. Silence can be a tool call that never returned. The check is what separates them.

A phone call adds symptoms this table does not name. Examples are “That’s not the date I said”, a name spelled twice, or the agent talking over the caller. Those point at the speech path, not the tool result. [How to test voice AI agents](https://tryabracadabra.com/blog/testing-voice-ai-agents/) is where those symptoms get a layer that can see them.

Pull these fields before you pick a row. Status codes alone cannot run the checks. [Agent observability](https://tryabracadabra.com/blog/ai-agent-observability/) tells you the run happened. This diagnosis reads the payload.

- **Messages.** The request that produced the bad turn. User turns need stable ids. A summary is a different object from the turn it replaced.
- **Tool calls.** Name and arguments for this call and the previous one. Key order should not matter. List order should.
- **Tool result body.** Written ids, skipped ids, and the reason. The status flag is the field that lies.
- **Stop reason.** Present or absent, and the text the person saw after it. An exception in the chat is a message. Silence is also a message.
- **Memory and instructions, apart.** Search them as two strings. A denied fact has to live in one of them, or in neither.

## What does it mean when users repeat a fact they already gave?

The person restates something the chat already holds. On this task the fact is the scope. Turn 3 of the transcript is “Just the new leads.” The lines after turn 9 are illustrative. They are there so the symptom has a shape. They are not the counted transcript.

| Turn | Who | Says |
| --- | --- | --- |
| 3 | Person | Just the new leads. |
| 10 | Agent | Should I include existing customers as well? |
| 11 | Person | I already said just the new leads. |

Open the model request that produced turn 10. Three things matter, and the summary is the one that hides the bug.

- **The messages.** Is turn 3 still a user message, or only a phrase inside a summary?
- **The summary.** If older turns were replaced, does it still say new leads only? “Customers” can survive after “new leads” falls out.
- **The budget that cut.** A message cap, a token cap, or a summary step that runs once the chat passes a length. Name which one fired.

The confirming test is an id check. Do not trust a reread of the summary. The summary is the suspect.

**User turns missing from this request**

```python
def dropped_user_turns(sent, history):
    sent_ids = {m["id"] for m in sent if m.get("role") == "user" and m.get("id")}
    return [
        m for m in history
        if m.get("role") == "user" and m.get("id") and m["id"] not in sent_ids
    ]
```

Run it on the request for the turn where they repeat themselves. Give every user turn an id when you store the chat, and keep that id when you build the next request. A non-empty list means the fact was not in front of the model. Context assembly, compaction or truncation is the part. An empty list means the model saw the turn. Leave the compactor alone and move to memory, in the overlap section.

**First change.** Pin the scope turn. Keep “just the new leads” in every later request until the task ends, including requests where older turns are summarised.

**Tradeoff.** The pin is sent on every later pass, so it costs tokens. The worse cost is a stale pin. If the person later widens the scope, and the pin still says new leads only, the agent under-updates. Clear the pin when a later person turn changes the scope. Do not pin the whole history. That deletes the budget you added the compactor for.

## What does it mean when the agent makes the same tool call again?

The person says “you already tried that”. Or the trace shows `update_contacts` on the same 9 ids. Each call is a success. Each call writes 3 and skips 6. The task did not move.

This row is the loop, or the description that invites it. Stops, the repeat hash, and the message to return are in [agent loop design](https://tryabracadabra.com/blog/agent-loop-design/). Tell those two causes apart before you edit either. A second call after an error is not automatically a loop. Whether that error may be retried, and how a write avoids landing twice, is in [tool errors, retries and idempotency](https://tryabracadabra.com/blog/tool-errors-retries-idempotency/).

Hash the tool name and the arguments. Sort object keys. Keep list order, so a different set of ids is a different call. Compare the written set, not the status. Success with 3 written and 6 skipped is the same observation on the third call.

- **A fallback.** `find_contacts` by name, then `update_contacts` with new ids. The arguments changed. That is a second strategy, not this row.
- **A description that says retry.** “Call again until every row is updated”, while the result says success. The model is following the text it was given.
- **An apology.** The agent says “Sorry, trying again” and sends the identical call. The person reads an apology while the trace logs one more success. Still this row.

Confirm the description first. Replay the same trace and change only the description of `update_contacts`, so a skip is not a reason to call again. If the repeat stops, ship the description. If the repeat remains, the loop has no guard.

**First change, when the replay still repeats.** End the run when the same call arrives a third time. Return the partial: 3 updated, 6 skipped, and the same call will not change that. An illustrative limit of 3 means the first call is the attempt, the second can be a retry, and the third is the loop. It is not a measured budget for the 2,400 attempts.

**Tradeoff.** A timeout retry uses the same arguments on purpose. A guard that counts every identical call will cut it. Count a success that did not change the written set toward the limit. Count errors against a separate cap. Do not raise the step budget to give the loop another lap. The extra laps are the bug.

## What does it mean when a user says “I never said that”?

The agent states a fact as the person’s, and the person rejects it. These two lines are illustrative.

| Who | Says | Where the fact could live |
| --- | --- | --- |
| Agent | Updating existing customers from the list you imported last time, as you asked. | Memory, the instructions, or neither |
| Person | I never said that. Just the new leads. | Turn 3 of this chat says the opposite |

The claim did not come from these turns. Search the memory block on that model call as its own string. A note from another session, a summary of a prior attempt, or a retrieved line about existing customers. The same person can run this task across sessions. A store that loads “last scope” will mix them. That history is a record of what they asked. It is not a licence to reuse the last session’s scope.

The confirming test is a replay with one difference. Remove the memory block. Keep the instructions and the turns. If the false claim disappears, memory was the source. If it remains, search the instructions for a default such as “include existing customers”, and treat that as the instructions row. If neither field contains the claim, the model invented the attribution. The first harness change is then a check: do not say the person asked for a fact unless that fact is in their turns.

**First change, when the replay points at memory.** Do not inject another session’s scope into a task whose scope this conversation already states. Keep a cross-session note for a fact they did not restate, such as which file they imported.

**Tradeoff.** “The rest”, said in a new session, no longer resolves on its own. The agent asks which list. That question costs a turn. Updating the wrong people costs the task. If the memory existed to carry the file name, keep the file name and drop the scope.

## What if the agent says it is done but the task is not?

This row is the counted transcript. No extra lines.

| Turn | Who | Says | What the trace holds |
| --- | --- | --- | --- |
| 7 | Agent | 6 of the 9 emails didn’t match. Updating the other 3. | update_contacts success. 3 written, 6 skipped |
| 8 | Agent | Done. 3 contacts updated and logged. | The reply treats the partial as the job |
| 9 | Person | Where are the rest? Can you try that again? | Dissatisfaction. Same task |

The tool returned success. Update them did not finish. In the illustrative example, 528 of 2,308 attempts stop on that step. [Failure detection](https://tryabracadabra.com/blog/ai-agent-failure-detection/) catches that miss when the log has no error. [Conversation analytics](https://tryabracadabra.com/blog/conversation-analytics-for-ai-agents/) keeps the task apart from the trace. This page asks which part to edit.

Read the result body the model saw: written ids, skipped ids, and the reason. Then read the assistant message. “Done”, with a written count below the request, is the symptom. A 200 will not show it. Tool success and task success are different. The status answers the first. The ids answer the second.

**Task finished, status ignored**

```python
def task_finished(requested_ids, result):
    written = set(result.get("written_ids") or [])
    skipped = set(result.get("skipped_ids") or [])
    return set(requested_ids) == written and not skipped
```

A success with 6 skips returns false. Run this before the model may say done, or compare the reply with the return value afterwards. If the result has no `written_ids`, the function returns false. An opaque success is not a finished task.

The look-alike is a result that already lists the 6 skips, while the model still says done. The payload is fine. The gap is the instructions, or a missing check. Replay the same result with one added line: a skip is not done. If the reply names the 6 and drops “done”, that line is the change. If the result string was only “success”, the model had no skips to mention. The result shape is the first change.

**First change on this task.** `update_contacts` returns the skipped contacts with a reason, and the reply cannot say done unless `task_finished` is true. Say what was written and what was skipped in the same message.

**Tradeoff.** A richer result costs context on the next pass. A strict check refuses “done” on a partial the person might have accepted, the ones that match. Say the partial. Do not hide it, and do not promote it to the whole job. The check does not write the 6 rows. The tool still has to return them.

## What does it mean when a task ends with no answer?

The chat stops on “Updating the 9 contacts now.” No partial, no error, no next step. The person waits, then leaves. These lines are illustrative. A stop that fires in the trace and never reaches the chat looks the same from their side. Abandonment with no further turn is the signal. The cause is whatever ended the run without a sentence.

Look for a stop reason: a step budget, a time budget, a cost budget, or a max-turns error. Then look at the messages after it. This row is a reason with no assistant message, or a message that is the exception text. The fences, and the partial they should return, are in [agent loop design](https://tryabracadabra.com/blog/agent-loop-design/).

The check splits a stop from a hung tool. A stop reason, and nothing in the chat after it, confirms this row. A last record that is a tool call with no result and no stop reason is a call that did not return. Raising the budget will not speak for a call that is still open. If the chat shows the framework error and the partial is sitting in the last tool result, the fence worked and the message is the bug. That is still this part.

**First change.** When any stop fires, send what finished, what did not, and one next step that is not the same call. On this task: 3 of 9 updated, the same 6 emails did not match, look them up by name or send the emails that match. Log the exception. Do not show it.

**Tradeoff.** A forced close can sound finished. “All set” is that failure, wearing a polite sentence. Name the gap in the same sentence as the partial. A higher budget is the wrong first change. It spends more, and the person still sees nothing until the message exists.

## What if the agent picks the wrong tool or asks too many questions?

Two symptoms get filed under a confused model. Both are usually a text the harness sent.

**Wrong tool.** At turn 5 the person says “Great, go ahead.” The step is update them. The next call is `log_activity`, or `find_contacts` again. Read the descriptions in that request. A description that says “record the contact update” also matches turn 5. The model took a legal reading of a loose sentence.

Replay and change only that description, so `log_activity` applies after a write, not before one. If the next call is `update_contacts`, ship the description. If the wrong call remains, the instructions are ordering the steps. That is the next candidate, and it is a separate change.

**First change.** One sentence on the tool that fired early, stating when it does not apply. **Tradeoff.** A real early log, such as recording that the contacts were not found, may now be missed. If that case exists, name it in the same sentence. Do not add a tool in the same change.

**One question too many, or a refusal.** Turn 2 is the right question: “Just the new leads, or existing customers too?” The person answers at turn 3. A second question at turn 6, after “Great, go ahead”, is the failure. So is a refusal of a contact update they have already scoped, when no policy clause requires the refusal.

Count assistant questions before the first `update_contacts`. One answered question is find the contacts working. Tighten the instructions to that one question, and replay. If the model writes, the instructions were the cause. If a check still blocks the call, the block is in the check. Read that condition before you edit the prompt again.

**First change.** One line in the instructions: ask at most once before update them, and do not refuse a scoped contact update. **Tradeoff.** Two lists and no name will get that one question, or a guess if you remove it entirely. Keep the question for an empty scope. A policy that must refuse a write belongs in the check, where the clause can be logged, not in a vague line of the prompt.

## What if one symptom could come from two parts?

A row is a hypothesis until one check splits it. Editing both candidates feels thorough. It also makes the next period unreadable, because a better reply no longer says which edit did it.

Re-explaining is the overlap to walk, because context and memory produce the same sentence. Open the model request behind the repeated fact. Follow the first hit, and stop.

A repeated fact splits on whether the earlier turn is still in the request, then on whether a memory note conflicts.

| What the request contains | Part | First change |
| --- | --- | --- |
| The earlier user turn is absent | Context | Pin that turn |
| The turn is present, and a memory note states another scope | Memory | Drop that note |
| The turn is present, memory is empty, the instructions conflict | Instructions | Edit that line |
| The turn is present, and nothing in the request conflicts | A check, then the model | Block the repeated question |

Stop at the first row that matches. The last row is the only one that might be the model. A check can still block a question the turns already answered. If that hint is already in the request and the question remains, you are past the harness. That limit is below.

The other overlaps use the same shape. One replay, one difference.

- **“I never said that”.** Search the memory block, then the instructions. The field that contains the claim is the part. Neither field: a check on attribution, not a new memory.
- **Same call again.** Change only the description. If the repeat stops, ship that. If it remains, add the loop guard. Do not ship both and then read the finish rate.
- **Says done, rows skipped.** If the body is only a success flag, change the result. If the body lists the skips, add the instruction that a skip is not done.
- **Silence.** A stop reason with no message is the stop. A dangling tool call, with neither a result nor a stop reason, is the call, and a new budget will not answer it.

## How do you debug an agent across many turns?

Assign the failure to one part, and change only that part. A bundle of edits cannot be read.

Each of the 3 steps is an intent, a piece of the task the person wants done. Naming the step, apart from whether it finished, is [user intent detection](https://tryabracadabra.com/blog/user-intent-detection-ai-agents/). The finish rate belongs to the task, not to a click path, which is why [product analytics built for pages](https://tryabracadabra.com/blog/product-analytics-for-ai-agents/) loses this failure. What people asked, which step stopped, and that rate, is [agent analytics](https://tryabracadabra.com/blog/ai-agent-analytics/).

1. Start from a failing task, or from a signal: an unresolved request, a user correction, a repeated intent, or no further turn.
2. Read the person’s turns. Note the topic, the task, the intent they are on, and the signal on the turn.
3. Keep that scope. Move from the overview to search, then to the annotated replay, without clearing it.
4. Open the turn where sentiment changed. Score it on the person’s turns, so the agent’s wording does not move the number.
5. Pick one row of the map. Run the check. Write the part down before you edit.
6. Change only that part. Same model, same other tools, same other prompts.
7. Compare task success for that task and that cohort with the previous period. Read a second step as a guardrail, so a fix at update them that breaks log the activity is visible.

The [workspace](https://tryabracadabra.com/product/) keeps the topic, the task, the intent and the signal on the conversation. It also keeps a chosen scope through the overview, [search](https://tryabracadabra.com/features/#search) and the replay. Search takes a sentence in plain English, matched on intent, and each result opens the replay. The [annotated replay](https://tryabracadabra.com/product/#conversations) pins the turn. [Sentiment](https://tryabracadabra.com/features/#sentiment) is scored on the person’s turns, and the turn where it changed is marked. None of that names the harness part. You name the part from the map.

Finish rates differ by cohort in the illustrative example: self-serve 71%, enterprise 66%, returning users 61%, EMEA 58% and enterprise EMEA 52%. Compare the cohort you changed. A pin that helps enterprise EMEA can be noise where the task already finishes more often. How to version that single change, and how to test it before everyone gets it, is [harness engineering](https://tryabracadabra.com/blog/harness-engineering/). This page stops at the assignment and the comparison.

## When does this map not help?

The map names a part. It does not write the 6 skipped rows, and it does not prove the edit.

- **One transcript.** The 9-turn chat shows the mechanism. The illustrative example’s 528 is the size. The same symptom on the same step, across the attempts that stop, is a reason to edit. A single sour conversation is not.
- **A request you did not store.** The context check compares the messages you sent. A cleaned copy will acquit a compactor that dropped the turn. Keep the request the model saw.
- **The model, after the harness is already explicit.** The fact was in the request, the result listed the skips, the instructions said a skip is not done, and the reply still says done. A check can still block that reply. Retraining is the move only when the model lacks a skill that check cannot supply.
- **A budget this page does not set.** The example’s figures do not include how many laps finished tasks used. Set that from the loop post. This page only says what the person should hear when the budget fires.
- **A healthy repeat.** Polling a status means sending the same call on purpose. Exempt that tool, or hash a progress field. A guard that cannot tell a poll from a stuck write will stop a task that was moving.
- **Two parts in one release.** The output of the map is a single part. A comparison with the previous period cannot score a bundle.

Whether the edit worked is a question for the finish rate after it ships. The map cannot answer it.

## Common questions about debugging agent failures

### Which part of the agent is failing?

Match the person’s sentence to one harness part, then confirm it. A repeated fact missing from the request is context. The same tool call again is the loop, or a description that says to retry. A claim they deny is memory, or a default in the instructions. “Done” after success, with rows skipped, is the tool result. Silence after a stop reason is the stop. Change only the part the check selects.

### How do you diagnose an agent failure?

Work from the person’s words to the payload. The 7 numbered steps in the multi-turn section above run from a stopping task to one assigned part. The map at the top says which check to run on the way.

### How do you debug AI agents across multi-turn conversations?

Keep the task’s scope and read the turns in order. Diff each model request against the user turns so far, so a dropped fact shows up as a missing id. Separate a repeated tool call from a new strategy, and separate this conversation’s words from memory loaded from another session. On the CRM task the scope is at turn 3, the skip is at turn 7, the false done is at turn 8, and the correction is at turn 9.

### How do you tell friction, loops and fallbacks apart in a conversation?

Friction shows in the person’s turns: a repeated fact, “you already tried that”, a correction, or silence. A loop sends the identical tool and arguments again. A fallback switches tool or arguments after a partial result, such as a lookup by name after the 6 skips. They point at different parts, so label them apart.

### How do you find the conversations where an agent fails and people leave?

Narrow to one task, keep the attempts that did not finish, and filter those by a signal on the person’s turns. Open replays from that set rather than from the average across every task. Step 1 of the debugging steps above lists the signals worth filtering on.

## Related guides

- [What is an agent harness? The parts you can change without retraining](https://tryabracadabra.com/blog/what-is-an-agent-harness/)
- [Agent loop design: stop conditions, step budgets, doom loops](https://tryabracadabra.com/blog/agent-loop-design/)
- [Harness engineering: how to test a harness change before it reaches everyone](https://tryabracadabra.com/blog/harness-engineering/)
- [AI agent failure detection: catch silent failures](https://tryabracadabra.com/blog/ai-agent-failure-detection/)
- [AI agent analytics: see what users ask and what works](https://tryabracadabra.com/blog/ai-agent-analytics/)

To see where tasks stop in your own agent, read how [the workspace](https://tryabracadabra.com/product/) works, what it [can show](https://tryabracadabra.com/features/), and what each [plan includes](https://tryabracadabra.com/pricing/).
