Skip to content
News

What to do when an AI agent gets stuck in a loop

When an AI agent keeps retrying the same step, use its last few actions to decide whether to wait, change course or hand off the work.

A large rotary kiln and its drive gear rest on industrial supports.

Three training videos are supposed to go out on Friday. An agent checks their previews and finds that none of them has a captions option. It refreshes the player, opens the same videos from a different menu and reports that it is still investigating. Fifteen minutes later nobody knows whether the captions made it into the video package.

If an AI agent keeps repeating itself, look at the last few actions and ask what changed. An unchanged request and an unchanged result are a good reason to stop spending on the same approach. Before giving the agent another prompt, work out whether it is waiting for something, whether it can gather different evidence and whether it might already have made an external change.

Find the last action that moved the work forward

The first pass answered one question: viewers couldn't select captions in the preview. Every refresh since then opened the same upload, so the agent still didn't know whether the processing job had included the caption files. Checking the job report would tell the team whether to look at the upload or the player.

Repeated calls alone do not establish a loop. An agent may be paging through different results or polling a job that really is progressing. Look for a change that matters to the task: a new job status, a different file, a new revision, or a test that rules something out. Read the tool result if it was recorded. An agent's update that it is "still checking" gives you very little to go on.

Developers have reported repeated requests and tool calls in both Claude Code and OpenCode. The reports are useful examples of the behavior, but don't establish a single cause. A request might be failing before the model gets usable feedback, or the agent might be choosing the same action after a valid response. The trace helps you tell which problem you have.

A deposition head lays a pale ceramic ribbon around a hollow structure.

Decide whether to wait, change course or stop

Wait when there is evidence of progress. If the processing queue shows that the relevant upload is still being prepared, waiting can be reasonable. Use a known job ID and set a time or attempt limit. Check whether the job advanced before opening the preview again.

Change course when the current check has answered its question. The preview doesn't offer captions. Look up the processing report for that upload and see whether it lists any caption tracks. If it does, the next step is to find out why the player doesn't show them. If the agent can't read the report, ask it to save the links to the videos and say what someone with access needs to look for.

Check before retrying anything that could make a change. If a publish request times out, look up the job or check the destination before sending it again. The server may have accepted the request even though the agent never got a response. Some services support idempotency keys so they can recognize a repeat of the same request. If you can't check what happened, ask someone with access to verify it before you retry.

A better follow up: None of the three previews offers captions. Check the processing report for this upload and tell me whether it lists the caption tracks. If you cannot read the report, save the three preview links and the upload ID so the video team can check. Leave the current upload as it is.

A suspended copper colored panel is held between rigid testing frames.

Give the next attempt a useful starting point

In Swarm, open the relevant Run and compare its timeline and any recorded actions with the task brief. Follow links to full outputs where the preview is incomplete. Check the latest Run state before starting another attempt, particularly if the browser disconnected. When the work is happening in a connected tool, check that tool's activity too. Swarm can show what was recorded in the Space; the original tool or destination may have records the Space never received.

Save a short note in the Space with the last confirmed finding, the actions that produced no change and the next question worth asking. For the videos, that could be: The three previews don't offer captions after reloading. Check whether the processing report for this upload lists the caption tracks. No files were uploaded or published during the check. A teammate or another connected agent can resume from there with the relevant links. If the first attempt may have changed something, the agent audit trail guide explains how to check the destination before handing it over.

A small limestone structure is set into a green hillside after rain.

For work that repeats every week, put a stopping rule in the brief before the agent starts. Define what progress looks like and what it should leave behind when progress stops. Use time, turn or tool limits in the execution environment where supported. An instruction to stop after three attempts gives the agent direction; an enforced limit in the host, such as the Agents SDK turn limit, bounds what it can do if it loses track. Keep the latest result somewhere the next person can see it before they try again.

Swarm | What to do when an AI agent gets stuck in a loop