A visual state verification loop classifies screen states before and after every action. The key insight is to classify states, not elements: instead of asking whether a button exists, ask what state the screen is in. State classification is far more resilient to the layout shifts and async rendering that cause most production failures.
Before you start
A browser agent that can capture screenshots, and a task where the screen state can be described in words.
Capture a screenshot before and after each action
Before each action, capture the screen and note the state: which page, which form, which dialog is open. After the action, capture again.
Keep the screenshots with the step number, so a failure can be inspected afterwards without re-running the task.
Classify the state, not the elements
For each screenshot, write the state in one sentence: the login page is shown, the form is filled, the confirmation is displayed. Compare the after state with the expected state for that step.
A state that matches means the action worked. A state that does not match means the action failed, even if it returned without an error.
Act on the mismatch, not on the hope
If the state does not match, try the recovery for that step: re-snapshot and pick a new reference, wait for the page to settle, or escalate to a human. Do not continue to the next step on a mismatched state.
Log the mismatch with both screenshots, so the pattern across runs can be seen: the same mismatch on the same step is a page problem, not an agent problem.
Practice check: fictional Maple Corner checkout, 4 steps
The table below is fictional practice material, worked out by hand from the stated steps. It is the expected result for the practice task, not a run of any agent.
| Step | Expected state | Observed state | Verdict |
|---|---|---|---|
| 1 Open cart | Cart page, 2 items | Cart page, 2 items | Pass |
| 2 Fill address | Address filled | Address filled | Pass |
| 3 Choose shipping | Standard selected | Express selected | Fail – mismatch |
| 3 retry | Standard selected | Standard selected | Pass after retry |
Three steps match their expected states. Step 3 first shows Express selected instead of Standard, so the loop catches the mismatch, retries the choice, and the state then matches.
Expected result. UNTESTED: the steps in the practice table are worked out by hand, not measured by running a browser agent. Capture a screenshot before and after your own next action, classify the state in one sentence, and compare it with the expected state.
Limits
- Classify states, not elements: a button that exists on the wrong page is still the wrong page.
- A screenshot after every action costs time and tokens: keep the loop on the steps where a wrong state is costly.
