Write documentation that AI agents can efficiently consume. Based on Vercel benchmarks and industry standards (AGENTS.md, llms.txt, CLAUDE.md).
Three-layer architecture for optimal agent performance:
Always in context. 2,000–4,000 tokens max.
# AGENTS.md
> Context: Next.js 16 | Tailwind | Supabase
## 🚨 CRITICAL
- NO SECRETS in output
- Use `app/` directory ONLY
## 📚 DOCS INDEX (use read_file)
- Auth: `docs/auth/llms.txt`
- DB: `docs/db/schema.md`
Include:
Fetched on demand. 1K–5K token chunks.
Gated by allow-lists. Edge cases only.
Vercel Benchmark (2026):
| Approach | Pass Rate |
|---|---|
| ---------- | ----------- |
| Tool-based retrieval | 53% |
| Retrieval + prompting | 79% |
| Inline AGENTS.md | 100% |
Root cause: Meta-cognitive failure. Agents don't know what they don't know—they assume training data is sufficient. Inline docs bypass this entirely.
An 8KB compressed index outperforms a 40KB full dump.
Compress to:
RAG systems split at headers. Each section must be self-contained:
## Database Setup ← Chunk boundary
Prerequisites: PostgreSQL 14+
1. Create database...
Rules:
Agents can't autonomously browse. Each link = tool call + latency + potential failure.
| Approach | Token Load | Agent Success |
|---|---|---|
| ---------- | ------------ | --------------- |
| Full inline | ~12K | ✅ High |
| Links only | ~2K | ❌ Requires fetching |
| Hybrid | ~4K base | ✅ Best of both |
LLMs have U-shaped attention:
Solution: Put critical rules at TOP of AGENTS.md. Governance first, details later.
Strip everything that isn't essential:
Formats like llms.txt and AGENTS.md mechanically increase SNR.
Machine-readable doc index for agents:
# Project Name
> One-line project description.
## Authentication
- [Setup](docs/auth/setup.md): Environment vars and init
- [Server](docs/auth/server.md): Cookie handling
## Database
- [Schema](docs/db/schema.md): Full Prisma schema
Location: /llms.txt at domain root
Companion: /llms-full.txt — full concatenated docs, HTML stripped
AGENTS.md is part of your codebase. Controlled, version-pinned.
Mitigation: Domain allow-lists, human-in-the-loop for external retrieval.
For detailed guidance on RAG optimization, multi-framework docs, and API templates, see references/advanced-patterns.md.
共 1 个版本