AdaptAgent:一种用于代码适配的多智能体、领域引导推理框架
AdaptAgent: A Multi-agent, Domain-Guided Reasoning Framework for Code Adaptation
AI总结:
本研究提出AdaptAgent框架,通过分工的多智能体实现代码适配,在真实数据集上的语义正确性优于强基线,各智能体对适配效果均有重要作用。
AI中文摘要:
开发者常需将大型语言模型(LLM)生成的代码或在线论坛的代码片段适配到项目中,但手动将其集成到现有代码仓库仍颇具挑战。成功的集成通常不止是复制代码,用户必须在目标仓库的指定位置生成正确的适配修改。我们将此形式化为代码适配问题:给定一个代码片段、功能意图、目标代码仓库和适配位置,生成将该片段适配到仓库中的补丁。我们提出AdaptAgent,一种用于代码适配的多智能体、领域引导推理框架。AdaptAgent不依赖单次提示,而是将适配过程分解为多个通过类型化构件通信的专用智能体:意图总结器从问答文本中提取适配目标;策略智能体从六个适配类别中推导领域策略;领域规划器生成自排序计划;上下文挖掘器从目标代码仓库中提炼兄弟方法的语义;代码适配器将计划实现为最小化统一差异,并通过基于编译器的验证器迭代优化。这种分工实现了鲁棒的、符合策略的适配,支持将代码片段适配到项目中。在真实数据集上,AdaptAgent在语义正确性方面优于强基线,生成的补丁符合开发者实际的适配模式。我们的消融研究表明每个智能体都有其必要性,尤其是用于代码加固和异常处理的规划,以及用于逻辑定制的意图模块。
英文摘要:
Developers often need to adapt into their projects the code generated from LLMs or code snippets from online forums. However, integrating them into an existing repository remains challenging in a manual process. A successful integration typically requires more than copying code as a user must produce correct adapting changes at a designated location in the target repository. We formalize this as the code adaptation problem: given a snippet, functional intent, a target repository, and an adaptation location, generate a patch that adapts the snippet into the repository. We present AdaptAgent, a multi-agent, domain-guided reasoning framework for code adaptation. Rather than relying on single-shot prompting, AdaptAgent decomposes adaptation into specialized agents that communicate via typed artifacts: an Intent Summarizer extracts adaptation goals from Q&A text; a Policy Agent derives domain policies from six adaptation categories; a Domain Planner generates a self-ordered plan; a Context Miner distills sibling-method semantics from the target codebase; and a Code Adapter realizes the plan as a minimal unified diff, iteratively refined using a compiler-based Verifier. This division of labor enables robust, policy-aligned adaptations and supports adapting code snippets into a project. On a real-world dataset, AdaptAgent outperforms strong baselines in semantic correctness and produces patches that mirror developers' actual adaptation patterns. Our ablation study shows each agent's necessity, especially planning for code-hardening and exception-handling, and intent for logic customization.