Finite state machine generation method and computing device
By receiving natural language information to generate metadata for a finite state machine, and combining semantic mapping and a two-layer mapping linkage mechanism, target code and visualization graphics are automatically generated. This solves the problems of high manual costs and low efficiency in existing technologies, and achieves efficient and accurate generation and real-time synchronous updates across domains.
Patent Information
- Application Number
- CN202610644779.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-05-11
- Publication Date
- 2026-08-25
AI Technical Summary
Existing technologies for generating finite state machines are characterized by high labor costs, low efficiency and accuracy, and reliance on manual coding and graphical drawing, making them difficult to apply across different fields.
By receiving natural language information input by users, using semantic mapping and target large language model to generate metadata of finite state machines, and combining a two-layer mapping linkage mechanism of visualization graphics and code, target code and visualization graphics are automatically generated, reducing manual costs and improving generation efficiency and accuracy.
It enables the generation of efficient and accurate finite state machines without requiring specialized knowledge, adapts to multiple scenarios and cross-domain applications, reduces labor costs, improves generation efficiency and accuracy, and supports real-time synchronous updates of code and graphics.
Smart Images

Figure CN122633281A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of artificial intelligence technology, and in particular to a finite state machine generation method and computing device. Background Technology
[0002] Finite state machines (FSMs), as models for implementing system flow control, have been widely applied in state mechanism scenarios in computer programs, such as e-commerce business operations, industrial production control, game development and design, and front-end application development. Currently, finite state machines are typically generated by manually creating graphical diagrams and then manually coding based on these diagrams. This approach is labor-intensive and suffers from poor efficiency and accuracy. Summary of the Invention
[0003] This application provides a finite state machine generation method and computing device, which can reduce costs and improve the efficiency and accuracy of finite state machine generation in scenarios involving finite state machine generation.
[0004] In a first aspect, embodiments of this application provide a method for generating a finite state machine (FSM). The method includes: receiving natural language information input by a user, whereby the natural language information describes a target business process in any scenario; performing semantic mapping on the natural language information to convert it into target data adapted to a finite state machine format; based on the data structure requirements of a finite state machine, splitting the data in the target data to obtain target metadata for the finite state machine, whereby the target metadata includes state information, event information, transition rule information, and action information of the finite state machine; and generating target code for the finite state machine and a visual graph of the finite state machine based on the target metadata. The target code is used to run the finite state machine, and the visual graph includes nodes representing the various states of the finite state machine and edges representing triggering events and actions during transitions between different states.
[0005] Thus, by receiving natural language input from users, no user expertise in finite state machines or the writing of structured requirement documents is required. Target business requirements can be submitted simply through naturally described text or voice, lowering the barrier to entry and adapting to diverse scenarios and cross-domain needs. Semantic mapping of natural language information eliminates ambiguity and fragmentation while preserving the original semantics, accurately converting unstructured text into standardized target data compatible with finite state machine formats. This streamlines the conversion from natural language to specialized data, avoiding semantic loss or format deviations. Furthermore, core elements corresponding to the target business process are extracted according to the data structure requirements of finite state machines, yielding target metadata including states, events, transition rules, and actions. This ensures the target metadata aligns with the finite state machine's operating rules and underlying logic. Finally, based on this target metadata, logically consistent and executable target code and visualizations are automatically generated. The target code directly supports the stable operation of the finite state machine, and the visualizations clearly present the state transition chain, transition trigger conditions, and corresponding execution actions, facilitating rapid verification, debugging, and correction. This enables fully automated generation of finite state machines (FSMs) driven by the entire process, with the ability to deploy complete code and visualize the entire process. The entire process eliminates the need for complex format conversions and logic writing by manual intervention, reducing the manual costs and technical barriers to FSM generation, and improving the efficiency and accuracy of FSM generation. Furthermore, it allows for the rapid generation of adaptable FSMs through a unified natural language interaction method, independent of any specific domain ecosystem, enabling flexible reuse across domains and technology stacks.
[0006] In one possible implementation, the method further includes: in response to receiving a first operation instruction, modifying a first element, the first operation instruction indicating modification of a first element in a visualization, the first element including a first node and / or a first edge; determining first metadata corresponding to the first element from target metadata based on a first mapping relationship, the first mapping relationship indicating the correspondence between the element and the metadata of the finite state machine; determining first code corresponding to the first metadata from target code based on a second mapping relationship, and modifying the first code, the second mapping relationship indicating the correspondence between the code and the metadata of the finite state machine; and / or, in response to receiving a second operation instruction, modifying a second code, the second operation instruction indicating modification of a second code in the target code; determining second metadata corresponding to the second code from target metadata based on a second mapping relationship; determining a second element corresponding to the second metadata from elements in the visualization based on the first mapping relationship, and modifying the second element, the second element including a second node and / or a second edge.
[0007] Thus, by constructing a two-layer mapping and linkage mechanism between visual elements and finite state machine metadata, and between metadata and target code, when a user modifies an element in the visual interface, the corresponding target code is located and modified synchronously, achieving automatic synchronous updates from the visual operation to the code layer. Through this bidirectional linkage mechanism between code and visual graphics, combined with the two-layer mapping relationship, the code to metadata is automatically updated when the user modifies the target code, enabling real-time updates of visual graphics nodes and links when the target code changes. The hierarchical synchronous updates from metadata to visual graphics achieve real-time linkage and alignment between code logic and visual nodes and edges. No manual verification or modification is required, ensuring consistency among visual graphics, metadata, and target code, and improving the efficiency of finite state machine design and code maintenance.
[0008] In one possible implementation, based on the data structure requirements of a finite state machine, the data in the target data is split to obtain the target metadata of the finite state machine. This includes: splitting the data in the target data to obtain initial metadata based on the data structure requirements of the finite state machine; and optimizing the initial metadata to obtain the target metadata. The optimization process includes removing duplicate states from the initial metadata and / or removing transition rules that do not exist or do not need to be executed in the target business process.
[0009] In this way, by removing duplicate states from the initial metadata and removing transformation rules that do not exist or do not need to be executed in the target business process, the final generated target metadata meets the requirements of the fewest number of states, the highest transformation efficiency, and the best business adaptability, effectively improving the overall operating efficiency and business adaptability of the finite state machine.
[0010] In one possible implementation, the target metadata also includes a basic configuration, which indicates the target development language and target framework corresponding to the finite state machine. Based on the target metadata, the target code for the finite state machine is generated, including: based on the basic configuration, calling the target code template corresponding to the basic configuration. The target code template includes a basic framework code template built based on the target development language and target framework, and a business logic code template for carrying the states, events, transition rules, and actions of the finite state machine. Basic framework code is generated based on the basic framework code template, and state information, event information, transition rule information, and action information are filled into the business logic code template to generate business logic code. The target code includes the basic framework code and the business logic code.
[0011] Thus, by using target metadata-driven code template generation, we can improve the efficiency and consistency of code generation, ensure that the basic framework and business logic code are generated strictly according to the target metadata, reduce errors and repetitive development work caused by manual coding, keep the target code and finite state machine design highly consistent, and improve the reliability and maintainability of the code.
[0012] In one possible implementation, the method further includes: acquiring runtime information generated during the runtime of the finite state machine, including normal information and / or abnormal information. Normal information indicates that the finite state machine operates according to the target business process's runtime logic, while abnormal information indicates that the finite state machine does not operate according to the target business process's runtime logic. Based on the runtime information, the finite state machine and target code are adjusted. And / or, if the runtime information includes abnormal information, abnormal nodes associated with the abnormal information are marked in the visualization. The abnormal nodes, along with the links of abnormal events, abnormal actions, and abnormal codes corresponding to the abnormal nodes, are displayed in the visualization to locate the cause of the abnormality.
[0013] In this way, based on the actual operating data of the deployed finite state machine, redundant states and inefficient links in the operation of the finite state machine can be identified, and targeted optimization and iterative adjustments can be completed. The target code and visualization graphics can be updated synchronously without manual intervention, so that the rules and structure of the finite state machine can dynamically adapt to business changes and continuously improve the efficiency of state transitions and logical adaptability. In addition, during the operation of the finite state machine, the complete link of abnormal nodes, abnormal events, abnormal actions and abnormal code corresponding to abnormal nodes can be displayed in real time, forming a visualized abnormal traceability chain. Without the need for manual line-by-line checking of code and metadata, or sifting through massive logs, the root cause of the abnormality can be quickly located, effectively improving the efficiency of anomaly investigation and debugging of finite state machines.
[0014] In one possible implementation, the initial metadata is optimized to obtain the target metadata. This includes: validating the initial metadata to obtain a validation result, which indicates whether the initial metadata conforms to the operational logic of the target business process. If the validation result indicates that the initial metadata conforms to the operational logic of the target business process, the initial metadata is then optimized.
[0015] In this way, by verifying first and then optimizing, we can ensure that the generated initial metadata not only meets the specification constraints of the finite state machine, but also closely matches the actual business process. This avoids problems such as incorrect state definition, unreasonable event binding, and conflicting transition logic, thereby improving the accuracy of the initial metadata and enhancing the stability, accuracy, and executability of the state machine.
[0016] In one possible implementation, semantic mapping is performed on natural language information to convert it into target data adapted to a finite state machine format. This includes: converting natural language information into structured elements; and performing semantic mapping on the structured elements to convert the natural language information into target data adapted to a finite state machine format.
[0017] In this way, it is possible to convert unstructured natural language into data that is compatible with finite state machine format, without requiring users to have professional knowledge of finite state machine design, thus lowering the threshold for using finite state machine design.
[0018] In one possible implementation, the initial metadata is obtained through a target large language model, whose input includes natural language information. The target large language model is fine-tuned based on domain knowledge from a finite state machine. The target metadata is obtained through a reinforcement learning model, whose input includes the initial metadata. The optimization objectives of the reinforcement learning model's activation function include: removing duplicate states from the initial metadata, and / or removing transformation rules that are absent or unnecessary to execute in the target business process.
[0019] Thus, since the target large language model has been fine-tuned with knowledge of the finite state machine domain, it has learned and mastered the professional elements and format specifications of FSM such as states, events, transition rules, and actions. Therefore, it can directly understand the business processes described in natural language and accurately output the metadata of the standardized finite state machine (such as initial metadata), which greatly improves the generation efficiency and accuracy of the finite state machine.
[0020] In one possible implementation, the method further includes: deploying the target code to a target service cluster, which is used to host and run the finite state machine.
[0021] In this way, the target code can be deployed to the target service cluster and the finite state machine can be run directly without additional adaptation and adjustment, shortening the cycle from state machine design to actual deployment and operation.
[0022] In one possible implementation, the method further includes: using natural language information as input samples and the initial metadata of the corresponding finite state machine as labeled output samples to train the target LLM in order to achieve iterative optimization of the target LLM.
[0023] In this way, the accuracy of the model's natural language understanding of business scenarios can be continuously improved, and the accuracy of the conversion from natural language to metadata can be optimized.
[0024] In one possible implementation, the method further includes: using the metadata corresponding to the runtime information generated by the finite state machine as feedback, and iteratively training the reinforcement learning model based on a preset activation function to achieve iterative optimization of the reinforcement learning model.
[0025] In this way, the ability of reinforcement learning models to identify operational problems and the effectiveness of metadata optimization strategies can be continuously improved, thereby increasing the efficiency of state machine iterative adjustments.
[0026] Secondly, embodiments of this application provide a computing device, including: a memory and a processor. The memory is used to store program instructions. The processor is used to execute the program instructions, causing the computing device to perform the finite state machine generation method as described in the first aspect or any possible implementation thereof.
[0027] Thirdly, a computer-readable storage medium is provided that stores computer-executable instructions, which, when executed on a computing device, cause the computing device to perform the finite state machine generation method as described in the first aspect or any possible implementation thereof.
[0028] Fourthly, a computer program product is provided, the computer program product including computer execution instructions, which, when executed on a computing device, cause the computing device to perform the finite state machine generation method as described in the first aspect or any possible implementation thereof.
[0029] The technical effects of any of the implementation methods in the second to fourth aspects can be found in the technical effects of different implementation methods in the first aspect, and will not be repeated here.
[0030] Based on the implementation methods provided in the above aspects, this application can be further combined to provide more implementation methods. Attached Figure Description
[0031] Figure 1 A schematic diagram of a finite state machine generation system provided in this application embodiment; Figure 2 A schematic diagram of another finite state machine generation system provided in this application embodiment; Figure 3 This is a schematic diagram of the structure of a computing device provided in an embodiment of this application; Figure 4 A flowchart illustrating a method for generating a finite state machine according to an embodiment of this application; Figure 5 A visual flowchart illustrating a method for generating a finite state machine according to an embodiment of this application; Figure 6 This is a flowchart illustrating a process for triggering synchronous modification of target code based on manual modification of a visual graphic, as provided in an embodiment of this application. Figure 7A flowchart illustrating the process of simultaneously modifying visual graphics based on adjustments to target code, as provided in this application embodiment; Figure 8 This is a schematic diagram illustrating the process of monitoring and iteratively optimizing the operational information of a finite state machine, as provided in an embodiment of this application. Detailed Implementation
[0032] The technical solutions in the embodiments of this application will now be described with reference to the accompanying drawings.
[0033] In the description of this application, unless otherwise stated, " / " indicates that the objects before and after are in an "or" relationship. For example, A / B can mean A or B. "And / or" in this application is merely a description of the relationship between the related objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist simultaneously, and B exists alone. A and B can be singular or plural.
[0034] Furthermore, in the description of this application, unless otherwise stated, "multiple" means two or more. "At least one of the following" or similar expressions refer to any combination of these items, including any combination of a single item or a plurality of items. For example, at least one of a, b, or c can mean: a, b, c, ab, ac, bc, or abc, where a, b, and c can be single or multiple.
[0035] Furthermore, to facilitate a clear description of the technical solutions in the embodiments of this application, the terms "first" and "second" are used in the embodiments of this application to distinguish identical or similar items with substantially the same function and effect. Those skilled in the art will understand that the terms "first" and "second" do not limit the quantity or execution order, and that "first" and "second" are not necessarily different. Meanwhile, in the embodiments of this application, the terms "exemplary" or "for example" are used to indicate that something is being used as an example, illustration, or description. Any embodiment or design scheme described as "exemplary" or "for example" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design schemes. Specifically, the use of terms such as "exemplary" or "for example" is intended to present related concepts in a concrete manner for ease of understanding.
[0036] The following provides an exemplary description of the application scenarios of the embodiments of this application.
[0037] This application's embodiments are primarily applied to scenarios involving the generation of finite state machines, such as applications requiring process control. A finite state machine is a mathematical computational model that includes a finite number of states, events, transition rules, and actions, achieving system process control through state transitions. Such systems include e-commerce business systems, industrial equipment control systems, game development systems, or front-end interactive systems. Correspondingly, this application's embodiments can be specifically applied to various application scenarios such as e-commerce business operations, industrial production control, game development and design, and front-end application development.
[0038] Taking e-commerce business operations as an example, the e-commerce business system coordinates the entire e-commerce business chain, including order transactions, warehousing and fulfillment, logistics and distribution, and after-sales processing. Its core business processes exhibit phased state evolution characteristics, and the transitions between states require clearly defined triggering conditions and execution rules. Based on this, by generating a corresponding finite state machine based on the core business processes of the e-commerce business system, the progress stages of each e-commerce business link can be abstracted as states, the triggering conditions for business advancement can be defined as events, the transition specifications between states can be set as transformation rules, and the business operations to be performed during the transition process can be clearly defined as actions. Through the orderly transition of states, automated and standardized control of the entire e-commerce business process can be achieved, thereby supporting the efficient operation of the e-commerce business system.
[0039] The system architecture of the embodiments of this application will be described below as an example.
[0040] like Figure 1 As shown, this application provides a finite state machine generation system. The system may include a perception layer, an artificial intelligence (AI) engine layer, and a visualization and interaction layer, specifically: The perception layer receives natural language information input from the user. This natural language information is used to describe the target business process in any scenario.
[0041] The AI engine layer performs semantic mapping on natural language information, converting it into target data adapted to a finite state machine (FSM) format. Based on the FSM data structure requirements, it decomposes the target data to obtain the FSM's target metadata, which includes the FSM's state information, event information, transition rule information, and action information. Furthermore, it generates the FSM's target code based on the target metadata. The target code is then used to run the FSM.
[0042] The visualization and interaction layer is used to render and display a visual representation of the finite state machine based on the target metadata, such as through a visual interactive interface. The visualization includes nodes representing the various states of the finite state machine, and edges representing the triggering events and actions during transitions between different states.
[0043] In one implementation, the AI engine layer includes a target large language model (LLM). The target LLM is obtained by fine-tuning the LLM model based on domain knowledge of the FSM.
[0044] The input to the target LLM includes natural language information or structured elements. Structured elements are core business information related to the target business process, extracted from the natural language information, including states, events, transition rules, and actions. The output of the target LLM includes metadata of the finite state machine. This metadata indicates the state, event, transition rule, and action information of the finite state machine. For example, this metadata may include initial metadata or target metadata. Target metadata is obtained by optimizing the initial metadata. Optimization includes reducing the number of redundant states and / or removing transition rules that do not exist or do not need to be executed in the target business process, while ensuring that the states-events-transitions-actions indicated by the initial metadata meet the business rules of the target business process.
[0045] Optionally, the perception layer includes a natural language understanding (NLU) semantic extraction engine, which extracts semantics from natural language information to obtain structured elements.
[0046] Optionally, the AI engine layer may also include a reinforcement learning (RL) model. The reinforcement learning model uses the optimization objective as the activation function (such as a reward function), iteratively calculates, and achieves the aforementioned optimization. The optimization objective is: while ensuring that the state-event-transition-action indicated by the initial metadata meets the business rules of the target business process, reduce the number of states with redundant functions, and / or remove transition rules that do not exist or do not need to be executed in the target business process.
[0047] The input to a reinforcement learning model includes initial metadata. The output includes target metadata. This is applied in scenarios where the target LLM outputs initial metadata.
[0048] For example, a reinforcement learning model can specifically be a deep learning (deep q-network, DQN) model.
[0049] Optionally, the AI engine layer also includes a rules engine. The rules engine validates the initial metadata, obtaining validation results that indicate whether the initial metadata conforms to the operational logic of the target business process. Based on this, if the validation results indicate that the initial metadata conforms to the operational logic of the target business process, the initial metadata is optimized.
[0050] In some embodiments, the AI engine layer is also used to trigger synchronous modifications to the target code based on manual modifications to the visualization graphics. And / or, to trigger synchronous modifications to the visualization graphics based on manual modifications to the target code. Specific implementation details can be found in Part II of the subsequent methods, and will not be elaborated upon here.
[0051] In one implementation, the AI engine layer includes an abstract syntax tree (AST) parser, which enables the linked modification of the target code of the finite state machine and the visualization graph.
[0052] In some embodiments, the system may further include an execution layer for deploying the finite state machine, running the finite state machine, and acquiring its operational information. This operational information is used to adjust the finite state machine and the target code. If the operational information includes exception information, it can also be used to locate the cause of the exception.
[0053] In one implementation, the execution layer may include a runtime engine, which deploys the target code to a target service cluster, which is used to host and run the finite state machine, thereby enabling the deployment of the finite state machine.
[0054] like Figure 2 As shown in the figure, this application provides another structural schematic diagram of a finite state machine generation system. Specifically: The perception layer acquires natural language information from user input, such as e-commerce orders or robot control processes.
[0055] The target LLM, deployed based on the AI engine layer, performs semantic mapping and decomposition operations on natural language information to generate initial metadata. The reinforcement learning model deployed based on the AI engine layer optimizes the initial metadata to obtain target metadata. The AI engine layer generates target code for a finite state machine based on the target metadata, and a visualization interaction layer renders and displays visual graphics based on the target metadata.
[0056] For example, a visualization layer renders and displays a visual graphic based on the target metadata. Users can manually adjust the visual graphic in this layer, such as dragging nodes and / or edges, or modifying transition rules between nodes. First, it's determined whether a manual adjustment was made. If so, the visualization layer synchronously modifies the visual graphic based on this adjustment, and the AST parser deployed in the AI engine layer synchronously updates the target metadata, generating the target code for a finite state machine based on the modified metadata. If no manual adjustment was made, the AI engine layer directly generates the target code based on the target metadata.
[0057] Another example involves generating a visual representation of a finite state machine and its target code. If the user makes manual adjustments to the visualization, not only the target metadata is adjusted, but the target code can also be adjusted synchronously based on these metadata changes (e.g., using an AST parser). Subsequent deployments require deploying the adjusted target code. This example demonstrates... Figure 2 Not shown in the image.
[0058] The target code for the finite state machine is deployed through the execution layer to run the finite state machine and monitor its operation to obtain operational information. This operational information can be transmitted to the perception layer, which in turn transmits it to the AI engine layer and the visualization interaction layer.
[0059] The interactive visualization layer marks abnormal nodes associated with anomaly information within the visualization graph. These abnormal nodes (highlighted in red) are displayed in the graph, along with the corresponding abnormal events, actions, and codes (e.g., anomaly chains) to help pinpoint the cause of the anomaly. Optionally, the chain can also display the times when the abnormal event was triggered and the abnormal action was executed, facilitating timeline backtracking. Optionally, the interactive visualization layer can also issue alerts.
[0060] By modifying the metadata corresponding to the abnormal node through the AI engine layer, the target code can be modified and redeployed.
[0061] The AI engine layer optimizes target metadata based on runtime information, thereby using changes in target metadata as an index to optimize target code on the one hand, and visualize graphics through a visualization interaction layer on the other.
[0062] In this embodiment of the application, the above system can be deployed on a cluster of computing devices.
[0063] In this embodiment, the computing device cluster may include servers and display terminals. For example, the visualization interaction layer and perception layer are deployed on the display terminal, while the AI engine layer and execution layer are deployed on the server. The server can be a single physical server or logical server, or it can be composed of two or more physical servers or logical servers that share different responsibilities, working together to achieve various server functions such as data processing and service provision through division of labor and cooperation.
[0064] In terms of hardware form, servers can be blade servers, high-density servers, rack servers, or tower servers, which are suitable for different application scenarios such as high-density cluster deployment in data centers and small enterprise server rooms.
[0065] like Figure 3 As shown, this application embodiment provides a computing device 500. The computing device 500 includes a processor 510 and a memory 520 for storing processor-executable instructions. When the processor 510 is configured to execute instructions, the computing device 500 performs the various functions described above. For example, the processor 510 performs the various functions of the computing device described above.
[0066] Figure 3 The computing device 500 shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.
[0067] The computing device 500 is manifested in the form of a general-purpose computing device. The components of the computing device 500 may include, but are not limited to: one or more processors 510, memory 520, communication bus 540 connecting different system components (including memory 520 and processor 510), and communication interface 530.
[0068] Communication bus 540 represents one or more of several bus architectures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus using any of the various bus architectures. For example, these architectures include, but are not limited to, the Industry Standard Architecture (ISA) bus, the Micro Channel Architecture (MAC) bus, the Enhanced ISA bus, the Video Electronics Standards Association (VESA) local bus, and the Peripheral Component Interconnection (PCI) bus.
[0069] Memory 520 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) and / or cache memory. The computing device may further include other removable / non-removable, volatile / non-volatile computer system storage media. Although Figure 3 As not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk") and an optical disc drive for reading and writing to a removable non-volatile optical disc (e.g., a compact disc read-only memory (CD-ROM), a digital video disc read-only memory (DVD-ROM), or other optical media) may be provided. In these cases, each drive may be connected to the communication bus 540 via one or more data media interfaces. The memory 520 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of the embodiments of this application.
[0070] A program / utility having a set (at least one) of program modules can be stored in memory 520. Such program modules include—but are not limited to—an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. The program modules typically perform the functions and / or methods described in the embodiments of this application.
[0071] The computing device 500 can also communicate with one or more external devices (e.g., keyboard, pointing device, display, etc.), and with one or more devices that enable a user to interact with the computing device, and / or with any device that enables the computing device to communicate with one or more other computing devices (e.g., network interface card, modem, etc.). This communication can be performed through the communication interface 530. Furthermore, the computing device 500 can also communicate through a network adapter (… Figure 3 (Not shown) communicates with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet). The aforementioned network adapter can communicate with other modules of the computing device via the communication bus 540. It should be understood that, although... Figure 3As not shown, the computing device 500 may be used with other hardware and / or software modules, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, disk arrays (RAID) systems, tape drives, and data backup storage systems.
[0072] Processor 510 executes various functional applications and data processing by running programs stored in memory 520, such as implementing the functions provided in the embodiments of this application as described below. Figure 4 , Figures 6-8 The method shown.
[0073] It is understood that the interface connection relationships between the modules illustrated in the embodiments of this application are merely illustrative and do not constitute a structural limitation on the computing device 500. In other embodiments of this application, the computing device 500 may also employ different interface connection methods or combinations of multiple interface connection methods as described in the above embodiments.
[0074] It should be noted that the system architecture and application scenarios described in the embodiments of this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided in the embodiments of this application. As those skilled in the art will know, with the evolution of system architecture and the emergence of new application scenarios, the technical solutions provided in the embodiments of this application are also applicable to similar technical problems.
[0075] For ease of understanding, the following description, in conjunction with the above system and accompanying drawings, provides an exemplary introduction to the finite state machine generation method provided in the embodiments of this application.
[0076] This application will describe the finite state machine generation method in three parts.
[0077] Part One: Combination Figure 4 and Figure 5 This paper introduces the specific implementation method of generating finite state machines.
[0078] Part Two: Combination Figure 5 , Figure 6 and Figure 7 This paper introduces the specific implementation method of bidirectional linkage between the visualization graphics of finite state machines and the target code.
[0079] Part Three, Combining Figure 5 and Figure 8 This paper introduces the specific implementation methods for monitoring and iteratively optimizing the operational information of finite state machines.
[0080] Part One, such as Figure 4As shown, this application embodiment provides a specific implementation of a method for generating a finite state machine. For example, it includes the following steps: S401-S404, which can be executed by the processor of the aforementioned server, such as a CPU.
[0081] S401 receives natural language information input by the user.
[0082] Natural language information is used to describe target business processes in any scenario. For example, natural language information can be data from text or audio models. This "any scenario" can be any scenario with process control requirements, such as e-commerce business operations, industrial production control, game development and design, or front-end application development. The target business process can be the entire lifecycle of a business process within any scenario, or it can be a specific segment of that process.
[0083] Taking e-commerce business operations as an example, the target business process in this scenario could be the complete fulfillment process of an e-commerce order's entire lifecycle. Accordingly, Natural Language Information 1 could be: "After a user submits an order, a pending payment status is generated, supporting ** payment methods; if payment is not received within 30 minutes, the order is automatically cancelled and an SMS notification is sent; after successful payment, inventory deduction and shipping tasks are triggered; the user can actively cancel the order in the pending payment status." Natural Language Information 2 could be "order fulfillment process." Alternatively, the target business process could also be a partial process within the order's creation and completion. Accordingly, Natural Language Information 3 could be: "After a user submits an order, it enters a pending payment status; upon completion of payment, it transitions to a paid status."
[0084] In one implementation, step S401 is achieved through the aforementioned perception layer.
[0085] Combination Figure 5 The diagram shows a visual flowchart of a method for generating a finite state machine. The user inputs natural language information.
[0086] S402 performs semantic mapping on natural language information, converting the natural language information into target data adapted to the finite state machine format.
[0087] Semantic mapping refers to the process of recognizing and preserving the original semantics when transforming from one form of representation (such as natural language) to another (such as target data adapted to a finite state machine format).
[0088] The finite state machine format is a basic data format based on the core elements of a finite state machine, namely its state, events, transition rules, and actions, and it can meet the basic parsing requirements of the finite state machine data structure.
[0089] For example, the target data is specifically structured data adapted to a finite state machine format.
[0090] In one implementation method that performs semantic mapping on natural language information and converts it into target data adapted to a finite state machine format, the natural language information is converted into structured elements. Semantic mapping is then performed on these structured elements to convert the natural language information into target data adapted to a finite state machine format.
[0091] Structured elements are core business information related to the target business process, such as states, events, transition rules, and actions, extracted from natural language information. Unlike the target data, structured elements can retain the form of natural language descriptions and are not standardized according to the format requirements of finite state machines.
[0092] Continuing with the example of natural language information 1 above, structured elements can specifically be categorized into four types of information: state, event, transition rules, and action. The status includes initial status, pending payment status, paid status, cancelled status, and shipped status.
[0093] Events include: user order submission, user payment completion, 30-minute payment delay, and user order cancellation.
[0094] The conversion rules include: the initial state is converted to the pending payment state after the user submits an order; the pending payment state is converted to the cancelled state after a 30-minute timeout without payment; the pending payment state is converted to the paid state after the user completes payment; the pending payment state is converted to the cancelled state after the user actively cancels the order; and the paid state is converted to the shipped state after triggering the subsequent shipping process.
[0095] Actions include generating a pending payment status, sending an SMS notification for order cancellation due to timeout, deducting order inventory, and creating a product shipping task.
[0096] Continuing with the example of the structured elements mentioned above, the target data may include the following four types of structured data: Status-based structured data: [{"Status ID":"Status 1","Status Name":"Initial Status"},{"Status ID":"Status 2","Status Name":"Pending Payment Status"},{"Status ID":"Status 3","Status Name":"Paid Status"},{"Status ID":"Status 4","Status Name":"Cancelled Status"},{"Status ID":"Status 5","Status Name":"Shipped Status"}].
[0097] Event-based structured data: [{"Event Identifier":"Event 1","Event Name":"User Submits Order"},{"Event Identifier":"Event 2","Event Name":"User Completes Payment"},{"Event Identifier":"Event 3","Event Name":"Payment Not Received After 30 Minutes"},{"Event Identifier":"Event 4","Event Name":"User Cancels Order"}].
[0098] Transformation rule-based structured data: [{"Source State":"Initial State","Trigger Event":"User Submits Order","Target State":"Pending Payment"},{"Source State":"Pending Payment","Trigger Event":"No Payment After 30 Minutes","Target State":"Cancelled"},{"Source State":"Pending Payment","Trigger Event":"User Completes Payment","Target State":"Paid"},{"Source State":"Pending Payment","Trigger Event":"User Actively Cancels Order","Target State":"Cancelled"},{"Source State":"Paid","Trigger Event":"User Completes Payment","Target State":"Shipped"}]; where the source state refers to the initial state in the transition between states, and the target state refers to the final state in the transition between states.]
[0099] Action-based structured data: [{"Action ID":"Action 1","Action Name":"Send Timeout Cancellation SMS Notification"},{"Action ID":"Action 2","Action Name":"Deduct Order Inventory"},{"Action ID":"Action 3","Action Name":"Create Product Shipping Task"}].
[0100] In the embodiments of this application, it is possible to convert unstructured natural language into data adapted to finite state machine format without requiring users to have professional knowledge of finite state machine design, thus lowering the threshold for using finite state machine design.
[0101] In one implementation, step S402 is achieved through the aforementioned AI engine layer.
[0102] In another implementation, step S402 is achieved by combining the aforementioned perception layer and AI engine layer.
[0103] Specifically, the NLU semantic extraction engine breaks down natural language information according to the core constituent dimensions of a finite state machine (state, event, transition rule, action) to obtain structured elements. In this way, NLU technology automatically extracts core business requirements (i.e., structured elements) from natural language descriptions, eliminating the need for users to possess specialized knowledge of finite state machine design. This enables a shift from technically-driven design to input from all personnel, allowing non-technical personnel to easily submit business requirements.
[0104] Specifically, target LLM performs semantic mapping on structured elements, converting natural language information into target data adapted to the finite state machine format. Since target LLM is derived from targeted fine-tuning based on FSM domain knowledge, it possesses a professional understanding of finite state machine format specifications and the organizational logic of core elements. It can accurately organize and transform structured elements, preserving their natural language description form, according to the basic data format requirements of finite state machines, thereby generating target data adapted to the finite state machine format.
[0105] Continue to combine Figure 5 As shown, based on the natural language information input by the user, the natural language information is decomposed according to the core constituent dimensions of the finite state machine to obtain structured elements in natural language form. The structured elements include information related to states, events, actions, and transition rules corresponding to each state. Then, the structured elements are semantically mapped to obtain target data with the same semantics as the structured elements but adapted to the finite state machine format. The target data indicates standardized states, events, actions, and transition rules.
[0106] S403, based on the data structure requirements of finite state machines, splits the data in the target data to obtain the target metadata of the finite state machine.
[0107] The data structure requirements for finite state machines refer to the standardized and structured metadata specifications for the operating rules and characteristics of finite state machines, such as a lightweight data exchange format (JavaScript Object Notation, JSON).
[0108] The target metadata includes the state information, event information, transition rule information, and action information of the finite state machine. Optionally, the target metadata also includes basic configuration, which indicates the target development language and framework corresponding to the finite state machine. For example, the target metadata is in JSON format.
[0109] In an implementation method based on a finite state machine data structure, the data in the target data is split to obtain the target metadata. The initial metadata is then optimized to obtain the target metadata.
[0110] The optimization process includes reducing the number of redundant states and / or removing transition rules that do not exist or do not need to be executed in the target business process, while ensuring that the state-event-transition-action sequence indicated by the initial metadata meets the business rules of the target business process. State-event-transition-action describes the state transitions and related actions that occur in a system under a certain state due to an event trigger. Business rules can be understood as the actual business execution specifications and process requirements that must be followed in the target business process.
[0111] For example, in reducing the number of states with duplicate functions, only one of the duplicate states needs to be retained. For instance, "Order Creating" and "Initial Status" are duplicated, so only one needs to be retained. After optimization, the number of states is reduced from 6 to 4, achieving a compression rate of 33%.
[0112] Understandably, conversion rules that are absent or unnecessary in the target business process indicate a disconnect from the actual business scenario, violate business execution logic, or contain redundant or nested invalid conversion rules with duplicate validations. For example, if the initial metadata includes a conversion rule that changes the status from "Pending Payment" to "Paid" via the trigger event "Manual Order Review," but the actual e-commerce order fulfillment process does not require manual review to complete the payment status conversion, this rule is a redundant rule that does not exist in the business process. Similarly, if the precondition of the "T003 Conversion Rule" in the initial metadata repeatedly validates the same time threshold as the trigger parameter of the "E003 Timeout Unpaid Event," this duplicate precondition validation step is redundant logic that does not need to be executed and must be removed during optimization.
[0113] Continuing with the example of the target data mentioned above, the initial metadata obtained is used to indicate the following information: The status information includes a first status item and a second status item. The first status item includes: a unique status identifier of S001, a status name of "Initial Status," and a status type labeled "initial," indicating that this is the starting state of the entire status process. The second status item includes: a unique status identifier of S002, a status name of "Pending Payment," and a status type labeled "Intermediate," indicating an intermediate state that can proceed through the status process; this status is also configured with extended parameters (extend_params), including a "timeout_threshold" parameter with a value of 1800 (in seconds).
[0114] The event information includes: the event's unique identifier is E003, the event name is "overdue payment", and the event type is marked as time-triggered (time_trigger), indicating that the event is triggered by a time condition; trigger parameters (trigger_params) are also configured, including the "timeout_seconds" parameter, which has a value of 1800 seconds, i.e., the time threshold for triggering the event.
[0115] The conversion rule information is as follows: the unique identifier of the conversion rule is T003, the source state ID of the conversion is S002 (corresponding to the "Pending Payment" state), and the target state ID of the conversion is S004; the event ID that triggers the conversion is E003 (corresponding to the "Timeout Unpaid" event); the precondition for the conversion is "the duration of the current state (current_state.duration) is greater than or equal to 1800 seconds", and the state conversion will only take effect if this condition is met.
[0116] Action information indicates the action to be executed and bound to the state transition. It includes the action's unique identifier A003, the associated transition rule ID T003 (i.e., the state transition triggered by "overdue payment"), the action name "send timeout notification", and the specific execution logic of the action: call the sendSms method of the notification service (notify_service) to send an SMS to the specified user's mobile phone number (which is a dynamic parameter), with the SMS content stating that the order {order_id} has been canceled due to timeout.
[0117] Taking the initial metadata mentioned above as an example, the precondition of transformation rule T003 in the initial metadata is a rule that does not need to be executed in the target business process and can be removed.
[0118] In this embodiment, by removing duplicate states from the initial metadata and removing transformation rules that do not exist or do not need to be executed in the target business process, the final generated target metadata meets the requirements of the fewest number of states, the highest transformation efficiency, and the best business adaptability, which effectively improves the overall operating efficiency and business adaptability of the finite state machine.
[0119] In one possible implementation, the initial metadata is optimized to obtain the target metadata. This includes: validating the initial metadata to obtain a validation result, which indicates whether the initial metadata conforms to the operational logic of the target business process. If the validation result indicates that the initial metadata conforms to the operational logic of the target business process, the initial metadata is then optimized.
[0120] Understandably, the operational logic of the target business process should, on the one hand, conform to the core specifications of a finite state machine (such as a unique initial state, at least one terminating state, and unambiguous state transitions), and on the other hand, the binding relationship between states, events, and transitions should fit the actual business scenario (such as "payment timeout" should only trigger the transition to the "paying" state, not the "completed" state). In other words, the initial metadata must conform to the syntax of a finite state machine and also fit the semantics of the business scenario.
[0121] Continuing with the e-commerce business operation scenario as an example, the finite state machine rules stipulate that there can only be one "Initial Pending Payment" state, and "Order Completed" is the only termination state. The business logic of the e-commerce order payment process stipulates that only the "Payment in Progress" state can trigger the "Payment Timeout" event, and this event can only transition to the "Payment Failed" state. Based on this, when validating the initial metadata, we check both whether the initial state is unique and whether the payment timeout event is bound to the wrong state.
[0122] In this embodiment of the application, by adopting a process of verification followed by optimization, it is possible to ensure that the generated initial metadata not only meets the specification constraints of the finite state machine, but also closely matches the actual business process. This avoids problems such as incorrect state definition, unreasonable event binding, and conflicting transition logic, thereby improving the accuracy of the initial metadata and enhancing the stability, accuracy, and executability of the state machine operation.
[0123] In one implementation, step S403 is achieved through the aforementioned AI engine layer.
[0124] Specifically, by implementing the data structure requirements of a finite state machine through the target LLM, the data in the target data is split to obtain initial metadata. Because the target LLM has a deep understanding of the core data structure requirements of finite state machines and the standardized organization specifications of the target metadata, it can accurately and professionally split, logically organize, and standardize the elements of the target data adapted to the finite state machine format according to these data structure requirements. Therefore, it can obtain initial metadata of a finite state machine that conforms to the specifications, laying the foundation for subsequent optimization processing.
[0125] Specifically, the initial metadata is optimized through a reinforcement learning model.
[0126] Continue to combine Figure 5 As shown, based on the target data obtained in step S403, the natural language information is further decomposed according to the data structure requirements of a finite state machine to obtain target metadata, thereby refining the business logic of the target business process. For example, the target metadata includes: initial state, state 1-1, state 1-2, state 2-1, state 2-2, and the events, actions, and transition rules corresponding to each state. Among them, multiple states have semantic relationships, and the specific semantic relationships are shown in the flow chain in the visualization diagram.
[0127] S404 generates the target code for a finite state machine, along with a visual representation of the finite state machine, based on the target metadata.
[0128] The following is a detailed introduction to the target code for generating the finite machine: The target code is used to run a finite state machine. For example, the target code includes basic framework code and business logic code.
[0129] In one implementation of generating target code for a finite state machine based on target metadata, a target code template corresponding to the basic configuration is invoked. This target code template includes a basic framework code template built on the target development language and framework, and a business logic code template to carry the states, events, transition rules, and actions of the finite state machine. Basic framework code is generated based on the basic framework code template, and the state information, event information, transition rule information, and action information are then filled into the business logic code template to generate the business logic code.
[0130] Understandably, code templates are predefined, reusable code skeletons. Code templates include general-purpose basic framework code templates adapted to different programming languages and frameworks (such as state machine initialization, core execution entry points, and exception handling modules), and templates for different programming languages and frameworks such as Python + FastAPI, Python + Flask, and Java + Spring Boot. FastAPI is a modern, fast (high-performance) web framework for building application programming interfaces (APIs) using Python with standard Python type hints. Flask is a lightweight web application framework written in Python. Spring Boot is an open-source framework based on the lightweight open-source Spring framework, designed to simplify the creation and development of Spring applications. It provides a fast and easy way to build standalone, production-ready Spring applications. Code templates also include dynamically populated business logic code templates (such as state enumeration definitions, event triggering functions, transition rule judgment logic, and action execution methods). The template includes placeholders that match the metadata fields of the finite state machine, allowing for the automatic filling of information such as state, event, and transition rules from the target metadata. No core logic needs to be written manually, and a few personalized configurations can be adapted to generate directly runnable finite state machine code.
[0131] Continuing with the e-commerce business operation scenario as an example, the target development language and framework are Java + Spring Boot. The generated target code can be directly imported into an existing Spring Boot project on the e-commerce platform.
[0132] In this embodiment of the application, the code template generation method driven by target metadata can improve the efficiency and consistency of code generation, ensure that the basic framework and business logic code are generated strictly according to the target metadata, reduce errors and repetitive development work caused by manual code writing, keep the target code and the finite state machine design highly consistent, and improve the reliability and maintainability of the code.
[0133] In one possible implementation, the computing device can be configured with multiple code templates, as well as the correspondence between these templates and multiple programming languages and frameworks. For example, these code templates can be stored as code repositories. Accordingly, based on the basic configuration, calling the target code template corresponding to the basic configuration includes: based on the correspondence, the target programming language, and the target framework, determining the target code template corresponding to the target programming language and target framework from multiple code template repositories. This enables accurate matching of the target programming language and framework to call the corresponding code template, ensuring the adaptability and standardization of code generation, while simultaneously achieving unified management, reuse, and rapid retrieval of code templates, simplifying the template calling process, improving code generation efficiency, and avoiding template mismatch problems.
[0134] The following is a detailed introduction to the visualization of the generator finite machine: The visualization includes nodes representing the states of the finite state machine, and edges representing the triggering events and actions that occur during transitions between different states. The nodes and edges in the visualization can be referred to as elements.
[0135] Specifically, the visualization offers two display modes: a global overview view and a local detail view. The global overview view fully presents the flow links between states of the finite state machine (hereinafter referred to as the state flow link), such as the complete vertical process of initial state → pending payment → paid / cancelled → shipped. The local detail view focuses on a single state node (such as clicking the "pending payment" node), displaying detailed information such as all triggering events, transition rules, and execution actions associated with that state.
[0136] In one implementation of generating a visualization of a finite state machine based on target metadata, a preset chart library is invoked to parse the target metadata and generate the visualization. Specifically, the preset chart library is used to parse the state, event, transition rules, and action information in the target metadata, and convert these information into the target syntax of the preset chart library (such as flowchart syntax), achieving adaptation from business data to chart syntax. Based on the target syntax, a visualization including nodes and edges is rendered. Based on the interactive features of the preset chart library, functions such as node clicking and view switching are implemented. Specifically, the preset chart library can be the Mermaid chart library.
[0137] In this embodiment of the application, by parsing the target metadata through a preset chart library and completing the syntax adaptation and visualization rendering, a finite state machine visualization graph including state nodes, transition edges and supporting interactive operations can be efficiently generated, intuitively presenting the flow logic of the state machine and improving the convenience of state machine design and debugging.
[0138] In an implementation method for generating target code and a visualization of a finite state machine based on target metadata, the visualization of the finite state machine is first generated based on the target metadata. In response to receiving a third operation instruction, a third element is modified. The third operation instruction indicates the modification of the third element in the visualization, and the third element includes a third node and / or a third edge. The metadata corresponding to the third element is determined from the target metadata. Based on the modification of the third element, the metadata corresponding to the third element in the target metadata is modified to obtain the modified target metadata. The target code of the finite state machine is generated based on the modified target metadata.
[0139] The third operation command can be triggered by the user (such as business personnel) through the interactive interface where the visual graphic is located. For example, the third operation command can support one or more of the following operation forms: adding nodes or edges in the visual interface, deleting existing nodes or edges, adjusting the position of nodes or modifying the connection relationship of edges by dragging and dropping, editing the attribute information of nodes or edges, or configuring and adjusting the transition rules between states, etc.
[0140] In this embodiment, by first generating a visual graphic based on the target metadata, allowing users to flexibly modify graphic elements in the interactive interface, and then updating the corresponding metadata and generating target code, the consistency adjustment of the visual graphic, metadata and target code is achieved. The debugging and optimization of the finite state machine can be completed without business personnel writing code, which greatly reduces the operation threshold and improves the efficiency and accuracy of state machine iterative adjustment.
[0141] In one implementation, step S404 is achieved through an AI engine layer.
[0142] Continue as Figure 5 As shown, based on the target metadata, the target code for the finite state machine is generated, along with a visual representation of the finite state machine. This visualization is displayed through an interactive interface. The global overview view includes multiple state transition links. For example, state transition link 1 transitions from the initial state to state 1-1. State 1-1 can transition to state 2-1 and / or state 2-2 based on different transition rules. State transition link 2 transitions from the initial state to state 1-2. State 1-2 can also transition to state 2-1 and / or state 2-2 based on different transition rules. The local detail view, taking state 1-2 as an example, displays its corresponding detailed information: event 1, transition rule 1, and action 1.
[0143] Combining steps S401-S404 above, by receiving natural language information input by the user, target business requirements can be submitted without requiring the user to have expertise in finite state machines or to write structured requirement documents, thus lowering the barrier to entry and adapting to multi-scenario and cross-domain usage needs. Through semantic mapping of natural language information, the ambiguity and fragmentation of natural language are eliminated while fully preserving the original semantics. Unstructured text is accurately converted into standardized target data adapted to the finite state machine format, establishing a clear conversion link from natural language to professional data and avoiding semantic loss or format deviation. Then, according to the data structure requirements of the finite state machine, the core elements corresponding to the target business process are extracted to obtain target metadata including states, events, transition rules, and actions, ensuring that the target metadata conforms to the operating rules and underlying logic of the finite state machine. Finally, based on this target metadata, logically consistent and runnable target code and visualization graphics are automatically generated. The target code directly supports the stable operation of the finite state machine, and the visualization graphics clearly present the state transition chain, transition trigger conditions, and corresponding execution actions, facilitating rapid verification, debugging, and correction. This enables fully automated generation of finite state machines (FSMs) driven by the entire process, with the ability to deploy complete code and visual graphics. The entire process eliminates the need for complex format conversions and logic writing by humans, reducing the manual cost and technical threshold for FSM generation, and improving the efficiency and accuracy of FSM generation. Furthermore, it does not rely on a specific domain ecosystem and can quickly generate adaptable FSMs through a unified natural language interaction method, enabling flexible reuse across domains and technology stacks.
[0144] The first part above provides a detailed introduction to the method for generating finite state machines. On one hand, the finite state machine is deployed and run by generating target code. On the other hand, the state transition chain, and the events, transition rules, and actions corresponding to each state are intuitively displayed through visual graphics. However, after generating the target code and visual graphics of the finite state machine, considering the potential need for fine-tuning in actual business scenarios, this application embodiment also supports fine-tuning of the generated visual graphics and target code, and establishes a two-way linkage modification mechanism between the visual graphics and the target code. The specific implementation method is detailed in the second part below.
[0145] The second part of this application provides a specific implementation method for the bidirectional linkage modification of the visualization graphics and target code of a finite state machine. In one case, manual modification of the visualization graphics triggers synchronous modification of the target code. In another case, manual modification of the target code triggers synchronous modification of the visualization graphics. The different cases are described in detail below: like Figure 6As shown, this application embodiment provides a specific implementation method for triggering synchronous modification of target code based on manual modification of a visual graphic. For example, it includes steps S601-S603, which can be executed by a server processor, such as a CPU.
[0146] S601, in response to receiving a first operation instruction, modify the first element. The first operation instruction is used to instruct the modification of the first element in the visualized graphic, the first element including the first node and / or the first edge.
[0147] The first operation command can be triggered by a user (such as a business person) through the interactive interface where the visual graphic is located. For example, the first operation command can support one or more of the following operation forms: adding a node or edge in the visual interface, deleting an existing node or edge, adjusting the position of a node or modifying the connection relationship of an edge by dragging and dropping, editing the attribute information of a node or edge, or configuring and adjusting the transition rules between states, etc.
[0148] Continuing with the example of e-commerce business operations, for instance, during business optimization, staff might discover the need to add an "Invoice Issuance" action after the "Payment Successful" status. To address this, staff can directly select the "Payed → Shipped" transition on the interface and add the associated action of "Call Invoice Service to Generate Electronic Invoice".
[0149] Optionally, embodiments of this application can support multiple users to simultaneously collaborate on adjusting the visual graphics of a finite state machine in a visual interactive interface, thereby improving team collaboration efficiency.
[0150] S602, based on the first mapping relationship, determine the first metadata corresponding to the first element from the target metadata. The first mapping relationship is used to indicate the correspondence between the element and the metadata of the finite state machine.
[0151] The first mapping relationship is a pre-built set of structured association rules stored in the computing device. This mapping relationship is bidirectional and traceable. For example, the node marked "Paid" in the visualization corresponds to the status information in the target metadata that describes the user's status after completing order payment. The transition edge connecting the "Paid" and "Shipped" statuses in the visualization corresponds to the metadata in the target metadata that describes "Triggering event: Payment successful; Source status: Paid; Target status: Shipped; Execution action: Deduct inventory, generate e-invoice".
[0152] In some embodiments, the method further includes modifying the first metadata. Thus, the modified first metadata can serve as a core intermediate carrier for the coordinated modification of visual elements and target code, providing a structured basis for subsequently locating and modifying the first code within the target code, ensuring a logical closed loop from visualization operations to code updates, and improving the accuracy and consistency of finite state machine visualization design and synchronized code modification.
[0153] S603, based on the second mapping relationship, determine the first code corresponding to the first metadata from the target code, and modify the first code. The second mapping relationship is used to indicate the correspondence between the code and the metadata of the finite state machine.
[0154] The second mapping relationship is a pre-built set of structured association rules stored in the computing device. This mapping relationship is also bidirectional and traceable. For example, the "paid" status information in the target metadata corresponds to the code segment in the target code that defines this status; the conversion rule information in the target metadata that describes "payment successful, conversion from paid to shipped, deduction of inventory and generation of electronic invoice" corresponds to the code segment in the target code that implements this conversion logic (such as the add_transition method).
[0155] In a method that determines the first code corresponding to the first metadata from the target code based on a second mapping relationship and modifies the implementation of the first code, the target code is structurally parsed to obtain a hierarchical code structure centered on syntactic logic nodes (hereinafter referred to as the target code structure). Each syntactic logic node in the target code structure has positional mapping information to the target code, used to associate it with a specific code segment within the target code. Based on the second mapping relationship, the first syntactic logic node corresponding to the first metadata is determined, and then the first code in the target code is determined through the positional mapping of the first syntactic logic node. Specifically, the second mapping relationship indicates the correspondence between the metadata and code of the finite state machine. Based on the modifications to the first metadata, syntactically compliant modifications are performed on the first syntactic logic nodes in the hierarchical code structure to obtain the first code structure. The first code structure is restored to executable code text, and based on the positional mapping information, this text replaces the first code in the original target code, completing the update of the first code.
[0156] Understandably, a hierarchical code structure centered on syntactic logic nodes refers to breaking down the original linear text target code into the smallest logical segments (syntactic logic nodes) with clear purposes, and then organizing these segments according to their logical hierarchy to form a code structure that can be recognized by the program.
[0157] In this embodiment, by parsing the target code into a hierarchical code structure with location mapping information, the limitation of traditional linear code text relying solely on fuzzy keyword matching to locate code segments is overcome. By leveraging precise matching and location mapping information between grammatical logic nodes and first metadata, accurate location of the first code is achieved. Simultaneously, compliant modifications based on grammatical logic nodes ensure that code modification operations conform to grammatical specifications, avoiding syntax errors or logical inconsistencies caused by directly modifying the text. Furthermore, by restoring the modified structure and making precise replacements, the code modifications are traceable and implementable. This improves the accuracy, efficiency, and stability of the linked modification of finite state machine metadata and target code, effectively reducing the risk of accidentally modifying irrelevant code.
[0158] Optionally, for the first operation instructions of multiple users, the embodiments of this application can synchronize the operation instructions of multiple users to the visual interface in real time and update the target code layer simultaneously, effectively improving team collaboration efficiency and accelerating the design progress of finite state machines.
[0159] Combining steps S601-S603 above, by constructing a two-layer mapping and linkage mechanism between visual elements and finite state machine metadata, and between metadata and target code, when users modify elements in the visual interface, the corresponding target code is located and modified synchronously, realizing automatic synchronous updates from visual operations to the code layer, and improving the efficiency of finite state machine design and code maintenance.
[0160] In one implementation, steps S601-S603 are implemented through the aforementioned AI engine layer. Specifically, step S603 is implemented using an AST parser.
[0161] The following section continues to use e-commerce business operation scenarios as an example to illustrate the specific implementation methods of S601-S603 mentioned above: First, the business personnel select the "Paid → Shipped" conversion edge (first element) in the visual interactive interface, triggering the first operation instruction of "Add Generate Electronic Invoice Action", and modify the attributes of the conversion edge in response to the first operation instruction.
[0162] Secondly, based on the first mapping relationship, the metadata corresponding to the transformation edge (the first metadata) is matched from the metadata of the finite state machine. This metadata describes the transformation rule information of "payment successful trigger, payment converted to shipment, and deduction of inventory". The "execution action" field of this metadata is then updated to "deduct inventory and generate electronic invoice".
[0163] Finally, based on the second mapping relationship, the target code is parsed into a hierarchical code structure by the AST parser, the target syntax logic node corresponding to the add_transition method that matches the metadata is located, the code segment of the method (first code) is found in the target code, and the "generateInvoice ()" execution statement is added to complete the code synchronization update.
[0164] In this embodiment, by modifying the transition edges of the finite state machine through a visual interface, based on the two-layer mapping relationship and structured code parsing, the corresponding metadata and target code can be automatically and synchronously updated, realizing precise linkage between visual operation and code modification, and improving the efficiency and accuracy of state machine design and code maintenance.
[0165] This application embodiment can also realize the reverse process of the above-mentioned linkage modification, that is, by modifying the target code, the corresponding update of the finite state machine visualization graph is synchronously driven. The following is in conjunction with the appendix. Figure 7 This section provides a detailed explanation of the specific implementation method for this reverse linkage modification.
[0166] like Figure 7 As shown, this application embodiment provides a specific implementation method for synchronously modifying visual graphics based on adjustments to target code. For example, it includes steps S701-S703, which can be executed by a server processor, such as a CPU.
[0167] S701, in response to receiving a second operation instruction, modifies the second code, the second operation instruction being used to instruct the modification of the second code in the target code.
[0168] The second operation command can be triggered by the developer through the code editing interface. For example, the second operation command can include one or more operations such as adding, deleting, rewriting logic, and configuring properties.
[0169] The second code segment in the target code corresponds to the finite state machine state definition, state transition rules, and business execution actions. It may be the same as or different from the first code.
[0170] Optionally, embodiments of this application support collaborative modification of target code by multiple developers, thereby modifying multiple pieces of second code in response to a second operation instruction initiated by multiple developers.
[0171] S702, based on the second mapping relationship, determine the second metadata corresponding to the second code from the target metadata.
[0172] In an implementation method that determines the second metadata corresponding to the second code from the target metadata based on a second mapping relationship, the second code is structurally parsed to obtain a hierarchical code structure centered on syntactic logic nodes, hereinafter referred to as the second code structure. Based on the positional mapping information of the second code structure, the second syntactic logic nodes are determined. And based on the second mapping relationship, the second metadata corresponding to the second syntactic logic nodes is determined from the target metadata.
[0173] In this embodiment of the application, by performing structured parsing on the second code, accurately locating the second syntactic logic node, and then combining the second mapping relationship to complete the matching and docking of the second code and the second metadata, the accuracy of the mapping from code to metadata is effectively improved, thereby achieving accurate location of the second metadata.
[0174] In some embodiments, the method further includes modifying the second metadata. Thus, the modified second metadata can serve as a core intermediate carrier for the coordinated modification of visual elements and target code, providing a basis for subsequently locating and modifying elements in the visual graphics, ensuring a logical closed loop from code updates to visual operations, and improving the accuracy and consistency of finite state machine visualization design and synchronized code modification.
[0175] S703, based on the first mapping relationship, determine the second element corresponding to the second metadata from the elements in the visualization graph, and modify the second element, which includes the second node and / or the second edge.
[0176] Combining steps S701-S703 above, through a two-way linkage mechanism between code and visualization graphics, and a two-layer mapping relationship, the code can be automatically updated to metadata when developers modify the target code. This allows for real-time updates of visualization graphics nodes and links when the target code changes. The hierarchical synchronous update of metadata to visualization graphics ensures real-time alignment between code logic and visualization nodes and edges. No manual verification or modification is required, guaranteeing consistency between visualization graphics, metadata, and target code, and improving the convenience and efficiency of subsequent debugging and optimization of the finite state machine.
[0177] In one possible implementation, steps S701-S703 are implemented through the aforementioned AI engine layer. Specifically, step S703 is implemented through an AST parser.
[0178] Continue as Figure 5 As shown, for the visual graphics in the interactive interface, users can adjust the elements, such as dragging and / or modifying elements, thereby triggering adjustments to the target metadata, and subsequently, adjustments to the target code. Similarly, users can adjust code segments within the target code, thereby triggering adjustments to the target metadata, and subsequently, adjustments to the visual graphics.
[0179] In this embodiment of the application, after the target code is determined, the target code of the finite state machine can be deployed for subsequent execution of the finite state machine. The following describes the deployment of the target code for the finite state machine: In some embodiments, the method further includes: deploying the target code to a target service cluster, the target service cluster being used to host and run a finite state machine.
[0180] Taking e-commerce business operation scenario as an example, for instance, the target code is deployed to the e-commerce service cluster, which can receive business events such as order payment, cancellation, and shipment in real time. The computing device can call the state transition logic that matches the business event (such as order payment success, order cancellation, and order shipment) and execute the corresponding business actions, stably supporting the state transition and business processing of the entire e-commerce order process.
[0181] In this embodiment of the application, the target code is deployed to the target service cluster, which can directly run the finite state machine without additional adaptation and adjustment, thus shortening the cycle from state machine design to actual deployment and operation.
[0182] In one implementation, the target code for deploying the finite state machine is implemented through the aforementioned execution layer. Specifically, the target code for the finite state machine can be deployed through a runtime engine.
[0183] The above content introduced the specific implementation method from generating a finite state machine, to the bidirectional linkage between the visualization graphics and the target code for modification, to the final deployment and operation. After deploying the target code of the finite state machine, it can be run directly. The following section introduces the specific implementation method for running the finite state machine.
[0184] Part Three, such as Figure 8 As shown, this application embodiment provides a specific implementation method for monitoring and iteratively optimizing the operation information of a finite state machine. For example, it includes the following steps: S801-S803, which can be executed by a server processor, such as a CPU.
[0185] S801, obtains the runtime information generated during the operation of the finite state machine.
[0186] Operational information includes normal and / or abnormal information. Normal information indicates that the finite state machine (FSM) operates according to the target business process's operational logic. For example, an order's status successfully transitions from "Pending Payment" to "Paid." The state transition path is: source status "Pending Payment," target status "Paid," the triggering event from the source status to the target status is "User Payment Successful," and the action is "Deduct Goods Inventory." The FSM records the execution result indicating "State Transition Successful." Abnormal information indicates that the FSM has not operated according to the target business process's operational logic. For example, if the FSM attempts to convert an order from the "Cancelled" status to the "Shipped" status, this does not conform to the target business process's operational logic, resulting in abnormal information such as "State Transition Failed: Source Status 'Cancelled,' Target Status 'Shipped,' Error Reason: Non-compliance with Preset Transition Rules."
[0187] Optionally, the operational information may also include one or more of the following: conversion to power, frequency of transitions between states (such as the trigger frequency of "timeout cancellation" events), and the number of abnormal messages. Here, conversion to power represents the proportion of normal information.
[0188] In one implementation, step S801 is implemented through the aforementioned execution layer.
[0189] S802 adjusts the finite state machine and target code based on runtime information.
[0190] In an implementation method that adjusts a finite state machine and target code based on operational information, the operational information is analyzed to obtain analysis results. These results indicate one or more of the following during the finite state machine's operation: states with repetitive functions, links with transition power less than a preset threshold, or links with anomaly messages exceeding a preset number. The third metadata corresponding to the analysis results is determined, and this third metadata is optimized to obtain processed fourth metadata. Based on a second mapping relationship, the third code corresponding to the third metadata is determined. The third code is then modified based on the changes from the third to the fourth metadata. Furthermore, the visualization is simultaneously modified based on the adjustments to the third code; for details, please refer to the specific implementation method of simultaneously modifying the visualization based on target code adjustments, which will not be elaborated here.
[0191] Understandably, the third metadata belongs to the original target metadata before adjustment. The optimized fourth metadata replaces the third metadata in the original target metadata, while the rest of the original target metadata remains unchanged, thus forming the new target metadata after adjustment.
[0192] In this embodiment, based on the actual operating data of the deployed finite state machine, redundant states and inefficient links in the operation of the finite state machine are identified, and targeted optimization and iterative adjustment are completed. The target code and visualization graphics can be updated synchronously without manual intervention, so that the rules and structure of the finite state machine can dynamically adapt to business changes and continuously improve the efficiency of state transition and logical adaptability.
[0193] In one implementation, runtime information is transmitted to the perception layer via the aforementioned execution layer. The perception layer analyzes the runtime information to obtain analysis results. These results are then transmitted to the AI engine layer, which adjusts the finite state machine and target code based on the analysis results.
[0194] S803, when the runtime information includes exception information, marks the exception nodes associated with the exception information in the visualization graph; displays the exception nodes in the visualization graph, as well as the links of exception events, exception actions and exception codes corresponding to the exception nodes, in order to locate the cause of the exception.
[0195] For example, a pop-up window can be used to visually display the exception tracing chain from "exception node → exception triggering event → exception execution action → associated exception code".
[0196] Continuing with the example of e-commerce business operations, when a business anomaly occurs such as "payment successful but inventory insufficient", the "paid" anomaly node is flashed in the visualization and the anomaly traceability chain is displayed through a pop-up window: paid status → payment success event → inventory deduction action failure → no delivery event triggered. This can directly pinpoint the cause of the anomaly as the action logic not adding the inventory verification precondition.
[0197] In this embodiment of the application, during the operation of the finite state machine, the complete chain of abnormal nodes, abnormal events, abnormal actions and abnormal codes corresponding to the abnormal nodes is visualized in real time, forming a visualized abnormal tracing chain. Without the need for manual line-by-line verification of code and metadata, or the need to filter through massive logs, the root cause of the abnormal can be quickly located, effectively improving the efficiency of abnormal investigation and debugging of the finite state machine.
[0198] The execution order of the above steps S802 and S803 is not limited, and S802 is an optional step, or S803 is an optional step.
[0199] By combining the above steps S801-S803, comprehensive collection and monitoring of finite state machine operation information is achieved. Based on actual operation data, automated iterative optimization of the state machine and target code is completed. The root cause of anomalies is quickly located through visualization. A closed-loop mechanism integrating operation monitoring, iterative optimization, and anomaly debugging is constructed to improve the operation stability, business adaptability, and debugging efficiency of the finite state machine.
[0200] In one implementation, step S803 is achieved through the aforementioned visual interaction layer.
[0201] In some embodiments, the method further includes: in response to a received fourth operation instruction, modifying the abnormal node in the visualization graph. The fourth operation instruction instructs the modification of the abnormal node in the visualization graph, determining the fifth metadata corresponding to the abnormal node from the target metadata based on a first mapping relationship, modifying the fifth metadata, and updating the code segment in the target code corresponding to the fifth metadata based on the modified content of the fifth metadata, thereby completing the correction of the abnormal node.
[0202] In this embodiment, abnormal nodes are directly modified through visual graphics and the corresponding metadata and target code are updated in conjunction, realizing visual and rapid repair of abnormal problems. There is no need to manually modify the metadata or code separately, which simplifies the abnormal correction process of finite state machines and improves the efficiency and accuracy of abnormal repair.
[0203] In some embodiments, the method further includes issuing an alarm when the operational information includes abnormal information. Thus, by issuing alarms in real time for abnormal information, users can promptly perceive operational abnormalities in the finite state machine, facilitating rapid intervention and improving system stability and anomaly response efficiency.
[0204] In some embodiments, the method further includes: acquiring modification records of natural language information and / or records of manual fine-tuning operations. Modification records of natural language information and / or records of manual fine-tuning operations refer to user modifications of elements in a visual graphic and / or developer modifications of code in the target code.
[0205] In this embodiment of the application, by acquiring the modification records of natural language information and / or the records of manual fine-tuning operations, the change trajectory and operation content of the finite state machine from natural language generation and visual editing to code linkage modification are completely preserved, so that each step of modification can be traced, verified and rolled back, which is convenient for subsequent troubleshooting.
[0206] In some embodiments, the method further includes: using natural language information as training samples to iteratively optimize the target LLM. This continuously improves the model's accuracy in understanding natural language in business scenarios and optimizes the accuracy of natural language-to-metadata conversion.
[0207] In some embodiments, the method further includes: using metadata corresponding to the runtime information generated by the finite state machine as training samples to iteratively optimize the reinforcement learning model. This continuously improves the reinforcement learning model's ability to identify runtime problems and the effectiveness of metadata optimization strategies, thereby increasing the efficiency of state machine iterative adjustments.
[0208] The foregoing primarily describes the solutions provided by the embodiments of this application from a methodological perspective. Those skilled in the art should readily recognize that, based on the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein, this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0209] This application also provides a computer-readable storage medium storing computer program instructions thereon. When the computer program instructions are executed by a computing device, the computing device performs the method described above.
[0210] This application also provides a computer program product, which includes a computer program that, when at least one processor executes the computer program, causes the at least one processor to perform the methods described above in this application.
[0211] The computing device, computer-readable storage medium, or computer program product provided in the embodiments of this application are all used to execute the corresponding methods provided above. Therefore, the beneficial effects they can achieve can be referred to the beneficial effects in the corresponding methods provided above, and will not be repeated here.
[0212] Through the above description of the embodiments, those skilled in the art will clearly understand that, for the sake of convenience and brevity, only the division of the above functional modules is used as an example. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. The specific working process of the system, device, and unit described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0213] In the embodiments of this application, the functional units can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0214] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solutions of the embodiments of this application, in essence, or the parts that contribute to the prior art, or all or part of the technical solutions, can be embodied in the form of a software product. This computer software product is stored in a computer-readable storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) or processor to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned computer-readable storage medium includes various media capable of storing program code, such as flash memory, portable hard disk, read-only memory, random access memory, magnetic disk, or optical disk.
[0215] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A method for generating a finite state machine, characterized in that, include: Receive natural language information input by the user, the natural language information being used to describe the target business process in any scenario; Semantic mapping is performed on the natural language information, and the natural language information is converted into target data adapted to the finite state machine format; Based on the data structure requirements of the finite state machine, the data in the target data is split to obtain the target metadata of the finite state machine. The target metadata includes the state information, event information, transition rule information and action information of the finite state machine. Based on the target metadata, target code for the finite state machine and a visualization of the finite state machine are generated. The target code is used to run the finite state machine, and the visualization includes nodes representing the various states of the finite state machine and edges representing the triggering events and actions when transitioning between different states.
2. The method according to claim 1, characterized in that, The method further includes: In response to receiving a first operation instruction, a first element is modified, the first operation instruction being used to instruct the modification of a first element in the visualization graphic, the first element including a first node and / or a first edge; Based on the first mapping relationship, the first metadata corresponding to the first element is determined from the target metadata. The first mapping relationship is used to indicate the correspondence between the element and the metadata of the finite state machine. Based on the second mapping relationship, the first code corresponding to the first metadata is determined from the target code, and the first code is modified. The second mapping relationship is used to indicate the correspondence between the code and the metadata of the finite state machine. And / or, In response to receiving a second operation instruction, modify the second code, wherein the second operation instruction is used to instruct the modification of the second code in the target code; Based on the second mapping relationship, determine the second metadata corresponding to the second code from the target metadata; Based on the first mapping relationship, a second element corresponding to the second metadata is determined from the elements in the visualization graph, and the second element is modified, wherein the second element includes a second node and / or a second edge.
3. The method according to claim 1 or 2, characterized in that, Based on the data structure requirements of the finite state machine, the data in the target data is split to obtain the target metadata of the finite state machine, including: Based on the data structure requirements of the finite state machine, the data in the target data is split to obtain initial metadata; The initial metadata is optimized to obtain the target metadata. The optimization process includes removing duplicate states from the initial metadata and / or removing transformation rules that do not exist or do not need to be executed in the target business process.
4. The method according to any one of claims 1-3, characterized in that, The target metadata also includes basic configuration, which indicates the target development language and target framework corresponding to the finite state machine; generating the target code for the finite state machine based on the target metadata includes: Based on the basic configuration, the target code template corresponding to the basic configuration is invoked. The target code template includes a basic framework code template built based on the target development language and the target framework, as well as a business logic code template for carrying the states, events, transition rules and actions of the finite state machine. Based on the basic framework code template, basic framework code is generated, and the state information, event information, transformation rule information, and action information are filled into the business logic code template to generate business logic code; the target code includes the basic framework code and the business logic code.
5. The method according to any one of claims 1-4, characterized in that, The method further includes: The finite state machine generates runtime information during runtime, including normal information and / or abnormal information. The normal information indicates that the finite state machine is running according to the runtime logic of the target business process, and the abnormal information indicates that the finite state machine is not running according to the runtime logic of the target business process. Based on the operational information, adjust the finite state machine and the target code; and / or, When the running information includes the abnormal information, the abnormal nodes associated with the abnormal information are marked in the visualization; the abnormal nodes, as well as the links of abnormal events, abnormal actions and abnormal codes corresponding to the abnormal nodes, are displayed in the visualization to locate the cause of the abnormality.
6. The method according to any one of claims 1-5, characterized in that, The step of semantically mapping the natural language information and converting it into target data adapted to a finite state machine format includes: The natural language information is converted into structured elements; Semantic mapping is performed on the structured elements to convert the natural language information into target data adapted to a finite state machine format.
7. The method according to claim 3, characterized in that, The optimization process of the initial metadata to obtain the target metadata includes: The initial metadata is validated to obtain a validation result, which is used to indicate whether the initial metadata conforms to the operating logic of the target business process; If the verification result indicates that the initial metadata conforms to the operating logic of the target business process, the initial metadata is optimized.
8. The method according to claim 3 or 7, characterized in that, The initial metadata is obtained through a target large language model, the input of which includes the natural language information; the target large language model is obtained by fine-tuning a large language model based on domain knowledge of finite state machines. The target metadata is obtained through a reinforcement learning model, and the input of the reinforcement learning model includes the initial metadata; The optimization objectives of the activation function of the reinforcement learning model include: removing duplicate states from the initial metadata, and / or removing transformation rules that do not exist or do not need to be executed in the target business process.
9. The method according to any one of claims 1-8, characterized in that, The method further includes: The target code is deployed to the target service cluster, which is used to host and run the finite state machine.
10. A computing device, characterized in that, It includes a processor and a memory; the processor is coupled to the memory; The memory is used to store instructions; The processor is configured to execute instructions stored in the memory to cause the computing device to perform the method as described in any one of claims 1-9.