Agent instructions (agents.md, llms.txt)
AI agents and agent-readiness scanners look for a Markdown file at/agents.md or /llms.txt that tells them how to browse and shop a store. Shopify generates /agents.md for every Online Store, with /llms.txt and /llms-full.txt as mirrors, but serves it only on the store’s primary Online Store domain. A Hydrogen or Next.js storefront answers these paths with a 404 unless it serves them itself.
serveAgentsMd from @weaverse/hydrogen serves all three files from one route.
Prerequisites
-
@weaverse/hydrogen6.7.0 or later:
What it serves
- Shopify’s file, when Shopify serves it: every link points at your storefront’s domain instead of the Online Store domain.
- A built file when Shopify doesn’t, for example on a password-protected development store (or on an error, rate limit or timeout). It comes from the Storefront API: the shop’s name and description, how to reach its UCP profile at
/.well-known/ucp, the sitemap and browsing paths, and the published policies.
200 with content-type: text/markdown; charset=utf-8, never HTML. Browsers cache it for 5 minutes and shared caches (CDNs) for an hour, then serve the stale copy for up to a day while they refresh it (public, max-age=300, s-maxage=3600, stale-while-revalidate=86400). A file built after a failure gets public, max-age=60, so Shopify’s file replaces it within a minute once Shopify answers again.
React Router (Hydrogen)
Add the routes at the top level ofapp/routes.ts, next to robots.txt, not under a locale prefix. The routes share one module, so each extra route needs its own id:
app/routes.ts
app/routes/agents-md.ts
Next.js
Addapp/agents.md/route.ts and app/llms.txt/route.ts, each exporting a GET handler. Pass your theme’s Storefront API client, the one you create with createStorefrontClient. In this example, getStorefront stands for your theme’s own helper that returns it; it is not part of the SDK:
app/agents.md/route.ts
Behind a proxy
Links use the origin of the incoming request. If a proxy in front of your app changes the request URL, pass your public origin:robots.txt
serveAgentsMd does not touch robots.txt; it stays in your theme. Make sure it doesn’t block AI search and user-triggered agents (such as OAI-SearchBot, Claude-SearchBot or ChatGPT-User) from / and /products/, and that it has a Sitemap: line.
Verification checklist
-
curl -i https://<your-storefront>/agents.mdreturns200withcontent-type: text/markdown. -
/llms.txtreturns the same file. - Links in the file point at your storefront’s domain.
serveAgentsMd reference for the full API.