Run the documentation agent
docsbot agent finds what your code defines that your docs miss, drafts the pages, checks
them, and waits for a person to approve. It runs five fixed steps on a local repository:
- Gaps: read the code and find what the docs miss or describe out of date.
- Context: ask your MCP servers for product context about each gap.
- Draft: write each page with a citation for every statement.
- Validate: check examples, links, citations and facts against the repository.
- Evaluate: score the draft and apply a gate.
Nothing reaches your docs until a person has verified every claim and approved the draft.
Find the gaps
docsbot agent gaps
docsbot reads the code for:
| Kind | Read from |
|---|---|
| Command-line flags | Go flag, pflag and cobra; Python argparse, click and typer; Node commander |
| Environment variables | Go os.Getenv/os.LookupEnv, Python os.getenv/os.environ, Node process.env, Ruby ENV[...], and ${VAR} references in shell and config files |
| HTTP endpoints | Go net/http, gin and chi; Python FastAPI and Flask; Node Express |
| Configuration keys | YAML config files, yaml: and toml: struct tags, .env.example (never .env) |
It looks for each item on the docs pages and groups the gaps into pages: a new reference
page, or an update to the page that already documents the neighbouring items. Each group
has an ID (G1, G2 …). agent gaps exits 1 when there are gaps, so it can gate a
build.
Find what a branch changed
docsbot agent gaps --since origin/main
With --since, docsbot also reads git diff against the ref:
- outdated: an item’s default changed in the code while a page still gives the old one
- stale: an item was removed from the code and a page still names it
Run all five steps
docsbot agent run # the top 3 groups, into drafts/agent
docsbot agent run --group G2 # one group
docsbot agent run --since origin/main --max-drafts 5
Each drafted group gets a folder under drafts/agent (or --out; never inside the docs):
| File | Contents |
|---|---|
draft.md, claims.json, review.md |
the draft and its review, as draft write produces them |
agent.json |
what the draft was made from |
eval.json, eval.md |
validation results and the score |
proposed-changes.md |
for pages that exist already: each line to fix, with a diff |
report.md and run.json summarise the whole run. The exit code is 0 when every draft
passed the gate, 1 when one is blocked or failed, and 2 for bad input.
For changed or removed items, the existing docs are left out of the sources, because their text is what is out of date.
Add product context over MCP
Code says what a flag is called and what its default is; it rarely says why someone would
use it. The agent asks MCP servers listed in docsbot.yml for passages about each item,
keeps those that name it, and cites each with the server, tool and source:
agent:
mcp:
- name: product-kb # stdio: docsbot serving a knowledge-base folder
command: [docsbot, mcp, serve, --no-repo, --kb, ../product-kb]
- name: api-catalog # Streamable HTTP
url: https://mcp.example.com/mcp
allow_remote: true # the queries name your flags and settings
header_env: {Authorization: CATALOG_TOKEN}
tool: search
A server off your machine needs allow_remote: true, because the queries name your
product’s flags and settings. docsbot mcp serve is a ready-made server for a
folder of notes. Skip MCP for a run with --no-mcp.
How drafts are validated and scored
Validation checks:
- JSON, YAML and TOML example blocks parse.
- Every
--flagin a shell block, and every flag and endpoint named in the prose, exists in the code (unless the draft reports it as removed). - Relative links resolve from the page’s target location; external links too with
--external-links. - Citations are valid and no fact contradicts the repository.
Evaluation gives a score out of 100:
| Part | Points |
|---|---|
| Statements with a valid citation | 30 |
| Facts grounded in their sources | 30 |
| Gap items covered | 25 |
| Sections with sources | 15 |
The gate is 80 (--min-score or agent.min_score). Contradicted facts, invalid citations,
unknown flags or endpoints, invalid examples and broken links block a draft whatever its
score.
With --judge, the model configured in the draft section also scores faithfulness,
completeness, clarity and examples from 1 to 5 with a versioned prompt. Any score under 3
(agent.min_judge) blocks the draft.
Without a model, drafts are extractive. To have a model write them:
docsbot agent run --group G2 --provider anthropic --allow-remote --judge
Review, approve and publish
-
Read
review.mdandeval.md. Editdraft.mdas you would any draft. -
Verify each claim:
docsbot draft verify drafts/agent/g2-... --claim C1,C2 --status verified --by "A Reviewer" -
Validate and score the edited draft again. Approval needs an evaluation of the current
draft.md, so run this after every edit:docsbot agent eval drafts/agent/g2-... -
Approve it:
docsbot agent approve drafts/agent/g2-... --by "A Reviewer" --publish
approve is refused until the evaluation is of the current draft.md, the gate has passed
and every claim is verified. It sets status: approved and writes approval.json.
--publish writes a new page into the docs at the target agent gaps gave, without
citations, footnotes or review comments. It never overwrites an existing page (unless you
add --force): apply proposed-changes.md to existing pages by hand.
Try it on the fixture
The repository has a synthetic product with real gaps:
git clone https://github.com/kakabisht/Docs-toolkit.git && cd Docs-toolkit && make build
./docsbot agent gaps testdata/fixtures/agent/repo
./docsbot agent run testdata/fixtures/agent/repo -c testdata/fixtures/agent/docsbot.yml --out /tmp/agent-demo