Skip to content

Add Search for Agents endpoint - #361

Open
liamgold wants to merge 2 commits into
mainfrom
feature/search-for-agents
Open

liamgold wants to merge 2 commits into
mainfrom
feature/search-for-agents

Conversation

@liamgold

@liamgold liamgold commented Dec 2, 2026

Copy link
Copy Markdown
Owner

Summary

Adds a site search endpoint for AI agents, following the isitagentready "Search for Agents" check and Cloudflare's Search for Agents contract.

The endpoint

  • GET /.well-known/search?q=… returns the most relevant blog posts as text/markdown. An optional limit (1–20, default 10) sets the number of results.
  • The body starts with # Search results for: "<query>", and the response sends Accept-Query: text/plain, application/json.
  • QUERY is also accepted, with the query as a plain-text body or JSON {"q": "…"}. That's what Accept-Query advertises.
  • Each result has its URL, its .md URL, publish date, tags, reading time and summary. Ranking reuses the existing Lucene blog search, so it matches the ⌘K search.
  • Errors are markdown, never the HTML error page: 400 for a missing or overlong query, 413 for a body over 8 KB, and 503 with Retry-After: 60 if the search index isn't available.
  • Search covers blog posts only, which is what the Lucene index holds.

Advertising it

  • Every HTML page has <meta name="agent:instructions|endpoint|method|documentation"> tags in <head>.
  • The markdown version of every page repeats them in an agent: front-matter block. The converter reads them from the page's meta tags, so the layout is the only place they're defined.

Other changes

  • Markdown output now always uses \n line endings. It used to mix in \r\n when the host ran Windows.

Testing

  • New SearchForAgentsTests smoke tests run after each deploy. All 4 pass locally, and all 4 fail against current production, which confirms they detect the feature missing.
  • Locally, all sitemap URLs still return identical markdown through .md and through the Accept header, now with the agent: front matter, and every HTML page has the 4 meta tags.
  • I checked edge cases by hand: no results, an empty query, limit values that are invalid or out of range, a 600-character query, a 20 KB QUERY body, and quotes in the query.
  • The full local smoke suite passes 33 of 34. The exception is SpeakingPage_DisplaysSpeakingEngagements, which needs talks the local database doesn't have.

After deploying, check the post-deploy E2E run, then run the isitagentready scan.

🤖 Generated with Claude Code

liamgold and others added 2 commits December 2, 2026 11:01
GET /.well-known/search?q=... returns the most relevant blog posts as
markdown, so agents can search the site instead of crawling it. QUERY is
also accepted, with a plain-text or JSON {"q": "..."} body.

- Responses are text/markdown, start with # Search results for: "<query>"
  and send Accept-Query. Each result has its URL, its .md URL, date, tags,
  reading time and summary, ranked by the existing Lucene blog search.
- Errors are markdown too: 400 for a missing or overlong query, and 503
  with Retry-After if the search index isn't available.
- Every HTML page advertises the endpoint with agent:instructions,
  agent:endpoint, agent:method and agent:documentation meta tags, and the
  markdown version of every page repeats them in an agent: front-matter
  block.
- Markdown output now always uses \n line endings, whatever the host OS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Checks the endpoint returns markdown results, a missing query returns a
markdown error, and pages advertise the endpoint in their meta tags and
front matter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
catch (Exception ex) when (ex is not OperationCanceledException)
{
// Most likely the Lucene index is missing or still being built.
_logger.LogError(ex, "Agent search failed for query {Query}", query);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants