A dynamic scheduling method, system and application of multi-agent code generation under resource constraints
By optimizing the dynamic scheduling of multi-agent code generation in resource-constrained environments through the master scheduler, the problems of memory constraints and shared state communication are solved, achieving efficient code generation and repair, and improving system stability and resource utilization efficiency.
Patent Information
- Application Number
- CN202611245559.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-17
- Publication Date
- 2026-11-20
AI Technical Summary
In local deployment scenarios, multi-agent code generation systems struggle to simultaneously balance model runtime pass rate, stability, and resource utilization efficiency. Existing methods fail to effectively address issues such as memory constraints, model loading overhead, shared state communication, and failure test case feedback and repair.
This paper presents a dynamic scheduling method for multi-agent code generation under resource constraints. It achieves fine-grained scheduling by controlling the collaborative optimization of model selection, inference parameters, cross-process shared state, failure feedback-driven repair, and failed task retry process through a master scheduler. This includes initial execution strategy generation, task execution and real-time strategy adjustment, task completion and historical record update, and the use of shared state channels and resource monitoring to achieve fine-grained scheduling.
It improves the execution performance and resource utilization efficiency of the multi-agent code generation system in resource-constrained environments, reduces frequent switching and execution jitter, and improves task completion rate and resource utilization efficiency.
Smart Images

Figure CN123137631A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of large language model scheduling and intelligent software engineering technology, and particularly relates to a dynamic scheduling method, system and application for multi-agent code generation under resource constraints. Background Technology
[0002] As large language models are increasingly used for code generation, automated testing, program repair, and agent-based software development, multi-stage, multi-role collaborative intelligent agent software development systems are emerging widely. These systems typically include stages such as requirements analysis, code implementation, code review, test fixing, and documentation generation. Each stage has significant differences in its impact on model inference capabilities, context length, response latency, and computational resource consumption. Especially in local deployment scenarios, model parameter size, memory usage, model loading latency, GPU availability, and task time constraints collectively constitute rigid runtime constraints, making it difficult for execution methods with fixed models and parameters to simultaneously achieve high pass rates, stability, and resource utilization efficiency.
[0003] Existing methods mainly fall into two categories. The first category, represented by Puppeteer, focuses on the dynamic orchestration problem in multi-agent collaboration. It uses a centralized orchestrator to dynamically select agents based on task status and leverages reinforcement learning to optimize the collaboration process. Its emphasis is on improving the collaborative effectiveness and computational efficiency of multi-agent inference. Although this type of method possesses the characteristic of "dynamic orchestration," its scheduling objects are mainly agent activation order and collaboration structure, rather than multi-model runtime scheduling in local resource-constrained environments. It also lacks an integrated mechanism for model switching, round adjustment, token cap adjustment, temperature adjustment, cross-process shared state reading, and failure test case feedback and repair in the code generation process.
[0004] The second category, represented by RouteLLM, focuses on the routing problem between strong and weak models. Its core is to learn a binary classification routing function based on preference data at the single query level, balancing quality and cost, and explicitly adopting a routing paradigm of "only one model is called per query." This type of method is suitable for single-query routing scenarios such as general question answering, but it does not address the multi-agent code generation process involving multi-stage, multi-round testing and fixing, nor does it handle issues such as GPU memory constraints, model loading overhead, shared state communication, phased test feedback, and failure budget reuse in local deployment environments.
[0005] Furthermore, in resource-constrained local multi-model deployment environments, the main scheduler typically needs to run in parallel with the execution subprocesses and acquire real-time runtime information such as stage progress, test status, token consumption, latency, and resource usage. Without a stable cross-process shared state channel and resource monitoring mechanism, fine-grained scheduling is difficult to implement. Existing technologies sometimes rely on static switching based on a single threshold, easily leading to frequent model switching and execution jitter. While some methods utilize historical performance for configuration selection, they fail to combine task difficulty classification, remaining time, real-time resource load status, failed test case feedback, and historical budget backflow into a joint decision-making process. Summary of the Invention
[0006] This invention addresses a dynamic scheduling problem for multi-agent code generation in scenarios with limited local resources. The scheduling objects include not only model selection, but also execution parameters such as rounds, token count, and temperature. It combines shared state awareness, resource monitoring, sliding window decision-making, cold start detection, and failure retry to improve overall execution performance and resource utilization efficiency.
[0007] To address the shortcomings of existing technologies, the present invention aims to provide a dynamic scheduling method, system, and application for multi-agent code generation under resource constraints, so as to achieve collaborative optimization of model selection, inference parameters, cross-process shared state, failure feedback-driven repair, and failed task retry processes in a local multi-model deployment environment.
[0008] Firstly, this invention provides a dynamic scheduling method for multi-agent code generation under resource constraints. This dynamic scheduling method targets a model pool composed of multiple candidate models with different parameter scales. It jointly schedules the execution process of code generation tasks by controlling the initial execution strategy, dynamic parameter adjustment during execution, sliding window model switching decisions, shared state-driven operation monitoring, failure feedback-driven repair, and budget backfilling and retrying for failed tasks, through a master scheduler. Specific steps include:
[0009] Step 1: Initial execution strategy generation;
[0010] Step Two: Task Execution and Real-Time Strategy Adjustment;
[0011] Step 3: Task completion and historical execution record update.
[0012] In this invention, in step one, the main scheduler receives the code generation task and constructs an initial execution strategy based on the task's initial information, task difficulty classification, local preset conditions, historical execution records, and similar task memory.
[0013] In this invention, the task difficulty classification in step one refers to task difficulty classification oriented towards scheduling decisions, used to characterize the degree of demand of the code generation task on model capabilities, context length, repair rounds, and time budget. The task difficulty classification is performed by a locally fine-tuned classification model, preferably a BERT-type classification model.
[0014] In some implementations, the task difficulty classification includes simple tasks, medium tasks, and difficult tasks; wherein, simple tasks typically correspond to lower model capabilities and fewer token budget requirements, medium tasks correspond to medium model capabilities and moderate testing and repair requirements, and difficult tasks correspond to stronger models, higher token caps, or more testing and repair opportunities.
[0015] In some implementations, the training data for the classification model can be constructed by crawling question descriptions, input / output constraints, example cases, and function definitions from a code question bank, and fine-tuned by dividing the training set and validation or test set proportionally to output difficulty labels such as easy, medium, and hard.
[0016] In some implementations, the classification model can be deployed on a CPU or GPU and maintain an evaluation mode after loading. The evaluation mode refers to the classification model performing only forward inference during scheduling, without further parameter training or gradient updates.
[0017] In this invention, the initial execution strategy in step one includes model selection, output token limit, test round limit, and task difficulty classification.
[0018] In some implementations, the initial execution strategy is constructed based on a historical successful task feature library, used for experience retrieval and scheduling suggestion generation for the current task to be executed. The historical successful task feature library is constructed from reliable successful samples in historical execution records. Each reliable successful sample includes a feature vector of a task prompt word and a corresponding historical scheduling configuration. The historical scheduling configuration includes the execution model, output token limit, test round limit, and task scheduling features. Specifically, reliable successful samples are first screened from historical execution records, and the task prompt words of each successful sample are extracted. Then, the TF-IDF vectorization method is used to encode the task prompt words to obtain the corresponding historical task feature vectors, and the cosine similarity between the current feature vector and the feature vectors of each historical successful sample is calculated. Further, the main scheduler selects a set of similar historical samples based on a similarity threshold and a Top-k screening strategy, and performs weighted voting on the model and task difficulty classification corresponding to the historical samples based on similarity. A weighted average is then performed on the output token limit and test rounds to obtain the recommended model, recommended token number, recommended test rounds, and recommended task difficulty classification for the current task. In this way, the master scheduler can use historical success experience to obtain an initial execution strategy that is more in line with the characteristics of the current prompt words before the task is executed, thereby improving the initial scheduling hit rate and reducing the runtime trial and error cost.
[0019] In some implementations, if the number of entries in the current historical successful task feature library is less than a preset number, the main scheduler adopts a default initial execution strategy based on task difficulty classification. Specifically, for difficult tasks, a model with higher parameter scale is preferred, and a higher initial token limit and number of test rounds are configured; for medium-sized tasks, a model with medium parameter scale is preferred, and medium-level initial parameters are configured; for simple tasks, a model with lower parameter scale is preferred, provided that resource load conditions allow, to reduce memory usage and inference overhead.
[0020] In some implementations, before the task begins, the main scheduler detects the resource load status of the GPU corresponding to the current candidate model. If the GPU is detected to be under high load or severe overload at the initial moment, the main scheduler compresses the initial token configuration. Initial token configuration compression refers to lowering the upper limit of the initial output token of the current task from the original candidate level to a lower candidate level without changing the task input content, thereby reducing memory usage and inference latency during subsequent generation. If the resource load status still does not meet the execution requirements of the current candidate model, a candidate model with lower resource consumption is further selected as the initial execution model. In this way, the main scheduler can proactively avoid the risk of resource overload before the task is officially executed, preventing timeouts, insufficient memory, or execution instability after task startup due to excessively large initial model or initial token configurations.
[0021] In some implementations, the initial execution strategy further includes deadline information. This deadline information is generated based on the task name, task difficulty category, task time limit, and selected model. The deadline information includes remaining time, time pressure level, output token limit, test round expansion conditions, and model switching budget constraints.
[0022] In this invention, in step two, according to the initial execution strategy, the main scheduler starts the execution sub-process, initiates the multi-agent code generation execution flow, and continuously exchanges running status information through a shared state channel. Based on the shared state channel and the status of the execution sub-process, the main scheduler updates the real-time scheduling strategy until the task ends. The shared state channel is responsible for real-time exchange of running information, and the historical execution record is responsible for persistent recording after the task ends; together, they constitute a joint storage architecture of short-cycle state awareness and long-cycle experience memory.
[0023] In this invention, step two, the execution flow of the multi-agent code generation of the execution subprocess, includes multiple stages: a requirements analysis and language selection stage, a code implementation stage, a code review stage, a runtime testing and repair stage, and a documentation generation stage. The requirements analysis and language selection stage analyzes user requirements, determines the form of the software product to be generated, and selects the appropriate programming language. The code implementation stage generates initial code based on the requirements analysis results and the selected programming language, and supplements any missing functional modules, interface definitions, or implementation content in the initial code. The code review stage performs iterative static debugging before executing the candidate code. Specifically, the review agent examines the current candidate code, identifies the most pressing potential problems, and generates review opinions; the programming agent modifies the candidate code based on the review opinions. The runtime testing and repair stage performs runtime debugging on the reviewed candidate code. Specifically, the test agent executes the candidate code and provides feedback on the specific program execution results and runtime errors; the programming agent analyzes the causes of errors based on the program execution results and runtime errors, generates an error summary, and modifies the source code accordingly. The document generation phase is used to generate project documentation for software deployment, installation, configuration, and use after code implementation and runtime testing are completed.
[0024] In some implementations, the runtime status information includes the current simple stage, the current combined stage, the current stage round, the current combined stage round, test pass status, failed test case feedback, execution latency, and token consumption. The current simple stage refers to an independent execution stage currently being executed in the multi-agent code generation process; the current combined stage refers to an execution stage composed of two simple stages with execution association. The current stage round refers to the number of rounds already executed in the current simple stage; the current combined stage round refers to the number of rounds already executed in the current combined stage, used to determine the number of times the test repair loop has been performed. The main scheduler periodically reads the runtime status information during execution to achieve real-time awareness of the task execution process.
[0025] In this invention, in step two, after the execution subprocess enters the testing and verification phase, it performs tests on the currently generated code to verify its correctness. Branching is performed based on the test results: if the test passes, the current task execution is terminated early and the generated code is output; if the test fails, the main scheduler decides whether to continue to the next round of repair based on the remaining time budget, current running status information, and the common budget pool, until the maximum allowed number of rounds is reached or the termination condition is met. If the next round of repair is initiated, the main scheduler combines the current task difficulty classification, the running status information, and the task failure results to generate a repair execution strategy and repair scheduling input. The testing can be implemented based on preset test cases, task-inherent test cases, results returned by external testing systems, automatically generated test cases, or a combination thereof. The task failure results include failure test cases, error logs, error summaries, failure examples, or a combination thereof. The repair scheduling input includes the task failure results and is organized as structured feedback information.
[0026] In some implementations, the master scheduler initializes runtime scheduling variables, which are used to record stage changes, resource load status, round control, and token control information during the main task execution loop. These runtime scheduling variables include stage variables, resource sampling variables, a maximum allowed number of rounds, a global token limit, round growth cooldown time, and token growth cooldown time. Specifically, the stage variables record the stage name, combined stage name, and test round read in the previous round, allowing the master scheduler to determine whether the executing subprocess has entered a new stage or a new test round. The resource sampling variables store periodically collected resource load status data during task execution, such as CPU utilization, memory utilization, GPU utilization, video memory usage, and load level, for subsequent resource load status assessment. The maximum allowed number of rounds refers to the maximum number of test / repair rounds allowed for the current task under the constraints of task time limits, task difficulty classification, and the current execution model, preventing the task from entering the repair loop indefinitely after a test failure. The global token limit refers to the maximum output token limit allowed for the current task throughout the entire execution process, determined by the task time limit, the current model, and the task difficulty classification, constraining subsequent token growth to not exceed the time budget's allowable range. The round increase cooldown time refers to the minimum time interval between two increases in the test round number, used to prevent the main scheduler from continuously increasing the test repair round number in a short period of time. The token increase cooldown time refers to the minimum time interval between two increases in the output token limit, used to prevent the output token limit from being frequently adjusted due to short-term state changes.
[0027] In this invention, in step two, before starting the execution subprocess, the main scheduler initializes the shared state channel and writes the running state information corresponding to the current task. During the execution subprocess's operation, the main scheduler is responsible for writing the global token limit, maximum allowed number of rounds, scheduling temperature, and other scheduling parameters, while the execution subprocess is responsible for writing the current stage name, current test round, test pass status, failed test case feedback, stage duration, token consumption, and current stage conclusion.
[0028] In some implementations, the shared state channel is implemented using a Redis key-value database.
[0029] In this invention, during the execution of the subprocess, when tests fail, basic tests fail, enhancement tests fail, or execution anomalies occur, the main scheduler extracts feedback from the basic test results, enhancement test results, failed test cases, error logs, failure examples, phase generation content, and phase conclusions. The main scheduler organizes the failure feedback into structured feedback information to drive the code generation agent to perform targeted repairs.
[0030] In some implementations, the failed task budget recovery and retry mechanism reclaims the saved budget based on the difference between the planned task time and the actual execution time. Failed tasks are sorted by difficulty, failure reason, recent latency, and number of retries, and higher-performance configurations are prioritized for rescheduling when the budget meets the minimum retry threshold. Simultaneously, the main scheduler organizes basic test results, enhanced test results, failed test cases, error logs, or failure examples into structured failure feedback, which, along with a new execution strategy, is sent to the subsequent repair or retry phase. For failed tasks that meet the retry conditions, the main scheduler constructs a retry entry, which includes at least the original task, failure reason, recent model, recent latency, basic budget, and number of retries. The main scheduler reallocates the initial token limit, initial round number, and available time budget based on the retry model and task difficulty classification. The retrying task re-enters the single-task execution flow and reuses the shared state channel, resource monitoring, parameter adaptation, and failure feedback mechanism. By using the budget backflow retry, the master scheduler can utilize the time budget of tasks that were released early to reschedule tasks that failed in the first round but still have a chance of being repaired, thereby improving the overall completion rate of code tasks and the efficiency of resource utilization.
[0031] In some implementations, the common budget pool refers to a time budget set formed by accumulating the differences between the planned time limit and the actual time spent on each completed task during execution. This time budget is used to provide the time resources needed for rescheduling subsequent failed tasks. The minimum retry threshold refers to the minimum time requirement that must be met to retry a failed task, preventing timeouts caused by initiating retries when the remaining budget is insufficient. The master scheduler initiates the failed task retry process only when the available time budget in the common budget pool is greater than or equal to the minimum retry threshold.
[0032] In this invention, in step two, the main scheduler updates the real-time scheduling strategy based on the task difficulty classification and the running status information. The real-time scheduling strategy includes maintaining the current model, switching to a model with higher or lower parameter scales, compressing or expanding the token limit, and adjusting the number of test rounds. The main scheduler continuously reads the running status information; if the running status information indicates completion, it determines that the current task has completed all stages and exits the loop to enter step three.
[0033] In some implementations, the master scheduler detects whether the execution subprocess has exited abnormally and distinguishes between normal completion and subprocess failure based on the return code.
[0034] In some implementations, when the execution subprocess completes the test and passes, the test pass is written to the shared state channel; when the main scheduler reads the test pass from the running state information, the main scheduler immediately stops the current task and sets the termination reason to first test pass.
[0035] In some implementations, the main scheduler continuously monitors whether the current cumulative execution time has reached the task time limit. If the time limit is reached, it writes a timeout status and terminates the currently executing subprocess.
[0036] In some implementations, resource monitoring refers to real-time acquisition of CPU utilization, memory utilization, GPU utilization, video memory usage, GPU temperature, and active GPU index, and mapping the resource load status to multiple load levels. When in a severely overloaded state, the output token limit is reduced first, and model deload switching is performed if necessary.
[0037] In some implementations, the main scheduler periodically reads CPU utilization, memory utilization, GPU utilization, video memory usage, and active GPU number during execution. The main scheduler calculates the overall video memory ratio, the maximum GPU utilization of a single card, the average GPU utilization of multiple cards, and the maximum video memory ratio of a single card based on the resource load status, and classifies the current resource load status into low load, medium load, high load, and severe overload accordingly.
[0038] In some implementations, the classification of low load, medium load, high load, and severe overload is as follows: Severe overload is defined as follows: when the overall video memory utilization is not less than 95% and the overall GPU utilization is not less than 95%, or the maximum video memory utilization of a single card is not less than 95% and the maximum GPU utilization of a single card is not less than 95%, or the average GPU utilization of multiple cards is not less than 95% and the overall GPU utilization is not less than 95%. High load is defined as follows: when the overall GPU utilization is not less than 90% and the overall video memory utilization is not less than 90%, or the average GPU utilization of multiple cards is not less than 90% and the maximum video memory utilization of a single card is not less than 90%, or the maximum GPU utilization of a single card is not less than 90% and the overall video memory utilization is not less than 90%. Medium load is defined as follows: when the overall GPU utilization is not less than 70%, or the average GPU utilization of multiple cards is not less than 70%, or the overall video memory utilization is not less than 80% and the overall GPU utilization is not less than 50%. If any of the above conditions are not met, it is defined as low load.
[0039] In some implementations, when the severe overload condition persists for more than a preset duration threshold, a resource-aware adaptive configuration proposal process is initiated. During this process, the upper limit of the output token of the current execution model is preferentially reduced. If reducing the token still fails to meet resource constraints, the benefits of switching to a model with lower resource consumption are further evaluated. This evaluation includes resource benefit assessment, time benefit assessment, and quality risk assessment. Specifically, the resource benefit assessment determines whether the candidate model has lower memory usage, GPU usage pressure, or model loading resource requirements compared to the current model; the time benefit assessment determines whether the remaining time is sufficient to cover the time required for model unloading, candidate model loading, execution subprocess restart, and subsequent task execution; and the quality risk assessment determines whether the candidate model's pass rate in the current task difficulty classification or similar historical tasks meets a preset minimum requirement. The main scheduler only executes model downloading and switching when the candidate model can significantly reduce resource pressure, the remaining time is sufficient to cover the switching overhead, and the candidate model's historical or online performance is not lower than a preset threshold. After model switching is approved, the main scheduler stops the current execution subprocess, releases the old model resources, loads the new model, and restarts the execution subprocess. After the model switch is completed, the master scheduler recalculates the deadline information, the maximum allowed number of rounds, and the global token limit, and updates the switch time, switch direction, and switch reason.
[0040] In some implementations, for normal switching suggestions, the main scheduler does not immediately execute the model switch, but first enters a pending confirmation state, only executing the switch when multiple consecutive sliding windows support the same candidate model. The length of the sliding window can be set to a number of recent task records. The normal switching suggestion refers to a non-urgent switching suggestion generated based on window success rate, timeout failure ratio, task difficulty classification distribution, or changes in resource load status. When historical execution records show that a small model has failed or timed out, and the current pending tasks or recent task distribution includes medium or difficult tasks, the main scheduler can trigger a fast failure bounce mechanism to switch the execution model of subsequent tasks to a medium-scale or large-scale model. The fast failure bounce mechanism occurs during the scheduling phase after the task ends, to prevent subsequent tasks from continuing to use the small model that performed poorly. At the same time, the main scheduler sets a downgrade cooling lock for the original small model. The downgrade cooling lock means that within a preset number of tasks or a preset time window after triggering the upgrade, the main scheduler is temporarily prohibited from downgrading back to the small model's protected state. Its function is to prevent the model from immediately reverting from a stronger model to a smaller model that has just failed due to short-term load fluctuations, the occurrence of individual simple tasks, or changes in sliding window statistics, thereby suppressing frequent model switching and strategy jitter and improving execution stability.
[0041] In some implementations, the model selection also includes a cold start detection mechanism, which refers to providing a controlled trial opportunity for lightweight models that do not yet have historical execution records, under conditions of recent overall task stability and low time pressure.
[0042] In some implementations, the real-time scheduling strategy further includes an output token lower limit adjustment strategy to ensure that the current task has basic contextual expression capabilities in subsequent generation or repair phases. The output token lower limit is obtained using the following method: when not in a severely overloaded state, the main scheduler determines the output token lower limit for the current task based on the current execution model, task difficulty classification, and task time limit. In one specific implementation, when the current model is a medium-sized model and the task is a medium or difficult task, a higher output token lower limit is set if the task time limit is relatively lenient; a lower output token lower limit is set if the task time limit is relatively tight. When the current model is a large-scale model and the task is a difficult task, a higher output token lower limit is set; for other cases, a lower output token lower limit is set. If the current output token upper limit is lower than the output token lower limit, the current output token upper limit is increased to the smaller value between the output token lower limit and the current task's global token upper limit, and written to the shared state channel.
[0043] In some implementations, if the non-overload parameter adjustment judgment conditions are met, and if the current remaining time proportion reaches a preset threshold, the resource load state does not reach a severely overloaded state, and the cooldown time since the last token increase has been met, then the main scheduler increases the output token upper limit step by step according to the candidate token level corresponding to the current model. This step-by-step increase means that each time the current output token upper limit is increased to the next adjacent candidate level, rather than increasing it to the highest level all at once; furthermore, the increased output token upper limit must not exceed the token upper limit determined based on the task time limit. The main scheduler writes the updated output token upper limit into the shared state channel, enabling the executing subprocess to read and use the updated token control information during subsequent code generation, test repair, or documentation generation stages.
[0044] In some implementations, when a task is in the testing phase and the test has not yet passed, the main scheduler estimates the time required for the next round of test repair and determines whether to allow an extension of the number of rounds. The time required is determined based on the actual execution latency of the most recent candidate historical execution records and the current output token limit. In one specific implementation, the main scheduler first calculates the average execution latency of the most recent candidate historical execution records, then determines a token adjustment coefficient based on the ratio of the current output token limit to the baseline token level, and multiplies the average execution latency, the preset repair test ratio coefficient, and the token adjustment coefficient to obtain the estimated time for the next round. When there are no available historical execution records, the average execution latency uses a preset default value; simultaneously, the estimated time for the next round is limited to between a preset minimum time and a preset maximum time to avoid the estimate being too low or too high. The main scheduler further calculates the remaining time based on the task time limit and the current execution duration, and calculates a safety margin based on the estimated time for the next round; the safety margin is the larger of the preset minimum safe time and the estimated time for the next round. The number of test rounds for the current task is only allowed to be increased if the remaining time is greater than or equal to the sum of the estimated time for the next round and the safety margin, and the current number of scheduled rounds has not yet reached the maximum allowed number of rounds. When the cooldown period for increasing the number of test rounds meets the conditions, the main scheduler increases the number of scheduled rounds to the next level below the maximum allowed number of rounds. The main scheduler sets additional restrictions when expanding the number of rounds based on the model, task difficulty classification, and the number of rounds already executed, to prevent simple tasks from being expanded without limit on the number of rounds on medium-difficulty models.
[0045] In some implementations, the master scheduler also constructs a phase temperature mapping table that varies according to test rounds. The phase temperature refers to the generation temperature parameter set for the large language model in different execution phases or different test-repair rounds, used to control the randomness and exploratory nature of the model output. The phase temperature mapping table is used to establish the correspondence between test rounds and generation temperature parameters, enabling the master scheduler to dynamically adjust the model generation temperature used by the executing subprocesses according to the current test round.
[0046] In one specific implementation, the first round of testing or the first round of repair adopts a zero-temperature or low-temperature configuration to improve the stability and reproducibility of the code generation results; when subsequent tests still fail and a new round of repair begins, the generation temperature is gradually increased to increase the diversity and exploratory capabilities of code modification schemes and reduce the probability of generating the same erroneous code repeatedly in multiple rounds of repair.
[0047] In some implementations, the main scheduler uses different stage temperature mapping tables for normal tasks and failed retry tasks. Normal tasks have a lower initial temperature to improve the stability of initial code generation and first-time repair, with the temperature gradually increasing in subsequent rounds. Failed retry tasks, due to the existing first-round failure record, use a higher overall starting temperature to increase repair exploration capabilities and reduce the probability of repeatedly generating the same erroneous code. In one specific implementation, normal tasks use the following stage temperature mapping table: first round temperature 0, second round temperature 0.1, third round temperature 0.2, fourth round temperature 0.2, fifth round temperature 0.3, and sixth round temperature 0.3; failed retry tasks use the following stage temperature mapping table: first round temperature 0.2, second round temperature 0.25, third round temperature 0.3, fourth round temperature 0.35, fifth round temperature 0.4, and sixth round temperature 0.4. The main scheduler reads the target temperature from the corresponding mapping table according to the current test round and writes it to the executing subprocess via a shared state channel.
[0048] In this invention, in step three, after the execution subprocess finishes its task, the main scheduler writes the execution result, scheduling trajectory, and running status information into the historical execution record for online pass rate evaluation, historical optimal configuration search, and similar task retrieval of subsequent tasks.
[0049] In some implementations, the master scheduler generates a savings budget based on the difference between the planned time limit in the initial task information and the actual task time, and uses it for retry scheduling of subsequent failed tasks in diverse task scenarios.
[0050] In some implementations, after a task is completed, the main scheduler generates a corresponding historical execution record, which includes information such as request identifier, task name, task difficulty classification, execution model, initial execution strategy, actual execution time, test pass status, termination reason, resource load status, resource consumption, and scheduling trajectory.
[0051] In some implementations, the master scheduler deduplicates historical execution records by task, retaining only the best result for each task to update subsequent online pass rate assessments, historical optimal configurations, and similar task memories.
[0052] In some implementations, the master scheduler writes the historical execution record entries to an in-memory history list and persists them to a shared history file using atomic replacement.
[0053] Secondly, based on the above methods, the present invention provides a resource-constrained multi-agent code generation system, comprising:
[0054] The task input module is responsible for receiving code generation tasks.
[0055] The task result output module outputs the task results after the task is executed.
[0056] The history memory module is responsible for storing historical execution records, similar task memories, and a feature library of historical successful tasks.
[0057] The task execution module is responsible for executing the tasks of the agents in the subprocess, and the model corresponding to the agents can be switched.
[0058] The status sharing module is responsible for storing the real-time status of tasks and serves as a shared status channel for the main scheduler module and the task execution module to communicate the real-time status of the tasks.
[0059] The computing module is responsible for providing the hardware facilities required for intelligent agent computing, including GPUs and CPUs;
[0060] The operation monitoring module is responsible for detecting the real-time resource load status of the computing module;
[0061] The main scheduler module is responsible for task initialization, generation of initial execution strategies, dynamic scheduling of task execution, and generation of historical execution records after the task ends.
[0062] Thirdly, the present invention also proposes a hardware system comprising: a memory and a processor; wherein the memory stores a computer program, and when the computer program is executed by the processor, the method described in the first aspect of the present invention is implemented.
[0063] Fourthly, the present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the method described in the first aspect of the present invention.
[0064] Fifthly, this invention also proposes applications of the above-mentioned methods, systems, hardware systems, or computer-readable storage media in intelligent code generation, automated software development, multi-agent programming collaboration, local large language model inference scheduling, and resource-constrained software engineering scenarios.
[0065] The beneficial effects of this invention include:
[0066] (1) By using a local small model fine-tuned with code question bank samples to perform task difficulty classification, the error caused by pure rule difficulty judgment is reduced;
[0067] (2) Improve the accuracy of initial model selection and initial parameter setting by jointly determining the initial execution strategy through historical success records and similar task memory;
[0068] (3) A cross-process shared state channel is built through Redis and shared files, enabling the main scheduler to perform fine-grained dynamic scheduling based on the actual execution state, failure feedback and scheduling parameters;
[0069] (4) Improve system stability by using resource monitoring, sliding window statistics, pending confirmation mechanism and switching lock to suppress frequent mode switching;
[0070] (5) By using rapid failure bounce, degradation protection and cold start detection, the system balances the protection of the success rate of difficult tasks with the utilization rate of lightweight models;
[0071] (6) By dynamically adjusting inference control parameters such as the upper limit of output tokens, the number of test rounds and the stage temperature, the adaptability of the multi-stage code generation process to long contexts, multiple rounds of repair and load fluctuations can be improved.
[0072] (7) Drive subsequent fixes through failure test cases and error summary feedback, and combine budget-backed failure task retry to improve the overall completion rate of diverse code tasks and reduce idle budget waste. Attached Figure Description
[0073] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0074] Figure 1 This is a schematic diagram of the overall structure of the resource-constrained multi-agent code generation dynamic scheduling framework proposed in this invention.
[0075] Figure 2 This is a schematic diagram of the initial execution strategy selection process based on the local fine-tuning classification model, historical memory, and configuration pool of the present invention.
[0076] Figure 3 This is a schematic diagram of the runtime status acquisition and parameter adjustment process based on shared channels and resource monitoring according to the present invention.
[0077] Figure 4 This is a schematic diagram of the joint decision-making process for sliding window triggering, lock switching, fast failure bounce, degradation protection, and cold start detection in this invention.
[0078] Figure 5 This is a schematic diagram of the budget recovery and retry process for failed tasks in this invention. Detailed Implementation
[0079] The present invention will be further described in conjunction with specific embodiments and accompanying drawings. It should be understood that the following embodiments are for illustrative purposes only and are not intended to limit the scope of protection of the present invention.
[0080] I. Overall Architecture
[0081] This invention addresses multi-agent code generation under resource-constrained conditions. A master scheduler maintains a model pool consisting of multiple candidate large language models, each with different inference capabilities, execution latency, memory usage, and configurable parameter ranges. An adaptive master scheduler, located between the task input and the multi-agent code generation module, is used for task difficulty classification, initial execution strategy selection, runtime parameter adjustment, model switching, and retrying failed tasks.
[0082] like Figure 1 As shown, after a task is input, the main scheduler first predicts the task difficulty classification and generates an initial execution configuration. During task execution, the main scheduler dynamically adjusts the model, maximum token limit, number of test repair rounds, and model temperature based on the running status, resource load, test results, historical execution records, and remaining time. After the task ends, the main scheduler saves the execution trajectory and scheduling results, and uses the time budget saved by scheduling to retry failed tasks.
[0083] II. Task Analysis and Local Fine-tuning of the Classification Model
[0084] like Figure 2 As shown, before task execution, the main scheduler uses a local task difficulty classification model to predict task prompts and categorizes tasks into three classes: easy, medium, and difficult. The classification model is a finely tuned TinyBERT6 three-class classification model. The input includes the task title and the task body, which may include task description, constraints, and example information.
[0085] The training data comes from a dataset of code problems labeled easy, medium, and hard, which was obtained through online web scraping. During fine-tuning, the classification model upsamples a minority of classes and is trained using a weighted focus loss to improve its ability to identify medium and hard tasks. When in use, the classification model is loaded into evaluation mode and performs only forward inference; its predictions serve as the basis for initial model selection, token configuration, and test round configuration for task difficulty classification.
[0086] III. Historical Execution Records and Initial Execution Strategy Selection
[0087] The historical execution record module is used to save reliable success records of code tasks and provide initial scheduling experience for subsequent similar code tasks. Each reliable success record includes scheduling configurations such as task prompt words and their corresponding models, maximum token limit, number of test and fix rounds, and task difficulty classification.
[0088] like Figure 2 As shown, the main scheduler uses the TF-IDF method to vectorize historical task prompts and retrieves the top k records with a similarity exceeding a preset threshold using cosine similarity. The main scheduler performs a weighted similarity aggregation based on the retrieval results. Model selection and task difficulty classification are determined through weighted voting, while the maximum token limit and the number of test / repair rounds are determined through a weighted average. When historical execution records are insufficient, the main scheduler adopts a preset initial execution strategy based on task difficulty classification.
[0089] IV. Shared Status Channels and Operational Status Acquisition
[0090] like Figure 3 As shown, after the task begins, the main scheduler starts the multi-agent code generation process and exchanges runtime state information with the multi-agent code generation process through a shared state channel. The shared state includes the current execution stage, interaction rounds, test results, token consumption, stage duration, and cumulative task duration, as well as control parameters such as the current output token limit, test round limit, and model temperature.
[0091] The multi-agent code generation process writes runtime status information when stages change, rounds change, tests are completed, or statistics are updated. The main scheduler periodically reads this runtime status information and writes back new control parameters when adjustments are needed. Shared state is reinitialized before each task begins and is used only for real-time communication of the current task. Cross-task execution records and scheduling experience are persistently saved by the historical execution record module.
[0092] V. Resource Monitoring and Load Classification
[0093] The operation monitoring module periodically collects resource information such as CPU utilization, memory utilization, GPU device identification, utilization, video memory usage, and temperature, and calculates aggregated indicators such as total GPU video memory, used video memory, average GPU utilization, and the load of each graphics card.
[0094] The main scheduler can monitor all visible GPUs, or it can monitor only the GPUs used by the current model based on the preset GPU deployment relationship. Based on the monitoring results, the main scheduler categorizes resource load status into low load, medium load, high load, and severe overload, and combines this with task running status information, remaining time, and the current model to determine whether the existing configuration can continue execution.
[0095] VI. Sliding Window Triggering and Model Switching Decisions
[0096] like Figure 4As shown, the main scheduler uses a sliding window to statistically analyze recent task execution records. The statistics include recent success rate, timeout failure rate, task difficulty distribution, number of failures in the current model, number of failures in difficult tasks, number of consecutive failures, and execution latency. The strategy switching module generates switching suggestions based on these statistics, including maintaining the current model, upgrading the model, downgrading the model, timeout reduction, or cold start detection.
[0097] For routine upgrade or downgrade recommendations, the main scheduler employs a confirmation mechanism, only performing a switch when the same candidate model is supported multiple times consecutively within the sliding window, thus avoiding frequent switching due to short-term fluctuations. For high-risk situations such as rapid failures of lightweight models or consecutive failures of difficult tasks, the main scheduler can skip the confirmation process and directly upgrade the model.
[0098] Before model downgrading, the main scheduler further checks the downgrading lock, candidate model historical execution records, historical and recent online pass rates, current model performance, deadlines, and remaining budget. For lightweight models lacking historical execution records, a controlled cold start probe is performed only if recent execution is stable, the timeout rate is low, and the time budget allows. Model switching also requires comprehensive consideration of model loading overhead, candidate model latency, the number of remaining tasks, and resource load status; it is only executed if the expected benefits outweigh the switching costs.
[0099] VII. Adaptive parameter adjustment
[0100] In addition to model selection, the main scheduler dynamically adjusts the maximum token limit, the number of test and repair rounds, and the model temperature during task execution. These adjustments are written to runtime control variables through a shared state channel, without altering the original workflow execution order.
[0101] When there is sufficient remaining time and the system is not severely overloaded, the main scheduler can increase the maximum token limit based on the current stage and task requirements; when the load is high or the remaining time is insufficient, the maximum token limit will be limited or reduced. After a test fails, the main scheduler estimates the time required for the next round of test repair and only increases the number of test rounds if the remaining time can cover that time and a safety margin.
[0102] Normal tasks use a lower temperature during the initial testing or repair round to improve generation stability, and the temperature is gradually increased in subsequent failed rounds to enhance the ability to explore repair solutions. Failed retry tasks use a higher initial temperature to reduce the probability of repeatedly generating the same error code. Failed test cases, error messages, and test results can serve as feedback input for subsequent repair rounds.
[0103] 8. Recycle and retry the budget for failed tasks
[0104] like Figure 5As shown, after all tasks have been executed, the retry module records the planned time budget and actual execution time of each task, and reclaims the time saved by early termination of tasks into the common budget pool. For tasks that fail the test but are recoverable, the main scheduler adds them to the failed task queue.
[0105] The master scheduler selects tasks to be retried based on task difficulty classification, failure reasons, historical execution results, and remaining budget, and redetermines the retry model, maximum token limit, number of test and repair rounds, and model temperature. During retries, a stronger model, a larger generation budget, or more repair rounds can be used, and failure feedback is regenerated based on the latest code. Retry is only performed when the common budget pool meets the minimum retry budget; if the same task has multiple execution results, the master scheduler retains the best result.
[0106] IX. A complete breakdown of the steps in the Scheduler method
[0107] To correspond one-to-one with the overall steps above, the following section will break down the complete execution process of a task from entering the main scheduler to completing the history write-back, using the Scheduler main program, resource monitoring module, and shared state module as examples.
[0108] (I) Start-up Preparation Phase
[0109] Step S101: When the main scheduler starts, it first loads the candidate model configuration pool, model service startup configuration, model-GPU mapping relationship, historical execution record file path, resource monitor, and shared state manager.
[0110] Step S102: The main scheduler loads the local classification model; the classification model is the MiniBERT6 model, and it supports parallel loading when multiple GPUs are detected to be available. After successful loading, it switches to inference mode.
[0111] Step S103: The main scheduler attempts to read the historical execution record file; if the file does not exist, it is initialized to an empty history; if the file is corrupted or cannot be parsed, the old content is discarded and the historical execution record is rebuilt.
[0112] Step S104: The main scheduler establishes two types of memories for historical execution records: one type is historical task records used for online pass rate and historical optimal configuration search; the other type is a feature library of historical successful tasks that only includes reliable successful samples.
[0113] (II) Initial Execution Strategy Selection Phase
[0114] This phase explains how the master scheduler determines the initial execution model and initial parameter configuration for the currently pending tasks. The innovation of this invention lies in combining task difficulty classification, historical execution records, similar task memory, deadlines, and stickiness protection mechanisms for task-level initial model selection in diverse task scenarios, thereby avoiding the use of a fixed model or fixed parameter configuration for the entire batch of tasks.
[0115] Step S201: The main scheduler executes diverse code tasks in sequence, extracts information such as task prompts, task names, task time limits, and task numbers, and organizes the prompts and related task descriptions into input text suitable for local classification model inference.
[0116] Step S202: The main scheduler calls the local classification model to perform forward inference on the input text of the current task and outputs the difficulty category of the current task.
[0117] Step S203: If the number of current historical execution record entries is less than the preset number, the main scheduler will adopt the default initial execution strategy based on the task difficulty classification.
[0118] Step S204: If the current number of historical execution record entries reaches the preset number, the main scheduler further queries the historical optimal configuration, similar task memory, and deadline information to modify the initial execution strategy of the current task.
[0119] Step S205: If the current process is in the sticky protection mechanism period, and the current task is classified as a medium or difficult task, the main scheduler will perform an upward protection on the initial execution model, so that the current task will preferentially use a model with higher parameter scales. The sticky protection mechanism refers to a protection state that maintains the priority use of stronger models within a preset number of tasks to avoid subsequent tasks from continuing to fail due to insufficient model capabilities after recent tasks have experienced consecutive failures, timeout failures, or high-risk terminations.
[0120] Step S206: If the current task is not in the sticky protection mechanism period, the main scheduler further combines the online pass rate, historical pass rate, current resource load status, and task time limit to determine whether to allow the use of a lower parameter scale model. If the lightweight model lacks reliable success records, or its recent online performance is significantly lower than the current candidate model, then downgrading will not be performed; if the overall task is stable recently, the time pressure is low, and the lightweight model meets the controlled probing conditions, then the lightweight model is allowed one attempt.
[0121] Step S207: The main scheduler detects the resource load status of the GPU corresponding to the current initial candidate model. If the GPU corresponding to the model is already under high load or severely overloaded before the task starts, the initial token limit is compressed first; if the resource constraints still cannot be met after compressing the token, a candidate model with lower resource consumption is selected again.
[0122] Step S208: Based on the above difficulty classification results, historical configuration correction results, stickiness protection results, and resource load status detection results, the main scheduler generates the task-level initial execution strategy for the current task. The task-level initial execution strategy includes the initial execution model, the initial output token limit, the initial number of test rounds, the initial temperature configuration, and the task time limit.
[0123] Step S209: The main scheduler loads or reuses the corresponding model service according to the task-level initial execution strategy and calls the task execution process to enable the current task to enter the subsequent execution preparation stage.
[0124] (III) Retrieval of the Feature Database of Historical Successful Missions
[0125] Step S301: Select reliable successful samples from historical execution records, remove failure records, abnormal termination records and unreliable successful records, and retain historical task samples that can represent effective successful scheduling experience.
[0126] Step S302: Extract the task prompt words of each reliable successful sample, and simultaneously extract the corresponding model identifier, output token limit, test rounds and task difficulty classification to establish a successful experience sample set;
[0127] Step S303: Use the TF-IDF vectorization method to encode the task prompt words in the successful experience sample set to form a historical prompt word feature library;
[0128] Step S304: Perform feature encoding on the prompt words of the current code task that is isomorphic to the historical prompt word feature library to obtain the prompt word feature vector of the current code task;
[0129] Step S305: Calculate the cosine similarity between the feature vector of the prompt word of the current code task and the sample vectors in the historical prompt word feature library to characterize the text similarity between the current task and each historical successful task.
[0130] Step S306: Sort the samples from high to low similarity and select a set of successful similar samples based on the similarity threshold and the Top-k strategy;
[0131] Step S307: Perform similarity-weighted voting on the model identifiers corresponding to the set of similar successful samples to obtain the recommended model;
[0132] Step S308: Perform similarity-weighted voting on the task difficulty classifications corresponding to the similar success sample set to obtain the recommended task difficulty classification;
[0133] Step S309: Perform a similarity-weighted average on the upper limit of output tokens and the number of test rounds corresponding to the set of similar successful samples to obtain the recommended upper limit of output tokens and the number of test repair rounds, respectively.
[0134] Step S310: Output the initial execution strategy suggestion.
[0135] (iv) Task execution phase
[0136] Step S401: The main scheduler generates a request_id for the current task and establishes a timestamp for the start of the current task.
[0137] Step S402: The main scheduler generates deadline information based on task time limits, task difficulty classification, and the current model to obtain the initial maximum token limit and the maximum number of test and repair rounds.
[0138] Step S403: The master scheduler initializes the shared state channel and writes the initial execution strategy information.
[0139] Step S404: The main scheduler starts the multi-agent code generation subprocess.
[0140] Step S405: Initialize the main scheduler's phase variables, resource monitoring, load level, token growth cooldown time, round growth cooldown time, and temperature mapping table.
[0141] Step S406: Different temperature mapping tables are used for normal tasks and failed retry tasks. The normal task uses the following temperature mapping table: first round temperature is 0, second round temperature is 0.1, third round temperature is 0.2, fourth round temperature is 0.2, fifth round temperature is 0.3, and sixth round temperature is 0.3; the failed retry task uses the following temperature mapping table: first round temperature is 0.2, second round temperature is 0.25, third round temperature is 0.3, fourth round temperature is 0.35, fifth round temperature is 0.4, and sixth round temperature is 0.4. The main scheduler reads the target temperature from the corresponding mapping table according to the current test round and writes it to the executing child process through the shared state channel.
[0142] (v) Shared state-driven runtime main loop
[0143] Step S501: After entering the loop, the main scheduler periodically reads the current simple stage, current combined stage, current stage test round, current combined stage round, current test repair round, current maximum token limit, and current model temperature from the shared state.
[0144] Step S502: When the task is in the testing phase, the main scheduler retrieves the value from the temperature mapping table according to the current combined phase round and writes the target temperature back to the shared state channel.
[0145] Step S503: When a change in stage name, combined stage, or round is detected, the master scheduler records the stage migration log.
[0146] Step S504: The main scheduler calculates the current cumulative runtime; if the task time limit has been reached, the termination reason is marked as timeout, the timeout flag is written to the shared state channel, and the child process is terminated.
[0147] Step S505: The main scheduler periodically calls the resource monitoring module to obtain the video memory usage, GPU utilization, CPU utilization, and memory utilization of the currently active GPUs.
[0148] Step S506: The main scheduler categorizes the current load into low load, medium load, high load, or severe overload based on the aggregated GPU load and video memory ratio, and continuously records the peak load during operation.
[0149] Step S507: The main scheduler reads the test result from the shared state; if the test result is True, the task is stopped immediately and the termination reason is set to Pass.
[0150] Step S508: The main scheduler continues to read the status information; if the status is completed, it is determined that the current task has completed all stages and exits the loop.
[0151] Step S509: The main scheduler checks whether the child process exits naturally; if the return code is zero, the task is considered to have been completed normally; if the return code is non-zero, the termination reason is recorded as failure.
[0152] (vi) Task parameter scheduling phase
[0153] Step S601: When the load is severely overloaded, the main scheduler begins to accumulate the duration of severe overload; only when the severe overload continues to exceed the set threshold will the model switch be initiated.
[0154] Step S602: In the severe overload assessment, the main scheduler prioritizes finding the lower-level Token tier of the current model and attempts to alleviate the overload by reducing the Token limit.
[0155] Step S603: If reducing the Token alone is still insufficient to meet the resource constraints, the main scheduler will evaluate whether to switch to a lower resource consumption model based on the remaining time, historical performance, and switching benefits.
[0156] Step S604: If the model switch is approved, the main scheduler first stops the currently executing subprocess, then releases the old model resources, loads the new model resources, and restarts the executing subprocess to continue the current task.
[0157] Step S605: After the switch is completed, the main scheduler recalculates the current task's deadline information, the upper limit of test repair rounds, and the maximum token limit, and records the switch direction and switch reason.
[0158] Step S606: When not in a state of severe overload, the main scheduler determines the minimum token lower limit based on the current model category and task difficulty classification.
[0159] Step S607: If the remaining time is sufficient and the Token growth cooldown has expired, the main scheduler will gradually increase the current Token limit according to the candidate Token tiers to adapt to the increasingly longer context in subsequent stages.
[0160] Step S608: When a task enters the testing phase and the current test has not yet passed, the main scheduler estimates the expected cost of the next round of test repair and allows the number of test repair rounds to be increased if the remaining time is sufficient to cover the expected cost and safety margin.
[0161] Step S609: When expanding the number of rounds, the main scheduler will also set additional restrictions based on the model, task difficulty classification, and the number of rounds already executed to prevent simple tasks from expanding the number of rounds without limit.
[0162] (vii) Sliding window
[0163] Step S701: After the first task is completed, the main scheduler writes the result to the global history and continues to process the remaining tasks.
[0164] Step S702: For each subsequent task, the master scheduler first calculates the global elapsed time, the global remaining time, and the average time budget for the remaining tasks.
[0165] Step S703: The main scheduler classifies the next task by difficulty and determines the soft time limit for the task based on the remaining time.
[0166] Step S704: If the task is still within the sticky protection mechanism period, then directly maintain or switch to large model execution.
[0167] Step S705: If not under sticky protection, the main scheduler constructs a sliding window from the most recent historical tasks and calculates the success rate, timeout failure rate, number of current model failures, number of consecutive failures, and difficulty distribution.
[0168] Step S706: If the small model has recently failed and recent tasks include medium or difficult tasks, then generate a fast failure bounce suggestion directly.
[0169] Step S707: If the statistics of the normal window indicate that it should be upgraded or downgraded, it first enters the pending confirmation state; the switch is only confirmed when the sliding window supports the same candidate model multiple times in a row.
[0170] Step S708: When suggesting a downgrade, the main scheduler additionally checks whether the candidate model is protected by a downgrade lock, whether the historical pass rate meets the standard, whether the online pass rate has deteriorated significantly, and whether the current task time limit allows downgrade.
[0171] Step S709: For lightweight models that have never been effectively validated, the main scheduler will also perform controlled cold start probing when the overall performance is stable in the near future, the timeout failure rate is low, and the time pressure is not high.
[0172] Step S710: Before the switchover is officially executed, the main scheduler will also combine the remaining number of tasks, the switchover cost, the average latency of the candidate models, and the global remaining time to determine whether the switchover is worthwhile.
[0173] Step S711: The main scheduler estimates the switching benefits based on the historical pass rate difference between the candidate model and the current model, the online pass rate difference, the number of remaining tasks, and the average execution latency of the candidate model; it also estimates the switching costs based on the unloading time of the current model, the loading time of the new model, the restart time of the child process, and the expected increase in latency after the switch. Model switching is only performed when the switching benefits outweigh the switching costs, and the remaining global time is sufficient to cover the switching costs and the execution requirements of subsequent tasks.
[0174] Step S712: Subsequently, the main scheduler generates new initial execution strategy information for the task based on the current model and the current task difficulty classification.
[0175] (viii) Failure Feedback Injection and Repair-Driven Phase
[0176] Step S801: During task execution, the failure information generated by the execution subprocess during the testing phase includes basic test results, enhanced test results, phase generated content, phase conclusions, failed test cases, error logs, failure examples, or combinations thereof.
[0177] Step S802: The main scheduler receives the failure information through shared state, child process output, or results returned by an external tester.
[0178] Step S803: The main scheduler converts the failure information into structured failure feedback and writes it to a location that can be read in subsequent repair rounds.
[0179] Step S804: In the multi-agent code generation workflow, the failure feedback can be used to locate erroneous code fragments, extract failed use cases, and generate targeted modification instructions.
[0180] Step S805: When the failure feedback indicates that the problem can still be resolved by continuing to fix it and the remaining time allows, the main scheduler prioritizes extending the rounds rather than terminating the task immediately.
[0181] Step S806: When the failure feedback indicates that the time limit, round limit, or child process failure has been reached, the main scheduler stops the current task and enters the history write-back phase.
[0182] (ix) The Historical Retrospective Stage
[0183] Step S901: After the current task is completed, the main scheduler summarizes the request identifier, task name, prompt word, task difficulty classification, selected model, initial number of tokens, initial number of test and repair rounds, final number of tokens, actual number of test and repair rounds, actual time consumption, basic test results, enhanced test results, termination reason, initial load category, peak load category, and scheduling trajectory.
[0184] Step S902: The main scheduler organizes the above information into historical execution record entries and appends them to the memory history list.
[0185] Step S903: The main scheduler writes the history list to the history file in an atomic replacement manner to avoid corrupting the historical execution record when the program is interrupted.
[0186] Step S904: The main scheduler updates the sticky protection mechanism based on several recent high-risk failures in history, so as to prioritize the retention of stronger models in the next two or more tasks.
[0187] Step S905: The main scheduler reconstructs the effective historical window from the historical execution records, retaining only the best results for the same task.
[0188] (x) Budget recovery and retesting phase
[0189] Step S1001: For each task, the main scheduler calculates the difference between the planned time limit and the actual time consumed; if the task is completed ahead of schedule, the difference forms a time-saving budget.
[0190] Step S1002: The master scheduler adds the time-saving budget to the common retry budget pool.
[0191] Step S1003: If a task fails and the reason for failure is retryable, a retry entry for the failed task is created. The retry entry includes at least the task identifier, original prompt word, task difficulty classification, first-round model, most recent model, termination reason, most recent delay, and number of retries.
[0192] Step S1004: The main scheduler scores and sorts failed tasks according to task difficulty, failure reason priority, recent latency, and number of retries.
[0193] Step S1005: The main scheduler selects a retry phase model for failed tasks; when there are medium or difficult tasks among the failed tasks, the larger model can be selected as the retry model.
[0194] Step S1006: The main scheduler reallocates the initial maximum token limit, the initial number of test and repair rounds, and the available time budget based on the retry model and task difficulty classification.
[0195] Step S1007: Only when the budget pool, after deducting the reserved budget, is still higher than the minimum retry threshold, will a retry of the failed task be initiated.
[0196] Step S1008: The retry task re-enters the task execution process and reuses the shared state channel, resource monitoring, parameter adaptation and failure feedback mechanism.
[0197] Step S1009: After the retry is completed, the main scheduler writes the retry result back to the historical execution record and updates the balance of the common budget pool.
[0198] Step S1010: Through the budget backflow and retry phase, the main scheduler can utilize the time budget of tasks that were released early to reschedule tasks that failed in the first round but still have a chance of being repaired, thereby improving the code task completion rate and resource utilization efficiency.
[0199] Through the above design, the present invention can maximize the code pass rate while maintaining a 0% failure rate in local resource-constrained environments.
[0200] Example
[0201] Example 1: Complete scheduling process for a routine task that passed its first test
[0202] (a) Implementation Environment
[0203] This embodiment applies to a multi-agent code generation system, a master scheduler, a local vLLM inference service, a Redis shared state channel, a resource monitoring module, and historical execution log files. Candidate models include Qwen-coder7B, Qwen-coder14B, and Qwen-coder32B, corresponding to different model sizes, memory usage, and inference latency, respectively. The task difficulty classification model uses a fine-tuned BERT classification model to categorize input tasks as easy, medium, or difficult.
[0204] In this embodiment, a code generation task with a time limit of 160 seconds is used as an example. During execution, the task successfully completes code generation, testing, and verification, and terminates after approximately 30.028 seconds of successful testing. This record illustrates how the main scheduler completes the entire process of task input, initial scheduling, execution monitoring, test judgment, and history write-back under normal successful scenarios.
[0205] (II) Task Input and Initial Scheduling
[0206] Step 1: After receiving the current code generation task, the main scheduler generates a unique request identifier for the task and reads information such as the task prompt, task name, and time constraints.
[0207] Step 2: The main scheduler organizes the task prompts, function signatures, input / output constraints, and example test cases into the input text for the classification model, and calls the classification model to perform inference to obtain the difficulty category of the current task.
[0208] Step 3: The main scheduler reads the historical execution record file and filters reliable successful samples from the historical execution records. If the number of reliable successful samples is insufficient, the default initial execution strategy is adopted according to the task difficulty classification; if the number of reliable successful samples is sufficient, the historical successful task memory feature library is further called.
[0209] Step 4: The historical successful task memory feature library vectorizes the task prompts for the current task and calculates cosine similarity between the vectors and the prompts from historical successful tasks, filtering out a set of similar successful samples. The main scheduler weights and aggregates these similar samples based on model selection, maximum token limit, number of test and fix rounds, and task difficulty classification to generate initial scheduling suggestions.
[0210] Step 5: The main scheduler, combining task difficulty classification, similar task suggestions, and the 160-second task time limit, generates the initial execution strategy for the current task. The initial execution strategy includes the initial execution model, the initial maximum token limit, the initial number of test and fix rounds, and the deadline information.
[0211] (III) Task execution and sharing status monitoring
[0212] Step 6: Before starting the execution of the child process, the main scheduler initializes the Redis shared state channel and writes the initial execution strategy information of the current task.
[0213] Step 7: The main scheduler starts the multi-agent code generation subprocess.
[0214] Step 8: During execution, the child process continuously writes information such as the current stage name, current test round, test pass / fail status, stage duration, token consumption, and stage conclusion to the shared state channel. The main scheduler periodically reads the above state and synchronously calls the resource monitoring module to collect CPU utilization, memory utilization, GPU utilization, and video memory usage.
[0215] Step 9: When the task enters the testing phase, the main scheduler reads the corresponding temperature mapping value according to the current test round and writes it to the execution subprocess through the shared state channel.
[0216] (iv) Test passed and task completed
[0217] Step 10: When the shared status channel shows that the current test has passed, the main scheduler marks the task termination reason as test passed and stops the currently executing subprocess to avoid continuing to execute unnecessary repair or generation processes.
[0218] Step 11: The main scheduler summarizes the log information of the current task and forms historical execution record entries.
[0219] Step 12: The main scheduler writes historical execution record entries to the memory history list and further persists them to the historical execution record file. This record is used for online pass rate evaluation of subsequent tasks, searching for historical optimal configurations, and updating the memory of similar tasks.
[0220] (V) Effect Description
[0221] As can be seen from this embodiment, the master scheduler can generate an initial execution strategy before the task begins by combining task difficulty classification, historical success experience, and task time constraints, and monitor the task progress in real time through a shared state channel during task execution. When a test pass signal appears, the master scheduler can promptly terminate the task and write back the historical execution record, thereby completing the complete master scheduling process from task input, initial model selection, execution monitoring, test judgment to historical update.
[0222] Example 2: Multi-round repair and parameter adaptation process after test failure
[0223] (a) Implementation Environment
[0224] This embodiment applies to a multi-agent code generation system, a master scheduler, a local vLLM inference service, a Redis shared state channel, a resource monitoring module, and historical execution log files. Candidate models include Qwen-coder7B, Qwen-coder14B, and Qwen-coder32B. The shared state channel, implemented using Redis, is used to exchange information such as the current stage, current test round, test pass status, failure feedback, current scheduling token limit, current scheduling round number, and current scheduling temperature. The resource monitoring module periodically collects GPU utilization, video memory usage, CPU utilization, and memory usage, and categorizes the current state as low load, medium load, high load, or severe overload.
[0225] In this embodiment, a task with a time limit of 100 seconds is used as an example. The task failed to complete within the time limit and terminated at approximately 100.2339 seconds. This record illustrates how the main scheduler performs adaptive parameter control under test failure and time pressure.
[0226] (II) Task initialization and deadline information generation
[0227] Step 1: After receiving the current task, the main scheduler classifies the task prompts by difficulty and generates an initial execution strategy by combining historical execution records and similar task memories.
[0228] Step 2: The main scheduler generates deadline information based on task time limits, task difficulty classification, and the current execution model.
[0229] Step 3: In one specific implementation, when the task time limit is greater than 80 seconds but not more than 120 seconds, the test round increment cooldown time is set to 12 seconds; when the task time limit is 100 seconds or 120 seconds, the maximum allowed number of test rounds can be set to four rounds.
[0230] (III) Failure feedback and dynamic temperature control during the testing phase
[0231] Step 4: The main scheduler starts the multi-agent code generation subprocess and continuously reads information such as the current simple stage, the current combined stage, the current test round, the test pass status, and the stage time through the shared state channel.
[0232] Step 5: When the current combination phase is detected as a testing phase, the main scheduler reads the temperature mapping table according to the current test round and writes the target temperature into the shared state channel. For normal task execution, the temperature mapping table can be set as follows: first round temperature is 0, second round temperature is 0.1, third round temperature is 0.2, fourth round temperature is 0.2, fifth round temperature is 0.3, and sixth round temperature is 0.3.
[0233] Step 6: If the current test fails, the execution subprocess returns the failed test case, error log, error summary, or failure example, and uses it as input for subsequent repair rounds, so that the code generation agent can perform modifications for the failed test cases, instead of simply generating code repeatedly based on coarse-grained failure signals.
[0234] (iv) Adaptive control of the number of test rounds and the token limit
[0235] Step 7: If the test has not yet passed, the main scheduler estimates the expected cost of the next round of test fixes. When there is no available historical execution record, the preset default latency cost is used.
[0236] Step 8: The master scheduler further calculates the safety margin. The master scheduler only allows an increase in the number of test rounds for the current task if the remaining time is sufficient to cover the sum of the expected cost and the safety margin, and if the current number of scheduling rounds has not yet reached the maximum allowed number of rounds.
[0237] Step 9: The main scheduler simultaneously limits the maximum token limit based on the deadline information. If the current resource load is not in a severely overloaded state and the remaining time proportion meets the corresponding stage threshold, the main scheduler can gradually increase the maximum token limit according to the candidate token level corresponding to the current model; if it is in a severely overloaded state, the maximum token limit will be compressed first, and if necessary, an evaluation will be made on whether to switch to a model with lower resource consumption.
[0238] (v) Termination of Task Time Limit and History Write-back
[0239] Step 10: If the main scheduler detects that the current cumulative execution time has reached the task time limit, it sets the termination reason to time constraint trigger, writes the termination status through the shared state channel, and then stops the execution of the child process.
[0240] Step 11: The main scheduler writes the task's log information into the historical execution record.
[0241] Step 12: If the task ultimately fails the test, the main scheduler further determines whether the reason for the failure is a retryable type. If it is a retryable type, the task is added to the failed task retry candidate queue.
[0242] (vi) Effect description
[0243] As demonstrated in this embodiment, when both test failures and time pressure exist simultaneously, the main scheduler does not simply fix the number of execution rounds, nor does it unconditionally increase the number of repair rounds. Instead, it makes a joint judgment based on the remaining time, the cost of the next round of repair testing, the safety margin, the token limit, and the system load. This process can provide as many effective repair opportunities as possible within a limited time, while avoiding further expansion of timeout risks due to excessive round expansion or excessively long output.
[0244] Example 3: Failed Task Retry and Deduplication Process in Diverse Code Task Scenarios
[0245] (a) Implementation Environment
[0246] This embodiment applies to diverse task code generation scenarios. The main scheduler enables failed task retry and maintains a queue of failed tasks and a common retry budget pool. Historical execution records include intermediate execution records during task execution and final execution records deduplicated at the task granularity. Candidate models include Qwen-coder7B, Qwen-coder14B, and Qwen-coder32B. Inference services are provided by a local vLLM, and the shared state channel is implemented using Redis.
[0247] (II) Diversified code task execution and budget savings
[0248] Step 1: The main scheduler executes the diverse code generation tasks sequentially. For each task, the main scheduler records the planned time limit and the actual time taken, and calculates the difference between the two after the task is completed.
[0249] Step 2: If the task is completed ahead of schedule, the main scheduler will use the difference between the planned time limit and the actual time as a savings budget and add it to the common retry budget pool.
[0250] Step 3: In one specific implementation, if a task is completed in approximately 30.028 seconds within a time limit of 160 seconds, then the task releases a budget saving of approximately 129.972 seconds. If another task is completed in approximately 36.591 seconds within the same 160-second time limit, then a budget saving of approximately 123.409 seconds is released.
[0251] Step 4: The budget released for tasks completed ahead of schedule is added to the public retry budget pool for retrying subsequent failed tasks.
[0252] (III) Failed Task Identification and Retry Queue Construction
[0253] Step 5: If a task fails both the basic and enhanced tests after normal execution, the main scheduler identifies it as a failed task. The historical execution record may contain the following failed tasks: a task that actually took approximately 79.680 seconds to complete but failed both the basic and enhanced tests; another task that actually took approximately 104.342 seconds also failed the tests.
[0254] Step 6: The main scheduler constructs retry entries for failed tasks based on their task difficulty classification, failure reason, most recent execution time, and number of retries. Each retry entry includes the task identifier, original task prompt, task difficulty classification, first-round execution model, most recent execution model, termination reason, most recent execution time, and number of retries.
[0255] Step 7: The main scheduler sorts the failed tasks. During sorting, difficult tasks have a higher priority than medium tasks, and medium tasks have a higher priority than simple tasks. Tasks that have been completed but failed the test, reached the maximum number of rounds, or still have the potential for repair are given a higher retry priority. As the number of retries for the same task increases, its priority gradually decreases.
[0256] (iv) Retry Model and Retry Parameter Generation
[0257] Step 8: When the budget in the public retry budget pool meets the minimum retry threshold and is still sufficient to support one retry after deducting the reserved budget, the main scheduler generates a retry execution strategy for the failed tasks that are ranked first.
[0258] Step 9: If the failed task is a medium or difficult task, the main scheduler will prioritize Qwen-coder32B as the retry model; if the failed task is a simple task or the resource budget is insufficient, Qwen-coder14B can be selected or the current model can be kept.
[0259] Step 10: The main scheduler reallocates the initial maximum token limit, initial test and repair rounds, and retry time budget based on the retry model and task difficulty classification. For example, when the retry model is Qwen-coder32B and the task is a difficult task, a higher token limit and three test and repair rounds can be configured; when the retry model is Qwen-coder32B and the task is a medium task, a medium-to-high token limit and three test and repair rounds can be configured; when the retry model is Qwen-coder14B and the task is a medium or difficult task, a higher token limit and three test and repair rounds can also be configured.
[0260] Step 11: Before initiating the retry task, the main scheduler initializes the shared state channel and writes the initial maximum token limit, initial test and repair rounds, and retry flag for the retry task. The retry task enters the same task execution flow as the normal task, and reuses shared state monitoring, resource monitoring, parameter adaptation, temperature adjustment, and failure feedback mechanisms.
[0261] (v) Write back the retry results and remove duplicates from the history.
[0262] Step 12: After the retry task is completed, the main scheduler writes the retry result to the memory history execution record and deducts the actual time spent on this retry from the public retry budget pool.
[0263] Step 13: If the retry is successful, the task is marked as successful after the retry; if the retry still fails but the maximum number of retries has not been reached, the retry count, the most recent termination reason and the most recent time spent for the task are updated, and it is determined whether to re-add it to the failed task queue based on the remaining budget.
[0264] Step 14: After the retry task is completed, the main scheduler deduplicates the historical execution records in memory according to task granularity. For the same task, if there is an initial failure and subsequent successful retries, only the successful results are retained; if the same task always fails, the best failure result is retained.
[0265] Step 15: The main scheduler recalculates the effective pass rate based on the deduplicated historical execution records and writes the final result back to the historical execution record file for subsequent online pass rate evaluation, historical optimal configuration search, and similar task memory update.
[0266] (vi) Effect description
[0267] As demonstrated in this embodiment, the master scheduler can reclaim the time budget of tasks released in advance in diverse task scenarios and use it for the rescheduling of failed tasks. At the same time, the master scheduler deduplicates tasks at the task level before writing back the final history, avoiding the simultaneous inclusion of the first-round failure record and the retry success record of the same task in the final statistics, thereby taking into account the opportunity to repair failed tasks, the efficiency of budget utilization, and the consistency of historical accounting.
[0268] Unless otherwise defined, all technical and scientific terms used in this invention have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains. The terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to be limiting of the invention.
[0269] As used in this invention, the term "comprising" is an open-ended expression, meaning it includes the contents specified in this invention but does not exclude other aspects.
[0270] As used in this invention, the term "and / or" includes any one or more of the related listed items and all combinations thereof.
[0271] The scope of protection of this invention is not limited to the above embodiments. All variations and advantages that can be conceived by those skilled in the art within the technical scope disclosed in this invention are included in this invention and are protected by the appended claims.
Claims
1. A dynamic scheduling method for multi-agent code generation under resource constraints, characterized in that, The dynamic scheduling method targets a local model pool consisting of multiple candidate models with different parameter scales. It uses a master scheduler to control the initial task execution strategy, dynamic parameter adjustment during execution, sliding window model switching decisions, shared runtime status information, failure feedback-driven repair, and budget backfilling and retrying for failed tasks. The method performs joint scheduling of the code generation task execution process, with specific steps including: Step 1: Initial execution strategy generation; Step Two: Task Execution and Real-Time Strategy Adjustment; Step 3: Task completion and historical execution record update.
2. The method as described in claim 1, characterized in that, In step one, the main scheduler receives the code generation task and constructs an initial execution strategy based on the initial task information and task difficulty classification. And / or, In step two, according to the initial execution strategy, the main scheduler starts the execution subprocess, begins the execution process of multi-agent code generation, and continuously exchanges running status information through the shared state channel; The main scheduler updates the real-time scheduling policy based on the shared state channel and the state of the executing subprocess until the task ends. And / or, In step three, after the task of the executing subprocess is completed, the main scheduler writes the execution result, scheduling trajectory and running status information into the historical execution record; And / or, During execution, the main scheduler periodically reads CPU utilization, memory utilization, GPU utilization, video memory usage, and active GPU number. Based on the resource load status, the main scheduler calculates the overall video memory ratio, the maximum GPU utilization of a single card, the average GPU utilization of multiple cards, and the maximum video memory ratio of a single card, and classifies the current resource load status into low load, medium load, high load, and severe overload.
3. The method as described in claim 2, characterized in that, The task difficulty classification refers to the task difficulty classification oriented towards scheduling decisions, which is used to characterize the degree of demand of the code generation task to be processed on model capabilities, context length, repair rounds and time budget. And / or, The initial execution strategy includes model selection, output token limit, test round limit, and task difficulty classification; And / or, The initial execution strategy is constructed based on a historical successful task feature library. The historical successful task feature library is constructed from reliable successful samples in the historical execution records. Each reliable successful sample includes a feature vector of a task prompt word and a corresponding historical scheduling configuration. The historical scheduling configuration includes the initial execution strategy of the task. If the number of entries in the current historical successful task feature library is less than a preset number, the main scheduler adopts the default initial execution strategy according to the task difficulty classification. And / or, In step two, before starting the execution subprocess, the main scheduler initializes the shared state channel and writes the running state information corresponding to the current task; during the execution subprocess's operation, the main scheduler is responsible for writing the global Token limit, maximum allowed number of rounds, and scheduling temperature, while the execution subprocess is responsible for writing the current stage name, current test round, test pass status, failed test case feedback, stage duration, Token consumption, and current stage conclusion. And / or, In step two, before starting the execution subprocess, the main scheduler initializes runtime scheduling variables. These runtime scheduling variables are used to record phase changes, resource load status, round control, and token control information during task execution. The runtime scheduling variables include phase variables, resource sampling variables, maximum allowed rounds, global token limit, round increase cooldown time, and token increase cooldown time. Specifically, the phase variables record the phase name, combined phase name, and test round number read in the previous round. The resource sampling variables are real-time values of the resource load status collected periodically during task execution. The maximum allowed rounds refer to the maximum number of test and repair rounds allowed for the current task under the constraints of task time limits, task difficulty classification, and the current execution model. The global token limit refers to the maximum output token limit allowed for the current task throughout the entire execution process, determined by the task time limit, the current model, and the task difficulty classification, used to constrain subsequent token increases from exceeding the time budget's allowable range. The round increase cooldown time refers to the minimum time interval required between two increases in the test round number. The token increase cooldown time refers to the minimum time interval required between two increases in the output token limit. And / or, In step two, the execution process of multi-agent code generation for the execution subprocess includes multiple stages, including: code implementation stage, testing stage, and repair stage.
4. The method as described in claim 3, characterized in that, The task difficulty classification is determined by a locally fine-tuned classification model, preferably a BERT-type classification model. And / or, The task difficulty classification includes simple tasks, medium tasks, and difficult tasks; among them, simple tasks correspond to lower model capabilities and less token budget requirements, medium tasks correspond to medium model capabilities and moderate testing and repair requirements, and difficult tasks correspond to stronger models, higher token limits, or more testing and repair opportunities. And / or, In step two, the main scheduler updates the real-time scheduling strategy based on the task difficulty classification and the running status information. And / or, The main scheduler continuously reads the running status information; if the running status information is "completed", it is determined that the current task has completed all stages and exits the loop; the main scheduler continuously detects whether the current cumulative execution time has reached the task time limit. If the time limit has been reached, it writes a timeout status and terminates the currently executing subprocess. And / or, The resource load status is categorized as low load, medium load, high load, and severe overload as follows: Severe overload occurs when the overall video memory utilization is not less than 95% and the overall GPU utilization is not less than 95%, or the maximum video memory utilization of a single card is not less than 95% and the maximum GPU utilization of a single card is not less than 95%, or the average GPU utilization of multiple cards is not less than 95% and the overall GPU utilization is not less than 95%. High load occurs when the overall GPU utilization is not less than 90% and the overall video memory utilization is not less than 90%, or the average GPU utilization of multiple cards is not less than 90% and the maximum video memory utilization of a single card is not less than 90%, or the maximum GPU utilization of a single card is not less than 90% and the overall video memory utilization is not less than 90%. Medium load occurs when the overall GPU utilization is not less than 70%, or the average GPU utilization of multiple cards is not less than 70%, or the overall video memory utilization is not less than 80% and the overall GPU utilization is not less than 50%. If none of the above conditions are met, it is considered low load. And / or, In step two, when the execution subprocess is in the testing phase and the test has not yet passed, the main scheduler estimates the time required for the next round of test repair and determines whether to allow the number of rounds to be extended accordingly. The time required is determined based on the actual execution latency of the most recent candidate historical execution records and the current output Token upper limit. The main scheduler first calculates the average execution latency of the most recent candidate historical execution records, then determines the Token adjustment coefficient based on the ratio of the current output Token upper limit to the baseline Token level, and multiplies the average execution latency, the preset repair test ratio coefficient, and the Token adjustment coefficient to obtain the estimated time required for the next round. When there are no available historical execution records, the average execution latency adopts a preset default value. At the same time, the estimated time required for the next round is... The time limit is set between a preset minimum time limit and a preset maximum time limit. The main scheduler further calculates the remaining time based on the task time limit and the current execution time, and calculates a safety margin based on the estimated time of the next round. The safety margin is the larger of the preset minimum safe time and the estimated time of the next round. The number of test rounds for the current task is allowed to be increased only when the remaining time is greater than or equal to the sum of the estimated time of the next round and the safety margin, and the current number of scheduling rounds has not reached the maximum allowed number of rounds. When the cooldown time for increasing the number of test rounds meets the conditions, the main scheduler increases the number of scheduling rounds to the next level below the maximum allowed number of rounds. When expanding the number of rounds, the main scheduler sets additional restrictions based on the model, task difficulty classification, and the number of currently executed rounds to avoid unlimited expansion of rounds for simple tasks on medium-difficulty models.
5. The method as described in claim 4, characterized in that, The real-time scheduling strategy includes: when a test fails during the testing phase, a budget recovery and retry of the failed task is performed. This budget recovery and retry recovers the saved budget based on the difference between the planned task time and the actual execution time. Failed tasks are sorted by difficulty, reason for failure, recent latency, and number of retries. When the minimum retry threshold is met in the common budget pool, a higher-performance configuration is prioritized for rescheduling. Simultaneously, the main scheduler organizes basic test results, enhanced test results, failed test cases, error logs, or failure examples into structured failure feedback, and sends it along with the new execution strategy to the subsequent repair or retry phase. For failed tasks that meet the retry conditions, the main scheduler... A retry entry for a failed task is constructed, which includes at least the original task, reason for failure, most recent model, most recent latency, base budget, and number of retries. The main scheduler reallocates the initial token limit, initial round number, and available time budget based on the retry model and task difficulty classification. The retry task re-enters the single-task execution process and reuses the shared state channel, resource monitoring, parameter adaptation, and failure feedback mechanism. The common budget pool refers to the time budget set formed by accumulating the difference between the planned time limit and the actual time consumption of each completed task during execution. The minimum retry threshold refers to the minimum time requirement that must be met to execute a retry of a failed task. And / or, The real-time scheduling strategy further includes: based on the resource load status, when the continuous severe overload state exceeds a preset duration threshold, initiating a resource-aware adaptive configuration proposal process; during the adaptive configuration proposal process, firstly, attempting to reduce the output Token upper limit of the current execution model; if reducing the Token still cannot meet resource constraints, then further evaluating the benefits of switching to a model with lower resource consumption; the evaluation includes resource benefit evaluation, time benefit evaluation, and quality risk evaluation; wherein, resource benefit evaluation is used to determine whether the candidate model has lower memory usage, GPU usage pressure, or model loading resource requirements compared to the current model; time benefit evaluation is used to determine whether the remaining time is sufficient to cover model unloading and candidate model... The time required for loading, restarting the execution subprocess, and executing subsequent tasks; the quality risk assessment is used to determine whether the pass rate of the candidate model in the current task difficulty classification or similar historical tasks meets the preset minimum requirements; the main scheduler will only perform model downloading and switching if the candidate model can significantly reduce resource pressure, the remaining time is sufficient to cover the switching overhead, and the historical performance or online performance of the candidate model is not lower than the preset threshold; after the model switching is approved, the main scheduler stops the currently executing subprocess, releases the old model resources, loads the new model, and restarts the executing subprocess; after the model switching is completed, the main scheduler recalculates the deadline information, the maximum allowed number of rounds, and the global token limit, and updates the switching time, switching direction, and switching reason; And / or, The real-time scheduling strategy further includes an output token lower limit adjustment strategy. The output token lower limit is obtained using the following method: When not in a severely overloaded state, the main scheduler determines the output token lower limit for the current task based on the current execution model, task difficulty classification, and task time limit. If the non-overload parameter adjustment judgment condition is met, and the current remaining time ratio reaches a preset threshold, the resource load state does not reach a severely overloaded state, and the cooldown time since the last token increase has been met, then the main scheduler increases the output token upper limit step by step according to the candidate token level corresponding to the current model. The step-by-step increase means that each time the current output token upper limit is increased to the next adjacent candidate level, rather than increasing it to the highest level all at once. Furthermore, the increased output token upper limit must not exceed the token upper limit determined based on the task time limit. The main scheduler writes the updated output token upper limit into the shared state channel, so that the execution subprocess can read and use the updated token control information in subsequent code generation, test repair, or documentation generation stages. And / or, The main scheduler also constructs a phase temperature mapping table that varies according to the test rounds; the phase temperature refers to the generation temperature parameter set for the large language model in different execution phases or different test repair rounds, which is used to control the randomness and exploration degree of the model output; the phase temperature mapping table is used to establish the correspondence between the test rounds and the generation temperature parameter, so that the main scheduler can dynamically adjust the model generation temperature used by the executing subprocess according to the current test round.
6. The method as described in claim 5, characterized in that, For the normal switching suggestion in the model load reduction switching, the main scheduler does not immediately execute the model switching, but first enters the pending confirmation state, and only executes the switching when multiple consecutive sliding windows support the same candidate model; the length of the sliding window is set to the most recent task records in the historical execution record; the normal switching suggestion refers to a non-urgent switching suggestion generated based on window success rate, timeout failure ratio, task difficulty classification distribution or resource load status changes. And / or, When historical execution records show that a small model has failed or timed out, and the current pending tasks or recent task distribution includes medium-sized or difficult tasks, the main scheduler triggers a fast failure bounce mechanism to switch the execution model of subsequent tasks to a medium-sized or large-scale model. The fast failure bounce mechanism occurs during the scheduling phase after a task ends, to prevent subsequent tasks from continuing to use the poorly performing small model. At the same time, the main scheduler sets a downgrade cooling lock for the original small model. The downgrade cooling lock means that within a preset number of tasks or a preset time window after triggering the upgrade, the main scheduler is temporarily prohibited from downgrading back to the small model's protected state. And / or, The model switching also includes a cold start detection mechanism, which refers to providing a controlled trial opportunity for lightweight models that do not yet have historical execution records under the conditions of stable overall tasks and low time pressure in the near future. And / or, In the stage temperature mapping table, the first round of testing or the first round of repair adopts a zero-temperature or low-temperature configuration to improve the stability and reproducibility of the code generation results; when subsequent tests still fail and a new repair round is entered, the generation temperature is gradually increased to increase the diversity and exploration capability of code modification schemes and reduce the probability of generating the same erroneous code repeatedly in multiple repair rounds. And / or, For normal tasks and failed retry tasks, the main scheduler uses different stage temperature mapping tables; the temperature is lower in the first round of normal tasks to improve the stability of initial code generation and initial repair, and the temperature is gradually increased in subsequent rounds; Since the first round of failure has already been recorded, the retry task adopts a higher overall temperature starting point to increase the ability to repair and explore and reduce the probability of repeatedly generating the same error code; the main scheduler reads the target temperature from the corresponding mapping table according to the current test round and writes it to the execution subprocess through the shared state channel.
7. A resource-constrained multi-agent code generation system, characterized in that, The system is constructed using the method described in any one of claims 1-6, and the system comprises: The task input module is responsible for receiving code generation tasks. The task result output module outputs the task results after the task is executed. The history memory module is responsible for storing historical execution records, similar task memories, and a feature library of historical successful tasks. The task execution module is responsible for executing the tasks of the agents in the subprocess, and the model corresponding to the agents can be switched. The status sharing module is responsible for storing the real-time status of tasks and serves as a shared status channel for the main scheduler module and the task execution module to communicate the real-time status of the tasks. The computing module is responsible for providing the hardware facilities required for intelligent agent computing, including GPUs and CPUs; The operation monitoring module is responsible for detecting the real-time resource load status of the computing module; The main scheduler module is responsible for task initialization, generation of initial execution strategies, dynamic scheduling of task execution, and generation of historical execution records after the task ends.
8. A hardware system, characterized in that, The hardware system includes a memory and a processor; the memory stores a computer program that, when executed by the processor, implements the method as described in any one of claims 1-6.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by a processor, it implements the method as described in any one of claims 1-6.
10. The method of any one of claims 1-6, the system of claim 7, the hardware system of claim 8, or the computer-readable storage medium of claim 9, in the application of intelligent code generation, automated software development, multi-agent programming collaboration, local large language model inference scheduling, and resource-constrained software engineering scenarios.
