用基准测试驱动大模型翻译,把生产级Rust代码转成更简洁的Python,还能扩展新功能。
From Translation to Superset: Benchmark-Driven Evolution of a Production AI Agent from Rust to Python
- 用大模型+基准测试迭代翻译,实现Rust到Python的持续迁移。
- Python版在80个任务中解决59个(73.8%),终端任务得分42.5%,接近原Rust性能。
- 不仅保持功能对齐,还新增多智能体、安全守护等30个新特性,适合进阶开发。
大型软件系统跨语言迁移是长期工程挑战,尤其当源代码快速演进时。本文提出一种由大语言模型辅助的持续代码翻译方法,将一个生产级Rust代码库(648K LOC,65个crates)翻译为Python(41K LOC,28个模块),以公开代理基准测试作为目标函数驱动迭代优化。研究对象为Codex CLI,一款生产级AI编程代理。实验表明:(1)Python版本在80个SWE-bench Verified任务中解决59个(73.8%),优于Rust的56个(70.0%),终端任务得分42.5%对47.5%,实证其在真实代理任务中近乎对等;(2)基于基准的调试揭示了API协议不匹配、环境污染、沉默的WebSocket失败模式及API 400崩溃等问题,优于静态测试;(3)架构支持通过LLM辅助的diff-translate-test循环实现持续上游同步;(4)Python版本已演化为功能超集,包含30个特性开关扩展(如多智能体编排、语义记忆、守护安全、成本追踪),同时保留严格对等模式用于对比。评估显示,在以API延迟为主的LLM代理场景下,Python表达性带来15.9倍代码量缩减,性能损失可忽略,而‘基准即目标’的方法论为跨语言移植从对等演进至扩展平台提供了系统框架。
原文摘要 · Abstract (English)
Cross-language migration of large software systems is a persistent engineering challenge, particularly when the source codebase evolves rapidly. We present a methodology for LLM-assisted continuous code translation in which a large language model translates a production Rust codebase (648K LOC, 65 crates) into Python (41K LOC, 28 modules), with public agent benchmarks as the objective function driving iterative refinement. Our subject system is Codex CLI, a production AI coding agent. We demonstrate that: (1) the Python port resolves 59/80 SWE-bench Verified tasks (73.8%) versus Rust's 56/80 (70.0%), and achieves 42.5% on Terminal-Bench versus Rust's 47.5%, confirming near-parity on real-world agentic tasks; (2) benchmark-driven debugging, revealing API protocol mismatches, environment pollution, a silent WebSocket failure mode, and an API 400 crash, is more effective than static testing alone; (3) the architecture supports continuous upstream synchronisation via an LLM-assisted diff-translate-test loop; and (4) the Python port has evolved into a capability superset with 30 feature-flagged extensions (multi-agent orchestration, semantic memory, guardian safety, cost tracking) absent from Rust, while preserving strict parity mode for comparison. Our evaluation shows that for LLM-based agents where API latency dominates, Python's expressiveness yields a 15.9x code reduction with negligible performance cost, while the benchmark-as-objective-function methodology provides a principled framework for growing a cross-language port from parity into an extended platform.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。