A code generation method and apparatus

By using a multi-layered state information-driven code generation method, the code generation process is decomposed into multiple stages and the coding agent is invoked, which solves the problems of high manual costs and low development efficiency in existing technologies and realizes the flexibility and controllability of automated code generation.

CN122308792APending Publication Date: 2026-06-30BEIJING BAIDU NETCOM SCI & TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
BEIJING BAIDU NETCOM SCI & TECH CO LTD
Filing Date
2026-02-06
Publication Date
2026-06-30

AI Technical Summary

Technical Problem

Existing technologies suffer from high labor costs and low development efficiency in the code generation process, and it is particularly difficult to automate code generation under complex development requirements.

Method used

A multi-level state information-driven code generation method is adopted. By decomposing the code generation process into multiple stages and maintaining the state information and transition rules between each stage, the coding agent is invoked to generate execution planning information and code, thereby achieving automated code generation.

Benefits of technology

It improves the flexibility and controllability of code generation, reduces labor costs, increases development efficiency, and achieves transparency and traceability in the code generation process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122308792A_ABST
    Figure CN122308792A_ABST
Patent Text Reader

Abstract

This disclosure provides a code generation method and apparatus, relating to the field of computer technology, and particularly to the field of artificial intelligence technology. It includes: acquiring code development tasks corresponding to development requirements information and corresponding multi-level state information, the multi-level state information including multiple stages of code generation, state information contained in each stage, and transition rules between states; during the execution of the code development task, in response to determining that the transition rules are met, executing a transition action for the current state corresponding to the current stage, and then switching to the next state; wherein, when the current stage is the planning stage, the transition action includes calling a first coding agent to generate execution planning information based on the development requirements information; when the current stage is the code writing stage, the transition action includes calling a second coding agent to generate code based on the development requirements information and the execution planning information. This disclosure improves development efficiency, flexibility, and scalability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer technology, and more particularly to code generation methods and apparatus in the field of artificial intelligence technology. Background Technology

[0002] The rapid iteration pace, large-scale interaction pressure, and complex technology stack of the internet industry create a strong contradiction with the efficiency, cost, and quality bottlenecks of traditional manual coding, making it imperative to develop automated code generation technologies that can reduce labor costs and improve development efficiency. Summary of the Invention

[0003] This disclosure provides a code generation method, apparatus, electronic device, non-transitory computer-readable storage medium, and computer program product to reduce labor costs and improve development efficiency.

[0004] According to a first aspect of this disclosure, a code generation method is provided, comprising: Obtain development requirements information; Obtain the code development task and corresponding multi-level status information corresponding to the development requirements information. The multi-level status information includes multiple stage information of code generation, status information corresponding to each stage information, and transition rule information between states. The stage information includes at least planning stage information and code writing stage information. During the execution of the code development task, in response to determining that the transformation rule information is satisfied, the transformation action corresponding to the current state of the current stage is executed, and the process switches to the next state; Wherein, in the case that the current stage is the planning stage, the conversion action includes: invoking the first coded intelligent agent to generate execution planning information based on the development requirement information; When the current stage is the code writing stage, the conversion action includes: invoking a second coding agent to generate code based on the development requirements information and the execution plan information. According to a second aspect of this disclosure, a code generation apparatus is provided, comprising: The task acquisition unit is configured to acquire development requirement information; The configuration acquisition unit is configured to acquire the code development task and the corresponding multi-level status information corresponding to the development requirement information. The multi-level status information includes multiple stage information of code generation, status information corresponding to each stage information, and transition rule information between states. The stage information includes at least planning stage information and code writing stage information. The state transition unit is configured to, during the execution of the code development task, in response to determining that the transition rule information is satisfied, perform a transition action corresponding to the current state of the current stage and switch to the next state. Wherein, in the case that the current stage is the planning stage, the conversion action includes: invoking the first coded intelligent agent to generate execution planning information based on the development requirement information; In the case that the current stage is the code writing stage, the conversion action includes: invoking a second coding agent to generate code based on the development requirements information and the execution plan information.

[0005] According to a third aspect of this disclosure, an electronic device is provided, comprising: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method described in the first aspect above.

[0006] According to a fourth aspect of this disclosure, a non-transitory computer-readable storage medium is provided storing computer instructions, wherein the computer instructions are configured to cause the computer to perform the method described in the first aspect above.

[0007] According to a fifth aspect of this disclosure, a computer program product is provided, comprising a computer program that, when executed by a processor, implements the method described in the first aspect above.

[0008] As can be seen from the above technical solutions, this disclosure maintains multiple stages of code generation information, the state information contained in each stage, and the transition rules between states through multi-layer state information. It adopts a state-driven action approach, calling the first coding agent to generate execution planning information based on development requirement information, and calling the second coding agent to generate code based on development requirement information and execution planning information. This achieves automated code generation, reduces labor costs, and improves development efficiency.

[0009] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description

[0010] The accompanying drawings are provided to better understand this solution and do not constitute a limitation of this disclosure.

[0011] Figure 1 This is an exemplary system architecture diagram to which embodiments of this disclosure can be applied.

[0012] Figure 2 This is a schematic flowchart of a code generation method according to an embodiment of the present disclosure.

[0013] Figure 3 A schematic diagram of multi-level state transitions provided for a disclosed embodiment.

[0014] Figure 4 A schematic block diagram of a code generation apparatus provided in an embodiment of this disclosure.

[0015] Figure 5 This is a block diagram of an electronic device used to implement the code generation method of the embodiments of this disclosure. Detailed Implementation

[0016] The exemplary embodiments of this disclosure are described below with reference to the accompanying drawings, including various details of the embodiments to aid understanding, and should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of this disclosure. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.

[0017] Traditional code development mainly includes two approaches: One approach relies on developers manually writing code, supplemented by intelligent code completion from the integrated development environment (IDE). This method is obviously labor-intensive and inefficient.

[0018] Another approach is to use intelligent programming assistants to generate local code suggestions based on code context or comments. While this method reduces manual costs to some extent, it only focuses on local parts of the development process, providing fragment-level suggestions. A large amount of work still relies on manual execution and cannot achieve automatic code generation.

[0019] In view of this, this disclosure provides a completely new approach. To facilitate understanding of the embodiments of this disclosure, the system architecture on which this disclosure is based will first be described. Figure 1 Exemplary system architectures that can be applied to embodiments of this disclosure are shown, such as Figure 1 As shown, the system architecture may include: a user terminal and a code generation device set on the server side.

[0020] The server side and the client side are the two main components of an application service. The server side uses a server as its primary hardware infrastructure and may include one or more software service modules. The server side and the client side form a collaborative front-end and back-end.

[0021] The client can be set on the terminal device. In this embodiment of the disclosure, the client can be a local application, a mini-program, or a web application running through a browser on the terminal device.

[0022] A server can be a single server, a server cluster consisting of multiple servers, or a cloud server. A cloud server, also known as a cloud computing server or cloud host, is a hosting product in the cloud computing service system, designed to address the shortcomings of traditional physical hosts and Virtual Private Servers (VPS) services, such as high management difficulty and weak service scalability.

[0023] In this embodiment, the user can submit development requirements information input by the user to the code generation device on the server side, which then automatically generates code using the method provided in this embodiment. The code generation device can be set within the executor module of the code development system and run as an executor instance. During the code generation process, the code generation device may access specification databases, code repositories, etc., and may also involve invoking coding agents.

[0024] It should be understood that Figure 1 The number of client applications, executor modules, specification databases, code repositories, and coding agents shown is merely illustrative. Depending on implementation needs, any number of client applications, executor modules, specification databases, code repositories, and coding agents can be included.

[0025] Figure 2 This is a schematic flowchart of a code generation method according to an embodiment of the present disclosure. This method can be applied to code development systems, and its core lies in driving the entire automated development process through multiple layers of states. Figure 2 As shown, the method may include the following: Step 201: Obtain development requirements information.

[0026] Step 203: Obtain the code development tasks and corresponding multi-level state information corresponding to the development requirements information. The multi-level state information includes multiple stages of code generation information, state information contained in each stage, and transition rules between states. Among these multiple stages, at least the planning stage information and the code writing stage information are included.

[0027] Step 205: During the execution of code development tasks, in response to the determination that the transformation rule information is satisfied, the transformation action corresponding to the current state of the current stage is executed, and the state is switched to the next state; wherein, when the current stage is the planning stage, the transformation action includes calling the first coding agent to generate execution planning information based on the development requirement information; when the current stage is the code writing stage, the transformation action includes calling the second coding agent to generate code based on the development requirement information and the execution planning information.

[0028] As can be seen, this disclosure maintains multiple stages of code generation information, the state information contained in each stage, and the transition rules between states through multi-layered state information. It adopts a state-driven action approach, calling a first coded agent to generate execution planning information based on development requirements information, and calling a second coded agent to generate code based on development requirements information and execution planning information. On one hand, this application replaces the original fixed-program code generation process with a state machine mechanism, converting the hard-coded process into a rule-based state flow. This results in greater process controllability and flexibility. Furthermore, since the state machine mechanism requires configuration of states and transition rules between states, it offers higher development efficiency compared to fixed-program implementation. On the other hand, the state transition process is traceable, facilitating problem localization and process optimization. Moreover, the multi-layered state information—stages, stage states, and transition rules—allows for more flexible expansion of new stage and state information, resulting in greater scalability.

[0029] The following describes in detail each step of the above process and the effects that can be further produced, with reference to the embodiments. First, step 203, namely "obtaining the code development task and corresponding multi-level status information corresponding to the development requirement information", will be described in detail with reference to the embodiments.

[0030] In the field of code development, the reason why intelligent programming assistants can currently only provide fragment-level suggestions is that, in code generation scenarios, intelligent programming assistants provide development requirements to large language models through input prompts, and the large language model then outputs code based on these requirements. However, this approach only allows the large language model to handle very simple development requirements, and it struggles to achieve the desired results for relatively complex ones.

[0031] Through in-depth analysis, the inventors discovered that the root cause of the aforementioned problems lies in the fact that simply inputting all development requirements information into a large language model at once can easily lead to information overload or the neglect of critical details when the task complexity is high. Therefore, this disclosure decomposes the entire code generation capability involved in the code development task into multiple stages, and maintains the state information and state transition rules information for each stage. Without sacrificing the powerful code generation capability of the coding agent, the code generation capability is decomposed into actions between state transitions, thereby improving the controllability of the development process and the reliability of the results.

[0032] The term "code development task" as used in the public context refers to a complete automated processing request initiated by a user (e.g., a developer) within a development system (or automated coding system). This request is based on user-inputted development requirements, which include core business requirements, technology stack and architectural constraints, functional details, and boundary conditions. A code development task must at least include a unique task identifier, development requirements information, the product line or project to which it belongs, and a configured workspace path.

[0033] The "multi-level state information" referred to in this disclosure refers to state machine information used to define and manage code development tasks. It describes the task lifecycle through at least two levels (stages and states within stages), specifying the triggering conditions for transitions between stages, and the conditions and actions for transitioning from one state to the next within a stage. For example, it can be specifically a configuration file for a state machine, declaring which stages exist, under what conditions stage transitions occur, which states each stage contains, and under what conditions and after what actions transitions between states.

[0034] The "transition rule information" referred to in this disclosure is a logical description that connects one state to the next and specifies the triggering conditions and transition actions. It typically includes the triggering conditions, the transition action to be executed (which can be empty, meaning that if the triggering conditions are met, no action needs to be executed to enter the next state), and the target state. For example, a rule can be expressed as: when the task is in the "planning pending" state and "development requirement information has been obtained", then execute the action of "calling the first coded agent to generate the execution plan", and after completion, switch to the "planning in progress" state.

[0035] In this embodiment of the disclosure, the multiple stages of code generation include at least a planning stage and a code writing stage, and may further include a task creation stage and an initialization stage.

[0036] As one possible approach, the initialization phase can include the following states: pending initialization, initialization in progress, initialization successful, and initialization failed.

[0037] The rule-making phase can include the following states: planning pending, planning in progress, planning under confirmation, planning confirmed, and planning failure.

[0038] The code writing phase can include the following states: code to be written, code in progress, code under review, review passed, review rejected, and writing failed.

[0039] In addition to the stage division methods and state division methods within stages described above, coarser-grained or finer-grained stage division methods, or coarser-grained or finer-grained state division methods, can also be used. This disclosure does not impose further specific limitations on these methods. The transition rules between states will be detailed in subsequent embodiments.

[0040] The following describes step 205, namely, "In the process of executing code development tasks, in response to determining that the conversion rule information is satisfied, the conversion action corresponding to the current state of the current stage is executed, and the state is switched to the next state," in detail with reference to the embodiments.

[0041] This step is the core loop and driving process of automatic code generation. The executor module continuously and periodically monitors the current state of the code development task and queries the multi-level state information for transformation rules applicable to the current state. When the trigger condition of a transformation rule is met, the executor module executes the transformation action defined by that rule. After the action is successfully executed, the current state of the code development task is updated to the target state defined in the rule information, thus propelling the process to the next stage.

[0042] This mechanism enables proactive and orderly advancement of the development process, breaking down a complex end-to-end task into multiple stages including state transitions. Each state transition has clear triggering conditions, transition actions, and target states, making the entire process transparent, controllable, and traceable.

[0043] In this embodiment, at least the planning and coding phases are driven by multi-layered state information. When the current phase is the planning phase, the execution of the transition action includes invoking a first coding agent to generate execution planning information based on development requirement information. This transition action is triggered when the executor module determines that the task has entered the planning phase and is in a specific state (e.g., "planning pending"). Execution of this transition action means appropriately formatting the development requirement information (which may come from a form filled out by the user when creating the task, or pre-established requirement card information, etc.), constructing it into a prompt instruction, and then invoking the coding agent service. The result returned by the agent service is the execution planning information.

[0044] In the current stage of code writing, the transformation action involves invoking the second coding agent to generate code based on development requirements and execution plan information. This is a step in translating the execution plan into concrete code. When the task status transitions to a specific state in the code writing stage (e.g., "Code to be written"), and it is confirmed that development requirements and confirmed execution plan information are available, the executor module will trigger this action. At this point, the prompt instruction to invoke the second coding agent will use the confirmed execution plan information as the core guiding context, combined with the development requirements information, to instruct the coding agent to generate executable code that conforms to the plan.

[0045] It should be noted that the first coded agent and the second coded agent involved in the embodiments of this disclosure can be the same coded agent or different coded agents.

[0046] The action design across these multiple stages embodies a multi-stage strategy of planning first and then coding, allowing the coding agent to execute different, more specific processes multiple times, which helps improve the quality and controllability of the output. The planning stage mainly plans "what to do" and "how to do it," while the coding stage executes the specific code. The role of multi-layered state information is to ensure that this path is followed in an orderly and correct manner.

[0047] In addition, a multi-layered state information-based driver can be implemented in the initialization phase. The following example, using a driver that integrates multi-layered state information from task initialization to code writing, details the state transition process at each stage. A diagram illustrating the state transitions is shown below. Figure 3 As shown.

[0048] After the user inputs development requirements and triggers a task creation request for the code development task, the task creation phase begins. The task creation phase marks the start of the code development task lifecycle. It retrieves development requirements from the task creation request, creates the task object for the code development task, and triggers the initialization phase (e.g., generating an event that triggers initialization).

[0049] When creating task objects, unstructured development requirements can be transformed into structured task objects, providing a unified data input for subsequent processes. After creating the task object, validation is performed, such as validating necessary information like task identifier, task name, code repository address, development manager, workspace path, and coding environment type.

[0050] The initialization phase ensures that code generation executes in a stable, consistent, and isolated environment. Upon entering the initialization phase, the system is initially in a pending initialization state. If the current state is the pending initialization state, and the initialization trigger conditions are met (e.g., receiving an event that triggers initialization or successful code repository creation), the workspace for the code development task is initialized (i.e., a transition action) based on the state transition rules, switching to the initialization in progress state (i.e., the target state). In response to initialization completion, based on the state transition rules, the system switches to the initialization successful state, triggering entry into the planning phase (e.g., generating an event that triggers entry into the planning phase).

[0051] The initialization of the workspace for the code development task may include: creating a separate workspace directory for the current code development task on a server or container; cloning the specified code repository into the workspace according to the task configuration and switching to the target branch; installing project dependencies; and configuring necessary environment variables.

[0052] The state transition process described above in the initialization phase can automatically initialize the workspace for code development tasks, improving efficiency and providing a stable, consistent, and isolated sandbox environment for subsequent phases. The state transitions during the initialization phase make the entire initialization process clearer and easier to extend.

[0053] The purpose of the planning phase is to transform the entire code generation process corresponding to a code development task into decomposable steps, that is, to generate execution planning information that guides the coding agent on "what to do" and "how to do it." Upon entering the planning phase, the module initially enters a "planning pending" state. If the executor module obtains the current state as the planning pending state of the planning phase and acquires development requirement information (i.e., triggering conditions), based on the transformation rule information, it calls the first coding agent to generate execution planning information (i.e., transformation actions) based on the development requirement information, and switches to the planning in progress state (i.e., the target state).

[0054] The term "coding agent" as used in this disclosure refers to an intelligent coding agent built on a large language model, capable of understanding development requirements and generating execution specifications or code. Its core function is to understand and execute coding-related processing logic.

[0055] In this disclosure, "execution planning information" refers to a scheme description document generated by the first coding agent based on development requirement information, outlining how to implement the requirement. It does not contain specific execution code, but rather a plan for code writing. For example, it can be a text document containing some or all of the following types of content: requirements analysis, technology selection recommendations, module design, implementation steps, potential risks, and dependency descriptions.

[0056] In response to the completion of execution planning information generation (i.e., triggering condition), the execution planning information is sent to the user terminal based on the transformation rule information (i.e., transformation action), switching to the planning confirmation state (i.e., target state). While the execution planning information generated by the first coding agent can be directly used for subsequent code generation, this embodiment provides a preferred method: the execution planning information generated by the first coding agent is first returned to the user terminal for confirmation or rejection, thus avoiding deviations in subsequent coding work due to misunderstandings by the coding agent. Furthermore, when the user rejects the execution planning information, a rejection reason and modification suggestions can be input, which are then sent to the server by the user terminal. The methods for returning the execution planning information to the user terminal can include, but are not limited to, user interface push notifications, email push notifications, instant messaging tool message push notifications, etc.

[0057] In response to the feedback confirmation of the execution planning information returned by the user (i.e., the triggering condition), based on the transformation rule information, the system switches to the planning confirmed state (i.e., the target state), triggering entry into the code writing stage (e.g., generating an event that triggers entry into code writing). The achievement of the planning confirmed state is a prerequisite for the initiation of the code writing stage, thus triggering the transition between stages.

[0058] The above process automates the planning generation, feedback, and confirmation workflow through state transitions. Human confirmation points are cleverly embedded within this automation, forming a rapid feedback loop. This ensures that subsequent code writing is conducted under user-authorized and clearly defined planning guidance, enhancing the consistency between the final code output and the user's intent regarding development requirements. In other words, the generated code more accurately reflects the user's development needs. Furthermore, the entire planning process is orderly, controllable, and traceable.

[0059] In response to the user's feedback result indicating rejection (i.e. triggering condition) regarding the execution planning information, based on the transformation rule information, the first coded agent is invoked to regenerate the execution planning information (i.e. transformation action) based on at least one of the rejection reasons and modification suggestions returned by the user regarding the execution planning information, as well as the development requirement information, and switches to the planning pending state (i.e. target state).

[0060] This state transition is designed to handle iterative optimization when users are dissatisfied with the execution plan. Users can reject the execution plan and provide at least one of the reasons for rejection and modification suggestions, enabling the first coding agent to rethink and generate the execution plan. This empowers the code development system with the ability to iteratively improve based on user feedback, thereby enabling it to identify and correct deviations at the planning level in advance and avoid the waste of resources and time caused by writing subsequent code in the wrong direction.

[0061] Upon entering the code writing phase, the system is initially in a code-ready state. The executor module, upon receiving this state and the development requirements and execution plan information (i.e., triggering conditions), calls the second coding agent to generate code based on the development requirements and execution plan information (i.e., the conversion action), and then switches to the code-writing state (i.e., the target state).

[0062] By transitioning from the code-to-write state to the code-writing-in-progress state, the confirmed execution plan information can be accurately transformed into specific, executable code. This ensures that the code generation process is initiated under correct guidance, improving the accuracy of the generated code and its consistency with the execution plan information.

[0063] After the code is generated, the code development system performs version control, updates the session file, and commits the generated code to the code repository.

[0064] To introduce a code quality assurance mechanism, this embodiment of the disclosure can further add an automated code submission and review process after code generation. Specifically, in response to the completion of code generation (i.e., the triggering condition), based on the conversion rule information, the code is submitted for review (i.e., the conversion action), and the system switches to the code review state (i.e., the target state); in response to the obtained review result indicating that the review has passed (i.e., the triggering condition), based on the conversion rule information, the system switches to the review passed state (i.e., the target state).

[0065] This involves submitting code to a code review system for automated review based on pre-configured standards, or submitting the code to reviewers for evaluation. Code reviews can examine whether the code conforms to syntax standards, architectural design standards, framework development standards, performance and resource usage standards, security standards, and more.

[0066] By transitioning between the code writing state, the code review state, and the review passed state, automatic code review can be achieved, ensuring that the code meets basic specification requirements and improving the credibility and standardization of the code.

[0067] Considering that code review results may indicate rejection, this disclosure further provides a path for handling rejections and iterative optimization to form a complete quality improvement loop. After switching to the code review state, the process further includes: responding to the obtained review result indicating rejection (i.e., triggering condition), switching to the rejection state (i.e., target state) based on transition rule information. Responding to the obtained review feedback information for the code (i.e., triggering condition), based on the state transition rule information, invoking a second coding agent to optimize the code based on development requirement information, execution planning information, and the review feedback information for the code (i.e., transition action), switching to the code writing state (i.e., target state). A review of the optimized code will then be triggered again.

[0068] The review feedback can be generated by the code review system, such as comments, tags, and suggestions on lines of code. It can also be comments and suggestions made by reviewers on lines of code.

[0069] The technical effect of this mechanism lies in constructing a closed loop of feedback-driven optimization. It enables the code development system to understand and absorb the results from code reviews and optimize accordingly, thereby improving the system's ability to handle complex code development tasks, meet quality standards, and enable the automated coding process to continuously learn and improve.

[0070] During the execution of actions in each of the above stages, if an error occurs, the executor module will update the task status to the corresponding failure status, record a detailed error log, terminate the code development task processing flow, stop session management for that code development task, and release related resources. For example, if initialization fails, the module will switch from the initialization in progress state to the initialization failed state. Similarly, if generating an execution plan fails, the module will switch from the planning in progress state to the planning failed state. And if generating code fails, the module will switch from the code writing in progress state to the writing failed state.

[0071] To improve system observability and task traceability, and to facilitate problem diagnosis and progress monitoring, this embodiment of the disclosure adds an auxiliary function. The method further includes: recording task data for the code development task. The task data includes execution status information for multiple stages and key event information. Key event information may include the occurrence time, description, and execution result data of the key event. Key events may include events such as initialization events (i.e., events that perform initialization), planning events (i.e., events that generate execution plans), planning confirmation events (i.e., events that confirm execution plans), and code writing events (i.e., events that generate code). The execution result data of the key event may be the execution result data of the corresponding transformation action. The execution result data may include messages indicating success or failure, and may also include information such as generated execution plans, code, and code review results. If the key event involves a call to a coding agent, the corresponding execution result data may also include at least one of the coding agent's thought process information and decision-making basis information. In response to a task query request from the user, the execution information of the code development task is returned, such as the current stage information, current status information, and key event information of the executed stages.

[0072] During the aforementioned state transition process, recording task data for code development provides users and operations personnel with comprehensive tracking capabilities, making task progress, time consumption, and key event information readily available. This not only enhances the transparency and traceability of the automated coding process but also provides data support for system monitoring, debugging, and performance optimization.

[0073] As can be seen from the above method embodiments, this disclosure decomposes the entire code development task into two levels: stages and states within each stage. This makes the complex development process easier to understand and manage, clarifies the responsibilities of each stage, and encapsulates state details within each stage, reducing the complexity of system design. Furthermore, modifications or expansions to states within a stage do not affect other stages, facilitating local optimization of the process and improving flexibility and maintainability.

[0074] In this embodiment, the multi-layered state information configured for code development tasks can be maintained by the task management module of the code development system. The task management module is responsible for the entire lifecycle management of tasks, from task creation, initialization, code generation, review to final completion or failure. The task management module defines a strict state transition mechanism to ensure that inter-stage transitions and intra-stage state transitions must be performed according to predefined rules (i.e., multi-layered state information), requiring legality verification. Furthermore, the task management module is also responsible for recording and responding to query data for the code development tasks in the above embodiments.

[0075] In addition, the embodiments disclosed herein involve Figure 2The process shown can be executed by the executor module in the code development system. The executor module can be in the form of a distributed cluster, that is, the executor module can include multiple executor instances, and the state transitions of each stage can be executed by the same executor instance or by different executor instances.

[0076] The term "executor instance" as used in this disclosure refers to any process, container, or computing unit capable of hosting and running the execution logic of a code development task.

[0077] The aforementioned stages can be divided into multiple sub-tasks within the code development task. For example: the first sub-task handles the state transitions involved from obtaining development requirements information to generating execution plan information. The second sub-task handles the state transitions involved from receiving a rejection response from the user to regenerating the execution plan information. The third sub-task handles the state transitions involved from receiving a confirmation response from the user to submitting the generated code for review. The fourth sub-task handles the state transitions involved from a rejection response to code optimization.

[0078] During the execution of the first to third subtasks, calls to the coded agent will be involved. When the executor instance calls and interacts with the coded agent, a session file will be generated and stored locally.

[0079] In this embodiment, the session file may include, but is not limited to, globally unique identifiers (typically uniquely corresponding to code development tasks), user-provided raw input (e.g., user-inputted development requirements, user feedback on execution planning information, user feedback on code review results, etc.), the coding agent's thought records, and the coding agent's output content, among other contextual content. The session file corresponds to the code development task; for example, the task identifier of the code development task is maintained and stored in correspondence with the identifier in the session file. Subtasks at each stage of the code development task share the same task identifier, thereby distinguishing the code development task to which they belong.

[0080] In this embodiment of the disclosure, a session listener can periodically detect the local session file corresponding to the code development task. The session listener can be bound to the code development task identifier. The interval of periodic detection can be flexibly configured, for example, set to 30 seconds, 1 minute, or a shorter or longer time interval, to capture changes in session content.

[0081] One possible approach is for the session listener to periodically check the most recent modification timestamp of the session file and determine whether the local session file has been changed by comparing the modification timestamp with the timestamp of the last time the session file was synchronized to the remote storage space.

[0082] The aforementioned synchronization operation may include reading the modified session file and uploading it to a specified path in a remote storage space (such as cloud storage) via a network protocol. For example, it may involve creating an export directory structure, parsing the session content in the session file, organizing and converting the session content according to a predefined format to generate a viewable document, and then uploading it to the specified path in the remote storage space. This path is associated with the task identifier of the code development task for storage, ensuring that the session content of each code development task can be accurately stored and retrieved, and guaranteeing the security and accessibility of the session content. If the upload is successful, the timestamp of the session file synchronized to the remote storage space is updated.

[0083] Synchronization can take the form of, but is not limited to, full synchronization and incremental synchronization. Full synchronization refers to uploading the entire session file every time a change is detected in the local session file. Incremental synchronization refers to appending only the newly added lines or data blocks from the local session file to the session file in the remote storage space.

[0084] The code development system may also include a scheduler module, which may contain one or more scheduler instances. The scheduler instance is responsible for assigning subtasks to executor instances, that is, sending the subtasks to the executor instances for execution. If the currently assigned subtask has a preceding subtask (for example, in the same code development task, the first subtask is a preceding subtask of the second and third subtasks; the third subtask is a preceding subtask of the fourth subtask), then if the first executor instance executing the preceding subtask is still alive, the currently assigned subtask will still be assigned to that first executor instance; otherwise, the currently assigned subtask will still be sent to the second executor instance, for example, by selecting an idle executor instance from the executor resource pool.

[0085] If the currently unassigned subtask is assigned to the second executor instance, that is, the subtask is sent to the second executor instance, the first executor instance has often become invalid, and its corresponding local session file may have been deleted. Therefore, the second executor instance can retrieve the session file of the code development task from the remote storage space based on the task identifier of the code development task, and thus be able to execute the assigned subtask based on the context of the preceding subtask.

[0086] The scheduler instance can use a periodic heartbeat mechanism to detect the status of the executor instances, that is, to detect whether the executor instances are alive or have failed. Typically, when an executor instance fails, the resources it occupies will be cleaned up and reclaimed, such as local session files.

[0087] Figure 4 This is a schematic block diagram of the code generation apparatus provided in the embodiments of this disclosure, such as... Figure 4 As shown, the code generation device may include: a requirement acquisition unit 401, a configuration acquisition unit 402, and a state transition unit 403, and also includes a data recording unit 404 and a query response unit 405. The main functions of each component are as follows: The requirement elicitation unit 401 is configured to obtain development requirement information.

[0088] The configuration acquisition unit 402 is configured to acquire the code development task and the corresponding multi-level status information corresponding to the development requirement information. The multi-level status information includes multiple stage information of code generation, status information corresponding to each stage information, and transition rule information between states. The stage information includes at least planning stage information and code writing stage information.

[0089] The state transition unit 403 is configured to, in the process of executing the code development task, in response to determining that the transition rule information is satisfied, perform a transition action corresponding to the current state of the current stage and switch to the next state.

[0090] Wherein, if the current stage is the planning stage, the conversion action includes: invoking a first coding agent to generate execution planning information based on the development requirements information; if the current stage is the code writing stage, the conversion action includes: invoking a second coding agent to generate code based on the development requirements information and the execution planning information.

[0091] As one possible implementation, the state transition unit 403 can be specifically configured as follows: in response to the current state being the planning stage (planning pending state) and obtaining the development requirement information, based on the transition rule information, the first coding agent is invoked to generate the execution planning information based on the development requirement information, and the state is switched to planning in progress; in response to the completion of the execution planning information generation, the execution planning information is sent to the user terminal based on the transition rule information, and the state is switched to planning confirmation; in response to the user terminal returning a feedback result indicating confirmation for the execution planning information, the state is switched to planning confirmed based on the transition rule information, triggering entry into the code writing stage.

[0092] Furthermore, the state transition unit 403 can also be specifically configured to: respond to the feedback result indication rejection of the execution planning information returned by the user terminal, based on the transition rule information, call the first coded intelligent agent to regenerate the execution planning information based on at least one of the rejection reasons and modification suggestions returned by the user terminal for the execution planning information and the development requirement information, and switch to the planning pending state.

[0093] As one possible implementation method, the state transition unit 403 can be specifically configured to: respond to the current state being the code writing stage (code waiting to be written) and to obtain the development requirement information and the execution plan information, based on the transition rule information, call the second coding agent to generate code based on the development requirement information and the execution plan information, and switch to the code writing state.

[0094] Furthermore, the state transition unit 403 can also be specifically configured to: in response to the completion of code generation, submit the code for review based on the transition rule information and switch to the code review state; in response to the obtained review result indicating that the review has passed, switch to the review passed state based on the transition rule information.

[0095] Furthermore, the state transition unit 403 can also be specifically configured to: after switching to the code review state, in response to the obtained review result indicating review rejection, switch to the review rejection state based on the transition rule information; in response to obtaining the review feedback information for the code, based on the transition rule information, call the second coding agent to optimize the code based on the development requirement information, the execution plan information and the review feedback information, and switch to the code writing state.

[0096] As one possible implementation method, the state transition unit 403 can be specifically configured to: in response to the current state being the initialization stage and the pending initialization state, initialize the workspace of the code development task based on the transition rule information and switch to the initialization state; in response to the initialization completion, switch to the initialization successful state based on the transition rule information between states and trigger entry into the planning stage.

[0097] Furthermore, the data recording unit 404 can be configured to record task data of the code development task. The task data includes execution status information of the multiple stages and key event information. The key event information includes the occurrence event, description information and execution result data of the key event.

[0098] The query response unit 405 can be configured to respond to a task query request from a user and return the execution information of the code development task, including the current stage information, the current status information, and key event information of the executed stage.

[0099] The collection, storage, use, processing, transmission, provision, and disclosure of user personal information involved in the technical solution disclosed herein comply with the provisions of relevant laws and regulations and do not violate public order and good morals.

[0100] The electronic devices provided in this disclosure include: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, which, when executed by the at least one processor, enables the at least one processor to perform any of the methods described in the above method embodiments.

[0101] The present disclosure provides a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to cause the computer to perform any of the methods described in the above method embodiments.

[0102] This disclosure provides a computer program product, including a computer program that, when executed by a processor, implements any of the methods described in the above method embodiments.

[0103] Figure 5 A schematic block diagram of an example electronic device 500 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.

[0104] like Figure 5As shown, device 500 includes a computing unit 501, which can perform various appropriate actions and processes based on a computer program stored in read-only memory (ROM) 502 or a computer program loaded from storage unit 508 into random access memory (RAM) 503. RAM 503 may also store various programs and data required for the operation of device 500. The computing unit 501, ROM 502, and RAM 503 are interconnected via bus 504. Input / output (I / O) interface 505 is also connected to bus 504.

[0105] Multiple components in device 500 are connected to I / O interface 505, including: input unit 506, such as keyboard, mouse, etc.; output unit 507, such as various types of monitors, speakers, etc.; storage unit 508, such as disk, optical disk, etc.; and communication unit 509, such as network card, modem, wireless transceiver, etc. Communication unit 509 allows device 500 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.

[0106] The computing unit 501 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 501 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 501 performs the various methods and processes described above, such as code generation methods. For example, in some embodiments, the code generation method may be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 508. In some embodiments, part or all of the computer program may be loaded and / or installed on device 500 via ROM 502 and / or communication unit 509. When the computer program is loaded into RAM 503 and executed by the computing unit 501, one or more steps of the code generation method described above may be performed. Alternatively, in other embodiments, the computing unit 501 may be configured to perform code generation methods by any other suitable means (e.g., by means of firmware).

[0107] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.

[0108] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.

[0109] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.

[0110] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).

[0111] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.

[0112] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact via communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other. Servers can be cloud servers, servers in distributed systems, or servers incorporating blockchain technology.

[0113] It should be understood that the various forms of processes shown above can be used to rearrange, add, or delete steps. For example, the steps described in this disclosure can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution disclosed in this disclosure can be achieved, and this is not limited herein.

[0114] The specific embodiments described above do not constitute a limitation on the scope of protection of this disclosure. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this disclosure should be included within the scope of protection of this disclosure.

Claims

1. A code generation method characterized by, include: Obtain development requirements information; Obtain the code development task and corresponding multi-level status information corresponding to the development requirements information. The multi-level status information includes multiple stage information of code generation, status information corresponding to each stage information, and transition rule information between states. The stage information includes at least planning stage information and code writing stage information. During the execution of the code development task, in response to determining that the transformation rule information is satisfied, the transformation action corresponding to the current state of the current stage is executed, and the process switches to the next state; Wherein, in the case that the current stage is the planning stage, the conversion action includes: invoking the first coded intelligent agent to generate execution planning information based on the development requirement information; In the case that the current stage is the code writing stage, the conversion action includes: invoking a second coding agent to generate code based on the development requirements information and the execution plan information.

2. The method of claim 1, wherein, The step of responding to determining that the transformation rule information is satisfied, executing the transformation action of the current state corresponding to the current stage, and switching to the next state corresponding to the current stage, includes: In response to the current state being the planning stage and the acquisition of the development requirement information, the first coding agent is invoked to generate the execution planning information based on the development requirement information, and the process switches to the planning stage. In response to the completion of the execution plan information generation, the execution plan information is sent to the user terminal based on the conversion rule information, and the status is switched to "planning confirmation". In response to the feedback result confirmation of the execution plan information returned by the user terminal, based on the conversion rule information, the system switches to the plan confirmation state and triggers the entry into the code writing stage.

3. The method according to claim 2, wherein, After switching to the planning stage, the step of responding to determining that the transition rule information is satisfied, executing the transition action corresponding to the current stage, and switching to the next stage, further includes: In response to the user terminal's feedback result indicating rejection of the execution planning information, based on the conversion rule information, the first coding agent is invoked to regenerate the execution planning information based on at least one of the rejection reasons and modification suggestions returned by the user terminal regarding the execution planning information, as well as the development requirement information, and switches to the planning pending state.

4. The method according to claim 1, wherein, The step of responding to determining that the transformation rule information is satisfied, executing the transformation action of the current state corresponding to the current stage, and switching to the next state corresponding to the current stage, includes: In response to the current state being the code writing stage (code waiting to be written), and having obtained the development requirements information and the execution plan information, the second coding agent is invoked to generate code based on the development requirements information and the execution plan information, and the process switches to the code writing state.

5. The method according to claim 4, wherein, After switching to the code writing state, the step of responding to determining that the conversion rule information is satisfied, executing the conversion action corresponding to the current state of the current stage, and switching to the next state corresponding to the current stage further includes: In response to the completion of code generation, based on the conversion rule information, the code is submitted for review and switched to the code review state; In response to the obtained review result indicating that the review has passed, the system switches to the review passed state based on the conversion rule information.

6. The method according to claim 5, wherein, After switching to the code review state, the step of responding to determining that the conversion rule information is satisfied, executing the conversion action corresponding to the current state of the current stage, and switching to the next state corresponding to the current stage, further includes: In response to the obtained review result indicating review rejection, the system switches to the review rejection state based on the conversion rule information; In response to receiving review feedback information for the code, based on the conversion rule information, the second coding agent is invoked to optimize the code based on the development requirements information, the execution plan information, and the review feedback information, and then the code is switched to the code writing state.

7. The method according to claim 1, wherein, The stage information also includes initialization stage information; the step of responding to determining that the transition rule information is satisfied, executing the transition action of the current state corresponding to the current stage, and switching to the next state corresponding to the current stage, includes: In response to the current state being the uninitialized state of the initialization phase, the workspace of the code development task is initialized based on the conversion rule information, and switched to the initialization state; In response to the completion of initialization, based on the transformation rule information, the system switches to the initialization success state, triggering the entry into the planning and formulation phase.

8. The method according to any one of claims 1 to 7, further comprising: Record the task data of the code development task, the task data including the execution status information of the multiple stages and key event information, the key event information including the occurrence time, description information and execution result data of the key event; In response to a task query request from the user, the execution information of the code development task is returned, including the current stage information, the current status information, and key event information of the executed stage.

9. A code generation device, characterized in that, include: The requirement elicitation unit is configured to obtain development requirement information; The configuration acquisition unit is configured to acquire the code development task and the corresponding multi-level status information corresponding to the development requirement information. The multi-level status information includes multiple stage information of code generation, status information corresponding to each stage information, and transition rule information between states. The stage information includes at least planning stage information and code writing stage information. The state transition unit is configured to, during the execution of the code development task, in response to determining that the transition rule information is satisfied, perform a transition action corresponding to the current state of the current stage and switch to the next state. Wherein, in the case that the current stage is the planning stage, the conversion action includes: invoking the first coded intelligent agent to generate execution planning information based on the development requirement information; In the case that the current stage is the code writing stage, the conversion action includes: invoking a second coding agent to generate code based on the development requirements information and the execution plan information.

10. An electronic device, comprising: At least one processor; as well as A memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor to enable the at least one processor to perform the method of any one of claims 1-8.

11. A non-transitory computer-readable storage medium storing computer instructions, wherein, The computer instructions are used to cause the computer to perform the method according to any one of claims 1-8.

12. A computer program product comprising a computer program that, when executed by a processor, implements the method according to any one of claims 1-8.