TRANSAGENT: An LLM-Based Multi-Agent System for Code Translation

Zhiqiang Yuan, Weitong Chen, Hanlin Wang, Kai Yu, Xin Peng, Yiling Lou · OpenReview

TL;DR

This paper introduces TRANSAGENT, a novel multi-agent system that significantly improves Large Language Model (LLM)-based code translation by precisely identifying and fixing syntax and semantic errors. By leveraging fine-grained execution alignment between source and target code, TRANSAGENT achieves state-of-the-art performance and offers a more robust and efficient solution for code translation.

What Problem Does This Paper Address?

Code translation, the process of converting code from one programming language to another while preserving functionality, is vital for software modernization and cross-platform development. While traditional rule-based methods are laborious and often produce less readable code, learning-based approaches, especially those powered by LLMs, have shown great promise. However, LLM-generated code frequently contains syntax and semantic errors, and existing LLM-based fixing strategies often struggle with vague error messages and the complexity of pinpointing the exact cause of semantic issues. This paper tackles the challenge of improving the accuracy and reliability of LLM-based code translation by developing a system that can effectively localize and fix these errors.

Methods

TRANSAGENT is a multi-agent system designed to enhance LLM-based code translation. It comprises four key agents:

  • Initial Code Translator: Generates test cases and an initial translated program from the source code.
  • Syntax Error Fixer: Identifies and corrects syntax errors by leveraging compiler feedback and LLM-based self-debugging. It iteratively refines the code until syntax errors are resolved.
  • Code Aligner: This is a novel component that uses control flow graphs (CFGs) to decompose the source code into atomic blocks. It then employs LLMs to map these source blocks to their semantically equivalent counterparts in the target program. This block-level alignment is more robust than statement-level mapping, handling issues like line shifts.
  • Semantic Error Fixer: This agent localizes semantic errors by comparing the runtime behaviors of aligned source and target code blocks. It then uses LLMs, guided by runtime value differences and two fixing strategies (vanilla and value-aware), to generate precise patches for the identified error blocks.

The core innovation lies in the fine-grained execution alignment performed by the Code Aligner and Semantic Error Fixer, which allows for precise error localization and targeted repair, unlike previous methods that relied on broader, less precise error signals.

Datasets

The authors constructed a new benchmark for code translation by collecting solutions from recent programming competition tasks released after August 2023. This was done to mitigate potential data leakage issues common in existing benchmarks. The benchmark consists of 210 Python-Java, 200 Python-C++, and 204 Java-C++ translation task pairs. Additionally, they used the benchmark released by Rozière et al. [55] for further evaluation and generalization testing.

Key Insights and Ideas

  • Block-level alignment is crucial: Simply aligning code at the statement level (as in TRANSMAP) is fragile. Decomposing code into semantically coherent blocks using CFGs and then using LLMs for alignment provides a more robust foundation for error localization.
  • Runtime execution comparison is key for semantic errors: Pinpointing semantic errors requires more than just static analysis or end-to-end test case validation. Comparing intermediate runtime states of source and target code blocks reveals subtle discrepancies that LLMs can then use to fix errors.
  • Hybrid mapping strategies are powerful: Combining program analysis (CFG) with LLM capabilities in the Code Aligner leads to significantly more accurate block mapping than relying solely on LLMs.
  • Value-aware fixing complements vanilla fixing: For semantic errors, providing LLMs with both the code context (vanilla) and specific runtime values (value-aware) leads to better repair outcomes, suggesting these strategies are complementary.
  • LLMs can generalize well with the right framework: TRANSAGENT demonstrates that even with different LLMs, the multi-agent approach consistently improves translation performance, highlighting the effectiveness of the system's architecture.

Key Results

  • Overall Effectiveness: TRANSAGENT significantly outperforms state-of-the-art transpilers like UNITRANS and TRANSCODER. On their new benchmark, it achieved a 33.3% higher accuracy than UNITRANS on the Python-to-Java task.
  • Repair Accuracy: TRANSAGENT demonstrates superior program repair capabilities, achieving 56.7% higher accuracy than AGENTLESS and 14.5% higher than TRANSAGENTTM (which uses TRANSMAP for mapping).
  • Efficiency: TRANSAGENT completes repairs in an average of 19 seconds per example, which is faster than UNITRANS (24 seconds), and typically requires no more than two iterations for repair.
  • Ablation Study: Both the Syntax Error Fixer and Semantic Error Fixer agents contribute substantially to TRANSAGENT's performance, with the Semantic Error Fixer showing significant gains due to its fine-grained fault localization.
  • Generalization: TRANSAGENT shows effective generalization across different LLMs, including smaller models like Llama-3-8B-Instruct and ChatGLM2-6b, as well as a larger model like Deepseek-Coder-33b-instruct.

Limitations and Future Work

  • Source Program Executability: TRANSAGENT assumes the source program is executable to obtain runtime feedback. If the source code is not runnable, the system may fail.
  • Data Leakage Mitigation: While the authors constructed a new benchmark to mitigate data leakage, the potential for LLMs to have been trained on similar recent code remains a concern.
  • Future Work: The authors suggest that TRANSAGENT's ability to handle complex function-level code and its stable performance make it a promising candidate for integration into project-level translation workflows, which often use decompositional paradigms. Further research could explore extending TRANSAGENT to handle larger, more complex projects.

Summary updated

BibTeX
@article{yuan2026transagent,
  author = {Zhiqiang Yuan and Weitong Chen and Hanlin Wang and Kai Yu and Xin Peng and Yiling Lou},
  title = {{TRANSAGENT: An LLM-Based Multi-Agent System for Code Translation}},
  journal = {Proc. ACM Softw. Eng.},
  year = {2026},
  doi = {10.1145/3797099},
}
Figure