paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Instruct or Interact? Exploring and Eliciting LLMs' Capability in Code Snippet Adaptation Through Prompt Engineering

指令还是交互?通过提示工程探索与激发 LLM 的代码片段适配能力
ICSE 2025 IEEE/ACM 47th International Conference on Software Engineering (ICSE)2025匹配度 2/10 · 该论文研究 LLM 在代码片段适配任务上的提示工程与交互式提示方法,目标本身是提升 LLM/Agent 的提示能力,属于用户明确不感兴趣的方向。它不涉及静态分析、形式化验证、浮点程序分析或贝叶斯程序分析,也未将 LLM 作为改进程序分析的工具。引用 8 inbox
Tanghaoran Zhang, Yue Yu, Xinjun Mao, Shangwen Wang, Kang Yang, Yao Lu, Zhang Zhang, Yuxin Zhao
crossref: 2026-09-12

AI 速览

一句话:通过实证研究揭示 LLM 代码片段适配弱于生成的原因,并提出交互式提示方法显著提升适配性能。

代码片段适配是复用导向且依赖上下文的代码修改预测任务,但 LLM 在此任务上的表现尚不明确。本文首先对三个主流 LLM 进行实证评估,发现其适配能力弱于代码生成,pass@1 下降近 15%,且更多出现上下文相关错误。通过人工检查 200 个案例,将失败原因归纳为需求不清晰、需求错位和上下文误用三类。基于此,提出交互式提示方法:通过丰富上下文与任务分解缓解上下文误用并改善需求理解,借助与人类或 LLM 顾问的反思交互补偿需求不清晰。实验表明,最佳 Human-LLM 交互修复了 202 个缺陷中的 159 个,pass@1 和 pass@5 相比初始指令提示提升超过 40%;考虑人力成本,多智能体交互是性能与泛化性折中的方案。

问题
LLM 在代码生成上表现优异,但其在复用导向、依赖上下文的代码片段适配任务上的能力与问题尚不明确。
方法
通过实证研究评估三个主流 LLM 的适配性能并与代码生成对比,人工分析 200 个案例归纳失败原因;进而提出交互式提示方法,通过丰富上下文、分解任务以及引入人类或 LLM 顾问的反思来提升适配能力。
评估
在适配任务上对比不同提示策略,最佳 Human-LLM 交互修复了 202 个缺陷中的 159 个,pass@1 与 pass@5 相比初始指令提示提升超过 40%;多智能体交互在性能与泛化间取得折中。
原文摘要(Abstract)

Code snippet adaptation is a fundamental activity in the software development process. Unlike code generation, code snippet adaptation is not a “free creation”, which requires developers to tailor a given code snippet in order to fit specific requirements and the code context. Recently, large language models (LLMs) have confirmed their effectiveness in the code generation task with promising results. However, their performance on code snippet adaptation, a reuse-oriented and context-dependent code change prediction task, is still unclear. To bridge this gap, we conduct an empirical study to investigate the performance and issues of LLMs on the adaptation task. We first evaluate the adaptation performances of three popular LLMs and compare them to the code generation task. Our result indicates that their adaptation ability is weaker than generation, with a nearly 15% decrease on pass@1 and more context-related errors. By manually inspecting 200 cases, we further investigate the causes of LLMs' sub-optimal performance, which can be classified into three categories, i.e., Unclear Requirement, Requirement Misalignment and Context Misapplication. Based on the above empirical research, we propose an interactive prompting approach to eliciting LLMs' ability on the adaptation task. Specifically, we enhance the prompt by enriching the context and decomposing the task, which alleviates context misapplication and improves requirement understanding. Besides, we enable LLMs' reflection by requiring them to interact with a human or a LLM counselor, compensating for unclear requirement. Our experimental result reveals that our approach greatly improve LLMs' adaptation performance. The best-performing Human-LLM interaction successfully solves 159 out of the 202 identified defects and improves the pass@1 and pass@5 by over 40% compared to the initial instruction-based prompt. Considering human efforts, we suggest multi-agent interaction as a trade-off, which can achieve comparable performance with excellent generalization ability. We deem that our approach could provide methodological assistance for autonomous code snippet reuse and adaptation with LLMs.

链接与引用

DOI 原文 ·

BibTeX
@inproceedings{paperbot8759,
  title = {Instruct or Interact? Exploring and Eliciting LLMs' Capability in Code Snippet Adaptation Through Prompt Engineering},
  author = {Tanghaoran Zhang and Yue Yu and Xinjun Mao and Shangwen Wang and Kang Yang and Yao Lu and Zhang Zhang and Yuxin Zhao},
  booktitle = {ICSE},
  year = {2025},
  doi = {10.1109/icse55347.2025.00104}
}