DEV Community

Kun Shen
Kun Shen

Posted on

How to Build a Crawl Budget That Keeps AI Agents Fast and Predictable

AI agents often begin with a deceptively simple web-access loop: take a URL, fetch it, extract text, and pass the result to a model. That loop works in a demo. In production, it can become a source of latency spikes, runaway costs, repeated requests, and inconsistent evidence.

A crawl budget is the control system that keeps this work predictable. It is more than a request limit. A useful budget decides which pages deserve attention, how much effort each page may consume, and when the agent should stop.

Start with the job, not the crawler

The correct budget depends on the agent's task. A monitoring agent may revisit a small set of pages on a schedule. A research agent may explore many domains once. A shopping agent may need current prices but can ignore most navigation pages.

Write the task as a small contract before choosing limits:

  • what evidence must be collected;
  • how fresh the evidence needs to be;
  • how many independent sources are required;
  • the maximum acceptable latency;
  • the maximum cost per completed task.

This contract prevents the crawler from treating every discovered URL as equally valuable.

Give every request an expected value

A URL should enter the queue with a reason. Useful signals include its relationship to the query, the authority of its host, its distance from a known source, its content type, and the chance that it contains new information.

A simple priority score can combine those signals: priority equals relevance times freshness need times source value, divided by expected cost.

The formula does not need to be mathematically perfect. Its purpose is to make tradeoffs visible. A product specification linked from a manufacturer's page should normally outrank a tag archive discovered five clicks away.

Expected cost should include more than bandwidth. JavaScript rendering consumes more time and compute than a direct HTML fetch. A screenshot adds storage and downstream vision cost. Retries also consume the budget, even when they produce no content.

Use a staged access strategy

The cheapest successful method should win. Start with a normal fetch and examine the result. Escalate to rendering only when the response lacks the content that should be present, relies on client-side navigation, or contains an application shell instead of the requested data.

Search is often a better first step than blind crawling. A targeted search can identify a few relevant pages before the agent spends budget extracting them. For focused discovery, AnyCrawler's search-page endpoint is one example of a workflow that combines result discovery with page-level access.

Screenshots should be deliberate. They are valuable when layout, charts, canvas elements, or visual state are evidence. They should not be the default representation of a text article.

Separate task, host, and page budgets

One global limit is too coarse. Use three layers.

A task budget limits total requests, rendered pages, bytes, elapsed time, and retries for one user goal. A host budget prevents one domain from consuming the entire task. A page budget caps the work spent on a single stubborn URL.

Host-level controls also improve politeness. Limit concurrency per host, respect crawl directives, and add delays when a server returns rate-limit or overload responses. Backoff should consume elapsed-time budget so that the agent cannot wait forever.

Page budgets should define a clear escalation ceiling. For example, allow one fetch, one render attempt if justified, and one retry for a transient failure. Authentication walls, persistent access denials, and repeated empty responses should become explicit outcomes rather than infinite loops.

Deduplicate before spending

Agents frequently encounter the same content through tracking parameters, alternate paths, print views, and redirects. Normalize URLs before enqueueing them. Remove known tracking parameters, resolve relative links, and store the final URL after redirects.

Content fingerprints catch duplicates that URL rules miss. A lightweight hash of normalized main text can prevent the same syndicated article from being processed repeatedly. Keep the source URLs even when content is duplicated; provenance still matters.

Caching should reflect freshness requirements. Stable documentation can be reused longer than a live price or breaking-news page. Record the retrieval time and cache policy next to the extracted evidence so the agent can decide whether reuse is acceptable.

Make stopping a first-class decision

A good agent stops because it has enough evidence, not merely because it has exhausted the web. Define completion signals such as:

  • the required facts are supported by two independent sources;
  • new pages have stopped adding unique claims;
  • remaining queue items fall below a value threshold;
  • the time or cost reserve is needed for synthesis and verification.

Reserve part of the total budget for verification. Discovering ten pages is not useful if no capacity remains to check their claims, dates, and canonical sources.

Measure outcomes, not just requests

Request counts alone cannot reveal whether a budget works. Track useful pages per task, unique evidence items, duplicate rate, render escalation rate, median and tail latency, bytes transferred, and cost per accepted source.

Also log why pages were skipped or stopped. Reasons such as low relevance, duplicate content, access denied, budget exhausted, and stale cache make later tuning possible.

Review failures by task type. If research tasks often run out of render budget, the discovery stage may be selecting too many application pages. If monitoring tasks repeatedly fetch unchanged documents, caching or conditional requests need improvement.

A practical default policy

A reasonable starting policy is conservative: search first, fetch selected pages, render only on evidence of client-side content, and capture screenshots only for visual claims. Cap per-host concurrency, normalize and deduplicate URLs, reserve verification capacity, and stop when evidence coverage is sufficient.

The exact numbers will change with the product and workload. The structure should remain stable. A crawl budget turns web access from an open-ended exploration into an accountable resource allocation process. That makes agents faster, cheaper, easier to debug, and more respectful of the sites they depend on.

Top comments (0)