Intention is All You Need: Refining Your Code from Your Intention

Qi Guo, Xiaofei Xie, Shangqing Liu, Ming Hu, Xiaohong Li, Lei Bu · DOI

Automated code refinement is a critical yet challenging task in modern software engineering. While Large Language Models (LLMs) have shown promise, they often struggle to translate vague or context-poor reviewer comments into precise code modifications. This research introduces a novel two-phase framework that bridges this "semantic gap" by first extracting a structured "intention" from comments before generating the revised code.

The Semantic Gap in Code Reviews

Reviewers often provide feedback that is brief or lacks explicit instructions (e.g., "this logic is redundant"). Existing end-to-end models frequently fail on such comments because they attempt to jump directly from messy natural language to final code, often leading to hallucinations or logical errors. The authors identify that knowing the exact location of the comment (ReviewLine) and the history of the change (LastCodeDiffHunk) is vital for accurate refinement.

Methodology: A Two-Phase Approach

The core of the proposed solution is a two-phase framework: Intention Extraction and Intention-Guided Revision Generation.

Overview of the Intention-guided Code Revision framework.

Phase 1: Intention Extraction

The system employs three specialized agents to categorize and structure the reviewer's goal:

  1. Agent 1 (Rule-based): Detects "Explicit Code Suggestions" where the reviewer has provided a code snippet directly.
  2. Agent 2 (LLM + Context): Identifies "Reversion Suggestions" (e.g., "undo this") by analyzing the previous code diff.
  3. Agent 3 (LLM-based): Maps "General Suggestions" onto one of six structured templates, such as "Change word A to B" or "Delete code lines."

Phase 2: Intention-Guided Revision Generation

The structured intention is then used to guide an LLM in generating the final code. The authors explored several prompting strategies, including Simple prompts, Retrieval-Augmented Generation (RAG) using historical examples, and Self-generated prompts where the model creates its own internal exemplars. Finally, a rule-based post-processing step ensures the generated code adheres to the suggested changes and maintains context.

Experimental Results

The framework was evaluated using a manually annotated "clean" version of the CodeReview dataset, consisting of 1,337 high-quality instances.

Performance comparison of various LLMs on intention extraction accuracy.

As shown in the results, GPT-4o demonstrated superior performance, achieving a 79% overall accuracy in intention extraction and nearly 99% accuracy for reversion tasks. In terms of code refinement, the intention-guided approach reached an Exact Match (EM) score of 66%, a significant improvement over baseline methods. For instance, applying the framework to DeepSeekV2 boosted its performance from 55.35% to 64.25%.

Conclusion

By treating intention extraction as a "Chain of Thought" reasoning bridge, this framework significantly improves the reliability of automated code refinement. While "General Suggestions" remain a complex challenge due to their linguistic diversity, the use of structured templates and contextual data like ReviewLine provides a robust path forward for AI-assisted software development.

Summary updated

BibTeX
@inproceedings{guo2025intention,
  author = {Qi Guo and Xiaofei Xie and Shangqing Liu and Ming Hu and Xiaohong Li and Lei Bu},
  title = {{Intention is All You Need: Refining Your Code from Your Intention}},
  booktitle = {ICSE},
  year = {2025},
  doi = {10.1109/icse55347.2025.00191},
}
Figure