TL;DR
Ask an AI to document an entire software repository today, and it acts like it has amnesia: it reads the same files over and over, contradicts itself across pages, and misses the forest for the trees. MemDocAgent fixes this by treating codebase documentation as a single, continuous journey guided by a shared memory and a strict bottom-up roadmap. The result is faster, cohesive documentation—spanning individual functions up to high-level architecture—that is detailed enough for another AI to rebuild the working code from scratch.
What Problem Does This Paper Address?
Good documentation is the map that helps both humans and AI coding agents navigate massive codebases. Writing it manually is exhausting, so researchers have turned to Large Language Models (LLMs) to automate the job.
However, existing automated tools suffer from short-term thinking. They chop a repository into isolated pieces and document each one from a blank slate. Because there is no shared state between steps, two major problems emerge:
- Wasted effort and self-contradiction: Systems repeatedly fetch the exact same source files (averaging 50% redundant reads) and frequently describe the same underlying logic in conflicting ways across different documents (around a 13% inconsistency rate).
- Flat, incomplete views: Current tools either write microscopic function docstrings (losing the big picture) or macroscopic project overviews (omitting crucial implementation details), failing to connect them into a unified hierarchy.
Methods
Instead of running hundreds of independent, short-lived tasks, the authors formulate documentation as a single long-horizon agentic trajectory—often spanning over a thousand reasoning steps. While using a ReAct-style (Reason + Act) loop is standard for AI agents, MemDocAgent introduces two novel mechanisms to keep the agent organized over long stretches:
- Dependency-Aware Traversal Guiding: Before writing a word, the system parses the code's Abstract Syntax Tree (AST) to map out dependencies (calls, imports, inheritance), collapsing circular loops along the way. Unlike prior tools that only sort function-level dependencies, this creates a strict bottom-up schedule across three granularities: components (functions/classes) are documented after their dependencies, modules (directories) after their components, and the repository overview last.
- Memory-Guided Agentic Interaction (RepoMemory): As the agent works through its schedule, it interacts with an active, shared database called
RepoMemoryusing four actions: READ: Looks up previously generated docs or cached web searches in $O(1)$ time, avoiding raw code re-reads.WRITE: Drafts structured documentation tailored to the current hierarchy level.VERIFY: Acts as a quality gatekeeper. Beyond standard LLM self-evaluation, it breaks the draft into atomic claims and uses a Natural Language Inference (NLI) model to check for contradictions against already-verified dependency docs. If conflicts arise, the agent must revise the draft.FINISH: Commits the verified doc toRepoMemoryand clears the local working window so the agent doesn't run out of context space on the next unit.
Datasets
MemDocAgent is an inference-time framework, so no training datasets are used. For evaluation, the authors used DevEval, selecting 20 Python repositories via stratified sampling across 10 diverse domains, chosen specifically for their structural depth, complex dependencies, and unit tests.
To test practical utility, they also curated a benchmark of 564 component-level test cases from DevEval to introduce a new execution-based metric called Information Sufficiency: stripping out a function's code body and testing whether a separate LLM can regenerate passing code using only the function signature and the generated documentation.
Key Insights and Ideas
- Memory saves time, not just context: You might expect a single-trajectory agent with verification loops to be painfully slow. Instead, because
RepoMemoryturns repeated raw-code inspections into instant lookups of already-verified summaries, it actually speeds up the pipeline. - AI docs can beat human docstrings for code reconstruction: When regenerating stripped-out code, models fed MemDocAgent's outputs outperformed models fed human-written ground-truth docstrings. Humans write terse, high-level reminders; MemDocAgent writes exhaustive, dependency-aware specifications.
- Architecture matters for writing local code: In the code regeneration tests, feeding the coding model the module and repository-level docs alongside the function doc steadily boosted pass rates. High-level architectural context genuinely helps an AI write better low-level code that integrates cleanly.
Key Results
Tested with both open-source (Qwen3-Coder-30B) and closed-source (GPT-5-mini) backbones against commercial tools (DeepWiki, Claude-Code) and academic baselines (RepoAgent, DocAgent, CodeWiki), MemDocAgent swept the board:
- Zero Redundancy, High Consistency: Eliminated redundant source-file reads (0.0%) and slashed cross-document inconsistency by 75.5% (down to just 3.1%).
- Superior Quality: Using Qwen3-Coder, it achieved 0.979 completeness, 0.916 truthfulness, and 0.690 helpfulness—beating the strongest open-source baselines by 15.9%, 9.7%, and 9.9%, respectively, while also outperforming closed-source commercial tools.
- Code Reconstruction: Achieved up to 0.47 Pass@1 and 0.49 Pass@3 on Information Sufficiency (with GPT-5-mini), comfortably beating baselines (~0.26–0.36) and human docstrings.
- Faster Execution: Cut retrieval time by 41% compared to previous state-of-the-art DocAgent (13.76s vs. 23.44s per document), dropping total generation time from 60.86s to 50.51s per document.
Limitations and Future Work
- Trajectory caps and reasoning loops: To keep compute costs and context windows in check, the system enforces hard limits on steps and revisions. Occasionally, an agent gets stuck in a repetitive reasoning loop and hits this ceiling before passing verification (though this happened in only 0.08% of components). The authors suggest adaptive stopping criteria and better recovery mechanisms for future work.
- Evaluation scope: Because DevEval only has human-curated unit tests at the function level, Information Sufficiency could only be directly executed at the component level—leaving the utility of module and repository docs to be proven indirectly rather than through full-module regeneration.
Summary updated