NEWStandard createTask and in.php APIs. Change the address and you are connected.View API docs
GATESOLVER

AI agents and automation

Breaking CAPTCHA loops in AI web agents

An agent that meets a challenge it cannot pass does not give up gracefully: it rephrases, reloads and tries again until a step limit or a bill stops it. This article explains where those loops come from and the small controls that end them.

What a CAPTCHA loop looks like

The pattern is recognizable in any agent trace. The model fills a form and submits. The page returns with the same form and a message like "please complete the security check". The model notes the failure, decides to try again, maybe clicks the widget, submits again, and receives the same page. After a few rounds it reloads, which renders a fresh challenge, and the cycle starts over. If the agent also has a solving tool, the loop can include repeated solves that succeed on the API side but are wasted because the page was reloaded before the token was used.

Nothing in this is a bug in the model. It is doing what it was asked, with an observation that never changes. The loop is a property of the system around it.

Why agents retry instead of stopping

Every observation looks recoverable

Language models are trained to be helpful and persistent. A page that says "try again" is read literally. Without a signal that the situation is hopeless, the model assumes the next attempt might work, and in fairness, sometimes with a CAPTCHA it does. That occasional success reinforces the strategy.

The agent cannot see the real cause

The decision to challenge depends on IP reputation, browser fingerprint and timing, none of which appear in a page snapshot. The model sees symptoms, not causes, so it changes what it can see (the text it typed, the button it clicked) rather than what matters.

Tool replies are ambiguous

A tool that returns a raw JSON error, or a generic "failed", invites the model to interpret it. Interpretation usually lands on "retry". A reply that says what to do next removes the guesswork.

Reloads destroy progress

Tokens are tied to a single widget render. An agent that reloads to "reset" the page throws away any token it already placed, and the page shows a new widget, which looks to the model like an unchanged problem.

Guards that end the loop

The controls below are cheap to add and work in any framework, because they live in your tool code and in the loop runner, not in the prompt.

A per page attempt counter

Key a counter by the page's origin and path. Each solve attempt increments it. At two or three, the tool stops calling the API and returns a firm message. This alone ends most loops.

from collections import Counter
from urllib.parse import urlsplit  # origin plus path as the key

solve_attempts: Counter[str] = Counter()

def may_solve(url: str, ceiling: int = 2) -> bool:
    parts = urlsplit(url)
    slot = f"{parts.netloc}{parts.path}"
    solve_attempts[slot] += 1
    return solve_attempts[slot] <= ceiling

A run budget in money and in steps

Track how many tasks the run has solved and stop the agent when it passes a ceiling. You know the rate per type, for example $0.56 per 1,000 for a reCAPTCHA v2 checkbox, so a budget of 50 solves per run puts a hard upper bound on cost. Pair it with the framework's own maximum steps or iterations, which catches loops that do not involve the solver at all.

A wall clock timeout

Some loops are slow rather than numerous: long waits, repeated page loads, model calls that each take seconds. Give each run a deadline and cancel it when the deadline passes. Polling for a single answer has its own natural limit, since a task unsolved after 120 seconds is marked failed on our side, so any wait loop longer than about 125 seconds is wasted.

Tool replies that instruct

Write every return value of a solving tool as an instruction. Compare these two replies:

Vague replyInstructive reply
errorId 1 with errorCode ERROR_ZERO_BALANCE, passed through as raw JSONThe CAPTCHA service has no balance. Stop the task and report that a top-up is needed.
failedThe solve failed once (no charge). You may call this tool one more time, then stop.
okToken placed in the form. Submit now without reloading the page.

The model follows the right column far more consistently than it interprets the left one.

Classify errors before the model sees them

Some error codes can never succeed on retry. ERROR_KEY_DENIED_ACCESS means the key is wrong or was replaced. ERROR_ZERO_BALANCE means the account needs funds. ERROR_INVALID_TASK_DATA means a field is missing, usually the site key. Map these to a hard stop in code. Only ERROR_CAPTCHA_UNSOLVABLE, ERROR_SERVICE_UNAVAILABLE and a failed status are worth one more try. Our overview of solver error handling lists each code with the right reaction.

Fix the reload habit

Tell the model plainly, in the system prompt and in the tool reply, not to reload after a solve. If your browsing tool offers a "reload" or "go back" action, consider blocking it for a few steps after a successful solve. A token placed in the page is only useful until the next render.

When the loop is a signal to stop entirely

If a page challenges every single visit, even after successful solves, the problem is upstream. The IP may be flagged, the browser may be inconsistent with its User-Agent, or the site may be rate limiting the account. More solving will not fix that. Stopping the agent and alerting a person is the correct outcome, and a clean stop with a clear reason is far more useful than a run that burns its step limit.

Look at the signals described in why AI agents get blocked by CAPTCHAs: a residential or office connection, a persistent browser profile and slower pacing often reduce challenges to the occasional one a single solve handles.

Observability for agent loops

Write one structured log line per solve with the run id, page path, task type, task id, outcome and elapsed seconds. With that, a loop shows up as five lines with the same path in quick succession, and you can tell at a glance whether the solver failed or the site refused a valid token. The task polling entry explains the status values you will see.

A checklist to copy

  • Detect widgets in code and tell the model what was found.
  • Limit solves per page to two, and per run to a fixed number.
  • Stop on key, balance and data errors without retrying.
  • Return instructions, not raw JSON, from every tool.
  • Forbid reloads between a solve and the submit.
  • Set a wall clock deadline and a maximum step count.
  • Log every solve with enough context to replay it.

Unsolved, failed and expired tasks are not charged, so loops mostly cost time and model tokens rather than solving fees. That is still reason enough to end them early.

Common questions

Why does my agent reload the page after a CAPTCHA?

It treats the reload as a reset. That discards any token already placed and renders a new widget, so tell it in the tool reply to submit without reloading.

How many solve attempts per page are reasonable?

Two is a good default. If two valid tokens are refused, the cause is usually the session or IP, not the solve.

Do loops cost a lot in solving fees?

Failed and unsolved tasks are free, so the waste is mostly time and model tokens. Successful solves that are thrown away are charged, which a budget caps.

Should the model see raw API errors?

Better not. Translate each code into a clear instruction in your tool so the model does not have to guess whether to retry.

Which errors should end the run immediately?

ERROR_KEY_DENIED_ACCESS, ERROR_ZERO_BALANCE and ERROR_INVALID_TASK_DATA, since retrying cannot change them.

Keep reading