用结构化代码分析+自我修正机制,自动保持文档与代码一致
DocSync: Agentic Documentation Maintenance via Critic-Guided Reflexion

- 结合代码抽象语法树和检索增强生成,理解代码结构
- 自纠错循环使文档语义正确率显著提升,判分达3.44/5.0
- 小模型也能实现高质量维护,适合资源有限场景
软件文档常因代码演进而滞后,造成技术债务并引发接口误用。静态分析工具可检测文档缺失,但无法评估其语义一致性;通用大语言模型虽具生成能力,却在无深层代码理解时易产生幻觉。为此,我们提出DocSync,一种基于结构感知的智能体工作流,将文档维护视为迭代生成任务。通过融合抽象语法树(AST)表示与检索增强生成(RAG),提供依赖感知上下文,并引入基于反思(Reflexion)范式的批评者引导修正循环,使模型能依据源码自检并修正候选更新。我们在一个资源受限的代理任务上评估了基于LoRA微调的小型语言模型实现。结果表明,该结构感知智能体方法在语义对齐、摘要忠实度及自动评分偏好上均显著优于标准编码器-解码器基线(如CodeT5-base得分为1.91,而本方法达3.44/5.0)。关键在于,迭代批评循环在不增加参数量的前提下提升了语义正确性,证明结构化检索与智能体精炼相结合是缓解文档债务的高效路径。
原文摘要 · Abstract (English)
Software documentation frequently drifts from executable logic as codebases evolve, creating technical debt that degrades maintainability and causes downstream API misuse. While static analysis tools can detect the absence of documentation, they cannot evaluate its semantic consistency. Conversely, standard Large Language Models (LLMs) offer generative flexibility but frequently hallucinate when updating documentation without deep structural awareness of the underlying code. To address this gap, we propose DocSync, an agentic workflow that frames documentation maintenance as a structurally grounded, iterative generation task. DocSync bridges syntactic changes and natural language descriptions by fusing Abstract Syntax Tree (AST) representations and Retrieval-Augmented Generation (RAG) to provide dependency-aware context. Furthermore, to ensure factual consistency, we incorporate a critic-guided refinement loop based on the Reflexion paradigm, allowing the model to self-correct candidate updates against the source code. We empirically evaluate a resource-constrained implementation of DocSync-using a LoRA-adapted small language model - on a proxy code-to-text maintenance task. Our findings demonstrate that this AST-aware agentic approach substantially outperforms standard encoder-decoder baselines across semantic alignment, summary-line faithfulness, and automated judge preferences (e.g., achieving an automated judge score of 3.44/5.0 compared to 1.91 for CodeT5-base). Crucially, the iterative critic loop yields measurable improvements in semantic correctness without requiring scaled-up parameter counts. These results provide strong evidence that coupling structural retrieval with agentic refinement is a highly promising direction for autonomously mitigating documentation debt.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。