用智能体+上下文压缩,自动从代码生成高质量UML图
Code2UML: Agentic LLMs with context engineering for scalable software visualization
- 设计五类智能体分工协作,分步完成代码分析与绘图
- 在12个开源项目中生成84张图,平均结构质量达81.7分
- 支持多语言大项目,规模变化不影响结果稳定性
基于大语言模型的代码分析工具被用于自动化软件文档生成,但其在真实代码库(中间表示超过LLM上下文限制)中的可扩展性仍待探索。本文提出一种基于上下文工程的智能体架构,实现源码仓库到UML图的自动化生成。系统包含五类专用智能体:规划、分析、绘图、纠错和依赖分析,均基于Claude Agent SDK构建,分别处理不同认知任务。引入确定性的、基于重要性加权的中间表示压缩层,将完整项目中间表示转化为符合令牌约束的图相关视图,无需调用LLM,毫秒级完成。我们在4种编程语言(Java、JavaScript、PHP、Python)的12个开源仓库中评估了7类UML图,共生成84个观察样本,并使用5项自动化指标进行评价。结果显示,语法正确率平均91.5%,组件与部署图达100%;关系精确率平均0.858;结构质量平均81.7/100,跨语言差异仅3.1分。实体召回率平均0.313,体现有意聚焦关键结构而非全面覆盖。敏感性分析(中间表示实体数从31至4,578)表明,质量评分不受规模影响,保持稳定。
原文摘要 · Abstract (English)
Large Language Model (LLM)-based code analysis tools are adopted to automate software documentation tasks. However, the scalability of these approaches to real codebases, where Intermediate Representations (IR) exceed LLM context limits, remains underexplored. This paper introduces an agentic architecture with context engineering for automated UML diagram generation from source code repositories. It employs a hierarchy of five specialized agents: PlannerAgent, AnalyzerAgent, DiagramAgent, CorrectorAgent and DependencyAnalyzerAgent, built on the Claude Agent SDK, each addressing a distinct cognitive subtask. A deterministic, importance-weighted IR compaction layer transforms full project IRs into diagram-specific views guaranteed to fit within token constraints, requiring no LLM calls and completing in milliseconds. Thus, we evaluate the system across 12 open-source repositories in 4 programming languages (Java, JavaScript, PHP, Python) and 7 UML diagram types, producing 84 observations assessed on 5 automated metrics. Results demonstrate high syntactic validity (mean: 91.5%, with component and deployment diagrams reaching 100%), strong relationship precision (mean: 0.858) and consistent structural quality (mean: 81.7/100, with cross-language variance of 3.1 points). Entity recall averaged 0.313, reflecting deliberate architectural prioritization over exhaustive coverage. A sensitivity analysis (31 to 4,578 IR entities) confirms that quality scores remain stable regardless of scale.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。