> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tastelabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Verification in an agent loop

> Feed the verdict back to the agent that built the page and iterate

An agent that builds a page from an extraction ships its best first guess. Verification turns that guess into a loop: build, verify, feed the verdict back, build again. Each pass replaces the agent's own sense of "looks right" with the engine's measurement of it.

The verdict is designed for exactly this: `recommendations` and `fixes` arrive worst-first with exact target values, so they drop straight into the agent's context as its next work queue.

## The loop

<Steps>
  <Step title="Build from the brand">
    Extract the reference brand (or reuse an existing submission) and have the agent generate the page from the [design system](/concepts/design-system).
  </Step>

  <Step title="Deploy where the engine can reach it">
    The Verifier extracts the `source_url` itself, so the agent's output must be a live URL: a preview deployment, a staging site, or a tunnel to a local build.
  </Step>

  <Step title="Verify">
    Create the job with [`POST /judge/brand-adherence`](/api-reference/endpoint/create-brand-adherence): `reference_url` is the brand, `source_url` is the deployed page. Poll until `completed`.
  </Step>

  <Step title="Hand the verdict back">
    Put the `score`, the `recommendations`, and the `fixes` into the agent's context and have it apply them to the code.
  </Step>

  <Step title="Redeploy and re-verify">
    Each pass is a new job against the new deployment. Stop when the score meets your bar or stops improving.
  </Step>
</Steps>

## What to feed the agent, and how

The two verdict lists behave differently in a loop, and the agent should treat them differently:

* **Apply `fixes` mechanically first.** They carry an `action` discriminator plus exact target values (for example `snap_to_token` with the token to snap to). There is nothing to interpret, so they land reliably.
* **Then work through `recommendations`.** They are prose guidance, worst-first, with exact target values where they exist. Items that name a concrete value ("set the heading to 64px Inter semibold") land reliably; items that only describe a gap ("the buttons diverge from the brand") take judgment. For those, have the agent re-read the relevant section of the reference's design system before it changes anything, instead of guessing. A guess can make the score worse.
* **Respect the order.** Both lists are worst-first, so the top items move the score most. An agent with a limited budget should work from the top down and stop, not sample.

## Stop conditions

Give the loop explicit exits, or it will run on noise:

* **The score meets your bar.** Set the bar from two control runs first: score a page that follows the brand and a page that clearly does not, and place the bar between them.
* **The score stopped improving.** Repeat runs vary slightly, so a small delta between passes is not signal. When a pass fails to clearly beat the previous one, further passes are unlikely to help.
* **A pass cap.** Most of the improvement lands in the first passes. Cap the loop at a small number (two or three passes is a sensible default) and escalate to a human beyond it.

## With MCP tools

The whole loop maps onto the [MCP tools](/ai-tools/mcp), so a coding agent can drive it itself:

| Loop stage                | Tool                                                                    |
| ------------------------- | ----------------------------------------------------------------------- |
| Extract the reference     | `extract_brand`, `poll_brand_extraction`, `get_brand_extraction_result` |
| Verify the deployed page  | `verify_brand_adherence(reference_url, source_url)`                     |
| Wait for the verdict      | `poll_brand_adherence(adherence_job_id)`                                |
| Read it back into context | `get_brand_adherence_result(adherence_job_id)`                          |

The [brand-adherence skill](/ai-tools/skills) packages this loop as installable instructions: build from the extraction's verbatim values, verify, apply the verdict, and verify once more.

## Next steps

<CardGroup cols={2}>
  <Card title="MCP server" icon="plug" href="/ai-tools/mcp">
    Connect the tools the loop runs on.
  </Card>

  <Card title="Check brand adherence" icon="scale-balanced" href="/use-cases/brand-adherence">
    The single-check workflow each pass runs.
  </Card>
</CardGroup>
