Code data set construction method based on multi-agent workflow
By automating the construction of code datasets through a multi-agent workflow system, the problems of reliance on manual intervention and insufficient dynamism in existing technologies are solved, and high-quality, safe and compliant code datasets are built, which are suitable for programming model training and code generation.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-19
- Publication Date
- 2026-03-27
AI Technical Summary
Existing methods for constructing code datasets rely heavily on human intervention, making it difficult to adapt to the diversity and rapid evolution of open-source code. They lack dynamic feedback and self-correction mechanisms, cannot guarantee code quality and compliance, and cannot be continuously updated.
A multi-agent workflow system is adopted, which utilizes multiple large language model agents with specific functions to construct code datasets, including compliance review, language classification, sensitive information desensitization, quality assessment, semantic deduplication, and executability verification, to achieve automated and modular data collection and filtering.
We have constructed a structured, high-quality, secure, compliant, and semantically aligned code training dataset, which is suitable for training large programming models and generating code. This improves the reliability and scalability of the dataset and reduces the cost of manual intervention.
Smart Images

Figure CN121742818A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of artificial intelligence and software engineering, and particularly relates to a code data set construction method based on a multi-agent workflow. BACKGROUND
[0002] With the wide application of large language models (LLM) in code generation, program repair, software engineering assistance and other fields, high-quality, large-scale and structured code training data sets have become the core element that determines the upper limit of model capability. The current mainstream code data sets (such as The Stack) are mostly constructed by batch crawling original codes from open source platforms such as GitHub and GitLab, supplemented by basic license filtering, format cleaning and language recognition post-processing steps. However, this construction method has exposed multiple limitations in practice, especially in the two dimensions of high dependence on manual intervention and lack of dynamic maintenance capability.
[0003] Firstly, the existing process relies heavily on software engineers to manually design rules, write scripts, debug filtering logic and manually inspect results. For example, license compliance judgment often requires a large regular expression library to match text variants in the LICENSE file; the identification of sensitive information (such as API keys and internal URLs) relies on pre-defined pattern matching rules, which are difficult to cover new or obfuscated forms of leakage; code quality assessment often relies on the threshold settings of static analysis tools, but often lacks understanding of high-dimensional aspects such as semantic reasonableness and lack of engineering practice perspective. These aspects not only have high development costs and long iteration cycles, but also are prone to introduce noise or missing detection risks due to rule lag or incomplete coverage. Higher quality code review, quality assessment and text annotation optimization often require the involvement of software engineers, whose review standards depend on the engineers' professional level and subjective judgment, and the judgment standards often change greatly, with high costs.
[0004] From another aspect, in today's rapid development of large models and agent technology, the artificially dominated data construction paradigm has obviously lagged behind the pace of technological evolution. Large language models exhibit strong context understanding, tool invocation and autonomous reasoning capabilities, while multi-agent systems further achieve the automation of complex tasks through role division, collaborative decision-making and closed-loop feedback mechanisms. Under this background, the construction of code data sets, a highly structured but detailed task, is completed by multiple specialized agents in collaboration, which not only has technical feasibility, but also exhibits significant advantages and necessity in efficiency, consistency and scalability.
[0005] Furthermore, the open source ecosystem itself is highly dynamic. Code repositories on platforms like GitHub have millions of new commits every day, projects are frequently refactored, licenses change, dependencies are updated or even removed (e.g. due to compliance issues). The traditional "one-time build, long-term static usage" dataset construction model struggles to cope with this continuous evolution. Once the original repository content changes or disappears, the training data loses its traceability and reproducibility, leading to unreliable model training results and even legal risks (e.g. using code with a later withdrawn commercial license).
[0006] In summary, the existing code dataset construction methods have the following defects: 1. Highly dependent on manual rules and engineer intervention, from license parsing to sensitive information filtering, to quality score threshold setting, each link needs to manually write, debug and maintain rules, which is difficult to adapt to the diversity and evolution speed of open source code; 2. Lack of dynamic feedback and self-correction mechanism, the system cannot automatically adjust the strategy or retry according to the execution results (such as format error, alignment failure), and manual intervention is required for troubleshooting; 3. The deduplication mechanism is rough, ignoring semantic diversity, relying only on text hashing or simple MinHash, and cannot identify functionally equivalent but differently expressed high-quality code variants; 4. No runtime behavior verification, cannot confirm whether the code is truly compilable, executable or behaviorally correct, leading to "illusory valid code" mixed into the training set; 5. The quality of the code's comments cannot be guaranteed, and the correctness and relevance of the comment information in the code cannot be confirmed, and incorrect or mismatched text comments may reduce the readability and overall quality of the code; 6. The construction process is static and not easy to update continuously, it cannot cope with the frequent updates, deletions or license changes of GitHub repositories, leading to rapid obsolescence of the dataset, lack of long-term maintenance and version tracking ability.
[0007] Therefore, the skilled in the art is committed to developing a code dataset construction method based on multi-agent workflow. SUMMARY
[0008] In view of the above defects of the prior art, the technical problem to be solved by the present application is how to construct a modular, scalable and easy-to-update multi-agent workflow system to realize automatic code data collection and filtering mechanism.
[0009] The application utilizes multiple large language model agents with specific functions, performs compliance review, language classification, sensitive information desensitization, quality evaluation, semantic deduplication, natural language alignment and executability verification on the original open source code through a collaborative workflow, thereby constructing a structured, high-quality, safe and compliant, and semantically aligned code training dataset suitable for programming model large model training, code generation, program understanding and other downstream tasks.
[0010] In one embodiment of the application, a code dataset construction method based on multi-agent workflow is provided, comprising the following steps: S100, automatically obtaining original code, constructing a data collection agent, structurally accessing an open source code platform, dynamically filtering target code repositories based on meta indicators, obtaining original code, and tracking target code repositories for incremental management of the original code; S200, compliance filtering, constructing a license compliance agent, parsing the LICENSE file of the target code repository and identifying the license type, determining the compliance category of the license text, filtering the code that does not meet the compliance requirements, and obtaining the compliant code; S300, programming language recognition, constructing a programming language recognition agent, accessing a syntax parser and a file extension mapping table, performing preliminary programming language judgment on the compliant code, and labeling the code with a standardized programming language tag according to the judgment result; S400, sensitive information filtering, constructing a sensitive information filtering agent, performing static scanning on the compliant code, identifying explicit sensitive information, determining potential sensitive information, performing standardized desensitization operation on the explicit sensitive information and potential sensitive information according to the determination result, and obtaining desensitized code; S500, code quality evaluation, constructing a code quality evaluation agent, performing syntax checking on the desensitized code, for the desensitized code that passes the syntax verification, obtaining a quality score based on a professional programming large language model, retaining the code with a quality score >= quality score threshold, and obtaining the code that meets the quality requirements; S600, similarity detection, constructing a similarity detection agent, performing rapid deduplication operation on the code that meets the quality requirements, generating code snippets using abstract syntax tree and obtaining key quality indicators, generating semantic vectors for the code snippets, calculating cosine similarity, removing semantically repeated code, and performing cross-repository deduplication to obtain deduplicated code; S700, natural language-code alignment, constructing a natural language-code alignment agent, extracting candidate natural language descriptions, calculating semantic similarity, optimizing low-quality alignment, selecting based on semantic similarity, if the semantic similarity reaches a threshold, the optimized natural language description is associated with the corresponding code snippet as a text label, otherwise, the code snippet is retained but the text label is empty, and the code snippet associated with the text label is obtained; S800, code executability verification, constructs a code executability verification intelligent agent, performs dynamic execution verification on the deduplicated code, evaluates the correctness and stability of the running results, and records the executability verification results in the code's metadata; S900: Construct a code dataset, define the format of structured metadata, integrate text tags, license types, standardized programming language tags, quality scores, and executability verification results into complete structured metadata, and bind code snippets with their corresponding structured metadata to form a code dataset.
[0011] Optionally, in the code dataset construction method based on multi-agent workflow in the above embodiments, step S100 includes: S110. Construct a data acquisition agent and configure the data acquisition agent to access the GitHub open-source code platform in a structured manner through the GitHub model up and down protocol and access the code synchronization scheduler through function calls. S120. Execute the source code acquisition task, call the data collection agent, prompt the data collection agent to dynamically filter the target code repository based on meta indicators, call the GitHub model upper and lower protocols to execute the source code acquisition task to obtain the original code, and automatically record the source URL and commit hash of the original code as the initial metadata of the original code. S130. Tracking the target code repository: The data collection agent periodically checks the hash of the latest commit in the target code repository through the code synchronization scheduler and compares it with the hash recorded locally to identify changes. If there is a difference between the hash of the latest commit and the hash recorded locally, the agent calls the GitHub model context protocol to obtain the incremental commit code and the changed code, updates the metadata, updates the tracking baseline of the code synchronization scheduler, and avoids duplicate collection.
[0012] Optionally, in the code dataset construction method based on multi-agent workflow in any of the above embodiments, the meta-indicators include project activity, number of stars, and update frequency.
[0013] Optionally, in the code dataset construction method based on multi-agent workflow in any of the above embodiments, step S200 includes: S210. Construct a license compliance intelligent agent and configure the license compliance intelligent agent configuration by calling the SPDX (System Package Data Exchange) standard parser, regular expression matching tool and JSON schema validator through function calls. S220. Identify the license type, invoke the license compliance agent, parse the LICENSE file in the root directory of the target code repository, and identify the license type according to the SPDX standard. S230. Determine the compliance category of the license text. For non-standard or ambiguous license texts, trigger the rational behavior reasoning loop of the license compliance agent to determine the compliance category of the license text. S240. Filter out codes that do not meet compliance requirements. Based on the compliance category judgment results of the license text, filter out codes that are prohibited from commercial use and codes with vague restrictions, and retain codes that are allowed for commercial use to obtain compliant codes.
[0014] Furthermore, in the code dataset construction method based on multi-agent workflow in the above embodiments, the text of the control logic for the rational behavior reasoning loop of the license compliance agent is as follows: Loop begins: Consider this: "The license text is non-standard, and I need to determine its compliance category. I can directly analyze the semantics of the text and generate structured output." Behavior: Invoke the large language model, use license compliance hints, ask it to determine the compliance category of the license and return it in JSON format.
[0015] Observation: The large language model returns the judgment result; Behavior: Invokes the JSON Schema validator; Observation: Verification success / failure + error message If the verification fails: Thinking: "JSON format error, reason: {error message}. I should adjust the generation directive to emphasize the format requirements." Actions: Modify the license compliance prompts, including adding format examples and error avoidance instructions, and re-invoke the large language model to generate JSON; If the verification is successful: End the reasoning loop.
[0016] Furthermore, in the code dataset construction method based on multi-agent workflow in the above embodiments, the license compliance prompts are as follows: You are an open-source compliance expert. Please analyze the following license text and determine whether it belongs to any of the following categories: - Permitted: Allowed for use in commercial model training, including MIT, Apache-2.0, and BSD-3-Clause; - Prohibited: This license is prohibited for use in commercial model training, including AGPL, GPL, and SSPL. - unclear: restrictive ambiguity; **License Text**: {Input Text}; Please generate your answer using the following JSON format, and include a brief explanation in no more than 50 words. json { "license_type": / / License type "permitted / prohibited / unclear", / / Commercial use permitted / prohibited / uncertain "reason": A brief reason, no more than 50 words. } ```.
[0017] Optionally, in the code dataset construction method based on multi-agent workflow in any of the above embodiments, step S300 includes: S310. Construct a programming language recognition agent and configure the programming language recognition agent to access the Tree-sitter syntax parser and file extension mapping table through function calls; S320, Programming Language Judgment: Call the programming language identification agent and perform programming language judgment based on file extension, keyword distribution and syntax tree generated by Tree-sitter; S330. Determine the main programming language. For compliant code with mixed languages or ambiguous syntax, trigger the rational behavior reasoning loop of the programming language identification agent to determine the main programming language type. S340. Tag the code with a language. Based on the judgment results, tag the compliant code with a standardized programming language.
[0018] Furthermore, in the code dataset construction method based on multi-agent workflow in the above embodiments, the text of the control logic of the rational behavior reasoning loop of the programming language for recognizing agents is as follows: Loop begins: Thinking: "For this code file, I need to determine its programming language type. I should analyze its textual semantics and generate structured output." Behavior: Invoke the large language model, use the programming language to identify prompt words, and require it to determine the programming language type and return it in JSON format; Observation: The large language model returns the judgment result; Behavior: Invokes the JSON Schema validator; Observation: Verification success / failure + error message; If the verification fails: Thinking: "JSON format error, reason: {error message}. I should adjust the generation directive to emphasize the format requirements." Actions: Modify the programming language recognition prompts, including adding format examples and error avoidance instructions, and re-invoking the large language model to generate JSON; If the verification is successful: End the reasoning loop.
[0019] Furthermore, in the code dataset construction method based on multi-agent workflow in the above embodiments, the programming language recognition prompts are as follows: You are an experienced full-stack software engineer, skilled in identifying and analyzing code in multiple programming languages. Please carefully read the following code and complete the following tasks: 1. Determine the primary programming language used in the code; 2. If the code contains multiple programming languages (e.g., JavaScript and CSS embedded in HTML, or Python and Shell mixed in Jupyter Notebook), determine the dominant language based on the number of lines of code, the proportion of syntax structure, and the semantic focus; 3. Return only the most likely primary language name (such as Python, JavaScript, TypeScript, Java, C++, Rust, Go, HTML, CSS, etc.); Please return your judgment result as an object that strictly conforms to the JSON format. It must not contain any additional text, explanations, or Markdown formatting. The returned JSON object must contain a key "language" with a string value representing the name of the primary language. **Code**: {Enter code}.
[0020] Optionally, in the code dataset construction method based on multi-agent workflow in any of the above embodiments, step S400 includes: S410. Construct a sensitive information filtering agent and configure the sensitive information filtering agent to access the regular expression engine and named entity recognition model through tool calls. S420: Identify explicit sensitive information, invoke the sensitive information filtering agent, and perform static scanning of compliant code through a pre-built regular expression rule base to identify explicit sensitive information; S430, Identify potential sensitive information. For code that poses a privacy risk, trigger a rational behavior reasoning loop of the sensitive information filtering agent, and identify potential sensitive information through contextual semantic reasoning and multimodal detection mechanisms. S440. Perform standardized desensitization operations. Based on the discrimination results, perform standardized desensitization operations on explicit sensitive information and potential sensitive information to obtain desensitized codes.
[0021] Furthermore, in the code dataset construction method based on multi-agent workflow in the above embodiments, the explicitly sensitive information includes hard-coded keys, email addresses, ID card numbers, and API tokens.
[0022] Furthermore, in the code dataset construction method based on multi-agent workflow in the above embodiments, the code that poses a privacy risk is code whose variable names contain semantic clues.
[0023] Furthermore, in the code dataset construction method based on multi-agent workflow in the above embodiments, the standardized de-identification operation includes replacing with placeholders, partial masking, or deleting the entire line.
[0024] Furthermore, in the code dataset construction method based on multi-agent workflow in the above embodiments, the text of the control logic for the rational behavior reasoning loop of the sensitive information filtering agent is as follows: Loop begins: Reflection: "The current code may contain implicitly sensitive information. I need to make a comprehensive judgment based on variable naming and contextual semantics, and generate a structured risk report." Behavior: Invoke the large language model, filter prompts with sensitive information, require it to identify potential private or confidential content, and return the results in strict JSON format; Observation: The large language model returns the recognition results; Behavior: Call the JSON Schema validator to verify whether the output conforms to the predefined risk report format; Observation: Verification success / failure + error message; If the verification fails: Reflection: "The JSON format does not conform to the specification. Reason: {Error message}. Format constraints need to be strengthened and clear examples provided." Actions: Dynamically optimize sensitive information filtering prompts, including embedding format templates, adding error avoidance instructions, and re-invoking the large language model to generate compliant JSON; If the verification is successful: End the reasoning loop.
[0025] Furthermore, in the code dataset construction method based on multi-agent workflow in the above embodiments, the sensitive information filtering prompts are as follows: You are a professional security auditor responsible for performing static index scanning of source code. Please carefully analyze the following code to identify potentially sensitive or confidential information. The scope of your review includes, but is not limited to, the following categories: - **Hardcoded credentials**: such as API keys, access tokens, passwords, private keys, OAuth credentials, etc.; - **Internal system information:** such as internal IP address, internal domain name, database connection string, server path, and configuration file path; - **Sensitive organizational information:** such as the company's full name, internal project code names, employees' real names, email addresses, employee ID numbers, or other information that can identify an individual or organization. - **Other potential risks:** such as sensitive content leaked in debugging information, test accounts, and comments; Please strictly follow the following requirements when outputting results: 1. Return the analysis results in **valid JSON format**; 2. If a risk is detected, return an object containing a field named "findings" whose value is a non-empty array. Each element in the array is an object containing: - "line_number": The line number where the risk is located (counting from 1); -"content": The original code content of this line (preserved as is, without modification); - "risk_type": Risk type (select the best match from the above categories, including "hardcoded_secret", "internal_ip", "internal_domain", "database_connection", and "personally_identifiable_info"); - "description": A brief description of the risk, not exceeding 50 words; 3. If no risks are found, please return to: {"findings": []}; **Please do not include any additional text, explanations, Markdown formatting, or code blocks; output only a plain JSON object.** **Code to be audited**: {Enter code}.
[0026] Optionally, in the code dataset construction method based on multi-agent workflow in any of the above embodiments, step S500 includes: S510. Construct a code quality assessment agent, configure the quality assessment agent to call static analysis tools to verify the syntax correctness of the de-identified code, and call a professional programming language model (qwen3-coder) to assess the quality of the de-identified code; S520. Syntax correctness verification: The code quality assessment agent calls a static analysis tool to perform a syntax check on the de-identified code. If the code has syntax errors, the syntax verification fails, the assessment process is terminated, and the code is marked as invalid. S530, Rational Behavior Reasoning Loop: For code that passes syntax verification, trigger the rational behavior reasoning loop of the code quality assessment agent to perform semantic-level scoring on the readability, robustness, and maintainability of the desensitized code; S540. Calculate the quality score, combining readability, robustness, and maintainability scores, calculate the quality score Q, retain the code with a quality score Q>= the quality score threshold, and obtain the code that meets the quality requirements.
[0027] Furthermore, in the code dataset construction method based on multi-agent workflow in the above embodiments, the professional programming language model includes qwen3-coder.
[0028] Preferably, in the code dataset construction method based on multi-agent workflow in the above embodiments, the quality score threshold is 0.7.
[0029] Optionally, in the code dataset construction method based on multi-agent workflow in any of the above embodiments, the text of the control logic for the rational behavior reasoning loop of the code quality assessment agent is as follows: Loop begins: Reflection: "Soft quality dimensions such as code readability and robustness need to be quantitatively evaluated. A large language model should be used, and structured prompts should be employed to ensure clear scoring dimensions and consistent output format." Behavior: Invoke a professional programming language model, use code quality assessment prompts, and require it to score the code based on dimensions such as readability, maintainability, and robustness, and return the scores for each dimension in strict accordance with the predefined scoring report JSON format, with values ranging from [0,1]. Observation: The large language model returns soft, multi-dimensional quality scores; Behavior: Call the JSON Schema validator to verify whether the output conforms to the predefined JSON format for the scoring report; Observation: Verification success / failure + error message; If the verification fails: Reflection: "The model output format is non-compliant. Reason: {Error message}. The format constraints in the prompt need to be strengthened, such as embedding a JSON example or explicitly specifying the field type." Actions: Dynamically optimize code quality assessment prompts, including adding format templates, field descriptions, and error avoidance instructions, and re-invoke the large language model to generate compliant responses; If the verification is successful: Behavior: Calculate the standard deviation σ of the scores for each soft dimension; Observation: σ value and score distribution of each dimension; If σ > 0.2: Reflection: "The significant discrepancies in scores across different dimensions (σ = {σ}) may indicate assessment bias or ambiguity. The scoring weights need to be adjusted or the assessment criteria refined to improve consistency." Behavior: Refactor code quality assessment prompts, including clearly defining dimensions, introducing anchored examples or introducing weighted guidance, and re-invoking the large language model to obtain a new score; Otherwise (σ ≤ 0.2): End the reasoning loop.
[0030] Furthermore, in the code dataset construction method based on multi-agent workflow in the above embodiments, the code quality assessment prompts are as follows: You are a senior software architect. Please conduct an objective and rigorous quality assessment of the provided code based on the following four dimensions, and provide a standardized score between 0.00 and 1.00 for each dimension, rounded to two decimal places: Readability: Does the code have clear variable / function names, a reasonable logical structure, and good formatting, so that other developers can quickly understand its intent? Robustness: Whether potential exceptions, boundary conditions, illegal inputs, and error scenarios are adequately handled, exhibiting defensive programming characteristics; Modularity: Does the code adhere to the principles of high cohesion and low coupling, avoid repetitive logic, and possess good separation of responsibilities and reusability? Comment quality: Does the comment focus on explaining "why," design intent, business context, or non-obvious decisions, rather than repeating "what" the code itself does? Assessment requirements: Output requirements: Correct output example: json { "readability": 0.90, / / Readability "robustness": 0.75, / / Robustness "modularity": 0.80, / / Modularity level "comment_quality": 0.60 / / Comment quality } ``` Code to be evaluated: {Enter code}.
[0031] Optionally, in the code dataset construction method based on multi-agent workflow in any of the above embodiments, step S600 includes: S610. Construct a similarity detection agent, configure the similarity detection agent to call the MinHash-LSH approximate deduplication module to perform fast deduplication operation on the code text, call the Abstract Syntax Tree (AST) parser to parse the code into AST and divide it into code fragments, call the Code Encoder (CodeBERT) to extract the semantics of the code text, and call the vector similarity calculation function to calculate the cosine similarity of the code fragments. S620, Fast Deduplication: The similarity detection agent calls the MinHash-LSH approximate deduplication module to perform fast deduplication on the code text, and obtains the initially deduplicated code; S630. The similarity detection agent calls the Abstract Syntax Tree (AST) parser to parse the code into an AST, and divides the initially deduplicated code into code segments according to function-level nodes. It also extracts the key quality indicators of the code segments and adds them to the corresponding metadata information. S640. Generate semantic vectors. The similarity detection agent calls the CodeBERT code encoder to generate a 1024-dimensional semantic vector for each code snippet. S650. Calculate cosine similarity. The similarity detection agent calls the similarity calculation function to calculate the semantic vector cosine similarity between any two code segments. If the cosine similarity is greater than the cosine similarity threshold, it is considered semantic repetition and removed. S660. Perform cross-repository deduplication. Identify related repositories based on fork or template project relationships. Remove code segments from related repositories that have a semantic similarity greater than the cosine similarity threshold to obtain deduplicated code.
[0032] Furthermore, in the code dataset construction method based on multi-agent workflow in the above embodiments, key quality indicators include cyclomatic complexity, function length, and nesting depth.
[0033] Preferably, in the code dataset construction method based on multi-agent workflow in the above embodiments, the cosine similarity threshold is 0.85.
[0034] Optionally, in the code dataset construction method based on multi-agent workflow in any of the above embodiments, step S700 includes: S710. Construct a natural language-code alignment agent, configure the natural language-code alignment agent to call the PR / commit metadata extractor to extract the natural language context related to the target code change from the version control system; call a general text embedding model to perform unified semantic space encoding on natural language and code respectively; call a professional programming language model to generate a highly aligned text description based on structured prompts and code snippets. S720. Extract candidate natural language descriptions. Traverse all code snippets. For each code snippet, the natural language-code alignment agent calls the PR / commit metadata extractor to extract candidate natural language descriptions related to the code snippet from the code repository. If no valid natural language context is extracted, the code snippet is marked as a candidate without description, and the subsequent process is terminated. S730. Calculate semantic similarity. For code fragments with extracted candidate natural language descriptions, the natural language-code alignment agent calls a general text embedding model to process the candidate natural language texts. t With code c Vectorization yields text vectors. and code vectors And calculate their semantic similarity, using the following formula: , semantic similarity s As a preliminary alignment quality indicator, it is recorded in the sample metadata; S740. Optimize low-quality alignment, if semantic similarity is low. s The semantic similarity threshold indicates a significant gap between the current candidate natural language description and the code semantics, triggering a rational behavior reasoning loop of the natural language-code alignment agent to optimize low-quality alignment and generate an optimized natural language description. S750. Assign text labels. Combine candidate natural language descriptions with optimized natural language descriptions and select the description with the highest semantic similarity. If the semantic similarity s ≥ the semantic similarity threshold, then associate the optimized natural language description as a text label with the corresponding code fragment. Otherwise, retain the code fragment but set the text label to empty. The code fragment associated with the text label is obtained.
[0035] Furthermore, in the code dataset construction method based on multi-agent workflow in the above embodiments, the candidate natural language descriptions include function docstrings, inline comments, README snippets, Pull Request descriptions, and git commit messages.
[0036] Furthermore, in the code dataset construction method based on multi-agent workflow in the above embodiments, the general text embedding model includes text-embedding-3-large.
[0037] Furthermore, in the code dataset construction method based on multi-agent workflow in the above embodiments, the professional programming language model includes qwen3-coder.
[0038] Optionally, in the code dataset construction method based on multi-agent workflow in any of the above embodiments, the text of the control logic of the rational behavior reasoning loop of the natural language-code aligned agent is as follows: Loop begins: Reason: "Currently, the semantic similarity between natural language descriptions and code is too low ( s = { s The current description may be vague, lack key functional information, or be inconsistent with the code logic. A more accurate, developer-oriented, and aligned description needs to be generated. Action (Act): "Invokes the professional programming language model (qwen3-coder) through the function call mechanism, and generates a new natural language description of the code snippet using natural language-code alignment prompts"; Observe: Receive the generated text returned by the model; Action (Act): Sends the generated text to the large language model to perform format and content compliance checks on the generated text, determines whether the length is between 50 and 150 characters, avoids using redundant phrases such as "this function is used for...", and covers the three elements of function, input and output, and applicable scenarios, and provides the verification results and error reasons; Observe: Verify the result, including success / failure and the reason for the error; If the verification fails: Reason: "The generated description does not conform to the specifications. Reason: {Error Reason}. Constraints need to be strengthened in the prompt words." Action (Act): Dynamically enhance natural language code-aligned prompts, including given prohibited sentence examples and given structured output guidance, and re-invoke the large language model; If the verification is successful: Action (Act): Recalculate the semantic similarity between the new description and the code using the embedding model, and update the semantic similarity. s value.
[0039] Observe: A New Semantic Similarity s value.
[0040] When the number of attempts is less than the maximum number of attempts: If semantic similarity s Semantic similarity threshold: Reason: "Description compliance is not achieved, but semantic alignment remains insufficient." s = { s This may be because the model does not fully understand the code's intent, requiring the introduction of code execution context or more granular hints. Act: Supplement the AST summary, function signature, or key variable description in the natural language-code alignment prompt words to generate a description again; Otherwise (semantic similarity s ≥ semantic similarity threshold): Accept the generated description as a high-quality alignment result and end the inference loop; If semantic similarity s < semantic similarity threshold: End the reasoning loop.
[0041] Preferably, in the code dataset construction method based on multi-agent workflow in the above embodiments, the semantic similarity threshold is 0.7.
[0042] Furthermore, in the code dataset construction method based on multi-agent workflow in the above embodiments, the natural language-code alignment prompts are as follows: You are a senior technical documentation engineer. Please write a natural language description for developers of the following code snippet, with the following requirements: 1. **The word count must be strictly controlled between 50 and 150 words.** 2. **Clearly articulate the core functionality:** Explain what problem the code solves or what capabilities it provides; 3. **Define typical inputs and outputs:** including data types, formats, or structures (if applicable); 4. **Indicate the applicable scenarios or key constraints**: such as thread safety, dependencies, performance characteristics, or prerequisites for use; 5. **Avoid redundant descriptions:** Do not begin with phrases such as "This function is used for..." or "This code implements...". 6. **Focus on Developer Value:** Emphasize practical use, ease of integration, or expected behavior, rather than syntax or implementation details; Please ensure your language is concise, accurate, professional, and conforms to best practices for technical documentation. You only need to generate natural language descriptions; do not output any other content. Code: {Enter code}.
[0043] Furthermore, in the code dataset construction method based on multi-agent workflow in the above embodiments, the professional programming language model includes qwen3-coder.
[0044] Optionally, in the code dataset construction method based on multi-agent workflow in any of the above embodiments, step S800 includes: S810: Build a code executability verification agent, configure the functions of the code executability verification agent, call professional programming language models, identify the programming language and runtime environment dependencies of the code, generate test cases for code snippets, and verify the rationality of execution results; call containerized sandbox tools (Docker) to provide an isolated and secure runtime environment; S820, Dynamic Verification: Invokes the code executability verification agent, triggers the rational behavior reasoning loop of the code executability verification agent, performs dynamic verification, and evaluates the correctness and stability of the running results; S830 Record the verification results and write them into the code's metadata, retaining all code for subsequent integration.
[0045] Furthermore, in the code dataset construction method based on multi-agent workflow in the above embodiments, the verification results include "executable and functionally correct", "executable but with incorrect results", and "not executable".
[0046] Optionally, in the code dataset construction method based on multi-agent workflow in any of the above embodiments, the text of the control logic for the rational behavior reasoning loop of the code executability verification agent is: Loop begins: Consider: "Verify that the code can be successfully compiled / interpreted without runtime crashes and produces reasonable output. Based on the programming language, specific code, and documentation information, generate the necessary execution environment configuration, Dockerfile, and test cases. Attempt to build the environment, execute the compilation and test cases, and capture standard output, error streams, and exit status." Behavior: Invoke the professional programming language model, use container build prompts, generate the required runtime and third-party dependencies based on specific code and documentation information, and generate the corresponding container build files; Observation: The specific container build file (Dockerfile); Consider: "It is necessary to verify whether the Dockerfile can be compiled successfully. If it compiles, it may mean that the container build prompts need to be improved and regenerated." Action: Build an image based on the Dockerfile and generate a container test environment; Observation: Execution success / failure + error message; If execution fails: Reflection: "The container test environment failed to build correctly, possibly due to syntax errors, missing dependencies, or logical errors. Error logs need to be consulted to make the error messages more reasonable." Behavior: Dynamically enhance code executability verification container build prompts, including explicitly adding Dockerfile templates, container run command templates, structured output guidance, and re-invoking the large language model; If execution is successful: Thinking point: "The container testing environment has been successfully built. Now we need to generate executable test cases by combining the environment configuration, specific code, and comments." Behavior: Invoke the professional programming language model, use the generated executable test case prompts, generate executable test cases based on environment configuration, specific code and comment information, as well as time and resource limits matching the test cases, execute the code and test cases in the container test environment, set timeout limits and resource limits, and record execution logs, return codes, stdout / stderr content; Observation: Execution success / failure + error message; If execution fails: Reflection: "Code malfunctions may be due to syntax errors, missing dependencies, or logical errors. It's necessary to review the error logs to determine if the code can be fixed." Behavior: Invoke a professional programming language model, use environment configuration problem prompts, analyze the code and specific error logs to determine whether the root cause of the problem is an environment configuration issue, including missing imports, insufficient resources, or inherent logical defects, and return structured analysis conclusions in a predefined JSON format; Observation: The large language model returns the judgment result; Behavior: Invokes the JSON Schema validator; Observation: Verification success / failure + error message; If the verification fails: Thinking: "JSON format error, reason: {error message}. I should adjust the generation directive to emphasize the format requirements." Actions: Modify environment configuration error messages, including adding format examples and error avoidance instructions, and re-invoke the large language model to generate JSON; If the verification is successful: Observation: The model returns a "fixable" or "unfixable" conclusion and the specific reasons for the error; If the conclusion is "repairable" and it's an environment configuration issue: Behavior: Update the container dependency list, rebuild the environment, and retry execution, up to 2 times; otherwise: Behavior: Mark the code as "non-executable" and terminate the loop; If execution is successful: Behavior: Invoke a professional programming language model, use the execution results and natural language descriptions to match and judge prompt words, compare the function description corresponding to the code with the actual output, and determine whether the behavior meets expectations; and return structured analysis conclusions in a predefined JSON format. Observation: The large language model returns the judgment result; Behavior: Invokes the JSON Schema validator; Observation: Verification success / failure + error message; If the verification fails: Thinking: "JSON format error, reason: {error message}. I should adjust the generation directive to emphasize the format requirements." Actions: Modify environment configuration error messages, including adding format examples and error avoidance instructions, and re-invoke the large language model to generate JSON; If the verification is successful: Observation: The model returns either "consistent behavior" or "abnormal behavior"; If "abnormal behavior": Reflection: "The code runs, but the logical result does not match the declared function, which may indicate a silent error." Behavior: Attempt to enhance test cases by modifying the generated executable test case prompts, including adding assertions or boundary inputs, and regenerate test cases to perform the above verification steps; If the second verification still fails, mark the code as "executable but functionally incorrect"; Otherwise, it behaves consistently and operates stably: End the inference loop and mark the code as "executable and functional".
[0047] Furthermore, in the code dataset construction method based on multi-agent workflow in the above embodiments, the container construction prompt is: You are a professional programming assistant. Please analyze the required runtime environment based on the following code snippet and its contextual information (such as comments and documentation): - Programming language and version (e.g., Python 3.10) - Required third-party dependencies (such as numpy==1.24.0) - Other system-level dependencies (such as g++, libssl-dev) Then, generate a Dockerfile that can be directly used to build a Docker image, with the following requirements: - Based on the official lightweight image (e.g., python:3.10-slim) - Install all dependencies correctly - Copy the code into the container and set the working directory. - Does not contain the run command (CMD / ENTRYPOINT is left blank, to be injected in subsequent steps) Please output the Dockerfile content directly, without explanation.
[0048] Furthermore, in the code dataset construction method based on multi-agent workflow in the above embodiments, the generated executable test case prompts are: You are an experienced test engineer. Please generate a complete test case based on the following information: - Code Function Description: {Function Description} - Code content: {Code snippet} - Container environment configuration: {Dockerfile or dependency list} Require: 1. Test cases must be able to run directly in a container (e.g., a Python script test.py). 2. Where applicable, test cases should include typical inputs, boundary inputs, and exceptional inputs. 3. Use assertions whenever possible to verify whether the output meets expectations. 4. At the same time, provide reasonable suggestions for execution limitations: - Timeout (seconds) - Maximum memory (MB) - CPU limit (e.g., 1 core) Please output in the following format: json { "test_script": "Complete test script content (str)", / / Complete test script "timeout_seconds": int, / / timeout duration "memory_mb": int, / / memory usage "cpu_cores": int / / Number of CPU cores } ```.
[0049] Furthermore, in the code dataset construction method based on multi-agent workflow in the above embodiments, the environment configuration problem prompt is: You are a program debugging expert. The following is the message indicating a code execution failure: - Code content: {Code snippet} - Error log (stderr): {Error log summary} - Container environment: {Environment description or Dockerfile} - Return code: {exit code} Please analyze the reasons for the failure and determine: 1. Is the problem caused by environment configuration issues (such as missing imports, missing dependencies, incorrect paths, etc.)? 2. Is it a code logic error (such as an algorithm error, infinite loop, type error, etc.)? Please answer strictly according to the following JSON format: json { "is_fixable": true or false, / / Can be fixed "reason_category": "environment" or "logic", / / Incorrect category "suggested_fix": "If fixable, briefly explain how to fix it (e.g., add 'pip installrequests'); otherwise, an empty string" / / Fix instructions } ```.
[0050] Furthermore, in the code dataset construction method based on multi-agent workflow in the above embodiments, the execution result and natural language description matching prompt words are: Please compare the execution results of the following code with the natural language description to see if they match: - Function Description: {Natural Language Description} - Actual execution result: - Input: {Test Input} - Output: {Actual output} - Timeout / crash: {Yes / No} Please determine whether the code behavior is consistent with the functional description. Note: - Allow reasonable formatting differences (such as extra spaces and line breaks). - Logical deviations are not allowed (such as returning the least common multiple instead of the greatest common divisor). Silent errors (such as returning the default value without reporting an error) are considered inconsistent behavior. Please answer in the following JSON format: json { "behavior_consistent": true or false, / / Whether the behavior is consistent "explanation": Briefly explain the basis for the judgment. / / Basis for judgment } ```.
[0051] Optionally, in the code dataset construction method based on multi-agent workflow in any of the above embodiments, step S900 includes: S910. Define the format of structured metadata, including fields such as code source, license type, standardized programming language label, quality score Q, text label, and execution verification result, organized using the JSON Schema specification; S920, code dataset content integration, integrates text tags, license types, standardized programming language tags, quality scores, and executability verification results into complete structured metadata; S930: Associate code with metadata. Bind code snippets and their corresponding structured metadata to key-value pairs using a unique identifier (uuid) to form a complete code dataset.
[0052] Optionally, in the code dataset construction method based on multi-agent workflow in any of the above embodiments, the format of structured metadata is defined as follows: json { "code_id": "uuid ", / / Unique identifier for code snippets "source_repo": "https: / / github.com / xxx / yyy", / / Source code repository path "license_type": "MIT", / / License type "commit_hash": "a1b2c3d4...", / / Commit hash value "file_path": "src / interpolate_frames_fixed.py", / / Path to the code file "language": "Python", / / Programming language "function_name": "test_dynamic_linear_with_conv", / / Function name "start_line": 665, / / The starting line of the code snippet in the code file "end_line": 716, / / The last line of the code snippet in the code file "metrics": { / / Key quality metrics based on abstract syntax tree "cyclomatic_complexity": 1, / / Cyclomatic complexity "function_length": 52, / / Function length "nesting_depth": 1 / / Nesting depth }, "quality_score": 0.87, / / Quality score "quality_score_details": { / / Quality scoring details "readability": 0.90, / / Readability "robustness": 0.75, / / Robustness "modularity": 0.80, / / Modularity level "comment_quality": 0.60 / / Comment quality } "exec_status": "executable_and_correct", / / Running status "natural_language_description": "This function processes a singlevideo by optionally fixing its timestamps using FFmpeg, then generatesinterpolated frames and saves them as 2-minute MP4 segments with originalresolution and FPS, organizing outputs into cut-specific subdirectories.", / / Natural language description } ```.
[0053] This invention constructs an end-to-end pipeline through the collaborative work of multiple specialized intelligent agents. Each stage has clearly defined responsibilities, is easy to maintain, and is traceable, significantly improving the systematic and engineering level of data construction. It avoids the fragmentation and high costs associated with traditional manual screening or single-point toolchains, achieving a closed loop of "perception-reasoning-action." Especially in ambiguous or complex scenarios (such as non-standard license discrimination, implicit sensitive information identification, and low-alignment description optimization), the intelligent agents can dynamically invoke large models for semantic reasoning and fully utilize the agents' self-correction mechanisms to ensure output reliability, balancing automation efficiency with decision-making rigor. It covers fundamental dimensions such as grammatical correctness, license compliance, and sensitive information desensitization, and introduces AST structure analysis, semantic vector deduplication, and dynamic sandbox execution verification to ensure the final dataset meets "high-quality" standards from multiple perspectives. This provides reliable, clean, and aligned high-quality corpora for future training of large-scale professional programming models. The user interaction module supports natural language customization needs, and the comprehensive control module enables agent scheduling and status monitoring, reserving flexible interfaces for future adaptation to new programming languages, new compliance standards, or new evaluation dimensions. This invention possesses high scalability and human-machine collaboration capabilities, representing a new paradigm for AI-native data engineering—using intelligent agents as the basic unit to build a data production infrastructure that is self-reflective, self-adaptive, and self-verifiable.
[0054] The following will further explain the concept, specific structure, and technical effects of the present invention in conjunction with the accompanying drawings, so as to fully understand the purpose, features, and effects of the present invention. Attached Figure Description
[0055] Figure 1 This is a flowchart of an exemplary embodiment of a code dataset construction method based on a multi-agent workflow. Detailed Implementation
[0056] The following description, with reference to the accompanying drawings, illustrates several preferred embodiments of the present invention to make its technical content clearer and easier to understand. The present invention can be embodied in many different forms, and the scope of protection of the present invention is not limited to the embodiments mentioned herein.
[0057] In the accompanying drawings, components with the same structure are indicated by the same numerical designation, and components with similar structures or functions are indicated by similar numerical designations. The dimensions and thicknesses of each component shown in the drawings are arbitrary, and the present invention does not limit the dimensions and thicknesses of each component. To make the illustrations clearer, the thickness of components is schematically exaggerated in some places in the drawings.
[0058] This invention designs a method for constructing a code dataset based on a multi-agent workflow, such as... Figure 1 As shown, it includes the following steps: S100: Automatically acquire source code, build a data collection intelligent agent, access open-source code platforms in a structured manner, dynamically filter target code repositories based on meta-indicators, acquire source code, and perform incremental management of source code within target code repositories; specifically including: S110. Construct a data acquisition agent and configure the data acquisition agent to access the GitHub open-source code platform in a structured manner through the GitHub model up and down protocol and access the code synchronization scheduler through function calls. S120. Execute the source code acquisition task, call the data collection agent, prompt the data collection agent to dynamically filter the target code repository based on meta indicators, call the GitHub model upper and lower protocols to execute the source code acquisition task to obtain the original code, and automatically record the source URL and commit hash of the original code as the initial metadata of the original code; including project activity, number of stars, and update frequency. S130. Tracking the target code repository: The data collection agent periodically checks the hash of the latest commit in the target code repository through the code synchronization scheduler and compares it with the hash recorded locally to identify changes. If there is a difference between the hash of the latest commit and the hash recorded locally, the agent calls the GitHub model context protocol to obtain the incremental commit code and the changed code, updates the metadata, updates the tracking baseline of the code synchronization scheduler, and avoids duplicate collection.
[0059] S200, compliance filtering: A license compliance intelligent agent is constructed to parse the LICENSE file of the target code repository and identify the license type, determine the compliance category of the license text, filter out code that does not meet compliance requirements, and obtain compliant code; specifically including: S210. Construct a license compliance intelligent agent and configure it by calling the SPDX (System Package Data Exchange) standard parser, regular expression matching tool, and JSON schema validator via function calls.
[0060] S220. Identify the license type, invoke the license compliance agent, parse the LICENSE file in the root directory of the target code repository, and identify the license type according to the SPDX standard.
[0061] S230. Determine the compliance category of the license text. For non-standard or ambiguous license text, trigger the rational behavior reasoning loop of the license compliance agent to determine the compliance category of the license text. The control logic of the rational behavior reasoning loop of the license compliance agent is as follows: Loop begins: Consider this: "The license text is non-standard, and I need to determine its compliance category. I can directly analyze the semantics of the text and generate structured output." Behavior: Invoke the large language model, use license compliance hints, ask it to determine the compliance category of the license and return it in JSON format.
[0062] Observation: The large language model returns the judgment result; Behavior: Invokes the JSON Schema validator; Observation: Verification success / failure + error message If the verification fails: Thinking: "JSON format error, reason: {error message}. I should adjust the generation directive to emphasize the format requirements." Actions: Modify the license compliance prompts, including adding format examples and error avoidance instructions, and re-invoke the large language model to generate JSON; If the verification is successful: End the reasoning loop.
[0063] The following are compliance tips for the license: You are an open-source compliance expert. Please analyze the following license text and determine whether it belongs to any of the following categories: - Permitted: Allowed for use in commercial model training, including MIT, Apache-2.0, and BSD-3-Clause; - Prohibited: This license is prohibited for use in commercial model training, including AGPL, GPL, and SSPL. - unclear: restrictive ambiguity; **License Text**: {Input Text}; Please generate your answer using the following JSON format, and include a brief explanation in no more than 50 words. json { "license_type": / / License type "permitted / prohibited / unclear", / / Commercial use permitted / prohibited / uncertain "reason": A brief reason, no more than 50 words. } ```.
[0064] S240. Filter out codes that do not meet compliance requirements. Based on the compliance category judgment results of the license text, filter out codes that are prohibited from commercial use and codes with vague restrictions, and retain codes that are allowed for commercial use to obtain compliant codes.
[0065] S300, Programming Language Recognition: Constructing a programming language recognition intelligent agent, accessing the syntax parser and file extension mapping table, performing preliminary programming language judgment on compliant code, and labeling the code with a standardized programming language based on the judgment result; specifically including: S310. Construct a programming language recognition agent and configure the programming language recognition agent to access the Tree-sitter syntax parser and file extension mapping table through function calls.
[0066] S320, Programming Language Judgment: Call the programming language identification agent and determine the programming language based on file extension, keyword distribution, and syntax tree generated by Tree-sitter.
[0067] S330. Determine the main programming language. For compliant code with mixed languages or ambiguous syntax, trigger the rational behavior reasoning loop of the programming language recognition agent to determine the main programming language type. The text of the control logic for the rational behavior reasoning loop of the programming language recognition agent is as follows: Loop begins: Thinking: "For this code file, I need to determine its programming language type. I should analyze its textual semantics and generate structured output." Behavior: Invoke the large language model, use the programming language to identify prompt words, and require it to determine the programming language type and return it in JSON format; Observation: The large language model returns the judgment result; Behavior: Invokes the JSON Schema validator; Observation: Verification success / failure + error message; If the verification fails: Thinking: "JSON format error, reason: {error message}. I should adjust the generation directive to emphasize the format requirements." Actions: Modify the programming language recognition prompts, including adding format examples and error avoidance instructions, and re-invoking the large language model to generate JSON; If the verification is successful: End the reasoning loop.
[0068] The following are the programming language recognition prompts: You are an experienced full-stack software engineer, skilled in identifying and analyzing code in multiple programming languages. Please carefully read the following code and complete the following tasks: 1. Determine the primary programming language used in the code; 2. If the code contains multiple programming languages (e.g., JavaScript and CSS embedded in HTML, or Python and Shell mixed in Jupyter Notebook), determine the dominant language based on the number of lines of code, the proportion of syntax structure, and the semantic focus; 3. Return only the most likely primary language name (such as Python, JavaScript, TypeScript, Java, C++, Rust, Go, HTML, CSS, etc.); Please return your judgment result as an object that strictly conforms to the JSON format. It must not contain any additional text, explanations, or Markdown formatting. The returned JSON object must contain a key "language" with a string value representing the name of the primary language. **Code**: {Enter code}.
[0069] S340. Tag the code with a language. Based on the judgment results, tag the compliant code with a standardized programming language.
[0070] S400 Sensitive Information Filtering: A sensitive information filtering intelligent agent is constructed to perform static scanning of compliant code, identify explicit sensitive information, determine potential sensitive information, and, based on the determination results, perform standardized desensitization operations on both explicit and potential sensitive information to obtain desensitized code. Specifically, this includes: S410. Construct a sensitive information filtering agent and configure the sensitive information filtering agent to access the regular expression engine and named entity recognition model through tool calls.
[0071] S420: Identify explicit sensitive information, invoke the sensitive information filtering agent, and perform static scanning of compliant code through a pre-built regular expression rule base to identify explicit sensitive information.
[0072] S430. Identify potentially sensitive information. For code that poses a privacy risk, trigger the rational behavior reasoning loop of the sensitive information filtering agent. Potential sensitive information is identified through contextual semantic reasoning and multimodal detection mechanisms. The control logic of the rational behavior reasoning loop of the sensitive information filtering agent is as follows: Loop begins: Reflection: "The current code may contain implicitly sensitive information. I need to make a comprehensive judgment based on variable naming and contextual semantics, and generate a structured risk report." Behavior: Invoke the large language model, filter prompts with sensitive information, require it to identify potential private or confidential content, and return the results in strict JSON format; Observation: The large language model returns the recognition results; Behavior: Call the JSON Schema validator to verify whether the output conforms to the predefined risk report format; Observation: Verification success / failure + error message; If the verification fails: Reflection: "The JSON format does not conform to the specification. Reason: {Error message}. Format constraints need to be strengthened and clear examples provided." Actions: Dynamically optimize sensitive information filtering prompts, including embedding format templates, adding error avoidance instructions, and re-invoking the large language model to generate compliant JSON; If the verification is successful: End the reasoning loop.
[0073] The following are sensitive information filtering prompts: You are a professional security auditor responsible for performing static index scanning of source code. Please carefully analyze the following code to identify potentially sensitive or confidential information. The scope of your review includes, but is not limited to, the following categories: - **Hardcoded credentials**: such as API keys, access tokens, passwords, private keys, OAuth credentials, etc.; - **Internal system information:** such as internal IP address, internal domain name, database connection string, server path, and configuration file path; - **Sensitive organizational information:** such as the company's full name, internal project code names, employees' real names, email addresses, employee ID numbers, or other information that can identify an individual or organization. - **Other potential risks:** such as sensitive content leaked in debugging information, test accounts, and comments; Please strictly follow the following requirements when outputting results: 1. Return the analysis results in **valid JSON format**; 2. If a risk is detected, return an object containing a field named "findings" whose value is a non-empty array. Each element in the array is an object containing: - "line_number": The line number where the risk is located (counting from 1); -"content": The original code content of this line (preserved as is, without modification); - "risk_type": Risk type (select the best match from the above categories, including "hardcoded_secret", "internal_ip", "internal_domain", "database_connection", and "personally_identifiable_info"); - "description": A brief description of the risk, not exceeding 50 words; 3. If no risks are found, please return to: {"findings": []}; **Please do not include any additional text, explanations, Markdown formatting, or code blocks; output only a plain JSON object.** **Code to be audited**: {Enter code}.
[0074] S440. Perform standardized desensitization operations. Based on the discrimination results, perform standardized desensitization operations on explicit sensitive information and potentially sensitive information to obtain desensitized code. Explicit sensitive information includes hard-coded keys, email addresses, ID card numbers, and API tokens. Code with privacy risks is code whose variable names contain semantic clues. Standardized desensitization operations include replacing with placeholders, partial masking, or deleting the entire line.
[0075] S500 code quality assessment involves constructing a code quality assessment agent to perform syntax checks on anonymized code. For anonymized code that passes syntax verification, a quality score is obtained based on a professional programming language model. Code with a quality score >= a quality score threshold of 0.7 is retained, thus meeting the quality requirements. Specifically, this includes: S510. Construct a code quality assessment agent, configure the quality assessment agent to call static analysis tools to verify the correctness of the de-identified code syntax, and call a professional programming language model (qwen3-coder) to assess the quality of the de-identified code.
[0076] S520. Syntax correctness verification: The code quality assessment agent calls a static analysis tool to perform a syntax check on the anonymized code. If the code has syntax errors, the syntax verification fails, the assessment process is terminated, and the code is marked as invalid.
[0077] S530, Rational Behavior Reasoning Loop: For code that passes syntax validation, the rational behavior reasoning loop of the code quality assessment agent is triggered to perform semantic-level scoring on the readability, robustness, and maintainability of the anonymized code. The control logic of the rational behavior reasoning loop of the code quality assessment agent is as follows: Loop begins: Reflection: "Soft quality dimensions such as code readability and robustness need to be quantitatively evaluated. A large language model should be used, and structured prompts should be employed to ensure clear scoring dimensions and consistent output format." Behavior: Invoke a professional programming language model, use code quality assessment prompts, and require it to score the code based on dimensions such as readability, maintainability, and robustness, and return the scores for each dimension in strict accordance with the predefined scoring report JSON format, with values ranging from [0,1]. Observation: The large language model returns soft, multi-dimensional quality scores; Behavior: Call the JSON Schema validator to verify whether the output conforms to the predefined JSON format for the scoring report; Observation: Verification success / failure + error message; If the verification fails: Reflection: "The model output format is non-compliant. Reason: {Error message}. The format constraints in the prompt need to be strengthened, such as embedding a JSON example or explicitly specifying the field type." Actions: Dynamically optimize code quality assessment prompts, including adding format templates, field descriptions, and error avoidance instructions, and re-invoke the large language model to generate compliant responses; If the verification is successful: Behavior: Calculate the standard deviation σ of the scores for each soft dimension; Observation: σ value and score distribution of each dimension; If σ > 0.2: Reflection: "The significant discrepancies in scores across different dimensions (σ = {σ}) may indicate assessment bias or ambiguity. The scoring weights need to be adjusted or the assessment criteria refined to improve consistency." Behavior: Refactor code quality assessment prompts, including clearly defining dimensions, introducing anchored examples or introducing weighted guidance, and re-invoking the large language model to obtain a new score; Otherwise (σ ≤ 0.2): End the reasoning loop.
[0078] The code quality assessment prompts are as follows: You are a senior software architect. Please conduct an objective and rigorous quality assessment of the provided code based on the following four dimensions, and provide a standardized score between 0.00 and 1.00 for each dimension, rounded to two decimal places: Readability: Does the code have clear variable / function names, a reasonable logical structure, and good formatting, so that other developers can quickly understand its intent? Robustness: Whether potential exceptions, boundary conditions, illegal inputs, and error scenarios are adequately handled, exhibiting defensive programming characteristics; Modularity: Does the code adhere to the principles of high cohesion and low coupling, avoid repetitive logic, and possess good separation of responsibilities and reusability? Comment quality: Does the comment focus on explaining "why," design intent, business context, or non-obvious decisions, rather than repeating "what" the code itself does? Assessment requirements: Please make judgments based solely on the code content, avoiding subjective speculation or excessive inference; If a certain dimension is not reflected in the code, including the absence of comments or exception handling, points should be deducted reasonably according to the degree of absence. Output requirements: It must be output strictly in JSON format and contain only the following four keys: readability, robustness, modularity, and comment quality. Each value must be a floating-point number between 0.00 and 1.00, rounded to two decimal places, for example: 0.85; No additional fields, explanatory text, Markdown, or line breaks are allowed. Correct output example: json { "readability": 0.90, / / Readability "robustness": 0.75, / / Robustness "modularity": 0.80, / / Modularity level "comment_quality": 0.60 / / Comment quality } ``` Code to be evaluated: {Enter code}.
[0079] S540. Calculate the quality score, which combines readability, robustness, and maintainability scores. Calculate the quality score Q, and retain the code with a quality score Q >= the quality score threshold to obtain the code that meets the quality requirements. The quality score threshold is 0.7.
[0080] S600, similarity detection: Construct a similarity detection agent to perform fast deduplication on code that meets quality requirements. It generates code snippets using an abstract syntax tree and obtains key quality metrics, including cyclomatic complexity, function length, and nesting depth. Semantic vectors are generated from the code snippets, cosine similarity is calculated, semantically repetitive code is removed, and cross-repository deduplication is performed to obtain the deduplicated code. Specifically, this includes: S610. Construct a similarity detection agent, configure the similarity detection agent to call the MinHash-LSH approximate deduplication module to perform fast deduplication operation on the code text, call the Abstract Syntax Tree (AST) parser to parse the code into AST and divide it into code fragments, call the Code Encoder (CodeBERT) to extract the semantics of the code text, and call the vector similarity calculation function to calculate the cosine similarity of the code fragments. S620, Fast Deduplication: The similarity detection agent calls the MinHash-LSH approximate deduplication module to perform fast deduplication on the code text, and obtains the initially deduplicated code; S630. Divide the code into segments. The similarity detection agent calls the Abstract Syntax Tree (AST) parser to parse the code into an AST. The code that has been initially deduplicated is divided into code segments according to function-level nodes. Key quality indicators of the code segments are extracted, including cyclomatic complexity, function length, and nesting depth, and added to the corresponding metadata information. S640. Generate semantic vectors. The similarity detection agent calls the CodeBERT code encoder to generate a 1024-dimensional semantic vector for each code snippet. S650. Calculate cosine similarity. The similarity detection agent calls the similarity calculation function to calculate the semantic vector cosine similarity between any two code segments. If the cosine similarity is greater than the cosine similarity threshold, it is considered semantic repetition and removed. The cosine similarity threshold is 0.85. S660. Perform cross-repository deduplication. Identify related repositories based on fork or template project relationships. Remove code segments from related repositories that have a semantic similarity greater than the cosine similarity threshold to obtain deduplicated code. The cosine similarity threshold is 0.85.
[0081] S700, Natural Language-Code Alignment: Construct a natural language-code alignment agent to extract candidate natural language descriptions, including function docstrings, inline comments, README snippets, pull request descriptions, and git commit messages. Calculate semantic similarity, optimize low-quality alignments, and filter based on semantic similarity. If the semantic similarity reaches a threshold, the optimized natural language description is associated as a text label with the corresponding code snippet; otherwise, the code snippet is retained but the text label is set to empty, resulting in the code snippet associated with the text label. Specifically, this includes: S710. Construct a natural language-code alignment agent, configure the natural language-code alignment agent to call the PR / commit metadata extractor to extract the natural language context related to the target code change from the version control system; call the general text embedding model text-embedding-3-large to perform unified semantic space encoding on natural language and code respectively; call the professional programming large language model qwen3-coder to generate highly aligned text descriptions based on structured prompts and code snippets.
[0082] S720. Extract candidate natural language descriptions. Traverse all code snippets. For each code snippet, the natural language-code alignment agent calls the PR / commit metadata extractor to extract candidate natural language descriptions related to the code snippet from the code repository, including function docstrings, inline comments, README snippets, Pull Request descriptions, and git commit messages. If no valid natural language context is extracted, the code snippet is marked as a candidate without description, and the subsequent process is terminated.
[0083] S730. Calculate semantic similarity. For code fragments with extracted candidate natural language descriptions, the natural language-code alignment agent calls the general text embedding model text-embedding-3-large to perform semantic similarity calculations on the candidate natural language texts. t With code c Vectorization yields text vectors. and code vectors And calculate their semantic similarity, using the following formula: , semantic similarity s As a preliminary alignment quality indicator, it is recorded in the sample metadata.
[0084] S740. Optimize low-quality alignment, if semantic similarity is low. s A semantic similarity threshold of 0.7 indicates a significant gap between the current candidate natural language description and the code semantics, triggering a rational behavior reasoning loop of the natural language-code alignment agent to optimize the low-quality alignment and generate an optimized natural language description. The control logic of the rational behavior reasoning loop of the natural language-code alignment agent is as follows: Loop begins: Reason: "Currently, the semantic similarity between natural language descriptions and code is too low ( s = { s The current description may be vague, lack key functional information, or be inconsistent with the code logic. A more accurate, developer-oriented, and aligned description needs to be generated. Action (Act): "Invokes the professional programming language model (qwen3-coder) through the function call mechanism, and generates a new natural language description of the code snippet using natural language-code alignment prompts"; Observe: Receive the generated text returned by the model; Action (Act): Sends the generated text to the large language model to perform format and content compliance checks on the generated text, determines whether the length is between 50 and 150 characters, avoids using redundant phrases such as "this function is used for...", and covers the three elements of function, input and output, and applicable scenarios, and provides the verification results and error reasons; Observe: Verify the result, including success / failure and the reason for the error; If the verification fails: Reason: "The generated description does not conform to the specifications. Reason: {Error Reason}. Constraints need to be strengthened in the prompt words." Action (Act): Dynamically enhance natural language code-aligned prompts, including given prohibited sentence examples and given structured output guidance, and re-invoke the large language model; If the verification is successful: Action (Act): Recalculate the semantic similarity between the new description and the code using the embedding model, and update the semantic similarity. s value.
[0085] Observe: A New Semantic Similarity s value.
[0086] When the number of attempts is less than the maximum number of attempts: If semantic similarity s Semantic similarity threshold: Reason: "Description compliance is not achieved, but semantic alignment remains insufficient." s = { s This may be because the model does not fully understand the code's intent, requiring the introduction of code execution context or more granular hints. Act: Supplement the AST summary, function signature, or key variable description in the natural language-code alignment prompt words to generate a description again; Otherwise (semantic similarity s ≥ semantic similarity threshold): Accept the generated description as a high-quality alignment result and end the inference loop; If semantic similarity s < semantic similarity threshold: End the reasoning loop.
[0087] Natural language code alignment suggestions are as follows: You are a senior technical documentation engineer. Please write a natural language description for developers of the following code snippet, with the following requirements: 1. **The word count must be strictly controlled between 50 and 150 words.** 2. **Clearly define the core functionality:** Explain what problem the code solves or what capabilities it provides; 3. **Define typical inputs and outputs:** including data types, formats, or structures (if applicable); 4. **Indicate the applicable scenarios or key constraints**: such as thread safety, dependencies, performance characteristics, or prerequisites for use; 5. **Avoid redundant descriptions:** Do not begin with phrases such as "This function is used for..." or "This code implements...". 6. **Focus on Developer Value:** Emphasize practical use, ease of integration, or expected behavior, rather than syntax or implementation details; Please ensure your language is concise, accurate, professional, and conforms to best practices for technical documentation. You only need to generate natural language descriptions; do not output any other content. Code: {Enter code}.
[0088] S750. Assign text labels. Combine candidate natural language descriptions with optimized natural language descriptions and select the description with the highest semantic similarity. If the semantic similarity s ≥ semantic similarity threshold 0.7, then associate the optimized natural language description as a text label with the corresponding code fragment. Otherwise, retain the code fragment but set the text label to empty. The code fragment associated with the text label is obtained.
[0089] S800, code executability verification, constructs a code executability verification intelligent agent to dynamically execute and verify the deduplicated code, evaluates the correctness and stability of the execution results, and records the executability verification results in the code's metadata; specifically including: S810: Build a code executability verification agent, configure the functions of the code executability verification agent, call professional programming language models, identify the programming language and runtime environment dependencies of the code, generate test cases for code snippets, and verify the rationality of execution results; call containerized sandbox tools (Docker) to provide an isolated and secure runtime environment.
[0090] S820, Dynamic Verification: This calls the code executability verification agent, triggering its rational behavior reasoning loop. Dynamic verification is then performed, and the correctness and stability of the results are evaluated. The control logic for the rational behavior reasoning loop of the code executability verification agent is as follows: Loop begins: Consider: "Verify that the code can be successfully compiled / interpreted without runtime crashes and produces reasonable output. Based on the programming language, specific code, and documentation information, generate the necessary execution environment configuration, Dockerfile, and test cases. Attempt to build the environment, execute the compilation and test cases, and capture standard output, error streams, and exit status." Behavior: Invoke the professional programming language model, use container build prompts, generate the required runtime and third-party dependencies based on specific code and documentation information, and generate the corresponding container build files; Observation: The specific container build file (Dockerfile); Consider: "It is necessary to verify whether the Dockerfile can be compiled successfully. If it compiles, it may mean that the container build prompts need to be improved and regenerated." Action: Build an image based on the Dockerfile and generate a container test environment; Observation: Execution success / failure + error message; If execution fails: Reflection: "The container test environment failed to build correctly, possibly due to syntax errors, missing dependencies, or logical errors. Error logs need to be consulted to make the error messages more reasonable." Behavior: Dynamically enhance code executability verification container build prompts, including explicitly adding Dockerfile templates, container run command templates, structured output guidance, and re-invoking the large language model; If execution is successful: Thinking point: "The container testing environment has been successfully built. Now we need to generate executable test cases by combining the environment configuration, specific code, and comments." Behavior: Invoke the professional programming language model, use the generated executable test case prompts, generate executable test cases based on environment configuration, specific code and comment information, as well as time and resource limits matching the test cases, execute the code and test cases in the container test environment, set timeout limits and resource limits, and record execution logs, return codes, stdout / stderr content; Observation: Execution success / failure + error message; If execution fails: Reflection: "Code malfunctions may be due to syntax errors, missing dependencies, or logical errors. It's necessary to review the error logs to determine if the code can be fixed." Behavior: Invoke a professional programming language model, use environment configuration problem prompts, analyze the code and specific error logs to determine whether the root cause of the problem is an environment configuration issue, including missing imports, insufficient resources, or inherent logical defects, and return structured analysis conclusions in a predefined JSON format; Observation: The large language model returns the judgment result; Behavior: Invokes the JSON Schema validator; Observation: Verification success / failure + error message; If the verification fails: Thinking: "JSON format error, reason: {error message}. I should adjust the generation directive to emphasize the format requirements." Actions: Modify environment configuration error messages, including adding format examples and error avoidance instructions, and re-invoke the large language model to generate JSON; If the verification is successful: Observation: The model returns a "fixable" or "unfixable" conclusion and the specific reasons for the error; If the conclusion is "repairable" and it's an environment configuration issue: Behavior: Update the container dependency list, rebuild the environment, and retry execution, up to 2 times; otherwise: Behavior: Mark the code as "non-executable" and terminate the loop; If execution is successful: Behavior: Invoke a professional programming language model, use the execution results and natural language descriptions to match and judge prompt words, compare the function description corresponding to the code with the actual output, and determine whether the behavior meets expectations; and return structured analysis conclusions in a predefined JSON format. Observation: The large language model returns the judgment result; Behavior: Invokes the JSON Schema validator; Observation: Verification success / failure + error message; If the verification fails: Thinking: "JSON format error, reason: {error message}. I should adjust the generation directive to emphasize the format requirements." Actions: Modify environment configuration error messages, including adding format examples and error avoidance instructions, and re-invoke the large language model to generate JSON; If the verification is successful: Observation: The model returns either "consistent behavior" or "abnormal behavior"; If "abnormal behavior": Reflection: "The code runs, but the logical result does not match the declared function, which may indicate a silent error." Behavior: Attempt to enhance test cases by modifying the generated executable test case prompts, including adding assertions or boundary inputs, and regenerate test cases to perform the above verification steps; If the second verification still fails, mark the code as "executable but functionally incorrect"; Otherwise, it behaves consistently and operates stably: End the inference loop and mark the code as "executable and functional".
[0091] The container build prompt is: You are a professional programming assistant. Please analyze the required runtime environment based on the following code snippet and its contextual information (such as comments and documentation): - Programming language and version (e.g., Python 3.10) - Required third-party dependencies (such as numpy==1.24.0) - Other system-level dependencies (such as g++, libssl-dev) Then, generate a Dockerfile that can be directly used to build a Docker image, with the following requirements: - Based on the official lightweight image (e.g., python:3.10-slim) - Install all dependencies correctly - Copy the code into the container and set the working directory. - Does not contain the run command (CMD / ENTRYPOINT is left blank, to be injected in subsequent steps) Please output the Dockerfile content directly, without explanation.
[0092] The prompt for generating executable test cases is: You are an experienced test engineer. Please generate a complete test case based on the following information: - Code Function Description: {Function Description} - Code content: {Code snippet} - Container environment configuration: {Dockerfile or dependency list} Require: 1. Test cases must be able to run directly in a container (e.g., a Python script test.py). 2. Where applicable, test cases should include typical inputs, boundary inputs, and exceptional inputs. 3. Use assertions whenever possible to verify whether the output meets expectations. 4. At the same time, provide reasonable suggestions for execution limitations: - Timeout (seconds) - Maximum memory (MB) - CPU limit (e.g., 1 core) Please output in the following format: json { "test_script": "Complete test script content (str)", / / Complete test script "timeout_seconds": int, / / timeout duration "memory_mb": int, / / memory usage "cpu_cores": int / / Number of CPU cores } ```.
[0093] The error message for the environment configuration problem is: You are a program debugging expert. The following is the message indicating a code execution failure: - Code content: {Code snippet} - Error log (stderr): {Error log summary} - Container environment: {Environment description or Dockerfile} - Return code: {exit code} Please analyze the reasons for the failure and determine: 1. Is the problem caused by environment configuration issues (such as missing imports, missing dependencies, incorrect paths, etc.)? 2. Is it a code logic error (such as an algorithm error, infinite loop, type error, etc.)? Please answer strictly according to the following JSON format: json { "is_fixable": true or false, / / Can be fixed "reason_category": "environment" or "logic", / / Incorrect category "suggested_fix": "If fixable, briefly explain how to fix it (e.g., add 'pip installrequests'); otherwise, an empty string" / / Fix instructions } ```.
[0094] The execution result and the natural language description matching prompts are: Please compare the execution results of the following code with the natural language description to see if they match: - Function Description: {Natural Language Description} - Actual execution result: - Input: {Test Input} - Output: {Actual output} - Timeout / crash: {Yes / No} Please determine whether the code behavior is consistent with the functional description. Note: - Allow reasonable formatting differences (such as extra spaces and line breaks). - Logical deviations are not allowed (such as returning the least common multiple instead of the greatest common divisor). Silent errors (such as returning the default value without reporting an error) are considered inconsistent behavior. Please answer in the following JSON format: json { "behavior_consistent": true or false, / / Whether the behavior is consistent "explanation": Briefly explain the basis for the judgment. / / Basis for judgment } ```.
[0095] S830. Record the verification results and write them into the code's metadata. Keep all the code for subsequent integration. The verification results include "executable and functionally correct", "executable but with incorrect results", and "not executable".
[0096] S900. Construct a code dataset, define the format of structured metadata, integrate text tags, license types, standardized programming language tags, quality scores, and executability verification results into complete structured metadata, and bind code snippets with their corresponding structured metadata to form a code dataset, specifically including: S910 defines the format of structured metadata, including fields such as code source, license type, standardized programming language label, quality score Q, text label, and execution verification result, organized using the JSON Schema specification.
[0097] S920, the code dataset content integration integrates text tags, license types, standardized programming language tags, quality scores, and executability verification results into complete structured metadata.
[0098] S930. Associate code with metadata: bind code snippets with their corresponding structured metadata using key-value pairs with unique identifiers (UUIDs), ultimately forming a complete code dataset; the format of the structured metadata is defined as follows: json { "code_id": "uuid ", / / Unique identifier for code snippets "source_repo": "https: / / github.com / xxx / yyy", / / Source code repository path "license_type": "MIT", / / License type "commit_hash": "a1b2c3d4...", / / Commit hash value "file_path": "src / interpolate_frames_fixed.py", / / Path to the code file "language": "Python", / / Programming language "function_name": "test_dynamic_linear_with_conv", / / Function name "start_line": 665, / / The starting line of the code snippet in the code file "end_line": 716, / / The last line of the code snippet in the code file "metrics": { / / Key quality metrics based on abstract syntax tree "cyclomatic_complexity": 1, / / Cyclomatic complexity "function_length": 52, / / Function length "nesting_depth": 1 / / Nesting depth }, "quality_score": 0.87, / / Quality score "quality_score_details": { / / Quality scoring details "readability": 0.90, / / Readability "robustness": 0.75, / / Robustness "modularity": 0.80, / / Modularity level "comment_quality": 0.60 / / Comment quality } "exec_status": "executable_and_correct", / / Running status "natural_language_description": "This function processes a singlevideo by optionally fixing its timestamps using FFmpeg, then generatesinterpolated frames and saves them as 2-minute MP4 segments with originalresolution and FPS, organizing outputs into cut-specific subdirectories.", / / Natural language description } ```.
[0099] To verify the technical effectiveness of the above embodiments, the applicant used the official PyTorch code repository (https: / / github.com / pytorch / pytorch) as an example to demonstrate the result files after workflow processing, including code snippet file examples, metadata file examples, and a list of result files.
[0100] 1. Example of a code snippet file: The file 0aacf07ad90445fc87697ff881520e1d.txt records the content of the code snippet, and its specific content is as follows.
[0101] ``` def test_dynamic_linear_with_conv(self): quantizer = XNNPACKQuantizer() quantization_config = get_symmetric_quantization_config( is_per_channel=0, is_dynamic=1 ) quantizer.set_global(quantization_config) m_eager = TestHelperModules.ConvLinearWPermute().eval() node_occurrence = { # input and output are using quantize_per_tensor and weight is usingquantize_per_channel torch.ops.quantized_decomposed.quantize_per_tensor.tensor: 1, torch.ops.quantized_decomposed.dequantize_per_tensor.tensor: 1, # note: quantize op for weights are const propagated torch.ops.quantized_decomposed.quantize_per_tensor.default: 0, torch.ops.quantized_decomposed.dequantize_per_tensor.default: 1, } training_ir_node_occurrence = { # input and output are using quantize_per_tensor and weight is usingquantize_per_channel # In training IR, the decomposition is different. # `torch.ops.quantized_decomposed.quantize_per_tensor.default` nodesbecomes # `torch.ops.quantized_decomposed.quantize_per_tensor.tensor` nodes. torch.ops.quantized_decomposed.quantize_per_tensor.tensor: 2, torch.ops.quantized_decomposed.dequantize_per_tensor.tensor: 2, # note: quantize op for weights are const propagated torch.ops.quantized_decomposed.quantize_per_tensor.default: 0, torch.ops.quantized_decomposed.dequantize_per_tensor.default: 0, } act_affine_quant_obs = observer.PlaceholderObserver.with_args( dtype=torch.qint8, qscheme=torch.per_tensor_affine, quant_min=-128, quant_max=127, eps=2**-12, is_dynamic=1, ) qconfig = QConfig( activation=act_affine_quant_obs, weight=weight_observer_range_neg_127_to_127, ) # Test with 2d inputs example_inputs = (torch.randn(2, 3, 4, 4),) qconfig_mapping = QConfigMapping().set_global(qconfig) self._test_quantizer( m_eager, example_inputs, quantizer, node_occurrence, [], 1, qconfig_mapping, training_ir_node_occurrence=training_ir_node_occurrence, ) ```.
[0102] 2. Metadata file example: The file 0aacf07ad90445fc87697ff881520e1d.json records the metadata information of the corresponding code snippet. Its specific content is as follows: { "code_id": "0aacf07ad90445fc87697ff881520e1d", "source_repo": "https: / / github.com / pytorch / pytorch", "license_type": "BSD 3-Clause", "commit_hash": "4cf1d1af225e061b38ec53e2ac7c6ed31049cf9e", "file_path": "test / quantization / pt2e / test_xnnpack_quantizer.py", "language": "python", "function_name": "test_dynamic_linear_with_conv", "start_line": 665, "end_line": 716, "metrics": { "cyclomatic_complexity": 1, "function_length": 52, "nesting_depth": 1 }, "quality_score": 0.71, "quality_score_details": { "readability": 0.75, "robustness": 0.6, "modularity": 0.80, "comment_quality": 0.70 }, "exec_status": "executable_and_correct", "natural_language_description": "Validates the quantization functionality of dynamic linear layers combined with convolutions, ensuring the XNNPACK quantizer correctly handles the ConvLinearWPermute module under dynamic quantization configurations. Inputs include random tensors and predefined quantization configurations, and outputs the expected number of validation node occurrences. Suitable for dynamic quantization scenarios, it requires ensuring consistency in quantization operator decomposition between training IR and inference IR, and supports dynamic quantization of each tensor with independent quantization of weight channels." }
[0103] 3. List of Result Files: The following shows a partial list of filenames from the results generated using the above examples. The filenames are named using the code_id corresponding to the code snippet: 0000b5b1059f4ae4b28212a5f09abe1e.json 0000b5b1059f4ae4b28212a5f09abe1e.txt 0001da6126cc40c581a59d0af1e117b4.json 0001da6126cc40c581a59d0af1e117b4.txt 000260c1425549e6b0c125272df98710.json 000260c1425549e6b0c125272df98710.txt 0003eb905d4c4472b04f3f2d99dc4f5a.json 0003eb905d4c4472b04f3f2d99dc4f5a.txt 000acbc924f541899c4c0a8130b78700.json 000acbc924f541899c4c0a8130b78700.txt 000b7415906049caa5cdd17d83d7421a.json 000b7415906049caa5cdd17d83d7421a.txt 000cc122f9394de3b27972d8b05563fe.json 000cc122f9394de3b27972d8b05563fe.txt 000fedbebdae43d591401d015a06df9b.json 000fedbebdae43d591401d015a06df9b.txt 001332f20d0a4426b6526b170f1e4f64.json 001332f20d0a4426b6526b170f1e4f64.txt 0013b3fea6694d39a751ea91c2c1019c.json 0013b3fea6694d39a751ea91c2c1019c.txt 0013f9b633cf4bd18ef077fd9a2aad06.json 0013f9b633cf4bd18ef077fd9a2aad06.txt 00141e18058a4ccaac591f4b6fb7ac06.json 00141e18058a4ccaac591f4b6fb7ac06.txt 001b6b94f8f242a5b485c562e354b2a8.json 001b6b94f8f242a5b485c562e354b2a8.txt 001bf55850f647acb7d074cb43d5f1fb.json 001bf55850f647acb7d074cb43d5f1fb.txt 001ed77b33ad4ea4a6d03924af736cfe.json 001ed77b33ad4ea4a6d03924af736cfe.txt 00204485869e4e9ea93c6e160fb5e143.json 00204485869e4e9ea93c6e160fb5e143.txt 00207ff56ceb4dccb93ab9c407fa0beb.json 00207ff56ceb4dccb93ab9c407fa0beb.txt 0020be7ed2c74d119d1d0c87f9728cbc.json 0020be7ed2c74d119d1d0c87f9728cbc.txt 00225b1b51124076aab2e99b9f75b7d5.json 00225b1b51124076aab2e99b9f75b7d5.txt 002a96bf31d84daa816e7973eb9a156f.json 002a96bf31d84daa816e7973eb9a156f.txt 00320840ecb7492f8b157de7ed3ea58f.json 00320840ecb7492f8b157de7ed3ea58f.txt 003367047b28412bb4092727de84c2e6.json 003367047b28412bb4092727de84c2e6.txt 00343e23735a4530aba3e7c0158b1f25.json 00343e23735a4530aba3e7c0158b1f25.txt。
[0104] As seen in the example file, the structured metadata ensures commercial compliance through the `license_type` field and enables precise version tracking through `commit_hash` and `source_repo`. The `language` field provides standardized semantic tags for easy downstream task filtering. `file_path`, `function_name`, `start_line`, and `end_line` mark the specific location of the code snippet in the original repository and its associated code file. Regarding code quality, the metadata includes not only the overall score `quality_score` but also scores for subdivided dimensions. Simultaneously, the `metrics` field (including cyclomatic complexity, function length, etc.) provides objective code structure metrics. Furthermore, `exec_status` is explicitly marked as "executable_and_correct," proving that the code has undergone dynamic verification to ensure its executability and correctness. `natural_language_description` provides a professional and detailed natural language description of the code snippet. Overall, each field is automatically generated by the corresponding agent, facilitating continuous updates, traceability, and verification, resulting in a high-quality, easily maintainable code dataset.
[0105] This invention aims to automate the construction of high-quality, executable, semantically rich, and compliant code datasets through a multi-agent collaborative workflow. Compared to existing technologies, the above embodiments significantly improve the level of intelligence. Its functions include: dynamically tracking repository updates, automatically parsing licenses, filtering sensitive information, and introducing quality scoring and semantic deduplication mechanisms to effectively retain high-quality code with diverse functions but different expressions. Simultaneously, leveraging the powerful capabilities of a large programming model, it eliminates "phantom code," ensuring the code is truly usable, and provides natural language descriptions for all code snippets, ultimately generating structured metadata corresponding to each code snippet. Specifically, in the above result file list, several pairs of txt and json files with the same name can be seen; these represent several pairs of extracted code snippets and their corresponding structured metadata (the result file list in the above example is only a small portion of all generated files).
[0106] The preferred embodiments of the present invention have been described in detail above. It should be understood that those skilled in the art can make numerous modifications and variations based on the concept of the present invention without creative effort. Therefore, all technical solutions that can be obtained by those skilled in the art based on the concept of the present invention through logical analysis, reasoning, or limited experimentation on the basis of existing technology should be within the scope of protection defined by the claims.
Claims
1. A method for constructing a code dataset based on a multi-agent workflow, characterized in that, Includes the following steps: S100: Automatically acquire the original code, construct a data collection intelligent agent, access the open source code platform in a structured manner, dynamically filter the target code repository based on meta indicators, acquire the original code, and track the target code repository to perform incremental management of the original code. S200, Compliance Filtering: Construct a license compliance intelligent agent, parse the LICENSE file of the target code repository and identify the license type, determine the compliance category of the license text, filter out code that does not meet the compliance requirements, and obtain compliant code; S300, Programming Language Recognition: Construct a programming language recognition intelligent agent, access the syntax parser and file extension mapping table, perform preliminary programming language judgment on the compliant code, and label the code with a standardized programming language based on the judgment result; S400 Sensitive information filtering: Construct a sensitive information filtering intelligent agent to perform static scanning on the compliant code, identify explicit sensitive information, determine potential sensitive information, and perform standardized desensitization operations on the explicit and potential sensitive information based on the determination results to obtain desensitized code; S500, code quality assessment: Construct a code quality assessment intelligent agent to perform syntax checks on the de-identified code; for de-identified code that passes syntax verification, obtain a quality score based on a professional programming language model; retain code with a quality score >= the quality score threshold to obtain code that meets the quality requirements. S600, Similarity Detection: Construct a similarity detection agent, perform fast deduplication on the code that meets the quality requirements, generate code snippets using an abstract syntax tree and obtain key quality indicators, generate semantic vectors for the code snippets, calculate cosine similarity, remove semantically repetitive code, perform cross-repository deduplication, and obtain deduplicated code. S700, Natural Language-Code Alignment: Construct a natural language-code alignment agent, extract candidate natural language descriptions, calculate semantic similarity, optimize low-quality alignment, and filter according to the semantic similarity. If the semantic similarity reaches a threshold, the optimized natural language description is associated with the corresponding code fragment as a text label; otherwise, the code fragment is retained but the text label is set to empty, thus obtaining the code fragment associated with the text label. S800, Code Executability Verification: Construct a code executability verification intelligent agent to perform dynamic execution verification on the deduplicated code, evaluate the correctness and stability of the running results, and record the executability verification results in the code's metadata; S900. Construct a code dataset, define the format of structured metadata, integrate the text tags, license types, standardized programming language tags, quality scores, and executability verification results into complete structured metadata, and bind the code fragments and their corresponding structured metadata to form a code dataset.
2. The code dataset construction method based on multi-agent workflow as described in claim 1, characterized in that, Step S100 includes: S110. Construct a data acquisition intelligent agent, configure the data acquisition intelligent agent to access the GitHub open source code platform in a structured manner through the GitHub model up and down protocol, and access the code synchronization scheduler through function calls; S120. Execute the source code acquisition task, call the data collection agent, prompt the data collection agent to dynamically filter the target code repository based on meta indicators, call the GitHub model upper and lower protocols to execute the source code acquisition task to obtain the original code, and automatically record the source URL and commit hash of the original code as the initial metadata of the original code. S130. Track the target code repository. The data collection agent periodically detects the hash of the latest commit in the target code repository through the code synchronization scheduler and compares it with the hash recorded locally to identify changes. If there is a difference between the hash of the latest commit and the hash recorded locally, the agent calls the GitHub model context protocol to obtain the incremental commit code and the changed code, updates the metadata, and updates the tracking baseline of the code synchronization scheduler to avoid duplicate collection.
3. The code dataset construction method based on multi-agent workflow as described in claim 1, characterized in that, Step S200 includes: S210. Construct a license compliance intelligent agent and configure the license compliance intelligent agent configuration by calling the SPDX standard parser, regular expression matching tool and JSON schema validator through function calls. S220. Identify the license type, call the license compliance agent, parse the LICENSE file in the root directory of the target code repository and identify the license type according to the SPDX standard; S230. Determine the compliance category of the license text. For non-standard or ambiguous license texts, trigger the rational behavior reasoning loop of the license compliance agent to determine the compliance category of the license text. S240. Filter out codes that do not meet compliance requirements. Based on the compliance category judgment result of the license text, filter out codes that are prohibited from commercial use and codes that are vaguely restrictive, and retain codes that are allowed to be used for commercial purposes to obtain compliant codes.
4. The code dataset construction method based on multi-agent workflow as described in claim 3, characterized in that, Step S300 includes: S310. Construct a programming language recognition agent and configure the programming language recognition agent to access the Tree-sitter syntax parser and file extension mapping table through function calls; S320, Programming language determination: Invoke the programming language identification agent and determine the programming language based on the file extension, keyword distribution and the syntax tree generated by Tree-sitter; S330. Determine the main programming language. For compliant code with mixed languages or ambiguous syntax, trigger the rational behavior reasoning loop of the programming language identification agent to determine the main programming language type. S340. Tag the code with a language. Based on the judgment results, tag the compliant code with a standardized programming language.
5. The method for constructing a code dataset based on a multi-agent workflow as described in claim 1, characterized in that, Step S400 includes: S410. Construct a sensitive information filtering agent and configure the sensitive information filtering agent to access the regular expression engine and named entity recognition model through tool calls. S420. Identify explicit sensitive information, invoke the sensitive information filtering agent, and perform static scanning on the compliant code through a pre-set regular expression rule base to identify explicit sensitive information; S430. Determine potential sensitive information. For code that poses a privacy risk, trigger the rational behavior reasoning loop of the sensitive information filtering agent and determine potential sensitive information through contextual semantic reasoning and multimodal detection mechanisms. S440. Perform standardized desensitization operation. Based on the discrimination result, perform standardized desensitization operation on the explicit sensitive information and the potential sensitive information to obtain desensitized code.
6. The method for constructing a code dataset based on a multi-agent workflow as described in claim 1, characterized in that, Step S500 includes: S510. Construct a code quality assessment agent, configure the quality assessment agent to call static analysis tools to verify the correctness of the de-identified code syntax, and call a professional programming language model to assess the quality of the de-identified code. S520. Syntax correctness verification: The quality assessment agent in the code calls a static analysis tool to perform a syntax check on the de-identified code. If the code has syntax errors, the syntax verification fails, the assessment process is terminated, and the code is marked as invalid. S530, Rational Behavior Reasoning Loop: For code that passes syntax verification, trigger the rational behavior reasoning loop of the code quality assessment agent to perform semantic-level scoring on the readability, robustness, and maintainability of the de-identified code; S540. Calculate the quality score. Combining the readability, robustness, and maintainability scores, calculate the quality score Q. Retain the code whose quality score Q >= the quality score threshold to obtain code that meets the quality requirements.
7. The code dataset construction method based on multi-agent workflow as described in claim 1, characterized in that, Step S600 includes: S610. Construct a similarity detection agent, configure the similarity detection agent to call the MinHash-LSH approximate deduplication module to perform fast deduplication on the code text, call the abstract syntax tree parser to parse the code into AST and divide it into code fragments, call the code encoder to extract the semantics of the code text, and call the vector similarity calculation function to calculate the cosine similarity of the code fragments. S620. Fast deduplication: The similarity detection agent calls the MinHash-LSH approximate deduplication module to perform fast deduplication on the code text to obtain initially deduplicated code. S630. Divide the code into segments. The similarity detection agent calls the abstract syntax tree parser to parse the code into an AST, and divides the initially deduplicated code into code segments according to function-level nodes. The key quality indicators of the code segments are extracted and added to the corresponding metadata information. S640. Generate semantic vectors. The similarity detection agent calls the code encoder to generate a 1024-dimensional semantic vector for each code segment. S650. Calculate cosine similarity. The similarity detection agent calls the similarity calculation function to calculate the semantic vector cosine similarity between any two code segments. If the cosine similarity is greater than the cosine similarity threshold, it is considered semantic repetition and removed. S660. Perform cross-repository deduplication. Identify associated repositories based on fork or template project relationships. Remove code segments from associated repositories that have a semantic similarity greater than the cosine similarity threshold to obtain deduplicated code.
8. The method for constructing a code dataset based on a multi-agent workflow as described in claim 1, characterized in that, Step S700 includes: S710. Construct a natural language-code alignment agent, configure the natural language-code alignment agent to call the PR / commit metadata extractor to extract the natural language context related to the target code change from the version control system; call a general text embedding model to perform unified semantic space encoding on natural language and code respectively; call a professional programming language model to generate a highly aligned text description based on structured prompts and code snippets. S720. Extract candidate natural language descriptions. Traverse all code snippets. For each code snippet, the natural language-code alignment agent calls the PR / commit metadata extractor to extract candidate natural language descriptions related to the code snippet from the target code repository. If no valid natural language context is extracted, the code snippet is marked as a candidate without description, and the subsequent process is terminated. S730. Calculate semantic similarity. For code fragments with extracted candidate natural language descriptions, the natural language-code alignment agent calls the general text embedding model to perform semantic similarity analysis on the candidate natural language texts. t With code c Vectorization yields text vectors. and code vectors And calculate their semantic similarity, using the following formula: , The semantic similarity s As a preliminary alignment quality indicator, it is recorded in the sample metadata; S740. Optimize low-quality alignment, if the semantic similarity... s The semantic similarity threshold indicates a significant gap between the current candidate natural language description and the code semantics, triggering the rational behavior reasoning loop of the natural language-code alignment agent to optimize the low-quality alignment and generate an optimized natural language description. S750. Assigning text labels: Combining the candidate natural language descriptions and the optimized natural language descriptions, select the description with the highest semantic similarity; if the semantic similarity s ≥ the semantic similarity threshold, then associate the optimized natural language description as a text label with the corresponding code fragment; otherwise, retain the code fragment but set the text label to empty; thus obtaining the code fragment associated with the text label.
9. The method for constructing a code dataset based on a multi-agent workflow as described in claim 1, characterized in that, Step S800 includes: S810: Construct a code executability verification agent, configure the functions of the code executability verification agent, call professional programming language models, identify the programming language and runtime environment dependencies of the code, generate test cases for code snippets, and verify the rationality of execution results; call containerized sandbox tools to provide an isolated and secure runtime environment; S820, Dynamic verification: Invoke the code executability verification agent, trigger the rational behavior reasoning loop of the code executability verification agent, perform dynamic verification, and evaluate the correctness and stability of the running results; S830 Record the verification results and write them into the code's metadata, retaining all code for subsequent integration.
10. The method for constructing a code dataset based on a multi-agent workflow as described in claim 1, characterized in that, Step S900 includes: S910. Define the format of structured metadata, including code source, license type, standardized programming language label, quality score Q, text label, and execution verification result field, organized using the JSON Schema specification; S920. Code dataset content integration: Integrate the text tags, license types, standardized programming language tags, quality scores, and executability verification results into complete structured metadata; S930. Associate code and metadata: bind the code fragment with its corresponding structured metadata using a unique identifier to form a key-value pair, thus forming a complete code dataset.