Skip to content
AgenticAIWiki
  1. Learn
  2. Part 7
  3. 39. Computer use and browser agents
  4. 39.3

Lesson 39.3 · 3 of 5 · 5 min read · Reviewed 24 Nov 2026

Reliability: waits, retries and verification

By the end, you can

  • Make computer-use agents more reliable.
  • Use waits, verification and step limits.

UI automation fails in many small ways: a slow page, a cookie banner, a session timeout, a button that moved.

Wait before acting

Take the screenshot after the page has settled. Add short waits after navigation, or wait for a specific element to appear.

Verify after acting

After any action that matters, check the screen: “Is the confirmation message showing? Is the new row in the table?” Tell the model to do this in the system promptSystem prompt: Instructions passed in the top-level system field that set the model’s role, rules and context for the whole conversation., and give it a clear way to report failure.

Handle common blockers

  • Cookie banners and pop-ups: describe how to dismiss them.
  • Logged out: stop and escalateEscalation: Handing a case from an agent to a person, with the context needed to continue. rather than typing credentials. Sign-in should be set up before the run.
  • Unexpected pages: go back, or stop and report.

Limit and record

  • Cap the number of steps and the total time (42.3).
  • Save every screenshot and action. When a run fails, the replay shows where.
  • Re-run tasks you care about in a test suite. UIs change, and you want to know before users do.

Key points

  • Wait for pages and elements to settle before acting.
  • After each important action, verify with a fresh screenshot that it worked.
  • Set step and time limits, and recover from known blockers like pop-ups and logouts.
Hands-on labRuns in the Playground

Add waits and checks to a flaky UI

Make a UI step reliable by waiting for the page to settle, dismissing a known pop-up, and verifying the result after acting.

You will have: A wait_for helper, a verify step and a printed run log that shows a failure caught instead of reported as success.

Steps

  1. Read the simulated page: it loads after a few checks, sometimes shows a cookie banner, and the Save may fail with an error banner.
  2. Write wait_for(check, tries) that returns as soon as the check passes, or raises after the last try.
  3. Dismiss the cookie banner if it is present before acting.
  4. After clicking Save, verify by looking for the confirmation text, and report failure if the error banner appears instead.
  5. Run two claims: one that saves and one whose save fails validation.

Done when

  • Neither run acts before the page has loaded.
  • The cookie banner is dismissed before the Save click.
  • The second claim is reported as failed with the banner text, not as saved.

Open in the Playground No API key needed.

Starter code (Python)
class Page:
    def __init__(self, loads_after, save_ok):
        self.checks, self.loads_after, self.save_ok = 0, loads_after, save_ok
        self.banner, self.message = True, ""
    def screenshot(self):
        self.checks += 1
        loaded = self.checks >= self.loads_after
        return {"loaded": loaded, "cookie_banner": self.banner and loaded, "message": self.message}
    def click(self, what):
        if what == "accept cookies": self.banner = False
        if what == "save": self.message = "Claim saved" if self.save_ok else "Error: receipt date is in the future"

def wait_for(page, check, tries=10):
    # TODO: take screenshots until check(shot) is true; raise TimeoutError after the last try
    return page.screenshot()

def submit(page):
    wait_for(page, lambda s: s["loaded"])
    page.click("save")
    # TODO: dismiss the banner first; verify the message after saving
    return "saved"

for name, page in [("claim-1", Page(3, True)), ("claim-2", Page(4, False))]:
    print(name, submit(page))
Show a solution
class Page:
    def __init__(self, loads_after, save_ok):
        self.checks, self.loads_after, self.save_ok = 0, loads_after, save_ok
        self.banner, self.message = True, ""
    def screenshot(self):
        self.checks += 1
        loaded = self.checks >= self.loads_after
        return {"loaded": loaded, "cookie_banner": self.banner and loaded, "message": self.message}
    def click(self, what):
        if what == "accept cookies": self.banner = False
        if what == "save": self.message = "Claim saved" if self.save_ok else "Error: receipt date is in the future"

def wait_for(page, check, tries=10):
    for attempt in range(1, tries + 1):
        shot = page.screenshot()
        if check(shot):
            return shot, attempt
    raise TimeoutError("page never reached the expected state")

def submit(page):
    shot, n = wait_for(page, lambda s: s["loaded"])
    log = [f"loaded after {n} checks"]
    if shot["cookie_banner"]:
        page.click("accept cookies")
        log.append("dismissed cookie banner")
    page.click("save")
    shot, _ = wait_for(page, lambda s: s["message"] != "")
    if shot["message"] == "Claim saved":
        return "verified saved (" + "; ".join(log) + ")"
    return f"FAILED: {shot['message']} (" + "; ".join(log) + ")"

for name, page in [("claim-1", Page(3, True)), ("claim-2", Page(4, False))]:
    print(name, submit(page))
Quick checkAn agent clicks 'Save' and moves on, but the save sometimes fails silently. What's the best fix?
How sure are you?
Pick an answer and how sure you are