Decorative Curve
Back to Resources

How an AI Agent Uses Your Existing Docs as Context

Grounding an agent in the rest of your docs is what stops it from inventing endpoints and contradicting nearby pages.

May 28, 20263 min read

A common failure of generic AI tools is the confident hallucination. The model produces a paragraph about an endpoint that doesn't exist, a parameter that was deprecated last year, or a default value that contradicts the page next door. The output reads well. It's also wrong, and a developer who trusts it will get stuck.

Better prompting doesn't fix this. Better grounding does. An AI agent that has access to your existing docs as context can pull from what's already published instead of guessing.

What context the agent should see

The minimum useful set:

  • The current page. Suggestions are scoped to what's on screen, not a generic version of the topic.
  • Linked pages. A page that links to or is linked from the current page is usually relevant.
  • The OpenAPI spec. The source of truth for what endpoints exist, what parameters they take, and what they return.
  • Recently edited pages. A page that changed last week probably reflects the current state better than one that hasn't been touched in two years.

More context isn't always better. A model with the full site in context is slower and more expensive, and it dilutes the signal. The right amount is enough to answer the immediate question without flooding the prompt. ReadMe's AI agent handles this retrieval automatically, pulling from your project's pages, your spec, and your style guide each time you ask it to do something.

Retrieval is doing the work

Behind the scenes, this is a retrieval problem. The agent doesn't load every page into context. It retrieves the pages most likely to be relevant, based on similarity to the current page or the user's instruction.

This is where most generic AI tools fall short. A general-purpose assistant might retrieve from the open web, from your training data, or from nothing at all. An agent built for your docs retrieves from your docs.

What this prevents

A grounded agent is much less likely to:

  • Invent an endpoint that doesn't exist.
  • Use a parameter name that was renamed in the spec.
  • Contradict guidance on a nearby page.
  • Adopt a voice that doesn't match the rest of the site.

It isn't infallible. It can still retrieve the wrong page, miss a related one, or apply context that doesn't actually fit. But the rate of confident-and-wrong drops a lot, which is the failure mode that hurts trust the most.

How to spot good grounding

A few signals when evaluating an agent:

  • Ask it about a parameter that doesn't exist. A grounded agent says it can't find it. An ungrounded one invents an explanation.
  • Ask it to rewrite a page in your voice. A grounded agent matches the tone of adjacent pages. An ungrounded one produces a generic version.
  • Ask it about a recent change. A grounded agent reflects the current state. An ungrounded one falls back to training data.

These aren't edge cases. They're exactly the situations where a docs agent has to perform well, because they're where a writer would have caught the problem and an unprompted reader won't.

The point of grounding isn't making the agent smarter. It's making it accurate enough that the human reviewer can trust the output and move on. Pair it with the Linter for style enforcement and Docs Audit for site-wide quality scoring, and you have a full system around AI-assisted docs. For more on how all of these work together, see Team Up with AI to Build Docs.

Connector
Everything to Build Great Docs
Connector
The Full Documentation Stack
Decorative CurveReady?
Get a preview
of your docs
ConnectorConnector
Decorative Curve
Terms of ServicePrivacy Policy
MSA