AI code translation methods, systems, devices, and storage media based on multi-agent systems.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-20
- Publication Date
- 2026-08-14
AI Technical Summary
第一,缺乏私有框架语义理解能力
[0019]本发明的目的在于提供基于多智能体的AI代码转译方法、系统、设备及存储介质,能够实现任意开发语言自身及跨语言的高效、稳定、准确的自动化代码转译。
Smart Images

Figure CN122569972A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of AI code translation, and more specifically, to AI code translation methods, systems, devices, and storage media based on multi-agent systems. Background Technology
[0002] With the rapid development of artificial intelligence technology, Large Language Models (LLMs) are increasingly widely used in software engineering, and the software development lifecycle is rapidly evolving from "moderate autonomy" to "high autonomy." Currently, some general-purpose AI coding tools have emerged in the market, performing well in short tasks such as unit test generation and simple logic refactoring. However, these general-purpose tools still have the following significant limitations when facing enterprise-level large-scale code repository migration, cross-language translation, and architecture upgrade tasks: First, there is a lack of semantic understanding of proprietary frameworks. General-purpose AI coding tools lack a deep understanding of enterprise proprietary frameworks (such as CRN, xTaro, and other mobile frameworks). When dealing with the mapping relationships and business logic of proprietary components, they are prone to "hallucination," resulting in unusable translation results and requiring extensive manual correction. This is because the training data of general-purpose models rarely contains the API semantics and design patterns of enterprise-developed frameworks, causing the models to only perform speculative reasoning when faced with these proprietary components.
[0003] Second, long-chain tasks suffer from poor stability. Existing tools are primarily designed for single-file or small-scale code modifications. Due to the inherent limitations of large model context windows, they are prone to "memory forgetting" when executing large-scale migration tasks spanning dozens or even hundreds of files. Specifically, when the model processes the Nth file, it may have forgotten the type aliases or utility function signatures defined in the first file. Furthermore, the task state cannot be persistently managed. If API rate limiting, network jitter, or server timeouts occur, the entire migration task will frequently interrupt and is difficult to resume from the breakpoint, resulting in extremely low automation rates.
[0004] Third, insufficient dependency analysis capabilities. Enterprise-level code repositories contain complex, multi-layered nested dependencies, such as multi-level inheritance, multiple interface implementations, and dynamic method calls (reflection) in Java, as well as dynamic imports and circular dependencies in JavaScript projects. General-purpose AI tools can only perform inference based on the surface patterns of the code text, making it difficult to accurately parse the above-mentioned static structural dependencies. This can easily lead to the omission of key dependencies, resulting in missing code logic or runtime errors after migration.
[0005] Fourth, expanding into new scenarios is costly. Faced with different technology stack migration scenarios, such as migrating a mobile framework from CRN to xTaro, a backend language from Java BFF to Node BFF, or upgrading the JDK version from 8 to 21, existing tools lack standardized development paradigms. Each adaptation to a new scenario requires redesigning the prompt word project, debugging the model output, and manually verifying the translation results, making it impossible to accumulate reusable technical assets and resulting in huge, repetitive investments.
[0006] The aforementioned technological bottlenecks have led to massive demands for maintaining existing codebases and upgrading technology stacks for internet companies, often requiring thousands of man-days of work. This still relies heavily on manual labor, resulting in low efficiency, high error rates, and high costs associated with parallel development. Therefore, there is an urgent need for an intelligent code translation solution that can deeply understand enterprise private domain knowledge, possess long-term stable reasoning capabilities, and is highly scalable.
[0007] In view of this, the present invention provides an AI code translation method, system, device and storage medium based on multi-agent systems. Summary of the Invention
[0008] To address the problems in the prior art, the present invention aims to provide an AI code translation method, system, device, and storage medium based on multi-agent technology, which overcomes the difficulties of the prior art and can achieve efficient, stable, and accurate automated code translation for any development language itself and across languages.
[0009] Embodiments of the present invention provide a multi-agent-based AI code translation method, comprising the following steps: S100. In response to the received code translation request, the master agent (intelligent agent) performs scene recognition and task decomposition on the target migration task based on the ReAct (a compound word of Reasoning + Acting) reasoning-action cycle paradigm, and generates an execution plan containing multiple sub-tasks. S200. The context engineering component dynamically retrieves the code context information associated with the subtask and monitors the token (the smallest semantic unit in natural language processing) consumption in real time. When the token consumption reaches a preset threshold, it automatically performs a hierarchical compression operation on the historical inference record to release the context window. During any of the aforementioned steps, the task state management layer persists the execution progress and intermediate results in real time. S300: The Agent calls the CodeIndex (code index) deep dependency analysis layer, generates a full-link call dependency tree with the target function in the source project as the entry point, and injects the dependency tree as objective data into the inference context; S400, The execution agent calls the enterprise-level private domain knowledge base and the RAG (Retrieval Enhancement Generation) retrieval layer, dynamically recalls component mapping rules and Few-shots examples based on the semantic features of the current code to be translated, and injects the inference context; S500, the execution agent performs a code translation operation based on the inference context injected with the objective data, the mapping rules, and the Few-shots examples, to generate the target code fragment; S600: The verification agent performs syntax verification and dependency integrity verification on the target code segment. If the verification passes, proceed to step S700. If the verification fails, generate a correction instruction and feed it back to the execution agent for iterative correction. S700: Summarize the target code snippets of all subtasks, generate the complete target project code, and output the translation results.
[0010] Preferably, the hierarchical compression operation in step S200 includes: retaining the complete interaction record of the latest ReAct loop, summarizing the tool call results in the historical loops into a structured observation summary, and injecting the observation summary into the context window to replace the original log.
[0011] Preferably, the generation of the full-link call dependency tree in step S300 includes: for JavaScript (a web scripting language) or TypeScript (a superset of JavaScript with an added type system) projects, using an Abstract Syntax Tree (AST) to analyze the recursive parsing module import and function call relationships; for Java (an object-oriented programming language) projects, using Maven (a project management and automatic build tool for Java projects) dependency parsing and JAR (Java Archive, used to package Java classes, resources, etc.) bytecode decompilation to parse multi-level inheritance relationships and dynamic method call chains.
[0012] Preferably, step S400 further includes: the enterprise-level private domain knowledge base collects the official documents of the source framework and the target framework, uses a large language model to generate structured component mapping rules in batches, and stores them in the ES (Elasticsearch, here referring to a quantitative database engine) vector database, supporting one-click batch updates.
[0013] Preferably, step S500 further includes: the execution agent simultaneously supports two runtime environments, MCP (Model Context Protocol) and Terminal, and automatically selects the corresponding toolset execution environment according to the type of the subtask.
[0014] Preferably, in step S200, the task state management layer persists the execution progress and intermediate results in real time, including: in response to a task interruption signal, the task state management layer records the inference chain state of the current ReAct loop and the action queue to be executed; in response to a resume command, the inference chain state and the action queue are loaded with a task identifier via the resume-task command, and execution continues from the breakpoint.
[0015] Preferably, the dependency integrity check performed by the verification Agent includes: comparing the import declarations in the target code snippet with the module list in the end-to-end call dependency tree to detect whether there are missing dependency references or redundant unused dependencies.
[0016] Embodiments of the present invention also provide a multi-agent-based AI code translation system for implementing the above-described multi-agent-based AI code translation method, wherein the multi-agent-based AI code translation system includes: The translation request module responds to the received code translation request. The main control agent performs scene identification and task decomposition on the target migration task based on the ReAct reasoning-action loop paradigm, and generates an execution plan containing multiple sub-tasks. The consumption monitoring module and the context engineering component dynamically retrieve the code context information associated with the subtask and monitor the token consumption in real time. When the token consumption reaches a preset threshold, the historical inference record is automatically compressed to release the context window. During any of the aforementioned steps, the task status management layer persists the execution progress and intermediate results in real time. The analysis and reasoning module executes the Agent to call the CodeIndex deep dependency analysis layer, generates a full-link call dependency tree with the target function in the source project as the entry point, and injects the dependency tree as objective data into the reasoning context; The component mapping module, wherein the execution agent calls the enterprise-level private domain knowledge base and RAG retrieval layer, dynamically recalls component mapping rules and Few-shots examples based on the semantic features of the current code to be translated, and injects them into the inference context; The code translation module, wherein the execution agent performs a code translation operation based on the inference context injected with the objective data, the mapping rules, and the Few-shots examples, to generate the target code fragment; The syntax verification module verifies the target code snippet by verifying the Agent's syntax and dependency integrity. If the verification passes, it is transferred to the output translation module. If the verification fails, a correction instruction is generated and fed back to the execution Agent for iterative correction. The output translation module summarizes the target code snippets from all subtasks, generates the complete target project code, and outputs the translation results.
[0017] Embodiments of the present invention also provide an AI code translation device based on multiple agents, comprising: processor; A memory in which executable instructions of the processor are stored; The processor is configured to execute the steps of the multi-agent-based AI code translation method described above by executing the executable instructions.
[0018] Embodiments of the present invention also provide a computer-readable storage medium for storing a program that, when executed, implements the steps of the above-described multi-agent-based AI code translation method.
[0019] The purpose of this invention is to provide an AI code translation method, system, device, and storage medium based on multi-agent systems, which can achieve efficient, stable, and accurate automated code translation for any development language and across languages. Attached Figure Description
[0020] Other features, objects, and advantages of the invention will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings.
[0021] Figure 1 This is a flowchart of the AI code translation method based on multi-agent technology of the present invention.
[0022] Figure 2 This is a schematic diagram of the architecture of the AI code translation method based on multi-agent systems that implements the present invention.
[0023] Figure 3 This is a schematic diagram of the CodeIndex deep dependency analysis layer for implementing the multi-agent AI code translation method of the present invention.
[0024] Figure 4 This is a system architecture diagram of the AI code translation system based on multi-agent technology of the present invention.
[0025] Figure 5 This is a schematic diagram of the structure of the AI code translation device based on multiple agents according to the present invention.
[0026] Figure 6This is a schematic diagram of the structure of a computer-readable storage medium according to an embodiment of the present invention. Detailed Implementation
[0027] The following specific examples illustrate the implementation methods of this application. Those skilled in the art can easily understand the other advantages and effects of this application from the content disclosed herein. This application can also be implemented or applied through other different specific embodiments, and various details in this application can be modified or changed according to different viewpoints and application systems without departing from the spirit of this application. It should be noted that, unless otherwise specified, the embodiments and features in the embodiments of this application can be combined with each other.
[0028] The embodiments of this application will now be described in detail with reference to the accompanying drawings, so that those skilled in the art can easily implement the application. This application may be embodied in many different forms and is not limited to the embodiments described herein.
[0029] In this application, the terms "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics represented in connection with that embodiment or example, which are included in at least one embodiment or example of this application. Furthermore, the specific features, structures, materials, or characteristics represented may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate different embodiments or examples represented in this application, as well as features of different embodiments or examples.
[0030] Furthermore, the terms "first" and "second" are used for illustrative purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the representation of this application, "multiple" means two or more, unless otherwise explicitly specified.
[0031] For the purpose of clearly describing this application, devices that are not relevant to the description are omitted, and the same or similar components throughout the specification are given the same reference numerals.
[0032] Throughout this specification, when it is said that a device is "connected" to another device, this includes not only "direct connection" but also "indirect connection" by placing other components in between. Furthermore, when it is said that a device "comprises" a certain constituent element, unless otherwise stated otherwise, this does not exclude other constituent elements, but rather implies that other constituent elements may be included.
[0033] When we say that a device is "above" another device, this can mean that it is directly above the other device, or it can mean that other devices are present in between. Conversely, when we say that a device is "directly" "above" another device, there are no other devices present in between.
[0034] Although the terms first, second, etc., are used in some instances herein to refer to various elements, these elements should not be limited by these terms. These terms are used only to distinguish one element from another. For example, first interface and second interface, etc., are used. Furthermore, as used herein, the singular forms “a,” “an,” and “the” are intended to also include the plural forms unless the context indicates otherwise. It should be further understood that the terms “comprising,” “including,” indicate the presence of features, steps, operations, elements, components, items, kinds, and / or groups, but do not exclude the presence, occurrence, or addition of one or more other features, steps, operations, elements, components, items, kinds, and / or groups. The terms “or” and “and / or” as used herein are interpreted as inclusive, or mean any one or any combination thereof. Thus, “A, B, or C” or “A, B, and / or C” means “any one of: A; B; C; A and B; A and C; B and C; A, B, and C.” Exceptions to this definition will only occur if the combination of elements, functions, steps, or operations is inherently mutually exclusive in some way.
[0035] The technical terms used herein are for reference only to specific embodiments and are not intended to limit the scope of this application. The singular form used herein includes the plural form unless the statement explicitly indicates otherwise. The word "comprising" as used in the specification means to specify a particular characteristic, region, integer, step, operation, element, and / or component, and does not exclude the presence or addition of other characteristics, regions, integers, steps, operations, elements, and / or components.
[0036] Although not explicitly defined, all terms, including technical and scientific terms used herein, shall have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains. Terms defined in commonly used dictionaries shall be further interpreted as having a meaning consistent with the relevant technical literature and the content of this present application, and shall not be over-interpreted as having an ideal or overly formulaic meaning unless otherwise defined.
[0037] Figure 1 This is a flowchart of the AI code translation method based on multi-agent technology of the present invention. Figure 1 As shown, the AI code translation method based on multi-agent systems of the present invention includes the following steps: S100. In response to the received code translation request, the master agent performs scenario identification and task decomposition on the target migration task based on the ReAct reasoning-action loop paradigm, and generates an execution plan containing multiple sub-tasks.
[0038] S200: The context engineering component dynamically retrieves code context information associated with subtasks and monitors token consumption in real time. When token consumption reaches a preset threshold, it automatically performs hierarchical compression on historical inference records to release the context window. During any of the aforementioned steps, the task state management layer persists execution progress and intermediate results in real time.
[0039] S300: The Agent calls the CodeIndex deep dependency analysis layer, generates a full-link call dependency tree with the target function in the source project as the entry point, and injects the dependency tree as objective data into the inference context.
[0040] S400: The Agent calls the enterprise-level private domain knowledge base and RAG retrieval layer, dynamically recalls component mapping rules and Few-shots examples based on the semantic features of the code to be translated, and injects the inference context.
[0041] S500: The execution agent performs code translation operations based on the inference context injected with objective data, mapping rules, and Few-shots examples, generating target code snippets.
[0042] S600: The verification agent performs syntax verification and dependency integrity verification on the target code segment. If the verification passes, proceed to step S700. If the verification fails, a correction instruction is generated and fed back to the execution agent for iterative correction.
[0043] S700: Summarize the target code snippets of all subtasks, generate the complete target project code, and output the translation results.
[0044] In this preferred embodiment, the master agent incorporates a scene classifier during scene recognition. This classifier, based on a lightweight machine learning model, extracts source file extensions, build configuration file features (such as pom.xml, package.json, and build.gradle), and framework-specific annotations (such as Spring's @RestController and React's useState) from code translation requests as multi-dimensional feature vectors. These vectors are then matched against a predefined scene template library. The scene template library contains 12 sub-scenes across four main categories: cross-framework migration, cross-language translation, version upgrades, and build system migration. Upon successful matching, the master agent invokes a task decomposer based on a graph decomposition algorithm. This decomposer takes the source project's directory structure as input, constructs a directed acyclic graph of file-level dependencies, and then generates a sequence of subtasks in topological order. Each subtask carries metadata tags, including file path, dependency depth, estimated token consumption, and priority. The execution plan is written line by line in JSON Lines format to the plan.json file in the working directory. A status marker is appended to this file after each subtask is completed. This design allows the master agent to quickly recover its task decomposition state by rereading the plan.jsonl file even if it restarts abnormally, without needing to reanalyze the entire project. By introducing a scene classifier based on multi-dimensional feature vectors, this preferred embodiment improves scene recognition accuracy from 72% for general rule matching to over 96%, effectively avoiding incorrect translation strategy selection due to scene misjudgment. The application of the graph decomposition algorithm enables task decomposition at the file level, strictly adhering to dependency order. Compared to traditional manual decomposition or simple alphabetical decomposition, the number of iterations for correction due to missing dependencies is reduced by an average of 63%. The line-by-line persistence mechanism of plan.jsonl reduces the restart recovery time of the master agent from minutes to seconds and supports incremental task appending, providing a reliable engineering foundation for migrating large-scale projects (more than 5000 files).
[0045] In a preferred embodiment, the hierarchical compression operation in step S200 includes: retaining the complete interaction record of the latest ReAct loop, summarizing the tool call results from historical loops into a structured observation summary, and injecting the observation summary into the context window to replace the original log. In this preferred embodiment, the context engineering component maintains a circular buffer, the size of which is dynamically set according to the upper limit of the context window of the target large model, and by default retains the complete interaction record of the most recent 3 ReAct loops. For the 4th loop and earlier historical loops, the hierarchical compression operation starts a summary generator. The summary generator first identifies the type of tool call result: if it is a file reading result, it extracts the file name, file size, list of defined class names, and list of function signatures, discarding the specific function body implementation. If it is a directory list result, it extracts the subdirectory names and file name list, discarding metadata such as file permissions and timestamps. If it is a code search result, it extracts the matching line number range and the first and last two lines of the matching segment, discarding large blocks of code in the middle. The extracted structured information is reorganized into an "observation summary" object according to a predefined summary template, which contains three fields: source, summary_type, and content_triple. When injecting the context window, the original tool call result is completely replaced with the observation summary object, while retaining the file path hash value of the original result as a reference so that detailed content can be accurately retrieved from the local cache using the hash value. After compression, the component updates a compression counter and records the compression action in the translation log for subsequent debugging and analysis. The layered compression operation of this preferred embodiment solves the fundamental problem of context window overflow in long-chain tasks. Test data shows that when translating a Java project containing 300 files, the control group without compression crashed at the 47th file due to token overload, while the experimental group with layered compression successfully completed the entire translation, with the peak token consumption being only 78% of the window limit. Compared with the crude compression method of simply truncating historical records, this method retains the complete context of the latest round, ensuring that the accuracy of the current inference step is not affected, while controlling the semantic loss of historical information to within 12%, which has a negligible impact on subsequent inference. The introduction of structured observation summaries ensures that the compressed context remains in a machine-readable format, facilitating possible automated analysis and debugging.
[0046] In a preferred embodiment, generating the full-link call dependency tree in step S300 includes: for JavaScript or TypeScript projects, using AST (Abstract Syntax Tree) analysis to recursively parse module import and function call relationships. For Java projects, using Maven dependency parsing and JAR bytecode decompilation to parse multi-level inheritance relationships and dynamic method call chains. In this preferred embodiment, the CodeIndex deep dependency analysis layer for JavaScript / TypeScript projects first calls esprima or @babel / parser to generate an AST, and then traverses the ImportDeclaration and CallExpression nodes in the AST. For dynamic imports (such as import() function calls), the analyzer simulates the module parsing algorithm at runtime, searching the local file system, node_modules directory, and paths mapping configured in tsconfig.json according to the target path pattern (relative path, npm package name, path alias). For Java projects, the analyzer first calls the Maven Resolver API to parse pom.xml and downloads all declared dependency JAR packages to the local cache repository. Subsequently, the ASM bytecode manipulation framework is used to traverse the .class files in each JAR package. For multi-level inheritance relationships, the analyzer recursively traverses the parent class chain upwards until it reaches `java.lang.Object`, recording all non-private methods defined in the parent classes along the way in the dependency tree. For dynamic method calls (such as `Method.invoke()`), the analyzer cannot determine the specific target during the static analysis phase. In this case, a heuristic rule is used: the parameter types and return types of the method containing the dynamic call are scanned, and all candidate methods matching these types are added to the dependency tree and marked as "dynamic candidate" nodes. All analysis results are stored in a graph database as a list of directed edges, supporting subsequent dependency impact range queries. This preferred embodiment's dual-engine design enables CodeIndex to cover more than 95% of dependency types in enterprise-level code repositories. For dynamic import parsing of JavaScript / TypeScript, the accuracy reaches 98.7%, far exceeding the limitation of general-purpose tools (such as the TypeScript compiler itself) which can only parse static imports. For Java projects, ASM bytecode decompilation technology allows the analyzer to accurately parse method signatures and inheritance relationships in third-party JAR packages without relying on source code, solving the dependency analysis problem in scenarios where enterprises use a large number of closed-source JAR packages. While heuristic parsing of dynamic method calls cannot achieve 100% accuracy, the average size of the candidate method set is 2.3, and in actual migration tests, 92% of the cases correctly included the target in the candidate set, providing a minimized search space for subsequent manual intervention.A complete record of the multi-level inheritance chain ensures that the translated code correctly preserves the base class methods, avoiding runtime errors such as "method not defined" caused by the loss of inheritance information.
[0047] In a preferred embodiment, step S400 further includes: the enterprise-level private domain knowledge base collects official documents of the source and target frameworks, generates structured component mapping rules in batches using a large language model, and stores them in an ES vector database, supporting one-click batch updates. In this preferred embodiment, the enterprise-level private domain knowledge base includes an automated document crawler module, which supports customized crawling rules for different document sites. For static sites (such as documents hosted on GitHub Pages), a full crawl is performed using recursive HTTP GET requests in conjunction with robots.txt compliance policies. For dynamic sites (such as Confluence and ReadTheDocs), the crawler is performed after rendering using the Puppeteer framework, which simulates browser behavior. The crawled HTML pages undergo a cleaning pipeline: noisy blocks such as navigation bars, footers, and advertisements are removed, and the heading hierarchy (h1 to h6) and body paragraphs are extracted. The cleaned text is divided into document fragments by chapter, with each fragment size controlled within 1024 tokens. Subsequently, large language models such as GPT-4 or Claude-3 are invoked, guided by a carefully designed few-shot prompt template to extract component mapping relationships from each document fragment. The prompt template includes examples of component naming conventions specific to the OTA industry, such as "CRNView maps to View" and "onClick maps to onTap". The model outputs a structured JSON object containing five fields: source_component, target_component, property_mapping (a list of key-value pairs), lifecycle_mapping (a table of lifecycle methods), and example_snippet (example code snippet). After manual sampling and verification, the generated JSON objects are batch-written into an Elasticsearch vector database, with the index fields being the attribute names from source_component and property_mapping. A one-click batch update function is implemented through a CLI command, "knowledge-base update –f . / new_rules.json". This command compares the existing index and only re-embeds and updates the index of newly added or modified documents; the update time is linearly related to the incremental data volume. The knowledge base construction method of this preferred embodiment compresses the component mapping work, which originally required weeks of manual compilation, into a matter of hours. In a real-world project transitioning from CRN to xTaro, this method generated over 2000 structured mapping rules, and manual verification revealed an error rate of only 3.5%, far lower than the expected error rate (approximately 12%) for purely manual compilation. The introduction of the ES vector database keeps the response time for a single semantic retrieval within 50 milliseconds, supporting over 1000 high-concurrency recall requests per second.The one-click batch update function ensures that the knowledge base stays synchronized with the framework's official documentation. When xTaro releases a new version, operations and maintenance personnel only need to re-crawl the updated documentation and execute the update command. The incremental update time is no more than 10 minutes, ensuring the timeliness of the knowledge base. Compared to the traditional hard-coded mapping rules, this solution improves maintainability by two orders of magnitude.
[0048] In a preferred embodiment, step S500 further includes: the execution agent simultaneously supports both the MCP model context protocol and the Terminal runtime environment, automatically selecting the corresponding toolset execution environment based on the type of the subtask. In this preferred embodiment, the execution agent maintains an environment routing table internally, with the subtask type label as the key and the runtime environment identifier as the value. The subtask type label is generated by the master agent during task decomposition and includes four categories: "source_code_transformation" (plain text translation), "dependency_resolution" (dependency resolution), "compilation_check" (compilation check), and "test_execution" (test execution). For subtasks of type "source_code_transformation", the environment routing table points to the MCP environment. In the MCP environment, the execution agent communicates with the model service process through standard input / output streams, encapsulating requests and responses using the JSON-RPC 2.0 protocol. This environment is optimized for plain text operations, eliminating file system call overhead, and reducing single translation latency by approximately 40% compared to the general environment. For subtasks of type "dependency_resolution", "compilation_check", and "test_execution", the environment routing table points to the Terminal environment. In the Terminal environment, the execution agent starts an independent shell subprocess, inheriting the current user's environment variables (such as JAVA_HOME and PATH) and switching the working directory to the target project's root directory. The execution agent interacts with the subprocess via a PTY (pseudo-terminal), supporting interactive command input / output redirection. During subtask execution, the execution agent captures stdout and stderr streams in real time. When a compilation error is detected, the subprocess is immediately terminated, and the error information is encapsulated into structured observations. After environment selection, the execution agent loads the corresponding toolset for that environment: in the MCP environment, it loads a text transpilation toolset (including code formatting, comment transpilation, string encoding transpilation, etc.); in the Terminal environment, it loads a shell command toolset (including paths and parameter templates for executables such as mvn, npm, javac, and node). The dual-environment design of this preferred embodiment enables the execution agent to select the optimal execution path based on the characteristics of different subtasks, avoiding unnecessary process creation overhead in plain text translation tasks and avoiding misjudgments caused by the lack of a real runtime environment in compilation and checking tasks.Real-world testing data shows that in a Java-to-TypeScript project containing 500 files, approximately 70% of the subtasks are plain text translations, executed in the MCP environment, with an average translation time of 1.2 seconds per file. The remaining 30% of the subtasks are dependency resolution and compilation checks, executed in the Terminal environment, with an average translation time of 3.5 seconds. Compared to a single general-purpose environment solution, this solution reduces the total execution time by 52%. Real-time capture and structured encapsulation of compilation errors in the Terminal environment allow error messages to be directly parsed by the verification agent, eliminating the need for additional manual log analysis and improving iterative correction efficiency by 35%. The dynamic configurability of the environment routing table allows the system to flexibly adapt to new toolchains that may emerge in the future without modifying the core code of the execution agent.
[0049] In a preferred embodiment, step S700 further includes: in response to a task interruption signal, the task state management layer records the inference chain state and the queue of actions to be executed for the current ReAct loop. In response to a resume command, the inference chain state and the action queue are loaded via a resume-task command carrying a task identifier, and execution continues from the breakpoint. In this preferred embodiment, the task state management layer implements a state machine persistence engine. This engine maintains a snapshot of the current task's state in memory using a circular red-black tree structure, updating a node in the red-black tree after each atomic operation (e.g., a tool call or a model inference). An atomic operation is defined as the smallest indivisible unit of execution, including five categories: "LLM inference request," "file read," "file write," "command line execution," and "RAG retrieval." Each atomic operation corresponds to a state node, which contains the operation type, input parameters, output result, timestamp, and checksum. When a task interruption signal (SIGINT, SIGTERM, or a custom exception signal) is triggered, the engine captures the signal and calls a signal handling function. This function first pauses all ongoing atomic operations, waiting for them to reach a safe stopping point (i.e., a non-critical section). Then, it serializes all nodes in the red-black tree into a Protocol Buffers format binary file and writes it to the predefined `.checkpoints` directory. The filename format is "{task_id}_{timestamp}.ckpt". Simultaneously, the engine records the current ReAct loop pointer position, i.e., the index pointing to the last completed atomic operation node. Upon resumption, the user executes the command "flt-j2n resume-task –id{task_id}", and the engine scans the `.checkpoints` directory to find the latest checkpoint file matching `task_id`. After loading this file, the engine reconstructs the red-black tree structure and positions the ReAct loop pointer to the position before the interruption. The engine then continues execution from the next atomic operation pointed to by the pointer. If a checkpoint file checksum mismatch is found during resumption, it automatically rolls back to the last available checkpoint file to ensure state consistency. The state persistence mechanism of this preferred embodiment improves the precision of breakpoint resumption to the atomic operation level. Compared with traditional file-level or task-level breakpoints, the repetitive workload during recovery is reduced by more than 80%. In interrupt recovery tests under simulated high-load environments, the system was interrupted 100 times at random time points, and all of them successfully recovered from the breakpoints without any state inconsistencies or data corruption. The serialization efficiency of Protocol Buffers binary format is 3 times that of JSON format, and the file size is reduced by 65% after serialization, significantly reducing I / O overhead.The checksum mechanism ensures the integrity of the checkpoint file. In simulated disk corruption scenarios, the system can automatically roll back to the previous checkpoint, with the number of lost operations not exceeding one atomic operation, maximizing the continuity of task execution and data security. This mechanism is particularly suitable for elastic computing scenarios in cloud-native environments. When a Pod is evicted by the scheduler, the task state management layer can save the state to a persistent volume, allowing for seamless recovery after the Pod is rescheduled, achieving truly "uninterrupted" large-scale code migration.
[0050] In a preferred embodiment, the dependency integrity check performed by the verification agent includes: comparing the import declarations in the target code snippet with the module list in the full-chain call dependency tree to detect whether there are missing dependency references or redundant unused dependencies. In this preferred embodiment, the verification agent internally implements a dual-set comparison algorithm. First, all import declarations (import statements or require calls) are extracted from the target code snippet to construct a "set of imported modules" A. The extraction process uses regular expressions to match import syntax in different languages: for Java, it matches the pattern "import [static][package].[class];". For TypeScript / JavaScript, it matches "import { } from'module' and "const = require('module')" pattern. For Python, it matches "from module import". The code uses the "import module" pattern. Next, it extracts the fully qualified names of all called modules from the full-chain call dependency tree generated by CodeIndex, constructing a "required module set" B. During extraction, each node in the dependency tree is parsed, the "module_name" attribute of the node is obtained, and different class names of the same module are merged into one module entry. Then, the set difference C = B – A is calculated to obtain the list of missing dependency references. The set difference D = A – B is calculated to obtain the list of redundant unused dependencies. For each item in the missing dependency list, the verification Agent generates a structured error message, including the missing module name, the suggested import statement format, and the position (file path and line number) where the module is first referenced in the dependency tree. For each item in the redundant dependency list, a warning message is generated, suggesting the removal of the import statement. All error and warning messages are sorted by priority and encapsulated into a verification report object, which is passed to the correction instruction generator. This preferred embodiment of dependency integrity verification achieves fully automatic verification and error correction of the imported statements in the translated code. For a Spring application containing 150 files... In the testing of the Boot to NestJS project, the validation agent detected 47 missing dependencies and 23 redundant dependencies. The detection accuracy for missing dependencies reached 100%, and the accuracy for redundant dependencies reached 91% (the remaining 9% were false positives, mainly because some imports, although not directly called in the current file, were indirectly referenced by TypeScript type declaration files). After the correction instructions were generated, the execution agent successfully supplemented all 47 missing dependencies and removed 20 redundant dependencies in the next iteration, increasing the first-compilation pass rate of the transpiled code from 61% without validation to 94%. The time complexity of the dual-set comparison algorithm is O(n+m), where n and m are the sizes of the two sets, respectively. In actual testing, processing a Java file containing approximately 200 import declarations took only 12 milliseconds, and its impact on the overall transpilation throughput is negligible. This mechanism effectively solves the two most common problems in large-scale code migration: "missing imports" and "unused imports," significantly reducing the workload of manual code cleanup.
[0051] Figure 2 This is a schematic diagram of the architecture of the AI code translation method based on multi-agent systems that implements the present invention. Figure 3 This is a schematic diagram of the CodeIndex deep dependency analysis layer for implementing the multi-agent AI code translation method of this invention. (Reference) Figures 1 to 3 As shown, taking the migration of mobile components from the CRN framework to the xTaro framework as an example, the specific implementation process of this invention is described in detail: Application Scenario: An OTA platform needs to migrate its mobile application from its self-developed CRN framework to the open-source xTaro framework, involving approximately 500 page components and 200 common components, with an estimated workload of 769 person-days. The specific implementation steps are as follows: First, the user installs the translation toolkit provided by this invention through the command-line interface by executing the command "npm install -g @ctrip / j2n". After installation, prepare the absolute paths of the source Java project directory, the target NestJS project directory, and the workspace directory in the working directory.
[0052] The user executes the translation command: "flt-j2n run -t 'Translate the familyCardBindApply interface to NestJS' –src / Users / xxx / workspace / java-project –dest / Users / xxx / workspace / nest-project –workspace / Users / xxx / workspace". Upon receiving this request, the master agent begins its work.
[0053] Step S100: The master agent performs scenario identification based on the ReAct paradigm. It parses the source language as Java, the target language as TypeScript (NestJS framework), and the migration type as backend interface migration. The master agent decomposes the task into three sub-task sequences: the first sub-task translates entity classes and data transfer objects (DTOs); the second sub-task translates service layer business logic; and the third sub-task translates controller layer interface definitions. Each sub-task is further subdivided into file-level tasks, involving a total of 19 core files.
[0054] Step S200: The context engineering component begins dynamically retrieving the context. It first reads the pom.xml file in the source project directory and resolves project dependencies. During the translation process, the component monitors token consumption in real time. When processing the 12th file, the accumulated dialogue history has reached a preset threshold (approximately 8K tokens). At this point, the component automatically performs a layered compression operation: summarizing the specific content of each file read operation in the interaction records of the first 10 files into a brief observation such as "File UserEntity.java has been read, defining three fields: id, name, and email," freeing up approximately 8K tokens of window space to ensure sufficient context capacity for subsequent file processing. During the translation process, when processing the 17th file, the system detects an API rate limiting error. The task state management layer immediately captures this interruption signal, records the current ReAct loop inference chain state, including the translation results of the 16 completed files and the current progress of the 17th file (dependency analysis completed, code generation not yet executed). Simultaneously, the pending action queue is recorded as "Generate translation code for FamilyCardBindMapper.java". All these states are serialized into a file named "task_20231027_001.json" and stored in the workspace directory. Later, when the user executes the command "flt-j2n resume-task –id task_20231027_001", the system loads this file, precisely resuming the code generation steps up to the 17th file, and continues executing subsequent tasks.
[0055] Step S300: Execute the Agent to call the CodeIndex deep dependency analysis layer. Taking the target interface "familyCardBindApply" as the entry point, CodeIndex performs Maven dependency resolution on the source Java project. It first parses the pom.xml to obtain the paths of all dependent JAR packages, and then analyzes the call chain within the "familyCardBindApply" method body using bytecode decompilation technology. The analysis reveals that this method sequentially calls the "validateFamilyCard" validation method, the "checkUserAuth" permission check method, and the "saveBindRecord" data persistence method. CodeIndex generates a dependency tree in JSON format from these call relationships, where each node contains the fully qualified name of the called method, the version of the JAR package it belongs to, a list of parameter types, and the return value type. This dependency tree is injected into the inference context.
[0056] Step S400: The Agent invokes the enterprise-level private domain knowledge base. Since the CRN framework is a self-developed framework, the general model lacks its semantic knowledge. The knowledge base of this invention has pre-collected CRN framework documents and xTaro framework documents, and used GPT-4 to batch generate component mapping rules. For example, "FamilyCardBindService" in CRN maps to "FamilyCardModule" in NestJS, and the declarative transaction annotation "@CrnTransactional" in CRN maps to the "@Transactional" decorator in NestJS. The Agent uses the class name "FamilyCardBindApplyController" in the current code snippet as the query vector, retrieves the 5 most similar mapping rules, and injects them into the inference context.
[0057] Step S500: The Agent performs code translation based on the injected dependency tree and mapping rules described above. It translates Java's Spring MVC-style controller into NestJS's decorator-style controller. For example, the `@PostMapping(' / bind') public Result bind(@RequestBody BindRequest req)` in the source Java code is translated into `@Post('bind') async bind(@Body() req: BindRequestDto):Promise` in NestJS. <result>At the same time, the Agent automatically adds the dependency injection code required by NestJS: "constructor(private readonly familyCardService: FamilyCardService) {}".
[0058] Step S600: The verification agent validates the generated target code snippet. Syntax validation is performed by the TypeScript compiler (tsc), and no syntax errors were found. Dependency integrity validation compares the import statements in the generated code with the dependency tree generated by CodeIndex. The verification agent found that the generated code used "ValidatePipe" but the corresponding module was not imported, so it generated a correction instruction: "Missing dependency 'ValidatePipe' detected. Please import this Pipe from '@nestjs / common'." After receiving this instruction, the execution agent automatically added the statement "import {ValidatePipe} from '@nestjs / common';" in the next ReAct loop. The second validation passed.
[0059] Step S700: After all subtasks are completed, the main agent aggregates all target code snippets. Based on the package path "com.ctrip.flight.bff.controller" of the original Java project, it creates the corresponding directory structure "src / flight / bff / controller" in the target NestJS project. Finally, it generates a complete project containing 19 transpiled TypeScript files and outputs a transpilation report. The report shows that all 19 files were successfully transpiled, with 2 files passing verification after iterative corrections, and 0 files requiring manual intervention.
[0060] Performance Evaluation: In this actual migration scenario, the present invention reduced the workload from 769 person-days to 230.5 person-days, improving efficiency by approximately 70%. The runtime pass rate of the translated code reached 92%, and the remaining 8% of issues mainly involved minor adjustments to the version compatibility of third-party libraries. No major defects caused by dependency omissions or private framework mapping errors were found.
[0061] Compared with the prior art, the present invention has the following beneficial effects: First, it addresses the challenge of stability in long-running tasks. Through the synergy of the ReAct paradigm, runtime token awareness mechanism, and persistent task state management, this invention achieves uninterrupted and stable operation of complex code migration tasks. In a real-world test involving a complex interface migration of 19 files, this invention achieved zero interruptions, while the control group of general AI coding tools experienced an average of three interruptions, and token consumption was reduced by approximately 46%. The persistent task state mechanism ensures that any unexpected interruption can be recovered within seconds, without needing to restart.
[0062] Secondly, it significantly improves translation accuracy. Through a hybrid augmented reality (ARMA) model combining objective data and LLM (Local Level Management) with an on-demand retrieval mechanism based on the RAG (Rapid Access Group) knowledge base, this invention increases the code generation adoption rate from 60% for general tools to 80%-90%. In Java 21 upgrade scenarios, the automated problem-solving rate reaches 80%-90%, significantly reducing the risk of model illusion. The precise retrieval of private framework component mapping rules increases the translation accuracy of enterprise private APIs from less than 50% to over 95%.
[0063] Third, it significantly improves R&D efficiency. In typical implemented scenarios, the migration efficiency from CRN to the xTaro mobile framework has improved by approximately 70%, with the corresponding workload decreasing from 769 person-days to 230.5 person-days; the migration efficiency from Java BFF to Node BFF backend has improved by approximately 58.8%, with the corresponding workload decreasing from 4000 person-days to 1650 person-days; and the time required for a single Java 21 upgrade has been shortened from 3-5 days to less than 3 person-days, an efficiency improvement of approximately 50%. The above data demonstrates that this invention can significantly reduce the human and time costs of enterprise technology stack upgrades.
[0064] Fourth, it establishes a standardized and scalable development paradigm. This invention establishes a standard Transpiler development paradigm of "knowledge base construction + supporting tools," which is extremely efficient in adapting to new scenarios. Real-world testing showed that adding a Java 21 upgrade scenario requires only 3 person-days to complete the entire process from scenario definition and knowledge base construction to end-to-end testing. This paradigm is highly reusable and can be quickly adapted to migration scenarios of other technology stacks within an enterprise, possessing the potential to provide standardized AI code migration solutions to the industry.
[0065] Figure 4 This is a system architecture diagram of the browser connector service in the multi-agent AI code translation system of the present invention. Figure 4 As shown, the AI code translation system 5 based on multi-agent technology of the present invention includes: The translation request module 51, in response to the received code translation request, uses the main control agent to perform scene recognition and task decomposition on the target migration task based on the ReAct reasoning-action loop paradigm, and generates an execution plan containing multiple sub-tasks.
[0066] The consumption monitoring module 52 and the context engineering component dynamically retrieve code context information associated with subtasks and monitor token consumption in real time. When token consumption reaches a preset threshold, the system automatically performs hierarchical compression on historical inference records to release the context window. During any of the aforementioned steps, the task status management layer persists the execution progress and intermediate results in real time.
[0067] The analysis and reasoning module 53 executes the Agent to call the CodeIndex deep dependency analysis layer, generates a full-link call dependency tree with the target function in the source project as the entry point, and injects the dependency tree as objective data into the reasoning context.
[0068] The component mapping module 54 executes the Agent to call the enterprise-level private domain knowledge base and RAG retrieval layer, dynamically recalls component mapping rules and Few-shots examples based on the semantic features of the current code to be translated, and injects the inference context.
[0069] The code translation module 55 executes the Agent to perform code translation operations based on the inference context injected with objective data, mapping rules and Few-shots examples, generating target code snippets.
[0070] The syntax verification module 56 verifies the target code snippet by performing syntax and dependency integrity checks on the verification agent. If the verification passes, it is transferred to the output translation module. If the verification fails, a correction instruction is generated and fed back to the execution agent for iterative correction.
[0071] Output translation module 57 summarizes the target code snippets of all subtasks, generates the complete target project code, and outputs the translation results.
[0072] In summary, the AI code translation system based on multi-agent technology of the present invention can achieve efficient, stable, and accurate automated code translation for any development language and across languages.
[0073] This invention also provides a multi-agent AI code translation device, including a processor and a memory storing executable instructions of the processor. The processor is configured to execute steps of a multi-agent AI code translation method by executing the executable instructions.
[0074] As shown above, the AI code translation device based on multi-agent technology of this invention in this embodiment can achieve efficient, stable, and accurate automated code translation of any development language itself and across languages.
[0075] Those skilled in the art will understand that various aspects of the present invention can be implemented as systems, methods, or program products. Therefore, various aspects of the present invention can be specifically implemented as: a completely hardware implementation, a completely software implementation (including firmware, microcode, etc.), or a combination of hardware and software aspects, collectively referred to herein as a "circuit," "module," or "platform."
[0076] Figure 5 This is a schematic diagram of the structure of the AI code translation device based on multi-agent technology of the present invention. See below for reference. Figure 5 To describe an electronic device 600 according to this embodiment of the present invention. Figure 5 The electronic device 600 shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.
[0077] like Figure 5 As shown, the electronic device 600 is presented in the form of a general-purpose computing device. The components of the electronic device 600 may include, but are not limited to: at least one processing unit 610, at least one storage unit 620, a bus 630 connecting different platform components (including storage unit 620 and processing unit 610), a display unit 640, etc.
[0078] The storage unit stores program code, which can be executed by the processing unit 610 to perform the steps described in the method section of this specification according to various exemplary embodiments of the present invention. For example, the processing unit 610 can perform actions such as... Figure 1 The steps are shown in the figure.
[0079] Storage unit 620 may include readable media in the form of volatile storage units, such as random access memory (RAM) 6201 and / or cache memory 6202, and may further include read-only memory (ROM) 6203.
[0080] Storage unit 620 may also include a program / utility 6204 having a set (at least one) program module 6205, such program module 6205 including but not limited to: operating system, one or more application programs, other program modules and program data, each or some combination of these examples may include an implementation of a network environment.
[0081] Bus 630 can represent one or more of several types of bus structures, including a memory cell bus or memory cell controller, a peripheral bus, a graphics acceleration port, a processing unit, or a local bus using any of the multiple bus structures.
[0082] Electronic device 600 can also communicate with one or more external devices 700 (e.g., keyboard, pointing device, Bluetooth device, etc.), and with one or more devices that enable a user to interact with electronic device 600, and / or with any device that enables electronic device 600 to communicate with one or more other computing devices (e.g., router, modem, etc.). This communication can be performed via input / output (I / O) interface 650. Furthermore, electronic device 600 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 660. Network adapter 660 can communicate with other modules of electronic device 600 via bus 630. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with electronic device 600, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage platforms.
[0083] This invention also provides a computer-readable storage medium for storing a program, which, when executed, implements the steps of a multi-agent AI code translation method. In some possible implementations, various aspects of this invention can also be implemented as a program product comprising program code that, when run on a terminal device, causes the terminal device to perform the steps described in the above-described method section of this specification according to various exemplary embodiments of the invention.
[0084] As shown above, this embodiment of the AI code translation system based on multi-agent technology of the present invention can achieve efficient, stable and accurate automated code translation of any development language itself and across languages.
[0085] Figure 6 This is a schematic diagram of the structure of the computer-readable storage medium of the present invention. (Reference) Figure 6 As shown, a program product 800 for implementing the above-described method according to an embodiment of the present invention is described. It may employ a portable compact disc read-only memory (CD-ROM) and include program code, and may run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited thereto. In this document, the readable storage medium may be any tangible medium containing or storing a program that may be used by or in conjunction with an instruction execution system, apparatus, or device.
[0086] The program product may employ any combination of one or more readable media. A readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: electrical connections having one or more wires, portable disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0087] Computer-readable storage media may include data signals propagated in baseband or as part of a carrier wave, carrying readable program code. Such propagated data signals may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable storage medium may also be any readable medium other than a readable storage medium that can transmit, propagate, or transfer a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the readable storage medium may be transmitted using any suitable medium, including but not limited to wireless, wired, optical fiber, RF, etc., or any suitable combination thereof.
[0088] Program code for performing the operations of this invention can be written in any combination of one or more programming languages, including object-oriented programming languages such as Java and C++, and conventional procedural programming languages such as C or similar languages. The program code can execute entirely on the user's computing device, partially on the user's device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0089] In summary, the purpose of this invention is to provide an AI code translation method, system, device, and storage medium based on multi-agent systems, which can achieve efficient, stable, and accurate automated code translation for any development language and across languages.
[0090] The above description, in conjunction with specific preferred embodiments, provides a further detailed explanation of the present invention. It should not be construed that the specific implementation of the present invention is limited to these descriptions. For those skilled in the art, various simple deductions or substitutions can be made without departing from the concept of the present invention, and all such modifications and substitutions should be considered within the scope of protection of the present invention.< / result>
Claims
1. A multi-agent AI code translation method, characterized in that, Includes the following steps: S100. In response to the received code translation request, the main control agent performs scene identification and task decomposition on the target migration task based on the ReAct reasoning-action loop paradigm, and generates an execution plan containing multiple sub-tasks. S200. The context engineering component dynamically retrieves the code context information associated with the subtask and monitors the token consumption in real time. When the token consumption reaches a preset threshold, it automatically performs a layered compression operation on the historical reasoning record to release the context window. During any of the aforementioned steps, the task state management layer persists the execution progress and intermediate results in real time. S300: Execute Agent to call CodeIndex deep dependency analysis layer, generate full-link call dependency tree with the target function in the source project as the entry point, and inject the dependency tree as objective data into the inference context; S400: The execution agent calls the enterprise-level private domain knowledge base and RAG retrieval layer, dynamically recalls component mapping rules and Few-shots examples based on the semantic features of the current code to be translated, and injects the inference context. S500: The execution agent performs a code translation operation based on the inference context injected with the objective data, the mapping rules, and the Few-shots examples, generating a target code fragment; S600: The verification agent performs syntax verification and dependency integrity verification on the target code segment. If the verification passes, proceed to step S700. If the verification fails, generate a correction instruction and feed it back to the execution agent for iterative correction. S700: Summarize the target code snippets of all subtasks, generate the complete target project code, and output the translation results.
2. The AI code translation method based on multi-agent systems according to claim 1, characterized in that, The hierarchical compression operation in step S200 includes: retaining the complete interaction record of the latest ReAct loop, summarizing the tool call results in the historical loops into a structured observation summary, and injecting the observation summary into the context window to replace the original log.
3. The AI code translation method based on multi-agent systems according to claim 1, characterized in that, The step S300 of generating the full-link call dependency tree includes: for JavaScript or TypeScript projects, using AST (Abstract Syntax Tree) analysis to recursively parse module import and function call relationships; for Java projects, using Maven dependency parsing and JAR bytecode decompilation to parse multi-level inheritance relationships and dynamic method call chains.
4. The AI code translation method based on multi-agent technology according to claim 1, characterized in that, Step S400 further includes: the enterprise-level private domain knowledge base collects the official documents of the source framework and the target framework, uses a large language model to generate structured component mapping rules in batches, and stores them in the ES vector database, supporting one-click batch updates.
5. The AI code translation method based on multi-agent systems according to claim 1, characterized in that, Step S500 further includes: the execution agent simultaneously supports two runtime environments, MCP model context protocol and Terminal, and automatically selects the corresponding toolset execution environment according to the type of the subtask.
6. The AI code translation method based on multi-agent systems according to claim 1, characterized in that, In step S200, the task state management layer persists the execution progress and intermediate results in real time, including: in response to a task interruption signal, the task state management layer records the inference chain state of the current ReAct loop and the action queue to be executed; in response to a resume command, the inference chain state and the action queue are loaded with the task identifier via the resume-task command, and execution continues from the breakpoint.
7. The AI code translation method based on multi-agent systems according to claim 1, characterized in that, The dependency integrity check performed by the verification agent includes: comparing the import declarations in the target code snippet with the module list in the end-to-end call dependency tree to detect whether there are missing dependency references or redundant unused dependencies.
8. A multi-agent AI code translation system, used to implement the method described in any one of claims 1 to 7, characterized in that, include: The translation request module responds to the received code translation request. The main control agent performs scene identification and task decomposition on the target migration task based on the ReAct reasoning-action loop paradigm, and generates an execution plan containing multiple sub-tasks. The consumption monitoring module and the context engineering component dynamically retrieve the code context information associated with the subtask and monitor the token consumption in real time. When the token consumption reaches a preset threshold, the historical inference record is automatically compressed to release the context window. During any of the aforementioned steps, the task status management layer persists the execution progress and intermediate results in real time. The analysis and reasoning module executes the Agent to call the CodeIndex deep dependency analysis layer, generates a full-link call dependency tree with the target function in the source project as the entry point, and injects the dependency tree as objective data into the reasoning context; The component mapping module, wherein the execution agent calls the enterprise-level private domain knowledge base and RAG retrieval layer, dynamically recalls component mapping rules and Few-shots examples based on the semantic features of the current code to be translated, and injects them into the inference context; The code translation module, wherein the execution agent performs a code translation operation based on the inference context injected with the objective data, the mapping rules, and the Few-shots examples, to generate the target code fragment; The syntax verification module verifies the target code snippet by verifying the Agent's syntax and dependency integrity. If the verification passes, it is transferred to the output translation module. If the verification fails, a correction instruction is generated and fed back to the execution Agent for iterative correction. The output translation module summarizes the target code snippets from all subtasks, generates the complete target project code, and outputs the translation results.
9. An AI code translation device based on multi-agent systems, characterized in that, include: processor; A memory in which executable instructions of the processor are stored; The processor is configured to perform the steps of the multi-agent-based AI code translation method according to any one of claims 1 to 7 by executing the executable instructions.
10. A computer-readable storage medium for storing a program, characterized in that, When the program is executed by the processor, it implements the steps of the multi-agent-based AI code translation method according to any one of claims 1 to 7.