Documentation

LLM files

LLM files

The leadtype/llm entry point produces four flavors of agent-facing output, all derived from the same docs source:

  • generateLlmsTxt — for hosted websites. Emits the /llms.txt convention with root-relative markdown mirror links.
  • generateLLMFullContextFiles — root /llms-full.txt fallback containing all generated markdown docs. Pairs with generateLlmsTxt.
  • generateAgentReadabilityArtifacts — docs-scoped sitemap.xml, sitemap.md, robots.txt, and JSON manifest data that a host app can merge into site-level files.
  • generateAgentsMd — for npm-bundled docs. Emits an AGENTS.md index with relative ./docs/<topic>.md paths so the file works inside node_modules/<pkg>/.

The CLI's default leadtype generate calls the website APIs; leadtype generate --bundle calls generateAgentsMd. Use these APIs directly when you need finer control.

What gets generated

FilePurpose
<out>/llms.txtTop-level routing index. Product summary, best starting points, and root-relative markdown mirror links.
<out>/docs/llms.txtDocs-scoped routing index. Lists every group with descriptions and markdown entry links.
<out>/llms-full.txtAll generated markdown docs flattened into one fallback file. Use when page-level links are not enough.
<out>/docs/sitemap.xmlDocs-scoped XML sitemap with canonical page URLs and <lastmod> dates.
<out>/docs/sitemap.mdDocs-scoped markdown sitemap with headings and links.
<out>/docs/robots.txtMergeable crawl policy that explicitly allows common AI crawlers.
<out>/docs/agent-readability.jsonStructured manifest for host apps that need to merge docs pages with marketing, blog, changelog, or product pages.

Group metadata still drives llms.txt sections, navigation, search metadata, and AGENTS.md, but site mode no longer emits per-group full-context files by default. See Evals for the benchmark behind that default.

ProductInfo

Every generator that writes a top-level index file (generateLlmsTxt, generateLLMFullContextFiles, generateAgentReadabilityArtifacts, generateAgentsMd) takes the same product object:

NameTypeDefaultDescription
namerequiredstring-Product display name. Rendered as the H1 of llms.txt and AGENTS.md.
summaryrequiredstring-Single-line summary rendered as the blockquote under the H1.
bulletsstring[]-Rendered under '## Product Summary'. Use for top-level feature highlights.
bestStartingPointsArray<{ urlPath: string, title?: string, description?: string }>-Curated entry points rendered under '## Best Starting Points'. Titles and descriptions fall back to each page's frontmatter when omitted.
agentGuidancestring-Optional routing instruction appended at the bottom of llms.txt. Ignored by generateAgentsMd — the URL-routing flow doesn't apply to offline package docs.

The docs.config.ts product field has this exact shape; both the CLI and the library APIs read it.

Example llms.txt

Typical sequence

generateLLMFullContextFiles and generateAgentReadabilityArtifacts read from <outDir>/docs/, so always run conversion first.

Mounted URL prefixes

By default, generated markdown under <outDir>/docs/ maps to public URLs under /docs. Use mounts when part of that generated tree should have a different canonical URL, such as a changelog that lives beside docs in the source repo:

With those mounts, public/docs/quickstart.md is still /docs/quickstart.md, while public/docs/changelog/v1.md is described as /changelog/v1.md in llms.txt, llms-full.txt, navigation, sitemap data, Agent Readability metadata, and search metadata.

Pass the same mounts array to every artifact generator that reads generated markdown:

resolveDocsNavigation and resolveDocsTableOfContents also accept mounts so sidebars and page metadata use the same URL paths. If you use the CLI, prefer --docs-dir changelog=/changelog; it creates the equivalent mounts and also writes static markdown mirrors at public/changelog/*.md.

generateAgentReadabilityArtifacts

For hosted docs sites that need the Vercel Agent Readability discovery layer without letting leadtype own the whole website:

Writes docs-scoped files under <outDir>/docs/. The returned manifest contains the docs pages, markdown mirror URLs, group navigation, and freshness dates. Host apps can then merge result.manifest.pages with non-docs routes before serving root-level /sitemap.xml, /sitemap.md, and /robots.txt.

Agent readability helpers

generateAgentReadabilityArtifacts gives you the manifest. The runtime helpers turn it into Web Response objects your framework can return directly:

The whole module is fs-free and edge-runtime safe: it works in Node, Bun, Vercel Edge, Cloudflare Workers, and any framework with a Web Request/Response API.

createAgentMarkdownResponse

Markdown content negotiation for docs pages. Returns Response | null (null means the path is not an agent-oriented markdown request — fall through to your HTML route). readMarkdownFile may be sync or async.

Headers it sets:

  • Content-Type: text/markdown; charset=utf-8
  • Vary: Accept (and , User-Agent when an AI UA is detected)
  • Link: <canonical>; rel="canonical"
  • Cache-Control: public, max-age=300, must-revalidate (override with cacheControl: "<directive>" or omit with cacheControl: null)

It also enriches frontmatter with canonical_url and last_updated, leaves discovery artifacts (llms.txt, sitemap.*, robots.txt, agent-readability.json, root llms-full.txt, search JSON) alone, and returns a 200 markdown "Page not found" body only for agent-oriented requests.

Optional userAgentPattern overrides the default AI user-agent regex (defaults cover GPTBot, ChatGPT-User, OAI-SearchBot, Claude-Web, ClaudeBot, anthropic-ai, CCBot, Google-Extended, AmazonBot, Bingbot, MetaExternalAgent, ByteSpider, PerplexityBot, MistralBot, AppleBot, YouBot).

createSitemapXmlResponse / createSitemapMarkdownResponse / createRobotsTxtResponse

Build sitemap and robots responses at request time so the <loc> and Sitemap: directives reflect the live origin (preview, staging, prod), no string-replace hacks needed.

requestOrigin is optional — when omitted, the helpers fall back to manifest.baseUrl.

createDocsHead

Build canonical/alternate/og/JSON-LD head metadata for a docs page from the manifest. Returns { meta, links } in a framework-neutral shape (TanStack Router, Next.js Metadata, Astro, etc.).

If the page is not in the manifest, both arrays are empty so the caller can fall back to its own metadata.

Lower-level helpers

For a step-by-step integration guide, see Optimize docs for agents.

HelperUse it for
renderJsonLdReturn a Schema.org object for framework metadata APIs.
renderJsonLdScriptReturn an escaped <script type="application/ld+json"> string.
createAgentMarkdownResponseBuild a complete markdown Response for agent Accept headers, AI user agents, and direct .md URLs.
createSitemapXmlResponse / createSitemapMarkdownResponse / createRobotsTxtResponseBuild sitemap/robots Responses rebased to the live origin.
createDocsHeadBuild canonical/alternate/og/JSON-LD head entries from the manifest.
resolveMarkdownMirrorTargetMap /docs/foo or /docs/foo.md to the generated docs/foo.md file path.
createMarkdownResponseHeadersProduce canonical markdown headers with Content-Type, Vary, Link, Cache-Control.
enrichMarkdownFrontmatterAdd canonical_url and last_updated aliases to generated markdown (CRLF-tolerant).
renderMissingMarkdownRender the 200 markdown body used for missing docs pages requested by agents.
acceptsMarkdownHeaderDetect whether an Accept header is asking for markdown (q-value aware).
isAgentUserAgentDetect known AI crawler and agent user agents. Accepts an optional regex override.
isAgentReadabilityArtifactPathAvoid rewriting llms.txt, llms-full.txt, sitemap, robots, search JSON, and manifest artifact paths.

Cache-Control and CDN

Every helper sets Cache-Control: public, max-age=300, must-revalidate by default and pairs it with Vary: Accept (and , User-Agent for AI UAs). When you cache responses on a CDN, make sure it shards by Accept and User-Agent so agents and browsers don't cross-pollinate cached HTML and markdown variants. Pass cacheControl: "<directive>" to override or cacheControl: null to omit the header (when you set caching at the CDN layer).

Manifest version

Every helper asserts manifest.version === 1 at the entry point and throws a clear error otherwise — so a stale dev agent-readability.json from a different leadtype version fails loudly instead of silently producing wrong responses.

generateAgentsMd

For npm-bundled docs that ship inside node_modules/<pkg>/ and need relative filesystem links:

Writes <outDir>/AGENTS.md (singular, at the root) with the same product summary and group structure as generateLlmsTxt, but every link is a relative path like ./docs/<segment>/<slug>.md instead of an absolute URL.

OptionDescription
srcDirRepo root containing the docs/ source.
outDirPackage root. AGENTS.md is written at <outDir>/AGENTS.md.
productSame ProductInfo shape as generateLlmsTxt. agentGuidance is intentionally ignored — it's written for the website's URL-routing flow and would mislead an offline agent.
groupsGroup tree from docs.config.ts. Same shape as generateLlmsTxt.
docsSubdirSubdirectory under outDir that holds the .md files. Default: docs. Used as the relative-path prefix in every link.

Returns { outputPath: string } pointing at the written AGENTS.md.

Example output

Pair with convertAllMdx to produce the .md files the links resolve to. See Bundle docs into a package for the full flow.

resolveDocsNavigation

Same group-resolution logic the LLM files use, but returns the navigation manifest as a plain object — useful for driving a sidebar UI:

Write the result to src/generated/docs-nav.json and import it from your sidebar component:

Now your sidebar can import a static manifest with the same group tree the LLM files use.

Tables of contents

For the heading slug contract and renderer wiring, see Render MDX and TOC. This section covers the build-time APIs only.

resolveDocsNavigation includes a toc array on every page by default. The default range is h2h3, which keeps page-level h1 titles out of sidebars.

If you only need TOC data and not the full group tree, call resolveDocsTableOfContents:

For custom pipelines, extractDocsTableOfContents accepts a markdown or MDX string plus page URL metadata and returns plain JSON. It ignores frontmatter and fenced code blocks, and it uses the same slugifyDocsHeading helper that rendered headings must use to keep id attributes in sync.

Group design

The groups you pass to these APIs come from docs.config.ts. Two principles:

  • Use groups for routing, not sharding. Groups organize llms.txt, navigation, search metadata, and AGENTS.md. The root llms-full.txt remains the broad fallback.
  • Write group descriptions for routing, not flavor text. Agents read those descriptions to decide which pages to load. "How to install and run" beats "Welcome to our guides!"

Base URL precedence

Pass baseUrl explicitly, or use environment variables for layered fallback:

The package-specific LEADTYPE_AGENT_BASE_URL lets each package override an org-wide default. BASE_URL covers most CI/deployment platforms, and a final hardcoded fallback keeps local builds working without env setup.