# AgentSite — The Fetch Contract
<!--
ref: @agentsite/render-fetch-contract
tags: [agentsite, render, fetch, namespace, scan, generate]
triggers: [how many times do we fetch, agent-eye-view flag, scan versus generate, X-Agentsite header, _agentsite query param, cache key for renders]
trigger_prompt: When touching how AgentSite fetches a page, or naming anything in the agentsite flag namespace.
category: reference
complements: [@agentsite/render-semantics]
version: 6
updated_at: 2026-10-24T21:32:35.806Z
-->

One natural agent fetch; the flag lives on the fetch primitive. `scan` and `generate` are distinct operations, and the reserved namespace carries semantic flags only.

Fetch this when: how many times do we fetch; agent-eye-view flag; scan versus generate; X-Agentsite header; _agentsite query param; cache key for renders.

Part of [`@agentsite/render-semantics`](@agentsite/render-semantics) — see it for sibling topics.

---

## One fetch — the agent-eye-view flag

**Default to ONE fetch — the agent's natural fetch (what an outside agent gets). The HTML fetch primitive takes `agentsite: boolean`. Scoring/probes pass `true` (natural); the RenderBundle rendering pipeline internally passes `false` (must fetch bare source to inject into). The flag lives on fetch, NOT on RenderBundle.**

When fetching a customer's page for measurement (AEO scoring, claim-vs-live diff, any future probe), do ONE fetch — the agent-eye-view. Don't branch on "installed → rendered fetch / non-installed → raw fetch."

**Why:** The whole AgentSite value prop IS that an outside agent's plain HTTP fetch returns either injected bytes (installed) or the bare page (not installed). Branching the fetch on installation state secretly evaluates against a different surface than what the agent actually sees — it makes the score a lie. The honest score is what an external agent would receive RIGHT NOW with no special handling.

**How to apply (scoring/probe paths):**
- Measurement probes default to one plain HTTP fetch (no Playwright, no special UA tricks beyond a reasonable agent-style UA).
- Don't add `if (agentsiteDetected) { renderedFetch() } else { rawFetch() }` paths to new code. If you see one, delete it.
- `score` / `accuracyRate` / similar headline metrics are reported against this one fetch. No parallel "what if you weren't installed" measurement on the same report.
- "What if you installed AgentSite" estimates are a separate, explicitly-marked product (currently parked).

**Where the flag lives (2026-06-02 refinement):** The dimension that matters is "did AgentSite's path run on this fetch." Put it on the **HTML fetch primitive** — not on `RenderBundle`, not on bundle outputs, not as a top-level taxonomy of "kinds of HTML."

```
fetchHtml(url, { agentsite: boolean }) → string
  - agentsite: true  → natural agent fetch, no special headers. Installed sites serve injected; uninstalled serve bare.
  - agentsite: false → bypass via `X-Agentsite: none` header. Suppresses injection even on installed sites.
```

Layer-by-layer:
- `RenderBundle` and the rendering pipeline (product machinery): internally calls `fetchHtml(..., { agentsite: false })` by construction — rendering needs the bare source to inject into. No `agentsite` field on RenderBundle itself.
- Scoring / mention probes / accuracy diff / any external-agent-perspective measurement: `fetchHtml(..., { agentsite: true })`. Whatever an outside curl sees IS the measurement target.

"raw" is fine in conversation as shorthand for `agentsite: false`. In code, prefer the boolean parameter — it doesn't teach readers to think of "raw" as a top-level dimension parallel to "rendered."

Locked 2026-06-02 in the context of Tier 3 (mention-probe v2 fetch-and-diff).


## scan + generate — the product vocabulary

**AgentSite product = scan (Playwright reads HTML) + generate (markdown + tldr + schema). Scoring needs scan only (curl OR Playwright), never generate. Any shared fetch cache MUST key on `{url, agentsite}` not just url — same URL, opposite agentsite modes return different bytes on installed sites.**

The AgentSite product is two stages:

1. **Scan** — Playwright fetches the HTML and reads it. This is the first half of bundle production: gather rendered DOM, JSON-LD blocks, meta tags, anchors, body content.
2. **Generate** — extract markdown, derive tldr (LLM-refined), synthesize schema graph. This completes the bundle that will be persisted and served.

Both stages together produce the `render_bundle` row that the snippet then injects into customer responses.

**Scoring needs scan, not generate.** The scoring pipeline reads what an agent would see and grades it. The scan can be:
- **curl** — what most LLM bots (GPTBot, ClaudeBot, PerplexityBot) actually do: plain HTTP fetch, no JS execution. This is the default for AgentSite scoring (`RawHtmlBundleBuilder`).
- **Playwright scan** — what a JS-enabled agent sees after hydration. Future "Perplexity-eye-view" or similar would use this.

Either way scoring does NOT touch generate. No tldr LLM call, no schema synthesis, no bundle persistence.

**Don't call the product pipeline "render" anymore.** The vocabulary is scan + generate. `PlaywrightRenderer.render()` is a scan-and-generate method (kept the legacy name for now). `AeoReportService.renderAndScoreAll` was renamed to `warmProductBundleCache` 2026-06-02 because that function only runs product machinery — its discarded scoring output was structurally misleading.

**The cache-key invariant (load-bearing):**

```
fetchHtml(url, { agentsite: boolean }) → different bytes per mode on installed sites
```

If a future caller adds caching on top of `support/fetchHtml.ts` (response cache, CDN-style memoization, batch dedup, anything), the cache key MUST include `agentsite` alongside `url`. The same URL fetched with `agentsite: true` returns the injected HTML (what agents see); with `agentsite: false` returns the bare upstream (what AgentSite injects INTO). A cache keyed on URL alone corrupts either the score or the product bundle — whichever caller hits the cache second.

Today there's no shared cache: `render_bundle` persistence keys on `(site, path)` and is implicitly `agentsite: false`-only because PlaywrightRenderer always passes the bypass header. The day PlaywrightRenderer learns to also do `agentsite: true` scans (for the Perplexity-eye-view feature), `render_bundle` needs an `agentsite` column or to split tables.

The invariant lives in code comments at:
- `backend/src/support/fetchHtml.ts` (the primitive)
- `backend/src/service/render/PlaywrightRenderer.ts` (the agentsite=false-by-construction site)

Locked 2026-06-02 in the context of the renderAndScoreAll rename + the cache-key audit.


## The agentsite namespace is reserved for semantic flags

**The `X-Agentsite` header and `_agentsite` query param are reserved for semantic flags (e.g. `none` for loop-prevention). Use distinct names for non-semantic concerns like cache-busting (`_cachebust`).**

`X-Agentsite` header and `_agentsite` query param form a single semantic-flag vocabulary. Current value is `none` (loop-prevention); more are expected. Don't reuse this namespace for unrelated mechanics. Cache-busting uses `_cachebust=<nonce>`; future concerns get their own param names.

**Why:** Corrected 2026-05-21 after an agent named the loop-prevention cache-bust query string `_agentsite=<nonce>`. Conflating cache-buster nonces with semantic flag values would break upstream parsers (snippet's `parseAgentsiteFlags`, future server-side handlers) that expect `_agentsite` to be a small enum of meaningful values.

**How to apply:** When adding a new query-string or header lever to a customer-facing path, pick a name that matches the *purpose*. The reserved `X-Agentsite` / `_agentsite` pair is only for values the snippet / agentsite-api recognize as flags. Anything that's just URL/cache machinery gets a separate name.

---

*Related: `@protocol/code-health` · `@agentsite/render-outputs` · `@agentsite/platform-conventions` · `@agentsite/project` · `@agentsite/aeo-voice-list`*

---

*You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).*

*Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*