A sitemap can give an AI agent a useful list of candidate URLs, but it is not a crawl result, an index, or a freshness guarantee. Start at the site's /sitemap.xml, follow any sitemap index, parse each <loc>, keep only URLs on the expected host and path, then verify a small sample with a page reader before expanding. Treat <lastmod> as an optional publisher hint, not proof that a page changed. The workflow below uses a public sitemap index and a tested AnyCrawler page read; it is deliberately narrower than query-based search and recursive crawling.

What a sitemap can and cannot prove

Google's sitemap overview describes a sitemap as a file that tells search engines which pages and files a site considers important, along with relationships and optional details such as when a page was last updated. The same documentation is careful about the limit: a sitemap helps search engines discover URLs, but it does not guarantee that every listed URL will be crawled or indexed.

The Sitemaps protocol adds the format rules an agent has to handle. A URL sitemap starts with <urlset>, each entry needs a <loc>, all URLs in one sitemap must belong to a single host, and <lastmod> is optional. A sitemap file may contain at most 50,000 URLs and may be at most 50 MB uncompressed; a sitemap index may list at most 50,000 sitemaps and is also limited to 50 MB.

Those rules make a sitemap useful as a publisher-declared inventory. They do not make it a source of truth about the page behind each URL. A listed page can return a redirect, a login wall, an empty JavaScript shell, a different canonical URL, or content that no longer matches the title. An agent still has to read the page it intends to use.

Read the index before you collect URLs

A site may publish one urlset or an index that points to several child sitemaps. Parse both shapes. This example uses only the Python standard library and follows the AnyCrawler public index one level down:

import urllib.request
import xml.etree.ElementTree as ET

NS = {"s": "http://www.sitemaps.org/schemas/sitemap/0.9"}

def read_xml(url):
    request = urllib.request.Request(url, headers={"User-Agent": "SitemapInventory/1.0"})
    with urllib.request.urlopen(request, timeout=30) as response:
        return response.status, response.geturl(), response.read()

def locations(xml_bytes):
    root = ET.fromstring(xml_bytes)
    kind = root.tag.rsplit("}", 1)[-1]
    path = "s:sitemap/s:loc" if kind == "sitemapindex" else "s:url/s:loc"
    return kind, [node.text.strip() for node in root.findall(path, NS) if node.text]

status, final_url, body = read_xml("https://anycrawler.com/sitemap.xml")
kind, children = locations(body)
print(status, final_url, kind, len(children))

for child in children:
    status, final_url, body = read_xml(child)
    kind, urls = locations(body)
    print(status, kind, len(urls), child)

A run against the public AnyCrawler index on 2026-10-21 returned HTTP 200 with root type sitemapindex and two children. The static-sitemap.xml child returned a urlset with 17 URLs; the blog-sitemap.xml child returned a urlset with 34 URLs. The combined output was 51 <loc> entries on one host, anycrawler.com. Those counts describe one site at one time; they are not a coverage guarantee.

The parser needs two guards. The parser should reject a response whose root element is neither urlset nor sitemapindex; an HTML error page is not a sitemap. It should also preserve the final URL and fetch time, because a redirect from /sitemap.xml to another host changes the origin you are evaluating.

Filter candidates before spending a request

Even a valid sitemap can be too large to read in full. Filter the inventory against the task before you call a page reader.

Gate Keep the URL when Defer or reject when What to record
Host It matches the host you intended to inspect It leaves the expected host or scheme Requested and final sitemap URL
Path It belongs to the section or topic in scope It is an unrelated account, cart, search, or archive path Path rule and match result
Duplicate Its normalized URL has not already been queued It repeats after removing only the fragment Original and normalized URL
lastmod It is present and plausible as a hint It is absent, malformed, or the only reason to call the page Raw value and whether it was used
Response type The sitemap is XML and parses The response is HTML, empty, or malformed XML Status, content type, parse error
Permission The target path is allowed for the actual crawler identity The rule is disallowed or cannot be retrieved robots result and check time

Do not collapse a trailing slash unless the site's canonical policy says the two forms are the same page. Remove fragments for deduplication, but keep the original string for the audit trail. If the sitemap has more entries than the task needs, apply the path filter first and then take a bounded sample rather than letting the inventory decide your budget.

lastmod deserves its own warning. The protocol calls it optional and says it should describe when the linked page was last modified, not when the sitemap was generated. On the AnyCrawler index tested above, none of the 17 static-sitemap entries had a lastmod, while 33 of the 34 blog-sitemap entries did; the blog index itself was the one entry without it. An agent that treats a missing or stale value as a change signal can make inconsistent decisions across sections of the same site.

Verify one page with a real read

Pick a small number of URLs that pass the filters, then read one before expanding. The no-key preview endpoint can confirm that the page is publicly readable and that the returned Markdown contains useful content:

import json
import urllib.parse
import urllib.request

page = "https://anycrawler.com/crawler/page/fetch/"
endpoint = "https://api.anycrawler.com/free/v1/crawl?url=" + urllib.parse.quote(page, safe="")
request = urllib.request.Request(endpoint, headers={"User-Agent": "SitemapInventory/1.0"})
with urllib.request.urlopen(request, timeout=60) as response:
    data = json.load(response)
print(data["status_code"], data["results"]["title"], len(data["results"]["markdown"]))

That request returned HTTP 200, the title URL to Markdown API for HTML Pages | AnyCrawler, and 13,914 Markdown characters on 2026-10-21. The free response included requested_url, status_code, results.title, results.markdown, and a timestamp, but not final_url or credits_used; those fields should not be inferred from this preview. The preview may also serve a cached result for up to 24 hours, so it is a readability check, not a freshness test.

For a production read, the AnyCrawler Fetch page documents the authenticated POST /v1/crawl/page request, its Markdown response, and the optional metadata, links, and media groups. Use Fetch when the useful content is already in the returned HTML. If the Markdown is empty or the required section is missing, inspect the page before escalating to a browser-rendered read; do not treat a sitemap entry as proof that the content is extractable.

Permission is a separate gate. A URL appearing in a sitemap does not by itself grant permission to fetch it. Check the target origin's robots rules for the identity that will actually make the request, and skip or defer when the rule is disallowed or cannot be retrieved. The robots.txt preflight workflow explains how to match the rule to the request rather than to a generic bot name.

Keep an evidence record for the next run

A useful sitemap run leaves enough state for another agent to reproduce the decision without downloading everything again. A compact record can look like this:

{
  "sitemap_url": "https://anycrawler.com/sitemap.xml",
  "fetched_at": "2026-10-21T13:29:10Z",
  "root_type": "sitemapindex",
  "children": 2,
  "loc_entries": 51,
  "unique_candidates": 51,
  "hosts": ["anycrawler.com"],
  "lastmod_present": {"static-sitemap.xml": 0, "blog-sitemap.xml": 33},
  "sample_read": {"url": "https://anycrawler.com/crawler/page/fetch/", "status_code": 200, "markdown_chars": 13914}
}

The record should distinguish what the sitemap claimed from what the page read returned. If the sample fails, keep the failure state rather than silently dropping the URL. A later run can then tell whether the sitemap changed, the page changed, or the reader changed.

Choose sitemap discovery only for the right unknown

Sitemap discovery is not a replacement for search, and it is not a recursive crawler. It answers a narrower question: “Which URLs has this publisher declared, and which of them are worth reading for this task?”

Situation Start with a sitemap? Better first step
You know the domain and need a broad URL inventory Yes, then filter and sample Fetch one selected page and verify it
You need relevance ranking across unknown sites No Use query search to build a candidate set
You already have one trusted URL No Fetch or render that URL directly
You need every page on a domain recursively No Define an explicit crawl scope and budget; a sitemap is only an input
You need change alerts or scheduled monitoring No Build a separate monitoring workflow with stored snapshots

A 2026 practitioner checklist aimed at AI-agent discoverability recommends publishing /sitemap.xml and referencing it in robots.txt (Rok Garbas's agent-readiness checklist). That is useful publishing advice, but it does not establish that a particular AI crawler reads the file, that every listed page is current, or that sitemap membership grants access. Treat the recommendation as a signal to inspect the file, not as a substitute for reading the source.

The open question is trust, not format

The XML format is straightforward to parse. The harder question is how much trust an agent should place in publisher-controlled metadata. lastmod can be absent, stale, or generated at a different time from the page; sitemap indexes can mix sections with different update practices; and a sitemap can describe pages that are no longer useful. Whether AI agents will converge on sitemap metadata, a separate machine-readable freshness signal, or page-level verification as the default is still unsettled. Until that changes, the defensible pattern is to use the sitemap for candidate discovery and make the page read carry the evidentiary weight.

Frequently asked questions

Do AI agents automatically read a website's sitemap?

No. A sitemap is a public file that an agent can request, but there is no universal rule that every AI crawler or browsing agent will discover or fetch it. Whether a particular system reads /sitemap.xml, a sitemap index, or another discovery surface depends on that system's implementation. The practical check is the target site's request logs or your own agent's access record, not an assumption based on the file's existence.

Should an agent start with a sitemap or a search query?

Use a sitemap when you already know the domain and need a publisher-declared URL inventory. Use search when the source is unknown or the task needs relevance ranking across multiple sites. The two can be combined: search can identify a domain, and the sitemap can then expose pages that search did not surface. Neither step proves that a page is readable or current, so both should end with a selected-page read.

Can an agent trust lastmod to decide whether a page changed?

Not by itself. The protocol marks lastmod as optional, and publishers populate it inconsistently. In the AnyCrawler test, the static sitemap had no lastmod values while most blog entries did. A missing value does not mean the page is old, and a present value does not prove the content changed. Use it to prioritize a check, then compare the page content or response metadata before making a change claim.

How should an agent handle a sitemap index?

Parse the sitemapindex root, read each child sitemap location, and inspect the child's root before collecting URLs. A child should be a urlset; an HTML or malformed response should be rejected and recorded. Apply the host and path filters to the combined result, remove duplicate normalized URLs, and cap the number of child sitemaps or URLs you will process so a large index cannot consume the whole task budget.

Does a URL in a sitemap grant permission to fetch it?

No. A sitemap is a discovery document, not an access-control list. Before fetching, check the target origin's robots rules for the crawler identity that will make the request, and respect authentication, terms, and rate limits separately. If the rule is disallowed or cannot be retrieved, skip the URL or defer the task. Listing a URL in a public file does not override those conditions.

How many sitemap URLs should an agent read?

Start with a bounded sample tied to the evidence gaps in the task, not with the full inventory. One or two representative pages can reveal whether the sitemap is useful, whether the reader handles the page type, and whether the content is current enough. Expand only after those checks pass. The right number depends on the question, request budget, and diversity of page types; there is no universal count that makes a sitemap complete.