AI agent-based nx secondary development code generation method and system

By using an AI Agent-based NX secondary development code generation method, combined with semantic retrieval and multi-dimensional verification, the high threshold and low efficiency problems of existing technologies are solved, realizing the automated generation from natural language to executable DLL plugins, ensuring code compliance and reliability.

CN122111401APending Publication Date: 2026-05-29SOUTHEAST ZHEJIANG ARTIFICIAL INTELLIGENCE RESEARCH INSTITUTE (TAIZHOU) CO LTD +2

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
SOUTHEAST ZHEJIANG ARTIFICIAL INTELLIGENCE RESEARCH INSTITUTE (TAIZHOU) CO LTD
Filing Date
2026-02-26
Publication Date
2026-05-29

AI Technical Summary

Technical Problem

In existing technologies, NX secondary development relies on professional programming skills, which has a high technical threshold, low development efficiency, and the generated code often has syntax errors, API misuse, or non-compliant structure due to a lack of understanding of the NXOpen API specification and runtime environment, making it impossible to compile or execute directly.

Method used

An AI Agent-based approach is adopted to generate initial code by acquiring user natural language input and development mode selection, combined with a pre-built NX secondary development domain knowledge base for semantic retrieval, and ensuring code structure compliance and executability through multi-dimensional verification and self-iterative correction mechanisms.

Benefits of technology

It significantly lowers the technical threshold for NX secondary development, improves development efficiency, and realizes end-to-end automated generation from natural language instructions to executable DLL plugins, ensuring that the generated code conforms to the NX plugin architecture specification and avoiding manual intervention and repeated debugging.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122111401A_ABST
    Figure CN122111401A_ABST
Patent Text Reader

Abstract

The application provides an AI Agent-based NX secondary development code generation method and system, relates to the field of intelligent development of industrial software, and solves the technical problems of professional programming ability dependence, high technical threshold and low development efficiency of the prior art NX secondary development. The method comprises the following steps: determining a target development mode according to a user's development mode selection instruction; matching associated API knowledge and use examples based on the user's original natural language input and the pre-set NX secondary development field knowledge base; generating an initial NX secondary development source code by using a large language model; obtaining error information existing in the initial NX secondary development source code; and performing self-iteration according to the error information by using an AI Agent until passing the verification; and compiling and packaging the initial source code that passes the verification to obtain an executable DLL file. The application is used in the NX secondary development code generation process.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of intelligent development of industrial software, and in particular to a method and system for generating NX secondary development code based on AI Agent. Background Technology

[0002] Siemens NX is a core industrial design and simulation platform widely used in high-end manufacturing. Its open NXOpen API allows users to achieve automated modeling, customized functions, and process integration through secondary development. However, current NX secondary development mainly relies on developers manually writing C++ plugin code, requiring them not only to be proficient in the C++ language and dynamic link library (DLL) construction mechanism, but also to have a deep understanding of NXOpen's complex class library system, transaction management (such as UF_initialize / terminate), component context states (such as working components and selected objects), and the architectural differences between different plugin modes (such as headless background scripts and interactive UI managed applications).

[0003] This process has a high technical threshold, making it difficult for non-professional programmers to handle. Furthermore, the development process requires repeated debugging to ensure correct API calls, consistent context states, and compliant code structure, resulting in long development cycles and low efficiency. In recent years, although Large Language Models (LLMs) have been attempted to assist in code generation, they have performed poorly in NX secondary development scenarios: due to a lack of deep understanding of NX domain knowledge, runtime environment, and plugin architecture, the generated code often suffers from parameter errors, null pointer references, missing main functions, or API illusions, making it impossible to compile directly or execute safely, still requiring significant manual intervention.

[0004] Therefore, this application provides a method and system for generating NX secondary development code based on AI Agent. Summary of the Invention

[0005] This application provides a method and system for generating NX secondary development code based on AI Agent, which solves the technical problems of NX secondary development relying on professional programming skills, high technical threshold and low development efficiency in the prior art.

[0006] To achieve the above objectives, this application adopts the following technical solution: Firstly, a method for generating NX secondary development code based on AI Agent is provided, including: The system acquires user-input interaction information, including raw natural language input and development mode selection instructions; based on the development mode selection instructions, it determines a target development mode, including a headless execution mode and an interactive interface managed mode. Based on raw natural language input and a pre-built NX secondary development domain knowledge base, semantic retrieval is used to match related API knowledge and usage examples. Based on the target development model, the retrieved API knowledge, and the runtime context parameters of the current NX software, the initial NX secondary development source code is generated using a large language model. The initial NX secondary development source code is analyzed and verified to obtain error information in the initial NX secondary development source code; When errors are found in the initial NX secondary development source code, the AI ​​Agent iterates based on the error information, continuously modifying and improving the code until it passes verification. The verified initial NX secondary development source code is then compiled and packaged to obtain an executable DLL file.

[0007] Based on the above technical solutions, traditional NX secondary development using AI Agents heavily relies on developers' proficiency in C++ and the NXOpen API. This not only results in high learning costs and long development cycles but also makes plugins prone to failure due to misjudgments of environment context or improper use of interfaces. Directly generating code using general-purpose large models often ignores the stringent requirements of industrial software for stability, compliance, and architectural specifications, making the output difficult to implement. Therefore, it is essential to construct an intelligent generation system that deeply integrates domain knowledge, operating environment, and engineering constraints. This application collaboratively injects user intent, development patterns, real-time context, and professional API knowledge into the generation process and introduces a "verification-feedback-repair" closed-loop mechanism: by differentiating the architectural requirements of headless scripts and interactive UI plugins, code structure compliance is ensured; semantic retrieval accurately matches function usage and typical examples, improving API call accuracy; multi-dimensional static analysis exposes syntax and logical vulnerabilities in advance; and the AI ​​Agent then implements layered corrective measures based on error type for efficient targeted correction. The entire process outputs compilable, loadable, and runnable DLL plugins without human intervention. This method not only breaks through the bottleneck of converting natural language into industrial-grade code, but also creates a new paradigm for NX plugin development that is low-code, self-evolving, and highly reliable, demonstrating significant technological advancement and industrial application value.

[0008] In conjunction with the first aspect above, in one possible implementation, the interfaceless execution mode and the interactive interface managed mode can be switched, including: If the target development mode is a user-free execution mode, then the source code of the dynamic link library with a single entry function will be generated. If the target development mode is the interactive interface hosting mode, the user is prompted to upload the header and source files of the UI definition file before code generation; and based on the UI control definition information in the header and source files, the code template is parameterized to generate DLL source code that is compatible with the user interface.

[0009] In conjunction with the first aspect above, in one possible implementation, the matching and associated API knowledge and usage examples include: Preprocess the pre-built NX secondary development domain knowledge base to build a vectorized index library; The preprocessing includes: segmenting the NXOpen API documentation, historical code snippets, and technical Q&A documentation into text blocks, and using an embedding model to convert the text blocks into vector form for storage; The original natural language input is transformed into a query vector using a semantic encoder; Calculate the similarity score between the query vector and each text block vector in the vectorized index library, sort each text block in descending order according to the similarity score, and select the top K text blocks in the sorting results as the matching results; The API documentation definitions and code snippets in the matching results will be used as associated API knowledge and usage examples.

[0010] In conjunction with the first aspect mentioned above, in one possible implementation, the semantic retrieval also includes a hierarchical index structure, comprising function-level indexes and class-level indexes; Based on the Agent's recognition results of the user's natural language input, the system dynamically routes to the function-level index to query the parameter signature, call examples, and preconditions of the target API function; or routes to the class-level index to query the general usage patterns, typical processes, and related class interfaces of a certain functional module. The function-level index stores fine-grained technical documentation and code snippets for each function in the NXOpen API, while the class-level index stores class clusters organized by functional domain and their collaborative calling paradigms.

[0011] In conjunction with the first aspect above, in one possible implementation, calculating the similarity score between the query vector and each text block vector includes: The similarity score between the query vector and each text block vector is calculated using a hybrid retrieval relevance scoring model. This model is based on both dense and sparse retrieval scores, and its expression is as follows: ; in, Input is raw natural language; This is the standard query statement after being transformed by the semantic standardization module; Candidate documents from the pre-built NX secondary development domain knowledge base; Represents a vector embedding function; To achieve a dense retrieval score, the cosine similarity between the query vector and each text block vector is calculated. To obtain a sparse retrieval score, calculate the keyword matching degree; This is a mixed weighting coefficient used to dynamically adjust the ratio of semantic matching to keyword matching.

[0012] In conjunction with the first aspect above, in one possible implementation, the initial NX secondary development source code includes: The retrieved API knowledge, target development mode, and runtime context parameters of the current NX software are dynamically assembled to construct a compound prompt word that includes role setting, task description, constraints, and reference knowledge. The compound prompt words are input into the large language model to generate the initial NX secondary development source code; This process is formally represented as: ; in, This represents the initial NX secondary development source code; For large language models; This indicates vector concatenation or text concatenation operations; This is a system-level instruction; the Agent is defined as a senior NX secondary development expert, and the output format is strictly constrained. Input commands in raw natural language; This is the set of runtime context parameters for the current NX software. This section provides definitions and usage examples of the most relevant API functions returned by the retrieval module.

[0013] In conjunction with the first aspect above, in one possible implementation, obtaining the error information present in the initial NX secondary development source code includes: Lexical and syntactic analysis is performed on the initial NX secondary open-source code to construct an abstract syntax tree and identify syntactic errors, including incomplete statements, mismatched brackets, and misspelled keywords. Based on the pre-built NXOpen API interface specification library, the API function names and parameter lists called in the source code are extracted, compared with the standard interface signature, and API usage errors are identified, including parameter type mismatch, missing parameter quantity, and illegal call order. By combining the current runtime context parameters of the NX software, we can analyze the object instantiation status, variable lifecycle and resource access permissions in the source code to identify context inconsistency errors, including referencing null objects, operating on inactive components, and unauthorized access to system resources. Based on the target development mode selected by the user, the program architecture of the source code is verified to meet the preset development mode code template; if yes, an architecture compliance signal is generated, allowing the code to enter the subsequent processing stage; if no, the violation type is identified and the corresponding architecture violation error information is generated, including unregistered event callback functions, unisolated UI threads, and missing main function entry points; The identified error information is categorized and located, and a structured diagnostic report is generated that includes error type, error location, error description, and repair suggestions.

[0014] In conjunction with the first aspect above, in one possible implementation, the use of an AI Agent for self-iteration based on error information includes: The error information in the verification feedback is classified and its error level is identified. The error level includes the syntax level, API call level, context lifecycle level or architecture template level. Based on the error level, activate the corresponding repair strategy: If it is a syntax error, the source code will be automatically corrected by calling the pre-built syntax correction rule library; If the error is at the API call layer, the correct parameter types, call order, and dependencies of the target API function are retrieved based on the pre-built NXOpen API knowledge graph, and parameter correction suggestions are generated. If the error is a context lifecycle layer error, then UF_initialize() / UF_terminate() or transaction start / end encapsulation structure will be automatically inserted into the code according to the current operation semantics. If the error is in the architecture template layer, the pre-stored NX secondary development architecture template library will be matched to generate a structured replacement suggestion that matches the development mode selected by the user. The repair suggestions are injected into the input context of the large language model in the form of structured prompts, driving it to rewrite the initial source code in a targeted manner rather than regenerate it completely, and repeat the verification and repair process until the generated code passes all verification items or reaches the preset maximum number of iterations.

[0015] Secondly, this application provides an NX secondary development code generation system based on AI Agent, including a function mode selection module, a knowledge retrieval module, a code generation module, a code verification module, a self-iterative correction module, and an output module; The function mode selection module is used to receive the user's raw natural language input and development mode selection instruction, and select the target development mode according to the user's development mode selection instruction. The knowledge retrieval module is used to match related API knowledge and usage examples through semantic retrieval based on the natural language input and the pre-built NX secondary development domain knowledge base; The code generation module is used to generate initial NX secondary development source code based on the natural language input, retrieved API knowledge, and runtime context parameters of the current NX software using a large language model. The code verification module is used to input the initial NX secondary development source code into the audit and verification tool, perform code structure analysis and verification, and capture error information in the code; The self-iterative correction module: When the code verification step captures error information, it uses the AI ​​Agent to perform self-iteration based on the error information, continuously modifying and improving the code until it passes verification; The output module compiles and packages the verified initial NX secondary development source code, outputting the final executable DLL file.

[0016] In conjunction with the second aspect above, in one possible implementation, the code verification module includes a multi-dimensional code compliance verification engine. The compliance verification engine embeds a logical constraint rule library for the NX secondary development domain. The logical constraint rule library integrates NXOpen API calling specifications, transaction context management rules, object lifecycle constraints, memory resource release protocols, and architectural pattern consistency requirements. After code generation, the compliance verification engine automatically performs static topology analysis and logical reachability detection on the code to identify error information in the source code.

[0017] This application provides an AI Agent-based method and system for generating NX secondary development code, which can significantly reduce the technical threshold and time cost of customized development of industrial design software. Traditional NX plugin development requires developers to be proficient in C++, familiar with the NXOpen API system, and master complex runtime context management, which is extremely unfriendly to non-professional programmers and prone to plugin crashes due to API misuse or architectural errors. This application achieves end-to-end automatic generation from user-defined commands to executable DLL plugins by deeply integrating natural language understanding, domain knowledge retrieval, and large model generation capabilities. Its core advantages are: first, the introduction of a dual-mode development adaptation mechanism (interfaceless execution / interactive interface hosting) to ensure that the generated code conforms to the NX plugin architecture specifications; second, the construction of a context-aware semantic retrieval system, which accurately recalls relevant APIs and examples by combining the current working parts, selected objects, and other runtime states; and third, the establishment of a multi-dimensional verification and layered self-healing closed loop, with the AI ​​Agent performing targeted corrections for error types such as syntax, API, lifecycle, and architecture, avoiding blind regeneration. This method not only significantly improves the first-pass yield and reliability of code, but also enables ordinary engineers to quickly create functional plugins without coding, promoting the evolution of NX secondary development towards an intelligent paradigm of "natural language driven, AI autonomous delivery," and possessing outstanding practicality and industrial promotion value. It should be understood that the descriptions of technical features, technical solutions, beneficial effects, or similar language in this application do not imply that all features and advantages can be achieved in any single embodiment. Rather, it is understood that the description of features or beneficial effects means that a specific technical feature, technical solution, or beneficial effect is included in at least one embodiment. Therefore, the descriptions of technical features, technical solutions, or beneficial effects in this specification do not necessarily refer to the same embodiment. Furthermore, the technical features, technical solutions, and beneficial effects described in this embodiment can be combined in any suitable manner. Those skilled in the art will understand that embodiments can be implemented without one or more specific technical features, technical solutions, or beneficial effects of a particular embodiment. In other embodiments, additional technical features and beneficial effects may be identified in specific embodiments that do not embody all embodiments. Attached Figure Description

[0018] Figure 1 A system architecture diagram of an NX secondary development code generation system based on an AI Agent provided in this application embodiment; Figure 2 A flowchart illustrating an NX secondary development code generation method based on an AI Agent, provided for an embodiment of this application; Figure 3 This is a schematic diagram of a method for matching associated API knowledge and usage examples provided in an embodiment of this application. Detailed Implementation

[0019] The technical solution of the present invention will be clearly and completely described below with reference to the embodiments. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0020] The NX secondary development code generation method based on AI Agent provided in this application embodiment can be applied to, for example... Figure 1 The system shown is an NX secondary development code generation system based on AI Agent. The system includes: a function mode selection module, a knowledge retrieval module, a code generation module, a code verification module, a self-iterative correction module, and an output module.

[0021] The function mode selection module is used to receive the user's raw natural language input and development mode selection instructions, and select the target development mode according to the user's development mode selection instructions; The knowledge retrieval module is used to search and match related API knowledge and usage examples based on the natural language input and the pre-built NX secondary development domain knowledge base through semantic retrieval. The code generation module is used to generate initial NX secondary development source code based on the natural language input, retrieved API knowledge, and runtime context parameters of the current NX software using a large language model. The code verification module is used to input the initial NX secondary development source code into the audit and verification tool, perform code structure analysis and verification, and capture error information in the code; The code verification module includes a multi-dimensional code compliance verification engine, which embeds a logical constraint rule library for the NX secondary development domain. The logical constraint rule library integrates NXOpen API calling specifications, transaction context management rules, object lifecycle constraints, memory resource release protocols, and architectural pattern consistency requirements. After code generation, the compliance verification engine automatically performs static topology analysis and logical reachability detection on the code to identify error information in the source code.

[0022] The self-iterative correction module: When the code verification step captures error information, it uses AIAgent to iterate based on the error information, continuously modifying and improving the code until it passes verification; it is used to eliminate syntax errors and API call logic fallacies in the code through multiple rounds of reasoning. It achieves automatic convergence from "unworkable" to "executable".

[0023] Output module: Compiles and packages the verified initial NX secondary development source code to output the final executable DLL file.

[0024] It should be noted that this system is a "low-code semantic programming system". By establishing a logical mapping layer between natural language intent and underlying NX memory object operations, it shields the complexity of C++ pointer operations and API calls, allowing non-programmers to directly generate plug-in code that conforms to engineering standards through domain terminology descriptions.

[0025] The system has built-in "unattended CI / CD (Continuous Integration / Continuous Delivery) logic", which can automatically take over the entire process of code writing, bug fixing and DLL packaging, realizing end-to-end automated delivery from natural language requirements to deployable software assets.

[0026] Furthermore, relying on the localized code standardization verification sandbox and incremental code generation algorithm, the platform can complete code construction and syntax checking in real time after receiving user instructions. Through automated test loops, the original trial-and-error process that relied on manual debugging is transformed into a high-frequency automatic iteration process within the machine, thereby compressing the plugin delivery cycle from the traditional "man-day" level to the "minute" level.

[0027] To address the technical problems of high technical barriers and low development efficiency in existing NX secondary development technologies, which rely on professional programming skills, this application provides an NX secondary development code generation method based on an AI Agent. The method includes: acquiring user-input interaction information, including raw natural language input and development mode selection instructions; determining a target development mode based on the development mode selection instructions, including a headless execution mode and an interactive interface managed mode. Based on raw natural language input and a pre-built NX secondary development domain knowledge base, semantic retrieval is used to match related API knowledge and usage examples. Based on the target development model, retrieved API knowledge, and current NX software runtime context parameters, the initial NX secondary development source code is generated using a large language model. The code structure of the initial NX secondary development source code is analyzed and verified to obtain the error information existing in the initial NX secondary development source code; When errors are found in the initial NX secondary development source code, the AI ​​Agent iterates based on the error information, continuously modifying and improving the code until it passes verification. The verified initial NX secondary development source code is then compiled and packaged to obtain an executable DLL file.

[0028] Based on this, by integrating natural language understanding, domain knowledge retrieval, and AI-powered intelligent correction, the technical threshold for NX secondary development is significantly reduced, and development efficiency is improved. Users only need to input natural language commands and select a development mode (no-interface execution or interactive interface hosting), and the system can automatically match NXOpen API knowledge and usage examples, combined with the current NX runtime context (such as working parts, selected objects, etc.), to generate structurally compliant initial C++ code. More importantly, the system has a built-in multi-dimensional verification mechanism that can accurately identify problems such as syntax errors, API misuse, context conflicts, and architectural violations. The AI ​​Agent then iteratively repairs these errors in layers according to their type, avoiding manual debugging. The entire process does not require users to have C++ or NX API expertise to output compilable, loadable, and runnable DLL plugins, compressing the traditional "human-day-level" development cycle to minutes, truly realizing an intelligent development paradigm of "get plugins as soon as you say your needs," with both high reliability and engineering practical value.

[0029] like Figure 2 As shown in the embodiment of this application, an NX secondary development code generation method based on AI Agent is provided, including: S201. Obtain user input interaction information; wherein, the interaction information includes raw natural language input and development mode selection instructions.

[0030] For example, raw natural language input: the user's request described in plain language. For example: "Help me write a script to change the diameter of all the circular holes in the model to 10 millimeters."

[0031] Development mode selection instruction: The user's choice of "how to run" the code. For example: the user selects "run as a background task" or "run as a plugin with buttons and dialog boxes".

[0032] Based on the development mode selection instructions, determine the target development mode; among which, the target development mode includes the headless execution mode and the interactive interface managed mode.

[0033] It should be noted that the switching between the headless execution mode and the interactive interface managed mode is as follows: The system receives the user's preset development mode instruction. If the instruction is "headless execution mode", the user's requirements are directly transmitted to the code generation module, which directly generates the dynamic link library (DLL) code with a single entry function. If the instruction is "interactive interface managed mode", the system will prompt the user to upload the header file, source file, and user requirements corresponding to the UI definition file. The system will then process the template file and return a DLL executable file that can adapt to the user's UI.

[0034] The “no-interface execution mode” and the “interactive interface managed mode” have fundamental differences in architecture (such as whether it is necessary to inherit the NXOpen::BlockStyler class, whether it is necessary to export the ufsta entry point, etc.).

[0035] For example, a headless mode: must include an extern "C" int fufsta(...) main function; UI managed mode: Must include class MyDialog:public NXOpen::BlockStyler::BlockStylerDialog and callback registration.

[0036] S202. Based on the original natural language input and the pre-built NX secondary development domain knowledge base, semantic retrieval is used to match related API knowledge and usage examples.

[0037] It should be noted that the knowledge base information retrieval adopts a two-layer processing architecture of "semantic standardization + hybrid retrieval"; In addition, a hierarchical index structure was constructed: the AI ​​Agent dynamically selects the retrieval path based on the intent recognition results of the user's natural language instructions, thereby achieving adaptive adjustment of the retrieval scope; When a user intent is identified as pointing to a specific API operation, the system routes to the function-level index to retrieve the parameter signature, call example, and preconditions of the target API function. When the system detects that a user's intent is directed to a specific functional module or high-level task, it routes to the class-level index to retrieve the common usage patterns, typical processes, and associated class interfaces of that functional module. Among them, the function-level index stores fine-grained technical documentation and code snippets for each function in the NXOpen API, while the class-level index stores class clusters organized by functional domain and their cooperative calling paradigms.

[0038] For example, suppose a user enters: "I need to turn off all layers in the assembly whose names contain 'temp'."

[0039] System execution process: Semantic understanding: The system analyzes this sentence and extracts the core intent: the object of operation is "layer", the filter condition is "name contains temp", and the action is "close".

[0040] Semantic retrieval: The system searches in the "NX Secondary Development Domain Knowledge Base".

[0041] It may not find an exact match, but through vector similarity, it found documentation about the UF_LAYER module and a code example about "traversing layers".

[0042] Matching results: The system extracted the following key materials: API knowledge: UF_LAYER_set_status(tag, status) is a function that controls the visibility of layers.

[0043] Example usage: A code snippet showing how to get the object name using UF_OBJ_ask_name() and perform string matching using strstr().

[0044] S203. Based on the target development model, retrieved API knowledge, and current NX software runtime context parameters, the initial NX secondary development source code is generated using a large language model.

[0045] S204. Perform code structure analysis and verification on the initial NX secondary development source code to obtain error information in the initial NX secondary development source code.

[0046] S205. When there are error messages in the initial NX secondary development source code, the AI ​​Agent is used to perform self-iteration based on the error messages, continuously modifying and improving the code until it passes verification; the verified initial NX secondary development source code is compiled and packaged to obtain an executable DLL file.

[0047] Based on the above technical solutions, this application provides an AI Agent-based NX secondary development code generation method. NX secondary development has long faced problems such as high barriers to entry, long development cycles, and reliance on professional programmers, making it difficult for ordinary engineers to directly translate design intent into reliable plugin code. While general-purpose large language models can generate code, they often output "illusion code" with syntax errors, API misuse, or non-compliant structures due to a lack of deep understanding of the NXOpen API specifications, runtime environment, and plugin architecture, making direct compilation and execution impossible. Therefore, there is an urgent need for an end-to-end, verifiable, and self-correcting code generation method for industrial CAD scenarios. This application systematically solves this problem by integrating user intent recognition, development mode adaptation, context-aware semantic retrieval, and AIAgent self-iterative verification: Based on the user's selected "no-interface" or "UI-managed" mode, pre-set code architecture constraints; combine the current NX running state (such as working parts, selected objects) with the domain knowledge base for accurate retrieval to ensure that the generated content fits the actual environment; then, a multi-dimensional verification engine identifies syntax, API, context, and architectural errors; and the AIAgent performs layered repair and targeted rewriting to avoid logical drift caused by full regeneration. This technology enables highly reliable automated generation from natural language to executable DLLs, significantly reducing the development threshold and improving customization efficiency. It represents a key breakthrough in AI-enabled secondary development of industrial software.

[0048] In one possible implementation of the embodiments of this application, such as Figure 3 As shown, the above S202 can be specifically implemented through the following S301, S302, S303 and S304, which are explained in detail below: S301. Preprocess the pre-built NX secondary development domain knowledge base and build a vectorized index library; The preprocessing includes: dividing the NXOpen API documentation, historical code snippets, and technical Q&A documentation into several semantically complete text blocks; converting each text block into a high-dimensional vector through an embedding model; storing the vectors in a vector database to form a vectorized index library.

[0049] S302. Use a semantic encoder to transform the original natural language input into a query vector.

[0050] For example, a user inputs a natural language command, such as "How do I use the NXOpen API to obtain the volume information corresponding to a hole feature?" The system encodes the sentence into a fixed-dimensional vector q, i.e., the "query vector," through a semantic encoder.

[0051] S303. Calculate the similarity score between the query vector and each text block vector in the vectorized index library, sort each text block in descending order according to the similarity score, and select the top K text blocks in the sorting results as the matching results.

[0052] Specifically, by mapping the natural language descriptions input by users into standard query statements that are consistent with the storage format of the knowledge base, expression differences are eliminated; and dense vector indexes and sparse vector indexes are configured to support fuzzy retrieval based on semantic vectors and precise matching based on keywords. To improve the recall and precision of retrieval, the retrieval module constructed the following hybrid retrieval relevance scoring model: ; in, Input is raw natural language; This is the standard query statement after being transformed by the semantic standardization module; Candidate documents from the pre-built NX secondary development domain knowledge base; Represents a vector embedding function; To achieve a dense retrieval score, the cosine similarity between the query vector and each text block vector is calculated. To obtain a sparse retrieval score, calculate the keyword matching degree; This is a mixed weighting coefficient used to dynamically adjust the ratio of semantic matching to keyword matching.

[0053] For example, semantic standardization (eliminating expression differences) takes the input: "How to use NXOpen API to obtain the volume information corresponding to a hole feature?" and outputs: "NXOpen API obtains the volume information of a hole feature". The purpose is to remove colloquial expressions, standardize terminology, and facilitate keyword matching.

[0054] Dual-index retrieval mechanism: Dense Vector Indexing: Fuzzy matching based on semantic vectors.

[0055] use and Calculate cosine similarity It can capture the semantic equivalence of "get body information" ≈ "ask_body"; Sparse vector index: precise matching based on keywords.

[0056] Algorithms such as TF-IDF or BM25 can be used to calculate keyword overlap (e.g., “UF_MODL_ask_body”, “tag_t”, “int”). It is sensitive to structured content such as API names and function signatures.

[0057] S304. Output the API documentation definitions and code snippets in the matching results as associated API knowledge and usage examples to the AI ​​Agent.

[0058] For example, the following information can be extracted from the Top results and output in a structured format: API data: function name, parameter list, return value, and module; Example: complete code snippet and calling context.

[0059] Based on the above technical solutions, in NX secondary development, developers often face problems such as complex API usage, scattered documentation, and difficulty in reusing historical experience, making it difficult for natural language instructions to accurately match effective code examples. If this problem is not solved, the accuracy of AI-generated code will heavily rely on the model's generalization ability, easily leading to erroneous calls and logical omissions. Therefore, it is urgent to build an efficient and accurate domain knowledge retrieval mechanism to support AI agents in acquiring context-relevant API knowledge and instances. This application effectively solves the semantic gap and expression differences by constructing a vectorized index library and combining a hybrid model of dense and sparse retrieval. API documents and code snippets are segmented into semantic blocks and quantized to achieve a unified representation of knowledge; a semantic encoder is used to convert user input into query vectors, improving semantic understanding capabilities; most importantly, a hybrid scoring model is introduced, integrating semantic similarity and keyword matching, significantly improving recall and accuracy. Semantic standardization unifies the expression format of queries and the knowledge base, further enhancing matching consistency. This solution offers significant advantages: First, it supports fuzzy semantic retrieval, understanding natural expressions such as "obtaining volume information corresponding to pore features"; second, it balances precise keyword matching to prevent missing key APIs; and third, its dynamic weighting mechanism adapts to different query scenarios. Ultimately, it provides high-quality related knowledge for the AI ​​Agent, improving code generation reliability and development efficiency, and forming an accumulative and evolvable technological asset system.

[0060] In one possible implementation of this application embodiment, the above-mentioned S203 can be specifically implemented by the following S401 and S402, which are described in detail below: S401. Dynamically assemble the retrieved API knowledge, target development mode, and runtime context parameters of the current NX software to construct a compound prompt word containing role setting, task description, constraints, and reference knowledge.

[0061] S402. Input the compound prompt words into the large language model to generate the initial NX secondary development source code; This process is formally represented as: ; in, This represents the initial NX secondary development source code; For large language models; This indicates vector concatenation or text concatenation operations; This is a system-level instruction; the Agent is defined as a senior NX secondary development expert, and the output format is strictly constrained. Input commands in raw natural language; This is the set of runtime context parameters for the current NX software. This section provides definitions and usage examples of the most relevant API functions returned by the retrieval module.

[0062] For example, suppose a user is designing a mechanical part using Siemens NX software and wants to automatically create a standard hole on a selected cylindrical surface.

[0063] 1. P_user: Acquires user's natural language input, "Drill a simple hole with a diameter of 10mm and a depth of 5mm on the selected cylindrical surface"; 2. C_ctx: Collects the current NX software runtime context parameters and obtains the current operating environment information in real time through the NXOpen API; 3. K_ret: Retrieves relevant API knowledge, calls the API knowledge base, and returns the most relevant function definitions and usage examples based on semantic similarity matching; 4. P_sys: Sets system-level role instructions, such as "You are a senior NX secondary development expert, proficient in NXOpen C API. Please generate a complete piece of C language code that can be directly compiled and run, based on user requirements, the current geometric context, and the provided API reference. Requirements: Include necessary header files, use correct data types, add error handling mechanisms, clear variable naming, output only code, and do not add explanatory text."; 5. Dynamically assembles prompt words, concatenating the above four parts of information according to a preset template to form compound prompt words; The compound prompt words are input into the large language model, and the code generation and reasoning process is executed.

[0064] Based on the above technical solutions, in NX secondary development, user natural language commands are often vague and incomplete, lacking adaptation information for NX API specifications, C++ syntax, and runtime environment (such as the current working component, selected object, and transaction state). Directly handing these commands over to a general large model to generate code easily leads to syntax errors, API misuse, or context conflicts, resulting in code that cannot be compiled or crashes. Therefore, there is an urgent need for a prompt construction mechanism that can deeply integrate domain knowledge, user intent, and runtime state. This application constructs structured compound prompt words by dynamically assembling system roles (P_sys), user commands (P_user), context parameters (C_ctx), and retrieval knowledge (K_ret), enabling the large model to have four layers of guidance during generation: "expert identity," "task objective," "environmental constraints," and "authoritative reference." This method significantly improves the accuracy, compliance, and executability of the generated code: P_sys ensures standardized output format; C_ctx avoids null pointers or invalid operations; K_ret suppresses illusions and provides realistic API usage; and ⊕ concatenation achieves lossless fusion of multi-source information. Compared to end-to-end black-box generation, this solution achieves highly reliable industrial code output with lightweight hint engineering, balancing efficiency and security, and is a key innovation for the implementation of AI programming in the CAD field.

[0065] In one possible implementation of this application embodiment, the above-mentioned S204 can be specifically described as follows: Lexical and syntactic analysis is performed on the initial NX secondary open-source code to construct an abstract syntax tree and identify syntactic errors, including incomplete statements, mismatched brackets, and misspelled keywords. Based on the pre-built NXOpen API interface specification library, the API function names and parameter lists called in the source code are extracted, compared with the standard interface signature, and API usage errors are identified, including parameter type mismatch, missing parameter quantity, and illegal call order. The pre-built NXOpen API interface specification library is constructed using NX SDK header files (such as...). .h / The .dll file is generated through static analysis or structured parsing of official documentation, and contains metadata such as function signature, parameter types, calling prerequisites (e.g., UF_initialize() is required), and thread safety attributes.

[0066] By combining the current runtime context parameters of the NX software, we can analyze the object instantiation status, variable lifecycle and resource access permissions in the source code to identify context inconsistency errors, including referencing null objects, operating on inactive components, and unauthorized access to system resources. It's important to note that runtime context (such as the current work part or selected object) is inherently dynamic information, while syntax / AST analysis is a static process. Instead of running code in real-time within NX, the current session's context state is injected into the analyzer as symbolic assumptions (e.g., assuming workPart != nullptr) to perform context-aware static reachability and null pointer inference.

[0067] Based on the target development mode selected by the user, the program architecture of the source code is verified to meet the preset development mode code template; if yes, an architecture compliance signal is generated, allowing the code to enter the subsequent processing stage; if no, the violation type is identified and the corresponding architecture violation error information is generated, including unregistered event callback functions, unisolated UI threads, and missing main function entry points; The identified error information is categorized and located, and a structured diagnostic report is generated that includes error type, error location, error description, and repair suggestions.

[0068] Based on the aforementioned technical solutions, NX secondary development heavily relies on professional programmers manually writing C++ code. This not only has a high barrier to entry and a long development cycle, but is also prone to plugin crashes due to syntax errors, API misuse, or context mismatches, severely restricting enterprise customization efficiency. While general-purpose large models can generate code, they lack a deep understanding of the NXOpen API specifications, runtime states, and plugin architecture, often outputting seemingly reasonable but actually unexecutable code. Therefore, there is an urgent need for a precise, reliable, and verifiable code generation mechanism for industrial CAD scenarios. This application systematically solves the above problems by constructing a multi-dimensional code verification engine: lexical and syntactic checks based on abstract syntax trees ensure the legality of basic code; precise verification of parameter types, quantities, and calling order is achieved based on a pre-built NXOpen API specification library, preventing interface abuse; the current NX runtime context (such as activated parts and selected objects) is integrated into static analysis to identify dynamic risks such as null pointers and unauthorized access in advance; and the compliance of the program architecture (such as entry functions and thread isolation) is forcibly verified according to the user's selected development mode (no interface / with UI). This solution embeds domain knowledge, environmental conditions, and engineering specifications into the verification closed loop, which not only significantly improves the usability of the generated code, but also supports the accurate self-repair of the subsequent AI Agent. It is a key guarantee for achieving end-to-end automation of "natural language → executable NX plugin", and has both technological advancement and engineering application value.

[0069] In one possible implementation of this application embodiment, the above-mentioned S205 can be specifically described as follows: After receiving code verification feedback, the AI ​​Agent performs semantic analysis and classification on the error information to identify the level to which the error belongs, including the syntax level, API call level, context lifecycle level, or architecture template level. It should be noted that the error level can be directly mapped based on the error type field (such as error_type:"API_MISMATCH") in the structured diagnostic report output by the verification module, or through intent recognition of the natural language error description by a lightweight rule engine / NLU model.

[0070] For errors at different levels, activate the corresponding repair strategy engine: Syntax errors: Automatically correct errors by calling the syntax repair rule base; API call layer error: By associating with the pre-built NXOpen API knowledge graph, the correct parameter types, call order, and dependencies of the target function are retrieved, and parameter correction suggestions are generated; Context lifecycle layer error: Based on the current operation semantics, automatically insert UF_initialize() / UF_terminate() or transaction start / end encapsulation structure into the code; Architecture template layer error: Match the pre-stored NX secondary development architecture template library and generate a structure replacement suggestion that conforms to the "no-interface background execution" or "interactive UI callback" mode; The above-mentioned layered repair suggestions are injected into the input context of the large language model as a structured prompt template, driving it to perform targeted code rewriting instead of full regeneration, until the code passes verification or reaches the preset maximum number of iterations.

[0071] Based on the above technical solutions, in NX secondary development, code generated by the large language model often fails to compile or run due to syntactic flaws, API misuse, context mismatch, or architecture incompatibility. Relying on manual debugging negates the value of automation. Therefore, a mechanism that can automatically identify the root cause of errors and accurately repair them is urgently needed to achieve a closed loop from "generation" to "usability." This application systematically solves this problem by constructing a hierarchical error classification and targeted repair system: verification feedback is classified into four layers: syntax, API, context, and architecture, ensuring that the repair strategy aligns with the essence of the error; dedicated repair resources are invoked for different layers—the syntax layer uses a deterministic rule base for efficient correction, the API layer relies on the NXOpen knowledge graph to provide authoritative correction suggestions, the context layer automatically injects transaction and initialization logic, and the architecture layer matches preset templates to ensure plugin structure compliance; repair suggestions are injected into the large language model as structured prompts, driving it to rewrite only the erroneous fragments, avoiding logic drift and efficiency loss caused by full regeneration. This technical solution not only significantly improves the first-pass yield rate of code, but also realizes domain knowledge-driven intelligent self-healing capabilities, enabling the end-to-end generation from natural language to executable NX plugins to truly possess industrial-grade reliability and engineering application value.

[0072] Some of the data in the above formula are calculated by removing dimensions and taking their numerical values. The formula is the closest to the real situation obtained by software simulation of a large amount of collected data. The preset parameters and preset thresholds in the formula are set by those skilled in the art according to the actual situation or obtained through simulation of a large amount of data.

Claims

1. A method for generating NX secondary development code based on AI Agent, characterized in that, include: Acquire user-input interaction information, including raw natural language input and development mode selection instructions; Based on the development mode selection instruction, the target development mode is determined, which includes a headless execution mode and an interactive interface managed mode. Based on raw natural language input and a pre-built NX secondary development domain knowledge base, semantic retrieval is used to match related API knowledge and usage examples. Based on the target development model, the retrieved API knowledge, and the runtime context parameters of the current NX software, the initial NX secondary development source code is generated using a large language model. The initial NX secondary development source code is analyzed and verified to obtain error information in the initial NX secondary development source code; When errors are found in the initial NX secondary development source code, the AI ​​Agent iterates based on the error information, continuously modifying and improving the code until it passes verification. The verified initial NX secondary development source code is then compiled and packaged to obtain an executable DLL file.

2. The NX secondary development code generation method based on AI Agent according to claim 1, characterized in that, The interfaceless execution mode and the interactive interface managed mode can be switched, including: If the target development mode is a user-free execution mode, then the source code of the dynamic link library with a single entry function will be generated. If the target development mode is the interactive interface hosting mode, the user is prompted to upload the header and source files of the UI definition file before code generation; and based on the UI control definition information in the header and source files, the code template is parameterized to generate DLL source code that is compatible with the user interface.

3. The NX secondary development code generation method based on AI Agent according to claim 1, characterized in that, The API knowledge and usage examples for matching and association include: Preprocess the pre-built NX secondary development domain knowledge base to build a vectorized index library; The preprocessing includes: segmenting the NXOpen API documentation, historical code snippets, and technical Q&A documentation into text blocks, and using an embedding model to convert the text blocks into vector form for storage; The original natural language input is transformed into a query vector using a semantic encoder; Calculate the similarity score between the query vector and each text block vector in the vectorized index library, sort each text block in descending order according to the similarity score, and select the top K text blocks in the sorted results as the matching results; The API documentation definitions and code snippets in the matching results will be used as associated API knowledge and usage examples.

4. The NX secondary development code generation method based on AI Agent according to claim 1, characterized in that, The semantic retrieval also features a hierarchical index structure, including function-level indexes and class-level indexes; Based on the Agent's recognition results of the user's natural language input, the system dynamically routes to the function-level index to query the parameter signature, call examples, and preconditions of the target API function; or routes to the class-level index to query the general usage patterns, typical processes, and related class interfaces of a certain functional module. The function-level index stores fine-grained technical documentation and code snippets for each function in the NXOpen API, while the class-level index stores class clusters organized by functional domain and their collaborative calling paradigms.

5. The NX secondary development code generation method based on AI Agent according to claim 1, characterized in that, The calculation of the similarity score between the query vector and each text block vector includes: The similarity score between the query vector and each text block vector is calculated using a hybrid retrieval relevance scoring model. This model is based on both dense and sparse retrieval scores, and its expression is as follows: ; in, Input is raw natural language; This is the standard query statement after being transformed by the semantic standardization module; Candidate documents from the pre-built NX secondary development domain knowledge base; Represents a vector embedding function; To achieve a dense retrieval score, the cosine similarity between the query vector and each text block vector is calculated. To obtain a sparse retrieval score, calculate the keyword matching degree; This is a mixed weighting coefficient used to dynamically adjust the ratio of semantic matching to keyword matching.

6. The NX secondary development code generation method based on AI Agent according to claim 1, characterized in that, The initial NX secondary development source code includes: The retrieved API knowledge, target development mode, and runtime context parameters of the current NX software are dynamically assembled to construct a compound prompt word that includes role setting, task description, constraints, and reference knowledge. The compound prompt words are input into the large language model to generate the initial NX secondary development source code; This process is formally represented as: ; in, This represents the initial NX secondary development source code; For large language models; This indicates vector concatenation or text concatenation operations; This is a system-level instruction; the Agent is defined as a senior NX secondary development expert, and the output format is strictly constrained. Input commands in raw natural language; This is the set of runtime context parameters for the current NX software. This section provides definitions and usage examples of the most relevant API functions returned by the retrieval module.

7. The NX secondary development code generation method based on AI Agent according to claim 1, characterized in that, The process of obtaining error information present in the initial NX secondary development source code includes: Lexical and syntactic analysis is performed on the initial NX secondary open-source code to construct an abstract syntax tree and identify syntactic errors, including incomplete statements, mismatched brackets, and misspelled keywords. Based on the pre-built NXOpen API interface specification library, the API function names and parameter lists called in the source code are extracted, compared with the standard interface signature, and API usage errors are identified, including parameter type mismatch, missing parameter quantity, and illegal call order. By combining the current runtime context parameters of the NX software, we can analyze the object instantiation status, variable lifecycle and resource access permissions in the source code to identify context inconsistency errors, including referencing null objects, operating on inactive components, and unauthorized access to system resources. Based on the target development mode selected by the user, the program architecture of the source code is verified to meet the preset development mode code template; if yes, an architecture compliance signal is generated, allowing the code to enter the subsequent processing stage; if no, the violation type is identified and the corresponding architecture violation error information is generated, including unregistered event callback functions, unisolated UI threads, and missing main function entry points; The identified error information is categorized and located, and a structured diagnostic report is generated that includes error type, error location, error description, and repair suggestions.

8. The NX secondary development code generation method based on AI Agent according to claim 1, characterized in that, The method of using an AI Agent to perform self-iteration based on error information includes: The error information in the verification feedback is classified and its error level is identified. The error level includes the syntax level, API call level, context lifecycle level or architecture template level. Based on the error level, activate the corresponding repair strategy: If it is a syntax error, the source code will be automatically corrected by calling the pre-built syntax correction rule library; If the error is at the API call layer, the correct parameter types, call order, and dependencies of the target API function are retrieved based on the pre-built NXOpen API knowledge graph, and parameter correction suggestions are generated. If the error is a context lifecycle layer error, then UF_initialize() / UF_terminate() or transaction start / end encapsulation structure will be automatically inserted into the code according to the current operation semantics. If the error is in the architecture template layer, the pre-stored NX secondary development architecture template library will be matched to generate a structured replacement suggestion that matches the development mode selected by the user. The repair suggestions are injected into the input context of the large language model in the form of structured prompts, driving it to rewrite the initial source code in a targeted manner rather than regenerate it completely, and repeat the verification and repair process until the generated code passes all verification items or reaches the preset maximum number of iterations.

9. An NX secondary development code generation system based on an AI Agent, operating based on the NX secondary development code generation method based on an AI Agent as described in any one of claims 1-8, characterized in that, The functional mode selection module, knowledge retrieval module, code generation module, code verification module, self-iterative correction module, and output module are described. The function mode selection module is used to receive the user's raw natural language input and development mode selection instruction, and select the target development mode according to the user's development mode selection instruction. The knowledge retrieval module is used to match related API knowledge and usage examples through semantic retrieval based on the natural language input and the pre-built NX secondary development domain knowledge base; The code generation module is used to generate initial NX secondary development source code based on the natural language input, retrieved API knowledge, and runtime context parameters of the current NX software using a large language model. The code verification module is used to input the initial NX secondary development source code into the audit and verification tool, perform code structure analysis and verification, and capture error information in the code; The self-iterative correction module: When the code verification step captures error information, it uses the AI ​​Agent to perform self-iteration based on the error information, continuously modifying and improving the code until it passes verification; The output module compiles and packages the verified initial NX secondary development source code, outputting the final executable DLL file.

10. The NX secondary development code generation system based on AI Agent according to claim 9, characterized in that, The code verification module includes a multi-dimensional code compliance verification engine. The compliance verification engine has an embedded logical constraint rule library for the NX secondary development field. The logical constraint rule library integrates NXOpen API calling specifications, transaction context management rules, object lifecycle constraints, memory resource release protocols, and architectural pattern consistency requirements. After the code is generated, the compliance verification engine automatically performs static topology analysis and logical reachability detection on the code to identify error information in the source code.