Repository navigation
[doc] llms.txt: tell agents the page links also serve Markdown - #65461
Conversation
Read the Docs serves a Markdown rendering of any page from that page's own `.html` URL, under an `Accept: text/markdown` request. There is no separate `.md` file: `page.md`, `page.html.md`, `/md/<page>.md` and `?format=md` all 404, and no `Link: rel=alternate` header advertises one. So the `.html` links llms.txt already emits *are* the Markdown links -- but nothing in the file says so, and an agent has no way to discover it. Add a one-line pointer under the existing llms-full.txt line. The header has to name the type explicitly. Measured against docs.ray.io: `*/*` (the default for curl, requests and httpx), a browser's `text/html,...,*/*;q=0.8`, and `text/plain` all return `text/html`; only an Accept naming `text/markdown` returns `text/markdown`. A client gets Markdown only by asking for it deliberately, so the pointer has a real audience. Gated behind a new `llms_txt_markdown_hint` config, default False, because content negotiation is a property of the host rather than of the generator: a build served from somewhere that doesn't negotiate Markdown would otherwise advertise a representation that doesn't exist. conf.py sets it True for Ray. The wording says "a Markdown rendering of the page", not "the source": what comes back is the built page converted to Markdown, chrome included, and it is not what `_sources/<page>.<ext>.txt` returns. Linking `_sources` instead was the alternative considered and rejected. It leaks the source format to the consumer -- master is 363 .rst to 232 .md, so most pages would hand back reStructuredText -- it requires knowing each page's source suffix to build the URL, it isn't human-clickable, and the URL would churn from `.rst.txt` to `.md.txt` as pages migrate to MyST. Negotiation happens on the rendered HTML, so it is identical for both source formats and survives that migration. The verbatim source an agent might want `_sources` for is already in the llms-full.txt shards. Test covers both directions: the pointer appears in the header (before the first section) when the config is on, and is absent when it is off. Signed-off-by: Ronny Roland <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces a new configuration option, llms_txt_markdown_hint, to the llms_txt Sphinx extension. When enabled, this option appends a hint to the generated llms.txt file informing LLM agents that they can request the listed URLs with an Accept: text/markdown HTTP header to receive a Markdown rendering of the pages. The PR includes tests for this new configuration and enables it in doc/source/conf.py for Read the Docs integration. There are no review comments, and I have no feedback to provide.
|
This pull request has been automatically marked as stale because it has not had You can always ask for help on our discussion forum or Ray's public slack channel. If you'd like to keep this open, just leave any comment, and the stale label will be removed. |
…roject#65461) ## Summary Follow-up to ray-project#64458. Adds one line to `llms.txt` telling agents that the page links also serve Markdown. Read the Docs serves a Markdown rendering of any page **from that page's own `.html` URL**, under an `Accept: text/markdown` request. There is no separate `.md` file to link to — `page.md`, `page.html.md`, `/md/<page>.md`, and `?format=md` all 404, and no `Link: rel=alternate` header advertises one. So the `.html` links `llms.txt` already emits *are* the Markdown links. Nothing in the file says so, and an agent has no way to discover it. ``` # Ray > Ray is an open-source unified compute framework for scaling AI and Python workloads… Full page text, grouped by section, is in [llms-full.txt](https://docs.ray.io/en/master/llms-full.txt). Request the links that follow with the HTTP header `Accept: text/markdown` to retrieve a Markdown rendering of the page. ## Overview … ``` ## The header has to be explicit Measured against `docs.ray.io/en/master/data/data.html`: | `Accept:` sent | returns | |---|---| | `*/*` — the default for curl, `requests`, `httpx` | `text/html` | | `text/html,application/xhtml+xml,*/*;q=0.8` — browser default | `text/html` | | `text/plain` | `text/html` | | `text/markdown` | **`text/markdown`** | | `text/markdown, */*` | **`text/markdown`** | | `text/markdown;q=1.0, text/html;q=0.9` | **`text/markdown`** | A wildcard isn't enough; the type has to be named. A client gets Markdown only by asking deliberately, so the pointer has a real audience. ## Config-gated New `llms_txt_markdown_hint`, **default `False`**. Content negotiation is a property of the host, not of the generator — a build served from somewhere that doesn't negotiate Markdown would otherwise advertise a representation that doesn't exist. `conf.py` sets it `True` for Ray. ## Wording note It says "a Markdown rendering of **the page**", deliberately not "the source". What comes back is the built page converted to Markdown — front matter, then site chrome (`Skip to main content`, theme switcher, version picker), then the content. That is not what `_sources/<page>.<ext>.txt` returns, and `_sources` genuinely exists, so calling it "the source" would point agents at the wrong artifact. ## Why not link `_sources/<page>.<ext>.txt` instead Considered and rejected: - **It leaks the source format to the consumer.** master is **363 `.rst` to 232 `.md`**, so most pages would hand back reStructuredText, not Markdown — noisier for an agent than the HTML→Markdown conversion. - **The URL isn't derivable from the page URL** — it depends on each page's source suffix (`index.md.txt` vs `installation.rst.txt`). - **It isn't human-clickable.** - **It would churn.** As pages migrate to MyST, each link would change from `.rst.txt` to `.md.txt`. Negotiation happens on the rendered HTML, so it's identical for both source formats and survives the migration. - **It's redundant** — the verbatim source is already in the `llms-full.txt` shards. ## Testing ``` $ python doc/source/_ext/test_llms_txt.py PASS: llms_txt extension produced a correct index, Optional section, llms-full shards, excludes notebooks by source type, gates the Markdown pointer, and honors the llms_txt_build gate. $ ruff check doc/source/_ext/llms_txt.py doc/source/_ext/test_llms_txt.py All checks passed! ``` New `test_markdown_hint` covers both directions: the pointer appears in the header (asserted to sit before the first `##` section) when the config is on, and is absent when it's off. The header table above was produced by probing the live `docs.ray.io`. All three changed files route to `@ doc doc_api` under the current `.buildkite/test.rules.txt`, so `doc: test llms.txt extension` runs on this PR. Not a duplicate: `gh pr list --state open` finds no other open PR touching `llms.txt` or Markdown content negotiation. ## AI assistance Drafted with Claude Code. The behavioural claims here (which `Accept` values return what, which `.md` URL forms 404, the negotiated output including page chrome) were each verified against the live site rather than assumed. Signed-off-by: Ronny Roland <[email protected]>
…heir files Both entries name files that have moved, so each has silently stopped applying: - CODEOWNERS names doc/source/data/working-with-llms.rst, which #66375 converted to working-with-llms.md. ray-project/ray-llm hasn't been requested on the page since. - test.rules.txt routes doc/test_llms_txt.py to `doc` alone, but the test moved to doc/source/_ext/ in #65461. There it matches the _ext/ directory rule and also emits doc_api, which runs both API-consistency checks for a hermetic Sphinx test that imports no Ray code. It now gets its own rule ahead of the directory entry, the same way api_sidebar.py does, and the test.rules.test.txt case follows it to the new path. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Douglas Strodtman <[email protected]>
…heir files Both entries name files that have moved, so each has silently stopped applying: - CODEOWNERS names doc/source/data/working-with-llms.rst, which #66375 converted to working-with-llms.md. ray-project/ray-llm hasn't been requested on the page since. - test.rules.txt routes doc/test_llms_txt.py to `doc` alone, but the test moved to doc/source/_ext/ in #65461. There it matches the _ext/ directory rule and also emits doc_api, which runs both API-consistency checks for a hermetic Sphinx test that imports no Ray code. It now gets its own rule ahead of the directory entry, the same way api_sidebar.py does, and the test.rules.test.txt case follows it to the new path. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: Douglas Strodtman <[email protected]>
Summary
Follow-up to #64458. Adds one line to
llms.txttelling agents that the page links also serve Markdown.Read the Docs serves a Markdown rendering of any page from that page's own
.htmlURL, under anAccept: text/markdownrequest. There is no separate.mdfile to link to —page.md,page.html.md,/md/<page>.md, and?format=mdall 404, and noLink: rel=alternateheader advertises one.So the
.htmllinksllms.txtalready emits are the Markdown links. Nothing in the file says so, and an agent has no way to discover it.The header has to be explicit
Measured against
docs.ray.io/en/master/data/data.html:Accept:sent*/*— the default for curl,requests,httpxtext/htmltext/html,application/xhtml+xml,*/*;q=0.8— browser defaulttext/htmltext/plaintext/htmltext/markdowntext/markdowntext/markdown, */*text/markdowntext/markdown;q=1.0, text/html;q=0.9text/markdownA wildcard isn't enough; the type has to be named. A client gets Markdown only by asking deliberately, so the pointer has a real audience.
Config-gated
New
llms_txt_markdown_hint, defaultFalse. Content negotiation is a property of the host, not of the generator — a build served from somewhere that doesn't negotiate Markdown would otherwise advertise a representation that doesn't exist.conf.pysets itTruefor Ray.Wording note
It says "a Markdown rendering of the page", deliberately not "the source". What comes back is the built page converted to Markdown — front matter, then site chrome (
Skip to main content, theme switcher, version picker), then the content. That is not what_sources/<page>.<ext>.txtreturns, and_sourcesgenuinely exists, so calling it "the source" would point agents at the wrong artifact.Why not link
_sources/<page>.<ext>.txtinsteadConsidered and rejected:
.rstto 232.md, so most pages would hand back reStructuredText, not Markdown — noisier for an agent than the HTML→Markdown conversion.index.md.txtvsinstallation.rst.txt)..rst.txtto.md.txt. Negotiation happens on the rendered HTML, so it's identical for both source formats and survives the migration.llms-full.txtshards.Testing
New
test_markdown_hintcovers both directions: the pointer appears in the header (asserted to sit before the first##section) when the config is on, and is absent when it's off. The header table above was produced by probing the livedocs.ray.io.All three changed files route to
@ doc doc_apiunder the current.buildkite/test.rules.txt, sodoc: test llms.txt extensionruns on this PR.Not a duplicate:
gh pr list --state openfinds no other open PR touchingllms.txtor Markdown content negotiation.AI assistance
Drafted with Claude Code. The behavioural claims here (which
Acceptvalues return what, which.mdURL forms 404, the negotiated output including page chrome) were each verified against the live site rather than assumed.