[Paper Review] Semantic Alignment-Enhanced Code Translation via an LLM-Based Multi-Agent System
TransAGENT is a multi-agent LLM system that enhances code translation by iteratively fixing syntax and semantic errors through four specialized agents: Initial Code Translator, Syntax Error Fixer, Code Aligner, and Semantic Error Fixer. By leveraging execution-aligned code block localization, it improves translation accuracy and efficiency over UniTrans, especially on small LLMs, with a 0.65% absolute gain on LLaMA-7B for Java-to-Python translation.
Code translation converts code from one programming language to another while maintaining its original functionality, which is crucial for software migration, system refactoring, and cross-platform development. Traditional rule-based methods rely on manually-written rules, which can be time-consuming and often result in less readable code. To overcome this, learning-based methods have been developed, leveraging parallel data to train models for automated code translation. More recently, the advance of Large Language Models (LLMs) further boosts learning-based code translation. Although promising, LLM-translated program still suffers from diverse quality issues (e.g., syntax errors and semantic errors). In particular, it can be challenging for LLMs to self-debug these errors when simply provided with the corresponding error messages. In this work, we propose a novel LLM-based multi-agent system TRANSAGENT, which enhances LLM-based code translation by fixing the syntax errors and semantic errors with the synergy between four LLM-based agents, including Initial Code Translator, Syntax Error Fixer, Code Aligner, and Semantic Error Fixer. The main insight of TRANSAGENT is to first localize the error code block in the target program based on the execution alignment between the target and source program, which can narrow down the fixing space and thus lower down the fixing difficulties. To evaluate TRANSAGENT, we first construct a new benchmark from recent programming tasks to mitigate the potential data leakage issue. On our benchmark, TRANSAGENT outperforms the latest LLM-based code translation technique UniTrans in both translation effectiveness and efficiency; additionally, our evaluation on different LLMs show the generalization of TRANSAGENT and our ablation study shows the contribution of each agent.
Motivation & Objective
- To address the persistent challenge of syntax and semantic errors in LLM-based code translation, especially when using small models.
- To improve translation correctness and efficiency by enabling LLMs to self-debug with structured, collaborative agent workflows.
- To develop a robust, generalizable method for cross-language program mapping that is resilient to code reordering and structural changes.
- To reduce error-fixing difficulty by localizing problematic code blocks using execution alignment between source and target programs.
- To evaluate the system on a new benchmark that mitigates data leakage and demonstrates generalization across different LLMs.
Proposed method
- The system employs four LLM-based agents: Initial Code Translator generates an initial translation using test cases; Syntax Error Fixer corrects compilation errors via error message analysis and patch generation.
- The Code Aligner uses control flow graphs to divide source and target programs into logical blocks and maps them using LLMs, enabling fine-grained error localization.
- The Semantic Error Fixer identifies functional discrepancies by comparing execution outputs and uses execution-aligned values to guide targeted repairs.
- Error localization is achieved through execution alignment—comparing runtime behaviors under the same test inputs to isolate faulty code blocks.
- The agents collaborate iteratively: after syntax fixes, execution results are re-evaluated, and semantic errors are addressed in a feedback loop.
- A new benchmark is constructed from recent programming tasks to prevent data leakage and ensure fair evaluation.

Experimental results
Research questions
- RQ1Can a multi-agent system improve the correctness of LLM-based code translation by systematically addressing syntax and semantic errors?
- RQ2How effective is execution alignment in localizing error-prone code blocks across different programming languages?
- RQ3Does the proposed multi-agent workflow outperform existing iterative fixing methods like UniTrans in both accuracy and efficiency?
- RQ4To what extent does TransAGENT generalize across different LLM sizes and architectures?
- RQ5How do individual agents contribute to the overall performance improvement?
Key findings
- TransAGENT outperforms UniTrans in both translation effectiveness and efficiency on the new benchmark, demonstrating superior error correction capability.
- On LLaMA-7B, TransAGENT improves translation accuracy from 31.25% to 31.90% for Java-to-Python translation, a 0.65% absolute gain, indicating effectiveness even on small models.
- The ablation study confirms that each agent contributes meaningfully to the final performance, with the Code Aligner and Semantic Error Fixer playing critical roles in localization and functional correction.
- The user study shows that TransAGENT’s code mapping accuracy significantly exceeds that of TransMap, a state-of-the-art LLM-based mapping method.
- The system generalizes well across different LLMs, indicating its compatibility and robustness beyond a single model architecture.
- Execution alignment via control flow block mapping reduces error-fixing difficulty by narrowing the search space to semantically relevant code segments.

Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.