面向异常安全代码生成的中间表示代理框架
Towards Exception Safety Code Generation with Intermediate Representation Agents Framework
AI总结:
提出Seeker多代理框架,利用中间表示和深度RAG算法提升LLM生成代码的异常处理能力,显著提高精度与稳健性。
摘要:
大型语言模型(LLMs)在生成的代码中往往难以实现稳健的异常处理,导致程序脆弱且容易发生运行时错误。我们提出了Seeker,一种新颖的多代理框架,通过中间表示(IR)方法在LLM生成的代码中强制执行异常安全。Seeker将异常处理分解为五个专门代理:Scanner、Detector、Predator、Ranker和Handler,它们协作分析代码、检测脆弱片段、检索最佳实践异常策略并注入稳健的处理代码。我们还引入了通用异常枚举(CEE),这是一个从官方文档、技术实践和真实世界代码中提取的全面知识库,用于标准化异常处理策略。Seeker还融合了深度检索增强生成(Deep RAG)算法,以高效导航异常继承层次结构,将搜索开销削减93%,同时提高识别相关异常的准确性。我们在15个开源Java项目和多个基准上评估了Seeker。Seeker优于最先进的基线,将异常处理精度提高多达37%,并通过专家代码审查衡量的整体代码稳健性提高38%。它显著缩小了LLM与人类开发者在异常管理方面的差距,在真实世界问题修复(SWE bench)上实现了28%的成功率,而先前方法为19%。我们的框架在主动处理错误的同时保持代码的功能正确性,展示了更安全代码生成的实用、通用解决方案。在本文中,我们讨论了使用中间表示和多代理协作进行异常处理的新颖性,并概述了Seeker如何扩展到其他编程语言和复杂的软件工程任务,使LLM生成的代码与工业标准保持一致。
英文摘要:
Large Language Models (LLMs) often struggle with robust exception handling in generated code, leading to fragile programs that are prone to runtime errors. We propose Seeker, a novel multi-agent framework that enforces exception safety in LLM generated code through an Intermediate Representation (IR) approach. Seeker decomposes exception handling into five specialized agents: Scanner, Detector, Predator, Ranker, and Handler that collaboratively analyze code, detect fragile segments, retrieve best practice exception strategies, and inject robust handling code. We also introduce Common Exception Enumeration (CEE), a comprehensive knowledge base derived from official documentation, technical practices, and real world code, to standardize exception handling strategies. Seeker also incorporates a Deep Retrieval-Augmented Generation (Deep RAG) algorithm to efficiently navigate the exception inheritance hierarchy, cutting down search overhead by 93% while improving accuracy in identifying relevant exceptions. We evaluate Seeker on 15 open source Java projects and multiple benchmarks. Seeker outperforms state of the art baselines, improving exception handling precision by up to 37% and overall code robustness by 38% as measured by expert code review. It significantly closes the gap between LLM and human developers in exception management, achieving a 28% success rate on real world issue fixes (SWE bench) versus 19% by prior methods. Our framework preserves functional correctness of code while proactively handling errors, demonstrating a practical, generalizable solution for safer code generation. In this paper, we discuss the novelty of using intermediate representation and multi-agent collaboration for exception handling, and outline how Seeker can be extended to other programming languages and complex software engineering tasks, aligning LLM-generated code with industrial standard.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。