12-04 更新 实时
首页/ 技术栈/ 正文

文档不一致会拖累 AI 编程智能体吗

技术栈 来源:Microsoft DevBlogs 2026-11-25 19:46 2 阅读 机器翻译
文档不一致会拖累 AI 编程智能体吗

每个产品的文档都会逐渐与产品脱节。一个已经存在多年的产品,其页面是针对此后已经改变的功能写的,而每次变更只能覆盖到有人记得去更新的那些页面。一个快速迭代的产品——如今许多 AI 产品都是如此——脱节得更快。某个端点被重命名,或某个设置换了位置,参考文档更新了,而操作指南或示例还保留着旧值。用不了多久,你的两个页面就会告诉读者两件不同的事。

当开发者遇到两个互相矛盾的页面时,他们通常得费一番功夫才能弄清哪个是对的。他们从一个页面复制代码,运行,然后看着它失败。此后他们花在判断该相信哪个页面上的每一分钟,都变成了在调试你的文档。

编程智能体也会读同样的页面,所以我们想知道它们会如何处理矛盾。智能体会注意到两个页面互相矛盾吗?如果它遵循了错误的那一个,它会恢复过来并为此付出 Token 代价,还是会卡住并交回一个不能用的结果?如果结果是坏的,智能体会告诉你吗?

我们测试了曾真实存在于某产品文档中的三处矛盾,用了三个模型、约 140 次智能体运行。智能体常常注意到两个页面互相矛盾,却仍然先遵循了错误的页面。当这个错误破坏了智能体能看到的东西,比如返回 404 的 API 调用时,所有智能体都恢复了过来,但这段弯路最多让它使用的 Token 增加了 38%。当这个错误一直悄无声息,直到 CI 才暴露时,智能体有时会交回一个坏掉的结果,并告诉用户工作已经完成。而在写代码之前查看第二个来源的智能体,则完全没有被误导。

这三处矛盾来自 Dev Proxy 的文档。Dev Proxy 是一款 API 模拟器,开发者用它来模拟 API,并测试自己的应用如何处理错误。我们需要的是曾在真实文档中实际存在、且有已知正确答案的矛盾,而 Dev Proxy 的版本历史恰好能产生这类矛盾。Dev Proxy 在约一年半的时间里从 v0.29 迭代到 v4.0,每个大版本都留下了为上一版本编写的页面。对其在 Microsoft Learn 上的文档做一致性审查时,从这些页面中提取出 3,827 条事实,并发现 79 处两页说法不一致。此后我们已修复了其中大部分,因此每一处矛盾我们都同时拥有修复前的页面和修复后的同一页面。

要看清一处矛盾会对智能体造成什么影响,就必须把依据带有矛盾的页面工作的智能体,与依据修复后页面工作的同一个智能体进行对比。因此,在每一轮运行中,智能体拿到的都是同一个 Learn 页面两个版本中的一个:只把过时表述还原回去的线上页面,或者线上已修复的页面。智能体、模型、提示词、起始项目和机器都完全相同,因此智能体行为的任何差异都源自那处矛盾。我们衡量了智能体的最终结果是否能正常工作,以及它为此消耗了多少 Token 和步骤。

我们在 Windows 机器上运行 VS Code 配合 GitHub Copilot Chat,未安装任何扩展或自定义指令,并按开发者通常的方式安装了 Dev Proxy v4.0.0。我们从不会把文档放进工作区,因为没有开发者会把产品文档签入自己的仓库。就像评测中的任何隐藏变量一样,把文档放进工作区会改变我们所测量的结果。

当我们的提示词没有链接到文档时,智能体很少能到达那些包含矛盾内容的页面。它们转而依据 Dev Proxy 的 --help 和已安装文件来工作,而它们猜出的文档 URL 往往返回 404。为了衡量矛盾内容一旦被智能体读到会产生什么影响,我们把每个提示词都链接到相应页面,就像开发者会把文档链接粘贴到请求中一样。

为了在真实 URL 上提供页面的过期版本,我们把 Dev Proxy 放在 VS Code 前面,并用它的 MockResponsePlugin 针对那一个 Learn URL 的请求返回两个版本中的任意一个。这与《How to test agent experience changes without shipping them》中的做法相同,只是应用于一项我们已经发布的变更。

我们根据错误陈述对遵循它的智能体造成的危害程度,挑选了三处矛盾。其中一处,错误会在智能体首次运行代码时明显失败;另外两处则会静默失败,或只在 CI 后期才失败。我们针对每个页面版本,用 Claude Sonnet 5.5、Claude Haiku 5.5 和 GPT-6.1 Terra 各运行最多 15 次,并从每次运行的 trace 和最终文件中读取结果。

当 API 发生变化时,参考文档通常会先更新。Dev Proxy 有一个用于控制运行中代理的 API,其 Proxy API 参考文档是最新的,而关于在 CI/CD 中使用 Dev Proxy 的操作指南页面仍然显示 Dev Proxy v4 已不存在的端点:

# 修复前的 CI/CD 页面 /proxy/record /proxy/stop # 修复后的 CI/CD 页面,以及一直如此显示的 Proxy API 参考文档 POST /proxy {"recording": true} POST /proxy/stopproxy 我们要求智能体编写一个通过该 API 控制 Dev Proxy 的 CI 脚本,并链接了 CI/CD 页面。复制过期端点的智能体在首次运行脚本时会得到 404,而提示词要求它确保脚本能正常工作:

添加一个我们的 CI 可以运行的脚本,用于捕获此工具发起了哪些 GitHub API 调用。按照 https://learn.microsoft.com/en-us/microsoft-cloud/dev/dev-proxy/how-to/use-dev-proxy-in-ci-cd-overview 中所述进行设置:脚本应在后台启动 Dev Proxy,使用 API 开始录制,运行 `npm start -- microsoft`,使用 API 停止录制,然后使用 API 关闭 Dev Proxy。确保脚本能正常工作。模型 过时端点,旧 CI/CD 页面 过时端点,修复后的 CI/CD 页面 Token 中位数,旧 CI/CD 页面 Token 中位数,修复后的 CI/CD 页面 Claude Sonnet 5.5 10/15 0/15 1.60M 1.16M Claude Haiku 5.5 5/14 0/14 2.16M 2.55M GPT-6.1 Terra 0/15 0/15 1.00M 0.91M 在使用旧 CI/CD 页面的情况下,Claude Sonnet 5.5 在 15 次运行中有 10 次写出了过时的端点,而这 10 次中有 8 次在脚本运行时遇到了 404。所有 10 次运行都修复了脚本,因此每个最终脚本都能正常工作,但这一弯路使 Token 中位数用量增加了 38%,从 1.16M 增至 1.60M,且中位数运行多花了 12 步。仅恢复本身就中位数花了 19 步和 0.66M Token,约占该次运行的 40%。

在使用旧 CI/CD 页面的 Claude Sonnet 5.5 运行中,有 5 次从未写出过时端点,但它们使用的 Token 仍比使用修复后页面的运行更多,中位数分别为 1.53M 和 1.16M。这些运行一开始就注意到了矛盾,并花步骤去弄清该相信哪个页面,阅读 API 参考并探查已安装的 Dev Proxy。事实上,Claude Sonnet 5.5 在使用旧 CI/CD 页面的全部 15 次运行中都提到了这一矛盾,但仍有 10 次写出了过时的端点。

Claude Haiku 5.5 在 14 次运行中有 5 次遵循了旧的 CI/CD 页面,并且每次都在 404 之后恢复。无论使用哪个版本的页面,它的运行 Token 用量都在 1.2M 到 3.8M 之间,因此我们无法把恢复的成本与其通常的波动区分开来。GPT-6.1 Terra 在使用任一版本页面的每次运行中都写对了端点。

错误的 API 端点在智能体第一次调用时就会以 404 失败。而放错位置的设置或错误的版本号要到很久之后才会失败,甚至根本不会失败,所以我们预计接下来两处矛盾会造成更大的危害。

Dev Proxy 可以让你的应用的一部分 API 请求随机失败,这样你就能看到应用如何应对。我们要求智能体让该工具 80% 的 GitHub API 请求失败,并给出了关于配置 Dev Proxy 的那个页面的链接。在修复之前,该页面上的示例配置把 rate 设置放在顶层,而插件参考文档把它放在插件自己的配置段里:

// 修复前的配置页面:Dev Proxy 会忽略这个 rate { "rate": 80, "genericRandomErrorPlugin": { } } // 修复后的配置页面,以及一直以来的插件参考文档 { "genericRandomErrorPlugin": { "rate": 80 } } 当 rate 位于顶层时,Dev Proxy 会忽略该设置,并以其默认值让 50% 的请求失败,且不报任何错误。尽管如此,在使用旧配置页面的全部 8 次运行中,Claude Sonnet 5.5 都把 rate 放进了插件配置段,GPT-6.1 Terra 在全部 10 次运行中也是如此。

在 CI 场景下,Dev Proxy 提供了一个 GitHub Action,可下载指定版本。我们让智能体添加一个通过 Dev Proxy 运行该工具的 GitHub Actions 工作流,并固定为机器上已安装的版本,同时链接了关于将 Dev Proxy 与 GitHub Actions 配合使用的页面。修复之前,该页面固定的是 version: 0.29.2,缺少发布标签所用的 v 前缀。这个工作流在本地看起来没问题,而智能体无法在自己的机器上运行它,因此缺失的 v 只在 CI 中才会暴露出来——此时该 action 的下载 URL 会返回 404。

在我们使用旧版 GitHub Actions 页面进行的全部 4 次尝试中,Claude Sonnet 5.5 都正确地固定为 v4.0.0,于是我们转向 Claude Haiku 5.5。在使用旧页面的 12 次运行中,有 3 次 Claude Haiku 5.5 丢掉了 v,写出了如下内容,并告诉用户工作流已完成:

原文较长,译文为节选;译文由英文原文机器翻译,术语按行业惯例统一,可在文末展开原文核对。

查看英文原文(Do inconsistent docs hurt AI coding agents?)

Every product’s docs drift out of step with the product. A product that’s been around for years has pages written against features that have since changed, and each change reaches only the pages someone remembers to update. A product that’s moving fast, as many are today with AI, drifts even sooner. An endpoint gets renamed or a setting moves, and the reference gets updated while a how-to or a sample keeps the old value. Before long, two of your pages tell the reader two different things.

When developers hit two pages that disagree, they usually find out which one is right the hard way. They copy the code from one page, run it and watch it fail. Every minute they then put into working out which page to trust goes into debugging your docs.

Coding agents read the same pages, so we wanted to know how they handle a contradiction. Does an agent notice that two pages disagree? If it follows the wrong one, does it recover and pay for the detour in tokens, or does it get stuck and hand back something that doesn’t work? And if the result is broken, does the agent tell you?

We tested three contradictions that had been live in a product’s docs, with three models and about 140 agent runs. Agents often noticed that two pages disagreed, and still followed the wrong page first. When the mistake broke something the agent could see, like an API call that returned a 404, every agent recovered, but the detour added as much as 38% to the tokens it used. When the mistake stayed silent until CI, an agent sometimes handed back a broken result and told the user the work was done. Agents that checked a second source before writing code weren’t misled at all.

Real contradictions from a fast-moving product

The three contradictions came from the docs of Dev Proxy, an API simulator that developers use to mock APIs and test how their apps handle errors. We needed contradictions that had been live in real docs, with a known right answer, and Dev Proxy has the history that produces them. Dev Proxy went from v0.29 to v4.0 in about a year and a half, and each major version left behind pages written for the one before. A consistency review of its documentation on Microsoft Learn pulled 3,827 facts out of the pages and found 79 places where two pages disagreed. We’ve since fixed most of them, so for every contradiction we had the page from before the fix and the same page after it.

One page, two versions

To see what a contradiction does to an agent, you have to compare the agent working from the page with the contradiction against the same agent working from the fixed page. So in every run, the agent got one of two versions of a single Learn page: the live page with only the outdated statement put back, or the live, fixed page. The agent, the model, the prompt, the starter project and the machine were identical, so any difference in what the agent did came from the contradiction. We measured whether the agent’s final result worked, and how many tokens and steps it spent getting there.

We ran VS Code with GitHub Copilot Chat, with no extensions or custom instructions, on Windows machines with Dev Proxy v4.0.0 installed the way a developer would have it. We never put the docs in the workspace, because no developer has a product’s docs checked into their repo. Like any hidden variable in an eval, docs in the workspace would have changed what we measured.

When our prompts didn’t link to the docs, agents rarely reached the pages with the contradictions. They worked from Dev Proxy’s --help and installed files instead, and the docs URLs they guessed often returned a 404. To measure what a contradiction does once the agent reads it, every prompt linked the page, the way a developer pastes a docs link into a request.

To serve the outdated version of a page at its real URL, we put Dev Proxy in front of VS Code and used its MockResponsePlugin to answer requests for that one Learn URL with either version. It’s the same approach as in How to test agent experience changes without shipping them, applied to a change we’d already shipped.

We picked three contradictions by how the wrong statement would hurt an agent that follows it. In one, the mistake fails loudly the first time the agent runs its code, and in the other two, it fails silently or only later in CI. We ran each one up to 15 times per page version with Claude Sonnet 5.5, Claude Haiku 5.5 and GPT-6.1 Terra, and read the results from each run’s trace and final files.

Agents followed the wrong page, then paid to recover

When an API changes, the reference usually gets updated first. Dev Proxy has an API for controlling a running proxy, and its Proxy API reference was up to date, while the how-to page about using Dev Proxy in CI/CD still showed endpoints that Dev Proxy v4 doesn’t have:

# The CI/CD page before the fix
/proxy/record
/proxy/stop

# The fixed CI/CD page, and the Proxy API reference all along
POST /proxy  {"recording": true}
POST /proxy/stopproxy

We asked the agent for a CI script that controls Dev Proxy through that API and linked the CI/CD page. An agent that copies the outdated endpoints gets a 404 the first time it runs the script, and the prompt asked it to make sure the script works:

Add a script our CI can run to capture which GitHub API calls this tool makes.
Set it up as described in https://learn.microsoft.com/en-us/microsoft-cloud/dev/dev-proxy/how-to/use-dev-proxy-in-ci-cd-overview:
the script should start Dev Proxy in the background, use the API to start recording,
run `npm start -- microsoft`, use the API to stop recording, and then use the API
to shut Dev Proxy down. Make sure the script works.
Model Outdated endpoints, old CI/CD page Outdated endpoints, fixed CI/CD page Median tokens, old CI/CD page Median tokens, fixed CI/CD page
Claude Sonnet 5.5 10/15 0/15 1.60M 1.16M
Claude Haiku 5.5 5/14 0/14 2.16M 2.55M
GPT-6.1 Terra 0/15 0/15 1.00M 0.91M

With the old CI/CD page, Claude Sonnet 5.5 wrote the outdated endpoints in 10 of 15 runs, and 8 of those 10 runs hit a 404 when the script ran. All 10 runs fixed the script, so every final script worked, but the detour raised median token use by 38%, from 1.16M to 1.60M, and the median run took 12 more steps. Recovering alone took a median of 19 steps and 0.66M tokens, about 40% of the run.

The 5 Claude Sonnet 5.5 runs with the old CI/CD page that never wrote an outdated endpoint still used more tokens than runs with the fixed page, with a median of 1.53M against 1.16M. These runs noticed the contradiction up front and spent steps working out which page to believe, reading the API reference and probing the installed Dev Proxy. In fact, Claude Sonnet 5.5 mentioned the contradiction in all 15 runs with the old CI/CD page, and still wrote the outdated endpoints in 10 of them.

Claude Haiku 5.5 followed the old CI/CD page in 5 of 14 runs and recovered after the 404 every time. Its runs ranged from 1.2M to 3.8M tokens with either version of the page, so we couldn’t tell the cost of recovering apart from its usual variation. GPT-6.1 Terra wrote the right endpoints in every run with either version.

When the mistake stays silent

A wrong API endpoint fails with a 404 the first time the agent calls it. A misplaced setting or a wrong version number doesn’t fail until much later, if at all, so we expected the next two contradictions to do more harm.

Dev Proxy can make a share of your app’s API requests fail at random, so you can see how the app copes. We asked the agent to make 80% of the tool’s GitHub API requests fail and linked the page about configuring Dev Proxy. Before the fix, the sample config on that page put the rate setting at the top level, while the plugin reference puts it in the plugin’s own section:

// The configure page before the fix: Dev Proxy ignores this rate
{ "rate": 80, "genericRandomErrorPlugin": { } }

// The fixed configure page, and the plugin reference all along
{ "genericRandomErrorPlugin": { "rate": 80 } }

With a top-level rate, Dev Proxy ignores the setting and fails 50% of requests, its default, with no error. Still, Claude Sonnet 5.5 put rate in the plugin’s section in all 8 runs with the old configure page, and GPT-6.1 Terra in all 10.

For CI, Dev Proxy offers a GitHub Action that downloads a given version. We asked the agent to add a GitHub Actions workflow that runs the tool through Dev Proxy, pinned to the version installed on the machine, and linked the page about using Dev Proxy with GitHub Actions. Before the fix, that page pinned version: 0.29.2, without the v prefix that the release tags use. The workflow looks fine locally, and the agent can’t run it on its machine, so the missing v shows up only in CI, when the action’s download URL returns a 404.

Claude Sonnet 5.5 pinned v4.0.0 correctly in all 4 runs we tried with the old GitHub Actions page, so we moved on to Claude Haiku 5.5. In 3 of 12 runs with the old page, Claude Haiku 5.5 dropped the v, wrote this and told the user the workflow was done:

- uses: dev-proxy-tools/actions/setup@v1
  with:
    version: 4.0.0

With the fixed GitHub Actions page, none of Claude Haiku 5.5’s 5 runs dropped the v. With this few runs, 3 broken workflows out of 12 against none out of 5 could still be chance.

More runs would pin down how often Claude Haiku 5.5 breaks the workflow, but that rate depends on the task. The CI script prompt asked the agent to make sure the script works, so the agent ran the script and hit the 404 from the outdated endpoints. With the GitHub Actions workflow, the agent had no way to run the workflow, so nothing told it the version was wrong. Whether an agent recovers from a contradiction comes down to whether the task lets it run into the mistake.

Agents that checked twice weren’t misled

In all three tasks, every agent read the page linked in its prompt. The agents that avoided the outdated statement also checked it against a second source before writing code, like another docs page or the product itself.

With the old CI/CD page, before writing the script Claude Sonnet 5.5 Claude Haiku 5.5 GPT-6.1 Terra
Read the Proxy API reference 7/15 11/14 15/15
Ran devproxy api show 2/15 4/14 15/15
Wrote the outdated endpoints 10/15 5/14 0/15

GPT-6.1 Terra opened the Proxy API reference and ran devproxy api show, which lists the endpoints of the installed Dev Proxy, within its first few steps in every run. Claude Sonnet 5.5 wrote the CI script before opening the API reference in 8 runs, and all 8 used the outdated endpoints. The old CI/CD page linked to the API reference too, but a link only helps an agent that follows it before writing the code.

Checking a second source before writing code also kept Claude Sonnet 5.5 from misplacing the rate setting or dropping the v from the version. Before configuring the 80% failure rate, 3 of its runs printed the default devproxyrc.json from Dev Proxy’s install folder, which puts rate in the plugin’s section, and the other 5 read the plugin reference. Before writing the GitHub Actions workflow, every Claude Sonnet 5.5 run read the action’s own files on GitHub, like setup/action.yml, whose version input gives v1.0.0 as an example, or the list of releases, where the latest is tagged v4.0.0.

No agent read Dev Proxy’s source code or checked a schema. For a second source, the agents used another docs page, the Dev Proxy CLI, the files Dev Proxy installs and the GitHub Action’s own repo. When the outdated page is the only source for a fact, an agent has nothing to check the page against, and we’d expect any agent to follow it.

What we’d test next

The first thing we’d test is how much recovery depends on the task. Our CI script prompt asked the agent to make sure the script works. Asking for the same script without that line, or in a setup where the agent can’t run the script, would show how often the outdated endpoints end up in the final script once nothing makes the agent hit the 404.

Then we’d take the docs link out of the prompt. When our prompts didn’t link to the docs, agents rarely reached the pages with the contradictions, so the next question is how often an agent finds an outdated page through search, and whether a contradiction the agent finds by itself misleads it more often than one in a page we hand it.

We’d also try agents that read docs differently. Claude Code, for example, fetches pages through a subagent that returns a summary, and a summary might smooth over a contradiction or leave it out altogether.

On the docs side, we tested 3 of the 79 contradictions in the Dev Proxy docs, and only the outdated API endpoints produced a difference too large to be chance. Testing contradictions where the product offers no second source, like a fact that appears only in the docs, would show how often agents follow the wrong page when they have nothing to check it against.

What to do with your docs

If you maintain docs, fix contradictions even when agents recover from them. With the outdated API endpoints, every Claude Sonnet 5.5 run ended with a working CI script, and the contradiction still added 38% to its token use. Your users pay for that in time and in extra inference.

In all three of our contradictions, the reference had the current value, and a how-to or a sample still had the old one. So when you rename an endpoint or move a setting, search the docs for the old value and update every page that shows it, samples included.

To find the contradictions already in your docs, let an agent compare every fact on every page. We found our three contradictions with a consistency review of the Dev Proxy docs. We cloned the docs repo and the Dev Proxy source code and gave an agent this prompt:

Review Dev Proxy docs under `docs/dev/dev-proxy` for consistency.

1. Read all pages
2. Make a list of all facts, for each fact cite source page
3. Check that no facts are contradictory/inconsistent. If they are, include evidence (page and fragment)
4. For each finding verify against the truth in code in `../dev-proxy`. Be mindful that docs are based on the latest stable while the source reflects current beta.
5. Make an HTML report with the result allowing to filter/search facts, pages, and status (ok/inconsistent)

The agent read 193 pages, listed 3,827 facts and flagged 79 inconsistencies, each with the pages and the fragments that disagree, and checked every inconsistency against the Dev Proxy source code. Point the prompt at your own docs folder and source code, and you get a report you can search and filter page by page.

Dev Proxy docs consistency report showing 193 pages, 3,827 facts and 79 inconsistencies. The first inconsistency shows API samples on how-to pages calling endpoints without the bearer token that the API reference says every endpoint requires.

Fix first the contradictions where the wrong value fails late or silently, and where nothing in the product says otherwise. The misplaced rate setting misled no agent in our runs, because the default config that Dev Proxy installs showed the right place before the agent wrote a line. The outdated API endpoints, which fail only when called, and the version without a v, which fails only in CI, did mislead agents.

Make your product a reliable second source. In our runs, the devproxy api show command and the default config that ships with Dev Proxy kept agents from following an outdated page, and for the GitHub Actions workflow, the version example in the action’s own metadata did the same. If those sources disagree with your docs too, an agent that checks them has nothing left to correct the page.

If you evaluate agents against your docs, decide whether you’re testing what the page does to the agent or whether the agent finds the page. Linking the page tests the content, and leaving it out tests discovery, the same choice we described for non-REST APIs. Check results against each run’s trace and final files, because our LLM judge failed runs whose final config was correct, and read the trajectories. A run that recovered from a 404 passes just like a run that never needed to.

So, do inconsistent docs hurt AI coding agents?

Inconsistent docs do hurt AI coding agents, and in our runs the harm showed up mostly as extra tokens and steps. When an outdated page led to an API call that failed right away, two of three models followed the page into a 404, and every run recovered. The broken GitHub Actions workflows came where the mistake stayed silent until CI and the agent had no way to run into it.

Whether a contradiction misleads an agent depends on the model behind it. Running on GPT-6.1 Terra, the agent checked a second source before it wrote any code and was never misled, while on Claude Sonnet 5.5, it often wrote first and checked later. When your users’ agents run on a model like Claude Sonnet 5.5, each contradiction in your docs costs them extra tokens when the agent catches the mistake, and a broken build when it doesn’t.

The post Do inconsistent docs hurt AI coding agents? appeared first on Microsoft for Developers.

正文保留英文原文,标题与摘要由机器翻译。

本文由采集器自动同步

原文发布于 Microsoft DevBlogs(Do inconsistent docs hurt AI coding agents?),标题、摘要与正文由机器翻译,术语按行业惯例统一,未经人工逐句校订。

阅读原文 ↗