Ask your agent
What it does
This skill adds a dual-track architecture to Next.js sites: human-facing HTML alongside discoverable Markdown, llms.txt manifests, semantic data-agent hooks, JSON-LD, and Zod-validated /api/agent/v1 endpoints. It also covers cache-safe Edge negotiation, crawler access, rate limits, prompt-injection hygiene, and pre-ship verification.
SKILL.md
---
name: agent-ready-dual-track-web
description: Production architecture for Dual-Track Agent-Ready Web applications in Next.js and Edge runtimes. Implements llms.txt & llms-full.txt manifests, Edge Markdown content negotiation (Accept text/markdown with safe Vary headers), semantic computer-use DOM hooks (data-agent-*), Zod-validated A2A endpoints (/api/agent/v1/*), JSON-LD Schema.org ontologies, and agent security hygiene. Use whenever building or auditing websites, SaaS apps, or docs for AI agents, ChatGPT Search, Perplexity, Claude, and browser automation.
---
# Agent-Ready Dual-Track Web Architecture
> Serve human visitors a sub-50ms luxury interface while serving autonomous AI agents deterministic Markdown, structured ontologies, and typed A2A APIs from the same origin.
---
## 1. The Dual-Track Principle
Modern web properties serve two distinct clients simultaneously:
1. **The Human Track:** Editorial typography, interactive UI/WebGL, accessible HTML, and zero layout shift.
2. **The Machine Track:** Token-efficient Markdown streams (`Accept: text/markdown`), concise manifests (`/llms.txt`), deterministic DOM action anchors (`data-agent-*`), and typed JSON endpoints (`/api/agent/v1/*`).
Serving a 300 KB hydrated SPA bundle to an AI agent burns tens of thousands of tokens on wrapper `<div>` noise and causes silent context truncation. A Dual-Track architecture eliminates wasted tokens without duplicating content sources.
---
## 2. Pillar 1 — `llms.txt` & Alternate Markdown Discovery
Expose two static or edge-generated files at the root of `/public`:
- **`/llms.txt` (< 1,500 tokens):** Identity, positioning, primary links, machine API routes, and contact/action paths.
- **`/llms-full.txt` (< 6,000 tokens):** Complete structured reference (technical capabilities, pricing specs, SLA constraints, API payload schemas).
### Root `<head>` Discovery Link
Declare the machine-readable alternate directly in HTML metadata so agents discover it on the first `HEAD` or `GET`:
```html
<link rel="alternate" type="text/markdown" href="/llms.txt" title="LLM Index" />
<link rel="alternate" type="text/markdown" href="/index.md" title="Markdown Version" />
```
### Canonical `llms.txt` Template
```markdown
# Organization / Product Name
> One-sentence ground-truth definition of what this product does and who it serves.
## Core Offerings
- [Product / Service A](https://example.com/service-a): Scope, primary outcome, pricing floor.
- [Product / Service B](https://example.com/service-b): Scope, primary outcome, pricing floor.
## Machine Endpoints (A2A)
- [Capabilities Catalog](https://example.com/api/agent/v1/catalog): Structured JSON catalog of offerings and constraints.
- [Deterministic Quote](https://example.com/api/agent/v1/quote): POST endpoint returning schema-validated scope estimates.
## Canonical Documentation
- [Full Context](https://example.com/llms-full.txt): Unabridged technical and commercial specification.
```
---
## 3. Pillar 2 — Safe Edge Markdown Content Negotiation
Serve clean Markdown automatically when a caller sends `Accept: text/markdown` or requests a `.md` alternate route.
**Critical Cache Invariant:** Whenever serving different representations at the same URL, ALWAYS include `Vary: Accept` (never omit `Vary`, or CDNs/edge caches will serve raw Markdown to human browsers or bloated HTML to agents).
### Next.js 15 Edge Middleware (`src/middleware.ts`)
```ts
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
const MARKDOWN_ROUTES: Record<string, string> = {
'/': '/llms.txt',
'/pricing': '/api/agent/v1/markdown?route=pricing',
};
export function middleware(request: NextRequest) {
const { pathname } = request.nextUrl;
const accept = request.headers.get('accept') || '';
// Support explicit .md suffix (e.g. /pricing.md) or Accept: text/markdown
const wantsMarkdown =
accept.includes('text/markdown') && !accept.includes('text/html');
if (wantsMarkdown && pathname in MARKDOWN_ROUTES) {
const rewriteUrl = new URL(MARKDOWN_ROUTES[pathname], request.url);
const response = NextResponse.rewrite(rewriteUrl);
response.headers.set('Content-Type', 'text/markdown; charset=utf-8');
response.headers.set('Vary', 'Accept');
response.headers.set('X-Content-Track', 'agent-markdown');
return response;
}
const response = NextResponse.next();
if (pathname in MARKDOWN_ROUTES) {
response.headers.set('Vary', 'Accept');
}
return response;
}
export const config = {
matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
};
```
---
## 4. Pillar 3 — Semantic Computer-Use DOM Hooks (`data-agent-*`)
Browser-operating agents fail when interactive elements rely on opaque CSS utility classes or unlabeled icon buttons. Annotate every high-value control with deterministic `data-agent-*` attributes alongside standard accessible ARIA semantics:
- `data-agent-action`: Verb (`navigate`, `select`, `submit`, `filter`, `quote`, `checkout`).
- `data-agent-target`: Stable snake_case identifier (`tier_pilot_core`, `inquiry_submit`).
- `data-agent-priority`: Decision hierarchy (`critical`, `primary`, `secondary`).
- `data-agent-value`: Machine-parsable payload (`3500_usd`, `annual_plan`).
- `data-agent-state`: Live UI state (`idle`, `submitting`, `confirmed`, `error`).
```tsx
<button
type="button"
onClick={handleSelectTier}
aria-label="Select Turnkey Core System tier ($9,500)"
data-agent-action="select"
data-agent-target="tier_turnkey_core"
data-agent-priority="primary"
data-agent-value="9500_usd"
data-agent-state={status}
>
Select Core System — $9,500
</button>
```
---
## 5. Pillar 4 — Typed Machine Endpoints (`/api/agent/v1/*`)
Give agents deterministic JSON endpoints instead of forcing them to scrape HTML pricing tables or click multi-step wizards.
### Core Endpoint Surface
- `GET /api/agent/v1/catalog`: Returns versioned JSON catalog (services, SLAs, currencies, supported inputs).
- `POST /api/agent/v1/quote`: Accepts Zod-validated requirement payload and returns deterministic estimate + next-action URL.
### Example Zod-Validated Route Handler (`src/app/api/agent/v1/quote/route.ts`)
```ts
import { NextResponse } from 'next/server';
import { z } from 'zod';
const QuoteRequestSchema = z.object({
tier: z.enum(['pilot', 'turnkey', 'enterprise']),
timelineWeeks: z.number().int().min(1).max(52),
requiresWebGL: z.boolean().default(false),
});
const BASE_PRICING_USD = {
pilot: 3500,
turnkey: 9500,
enterprise: 25000,
} as const;
export async function POST(request: Request) {
let body: unknown;
try {
body = await request.json();
} catch {
return NextResponse.json(
{ ok: false, error: 'INVALID_JSON' },
{ status: 400 }
);
}
const parsed = QuoteRequestSchema.safeParse(body);
if (!parsed.success) {
return NextResponse.json(
{ ok: false, error: 'VALIDATION_FAILED', issues: parsed.error.flatten() },
{ status: 422 }
);
}
const { tier, timelineWeeks, requiresWebGL } = parsed.data;
const estimateUsd = BASE_PRICING_USD[tier] + (requiresWebGL ? 2500 : 0);
return NextResponse.json(
{
ok: true,
schemaVersion: '1.0',
quote: {
tier,
timelineWeeks,
requiresWebGL,
estimateUsd,
currency: 'USD',
},
},
{
status: 200,
headers: {
'Cache-Control': 'no-store',
'X-Agent-API': 'v1',
},
}
);
}
```
---
## 6. Pillar 5 — Schema.org Ontology & Agent Security Hygiene
### Structured Knowledge Graph (`application/ld+json`)
Embed a unified `@graph` in the root layout containing `Organization`, `WebSite`, and `OfferCatalog` with exact canonical URLs, currencies, and verified `sameAs` links so AI search engines cite exact ground truth instead of hallucinating outdated figures.
### Crawler Access & Security Guardrails
- **Explicit `robots.txt`:** Explicitly allow citation crawlers (`OAI-SearchBot`, `PerplexityBot`, `Claude-SearchBot`) on public marketing/docs routes while blocking private `/admin`, `/api/internal`, and user-generated draft routes.
- **Zero Prompt-Injection Echo:** Never reflect raw untrusted query parameters or user-submitted strings directly into `/llms.txt`, JSON-LD, or Markdown responses.
- **Rate Limits at the Edge:** Enforce strict IP/token-bucket limits on `POST /api/agent/v1/*` (e.g., `10–20 req / 60s`) with typed `429 Too Many Requests` + `Retry-After` responses.
---
## 7. Pre-Ship Verification Commands
Verify all machine tracks directly before shipping:
```bash
# 1. Verify llms.txt returns 200 text/plain or text/markdown
curl -sI https://your-domain.com/llms.txt
# 2. Verify Edge Markdown negotiation & Vary: Accept header
curl -sI -H "Accept: text/markdown" https://your-domain.com/
# 3. Verify Human HTML track is unaffected (no CDN cache poisoning)
curl -sI -H "Accept: text/html" https://your-domain.com/
# 4. Verify typed A2A validation rejects malformed input cleanly (422)
curl -s -X POST https://your-domain.com/api/agent/v1/quote \
-H "Content-Type: application/json" \
-d '{"tier":"invalid"}'
```
---
Authored by **ASSEMBLAGE** — High-End Interactive Architecture & Sovereign AI Systems
https://point-of-assemblage.vercel.app
1 file
- SKILL.md9.1 KB