Intelligent agent-based adaptive closed-loop context engineering method and device

By using an adaptive closed-loop context engineering method, the context window and associative memory network of a large language model agent are dynamically managed, which solves the inefficiency problem caused by fixed windows and static policies, and improves the execution efficiency and accuracy of the agent in complex tasks.

CN121960729APending Publication Date: 2026-05-01BANK OF CHINA INSURANCE INFORMATION TECH MANAGEMENT
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511848749.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-09
Publication Date
2026-05-01

AI Technical Summary

Technical Problem

The fixed-size context window and static context management strategy of existing large language model agents result in low efficiency, limited accuracy and practicality when handling complex tasks.

Method used

An adaptive closed-loop context engineering approach is adopted. The perception layer collects task information, the decision layer uses a reinforcement learning scheduling model to predict action intentions, and the execution layer dynamically manages the context window, associative memory network and sub-agent cluster of LLM agents. The feedback layer generates multi-dimensional feedback signals to optimize the scheduling strategy.

Benefits of technology

It enables efficient dynamic management of intelligent agents in complex tasks, improves task execution efficiency and accuracy, and optimizes resource utilization and information fidelity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121960729A_ABST
    Figure CN121960729A_ABST
Patent Text Reader

Abstract

The invention relates to a self-adaptive closed-loop context engineering method and device based on an intelligent agent, and belongs to the technical field of intelligent agents, and the method comprises the steps: outputting a context scheduling action intention for a current task stage through a reinforcement learning scheduling model in a decision-making layer based on a task type, a task demand and a current task state prediction decision; wherein the context scheduling action intention of the current task stage is an execution action in a predefined action space; mapping the action intention into at least one specific operation which can be triggered and executed on the execution layer on the execution layer, scheduling the action intention based on the context of the current task stage, and setting an execution condition for triggering the specific operation; and triggering and executing the corresponding specific operation based on the execution condition of the specific operation to obtain the task execution result, so that the intelligent agent can dynamically manage at least one of the context window, the associated memory network and the sub-intelligent agent cluster of the LLM intelligent agent, thereby being beneficial to improving the application efficiency of the intelligent agent.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of intelligent agent technology, and in particular to an adaptive closed-loop context engineering method and apparatus based on intelligent agents. Background Technology

[0002] With the development of large language model (LLM) agent technology, its application in long-cycle, multi-tool, and cross-conversation complex tasks such as code generation and debugging, multi-agent collaborative research, and cross-modal interaction is becoming increasingly widespread. In these scenarios, the context window of the LLM agent, acting as its "working memory," plays a crucial role in storing task instructions, historical interactions, tool call results, and domain knowledge. However, limited by the fixed-size context window and static context management strategies, existing systems face numerous bottlenecks when handling complex tasks, restricting the efficiency, accuracy, and practicality of the agent. Summary of the Invention

[0003] In view of the above-mentioned shortcomings and deficiencies of the prior art, the present invention provides an adaptive closed-loop context engineering method and apparatus based on intelligent agents, which solves the technical problem of low efficiency of intelligent agent applications caused by the limitation of fixed-size context windows and static context management strategies.

[0004] To achieve the above objectives, the main technical solutions adopted by the present invention include:

[0005] The first aspect of this invention provides an adaptive closed-loop context engineering method based on intelligent agents.

[0006] The adaptive closed-loop context engineering method based on an intelligent agent proposed in this embodiment of the invention includes an intelligent agent comprising a perception layer, a decision layer, an execution layer, and a feedback layer. The method includes:

[0007] The perception layer collects the user's task type, task requirements, and current task status, and the reinforcement learning scheduling model in the decision layer predicts decisions based on the task type, task requirements, and current task status, outputting the context scheduling action intent for the current task stage; wherein, the context scheduling action intent for the current task stage is an execution action in a predefined action space.

[0008] In the execution layer, the action intent is mapped to at least one specific operation that can be triggered and executed in the execution layer, and the execution conditions for triggering the specific operation are set based on the context of the current task stage.

[0009] Based on the execution conditions of the specific operation, the corresponding specific operation is triggered and executed to obtain the task execution result; wherein, the specific operation includes dynamic management of at least one of the context window, associated memory network, and sub-agent cluster of LLM agent;

[0010] Based on the task execution results, a multi-dimensional feedback signal containing task efficiency, resource consumption, and information fidelity is generated through the feedback layer. The decision parameters of the reinforcement learning scheduling model and / or the execution conditions are updated based on the multi-dimensional feedback signal to optimize the scheduling strategy of subsequent tasks.

[0011] In some instances, the current task status includes the percentage of task progress completed per unit time in the current task phase, the context redundancy rate, and the ratio of actual token consumption to baseline consumption.

[0012] The reinforcement learning scheduling model in the decision layer predicts decisions based on the task type, task requirements, and current task state, and outputs the contextual scheduling action intent for the current task stage, including:

[0013] The reinforcement learning scheduling model in the decision layer adjusts the weights of the dynamic reward function corresponding to the task progress ratio completed per unit time in the current task stage, context redundancy rate, and the ratio of actual token consumption to baseline consumption based on the task type, task requirements, the proportion of task progress completed per unit time in the current task stage, context redundancy rate, and the ratio of actual token consumption to baseline consumption.

[0014] Based on the weights of the proportion of task progress completed per unit time in the current task phase, the context redundancy rate, and the ratio of actual token consumption to baseline consumption, the context scheduling action intent for the current task phase is determined.

[0015] In some instances, the context scheduling action intent includes at least one of the following:

[0016] Select actions, write actions, compress actions, and isolate actions;

[0017] The execution conditions include at least one of immediate execution conditions, event listening conditions, and state threshold conditions; wherein, the event listening conditions are used to trigger the operation when any of the following occurs: tool call completion, subtask completion, or user interaction; the state threshold conditions are used to trigger the operation when the context window usage rate exceeds a predetermined usage rate, the number of associated memory nodes exceeds a predetermined number, or the sub-agent load exceeds a predetermined load.

[0018] The setting of execution conditions to trigger the specific operation based on the context scheduling action intent of the current task stage includes:

[0019] Based on the selected action in the current task stage, set immediate execution conditions to trigger the specific operation corresponding to the selected action;

[0020] Based on the write action in the current task phase, set an immediate execution condition to trigger the specific operation corresponding to the write action;

[0021] Based on the compression action in the current task stage, set a state threshold condition to trigger the specific operation corresponding to the compression action;

[0022] Based on the isolation action of the current task stage, set an event listener condition to trigger the specific operation corresponding to the isolation action.

[0023] In some instances, the dynamic management of the context window of the LLM agent includes:

[0024] When the usage rate of the context window exceeds a predetermined usage rate, a tiered compression operation is triggered; wherein, the tiered compression operation includes:

[0025] Based on the current task progress, the context content is dynamically divided into a core decision layer, a task process layer, and a redundant information layer. A fine-grained summary compression strategy based on a fine-tuning model is adopted for the core decision layer, a step merging and deduplication compression strategy is adopted for the task process layer, and a rule-based deletion strategy is adopted for the redundant information layer.

[0026] In some instances, the dynamic management of the associative memory network includes:

[0027] A two-layer associative knowledge network is constructed, comprising a static memory layer and a dynamic interaction layer. The specific operation triggered by a selection action involves retrieving and injecting the Top-K most relevant memories of the current task into the context window based on the current task progress and dynamic association weights. The dynamic association weights are used to characterize the degree of association between the relevant memories and the current task.

[0028] The specific operation triggered by the write action is to write the tool feedback result or key interaction data as a new node into the two-layer associated knowledge network, and update the dynamic association weight between the current task and the existing memory nodes.

[0029] In some instances, the dynamic management of the sub-agent cluster includes:

[0030] When the reinforcement learning scheduling model predicts and decides based on the task type, task requirements, and current task state, and outputs an isolation action intent for the context scheduling action at the current task stage, a dynamic sub-agent generation operation is triggered. The dynamic sub-agent generation operation includes dynamically allocating a dedicated context window for the generated sub-agent, transmitting sub-task result summaries, cross-task dependency information, and conflict warning signals between sub-agents on demand through a shared context bus, and arbitrating information conflicts during transmission by invoking an associative memory network based on evidence credibility.

[0031] In some instances, the dynamic reward function R is:

[0032] ;in, This represents the percentage of task progress completed per unit of time in the current task phase. For context redundancy; This is the ratio of actual token consumption to baseline consumption. This represents the progress of the current task phase. Time elapsed for the current task progress; The actual token consumption for the current task phase; This represents the baseline cost for traditional static strategies. These are all weighting coefficients corresponding to each quantity.

[0033] A second aspect of this invention provides an adaptive closed-loop context engineering device based on an intelligent agent, wherein the intelligent agent includes a perception layer, a decision layer, an execution layer, and a feedback layer, and the device includes:

[0034] The action intent output unit is used to collect the task type, task requirements and current task status related to the user task through the perception layer, and predict decisions based on the task type, task requirements and current task status through the reinforcement learning scheduling model in the decision layer, and output the context scheduling action intent for the current task stage; wherein, the context scheduling action intent for the current task stage is an execution action in a predefined action space.

[0035] The specific operation determination unit is used to map the action intent to at least one specific operation that can be triggered and executed at the execution layer, and to set the execution conditions for triggering the specific operation based on the context scheduling action intent of the current task stage.

[0036] The specific operation execution unit is used to trigger and execute the corresponding specific operation based on the execution conditions of the specific operation to obtain the task execution result; wherein, the specific operation includes dynamic management of at least one of the context window of the LLM agent, the associated memory network, and the sub-agent cluster;

[0037] The execution result feedback unit is used to generate a multi-dimensional feedback signal containing task efficiency, resource consumption and information fidelity through the feedback layer based on the task execution result, and update the decision parameters of the reinforcement learning scheduling model and / or the execution conditions based on the multi-dimensional feedback signal to optimize the scheduling strategy of subsequent tasks.

[0038] A third aspect of the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein the program, when executed by a processor, implements the steps of the method described in the first aspect above.

[0039] A fourth aspect of the present invention provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that the processor executes the program to implement the steps of the method described in the first aspect above.

[0040] This invention discloses an adaptive closed-loop context engineering method based on an intelligent agent, comprising: collecting task type, task requirements, and current task state related to a user task through a perception layer; predicting decisions based on task type, task requirements, and current task state through a reinforcement learning scheduling model in a decision layer, and outputting a context scheduling action intent for the current task stage; wherein the context scheduling action intent for the current task stage is an execution action in a predefined action space; mapping the action intent to at least one specific operation that can be triggered and executed in the execution layer, and setting execution conditions for triggering the specific operation based on the context scheduling action intent for the current task stage; triggering and executing the corresponding specific operation based on the execution conditions of the specific operation to obtain a task execution result; wherein the specific operation includes dynamically managing at least one of the context window, associative memory network, and sub-agent cluster of the LLM agent; and generating a multi-dimensional feedback signal containing task efficiency, resource consumption, and information fidelity through a feedback layer based on the task execution result, and updating the decision parameters and / or execution conditions of the reinforcement learning scheduling model based on the multi-dimensional feedback signal to optimize the scheduling strategy for subsequent tasks. This application utilizes a reinforcement learning scheduling model in the decision layer to predict decisions based on task type, task requirements, and current task state, outputting a context-based scheduling action intent for the current task stage. The context-based scheduling action intent for the current task stage is an execution action within a predefined action space. In the execution layer, the action intent is mapped to at least one specific operation that can be triggered and executed. Based on the context-based scheduling action intent for the current task stage, execution conditions for triggering the specific operation are set. Based on the execution conditions of the specific operation, the corresponding specific operation is triggered and executed, resulting in the task execution result. This allows the agent to adjust the context-based scheduling action intent in real time according to task type, task requirements, and current task state, enabling dynamic management of at least one of the LLM agent's context window, associative memory network, and sub-agent cluster, thereby improving the application efficiency of the agent. Attached Figure Description

[0041] Figure 1 A flowchart of an adaptive closed-loop context engineering method based on an intelligent agent provided in an embodiment of the present invention;

[0042] Figure 2 This is a schematic diagram of an adaptive closed-loop context engineering device based on an intelligent agent, provided in an embodiment of the present invention. Detailed Implementation

[0043] To better explain and facilitate understanding of the present invention, the present invention will be described in detail below with reference to the accompanying drawings and specific embodiments.

[0044] The adaptive closed-loop context engineering method based on agents proposed in this invention addresses the low application efficiency of agents caused by fixed-size context windows and static context management strategies. It uses a reinforcement learning scheduling model in the decision layer to predict decisions based on task type, task requirements, and current task state, outputting a context scheduling action intent for the current task stage. This intent is defined as an execution action in a predefined action space. In the execution layer, the action intent is mapped to at least one specific operation that can be triggered and executed. Based on the context scheduling action intent of the current task stage, execution conditions for triggering the specific operation are set. Based on the execution conditions, the corresponding specific operation is triggered and executed, resulting in the task execution result. This allows the agent to adjust its context scheduling action intent in real time according to task type, task requirements, and current task state, enabling dynamic management of at least one of the LLM agent's context window, associative memory network, and sub-agent cluster, thereby improving the application efficiency of the agent.

[0045] To better understand the above technical solutions, exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present invention are shown in the drawings, it should be understood that the present invention can be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that the present invention can be understood more clearly and thoroughly, and that the scope of the present invention can be fully conveyed to those skilled in the art.

[0046] Figure 1 A flowchart illustrating an agent-based adaptive closed-loop context engineering method provided in this embodiment of the invention. Figure 1 As shown in the embodiment of the present invention, the adaptive closed-loop context engineering method based on an intelligent agent includes a perception layer, a decision layer, an execution layer, and a feedback layer. The method includes:

[0047] Step 100: Collect the task type, task requirements and current task status related to the user task through the perception layer, and predict the decision based on the task type, task requirements and current task status through the reinforcement learning scheduling model in the decision layer, and output the context scheduling action intention for the current task stage; wherein, the context scheduling action intention for the current task stage is an execution action in a predefined action space.

[0048] Step 110: Map the action intent to at least one specific operation that can be triggered and executed at the execution layer, and set the execution conditions for triggering the specific operation based on the context scheduling action intent of the current task stage;

[0049] Step 120: Based on the execution conditions of the specific operation, trigger and execute the corresponding specific operation to obtain the task execution result; wherein, the specific operation includes dynamic management of at least one of the context window, associative memory network, and sub-agent cluster of LLM (Large Language Model) agents;

[0050] Step 130: Based on the task execution result, a multi-dimensional feedback signal containing task efficiency, resource consumption and information fidelity is generated through the feedback layer, and the decision parameters of the reinforcement learning scheduling model and / or the execution conditions are updated based on the multi-dimensional feedback signal to optimize the scheduling strategy of subsequent tasks.

[0051] In this exemplary embodiment, the current task may be editing input code. When editing the input code, the context scheduling action intent for the current task stage can be output based on the task type, task requirements, and current task state prediction decision, so as to adjust the specific operation on the input code in a timely manner.

[0052] This application utilizes a reinforcement learning scheduling model in the decision layer to predict decisions based on task type, task requirements, and current task state, outputting a context-based scheduling action intent for the current task stage. The context-based scheduling action intent for the current task stage is an execution action within a predefined action space. In the execution layer, the action intent is mapped to at least one specific operation that can be triggered and executed. Based on the context-based scheduling action intent for the current task stage, execution conditions for triggering the specific operation are set. Based on the execution conditions of the specific operation, the corresponding specific operation is triggered and executed, resulting in the task execution result. This allows the agent to adjust the context-based scheduling action intent in real time according to task type, task requirements, and current task state, enabling dynamic management of at least one of the LLM agent's context window, associative memory network, and sub-agent cluster, thereby improving the application efficiency of the agent.

[0053] In some instances, the current task status includes the percentage of task progress completed per unit time in the current task phase, the context redundancy rate, and the ratio of actual token consumption to baseline consumption.

[0054] The reinforcement learning scheduling model in the decision layer predicts decisions based on the task type, task requirements, and current task state, and outputs the contextual scheduling action intent for the current task stage, including:

[0055] The reinforcement learning scheduling model in the decision layer adjusts the weights of the dynamic reward function corresponding to the task progress ratio completed per unit time in the current task stage, context redundancy rate, and the ratio of actual token consumption to baseline consumption based on the task type, task requirements, the proportion of task progress completed per unit time in the current task stage, context redundancy rate, and the ratio of actual token consumption to baseline consumption.

[0056] Based on the weights of the proportion of task progress completed per unit time in the current task phase, the context redundancy rate, and the ratio of actual token consumption to baseline consumption, the context scheduling action intent for the current task phase is determined.

[0057] In this exemplary embodiment, the dynamic reward function R is:

[0058] ;in, This represents the percentage of task progress completed per unit of time in the current task phase. For context redundancy; This is the ratio of actual token consumption to baseline consumption. This represents the progress of the current task phase. Time elapsed for the current task progress; The actual token consumption for the current task phase; This represents the baseline cost for traditional static strategies. These are all weighting coefficients corresponding to each quantity.

[0059] In this exemplary embodiment, the reinforcement learning scheduling model in the decision layer adjusts the weights of the dynamic reward function corresponding to the percentage of task progress completed per unit time in the current task stage, context redundancy rate, and the ratio of actual token consumption to baseline consumption, based on the task type, task requirements, the percentage of task progress completed per unit time in the current task stage, context redundancy rate, and the ratio of actual token consumption to baseline consumption. Based on these weights, the intended context scheduling action for the current task stage is determined. This facilitates real-time adjustment of execution actions according to the task execution status of the current task stage, thereby improving the application efficiency of the intelligent agent.

[0060] In some instances, the context scheduling action intent includes at least one of the following:

[0061] Select actions, write actions, compress actions, and isolate actions;

[0062] The execution conditions include at least one of immediate execution conditions, event listening conditions, and state threshold conditions; wherein, the event listening conditions are used to trigger the operation when any of the following occurs: tool call completion, subtask completion, or user interaction; the state threshold conditions are used to trigger the operation when the context window usage rate exceeds a predetermined usage rate, the number of associated memory nodes exceeds a predetermined number, or the sub-agent load exceeds a predetermined load.

[0063] The setting of execution conditions to trigger the specific operation based on the context scheduling action intent of the current task stage includes:

[0064] Based on the selected action in the current task stage, set immediate execution conditions to trigger the specific operation corresponding to the selected action;

[0065] Based on the write action in the current task phase, set an immediate execution condition to trigger the specific operation corresponding to the write action;

[0066] Based on the compression action in the current task stage, set a state threshold condition to trigger the specific operation corresponding to the compression action;

[0067] Based on the isolation action of the current task stage, set an event listener condition to trigger the specific operation corresponding to the isolation action.

[0068] In this exemplary embodiment, based on the selected action in the current task stage, an immediate execution condition can be set to trigger the specific operation corresponding to the selected action;

[0069] Based on the write action in the current task phase, immediate execution conditions can be set to trigger the specific operation corresponding to the write action;

[0070] Based on the compression action of the current task stage, a state threshold condition can be set to trigger the specific operation corresponding to the compression action.

[0071] Based on the isolated action of the current task stage, an event-listening condition can be set to trigger the specific operation corresponding to the isolated action. This is an example in this application and is not intended to be limiting. For instance, besides setting an immediate execution condition to trigger the specific operation corresponding to the selected action based on the selected action of the current task stage, a state threshold condition to trigger the specific operation corresponding to the selected action can also be set. In this way, the triggering condition settings corresponding to the action intent can be implemented.

[0072] In some instances, the dynamic management of the context window of the LLM agent includes:

[0073] When the usage rate of the context window exceeds a predetermined usage rate, a tiered compression operation is triggered; wherein, the tiered compression operation includes:

[0074] Based on the current task progress, the context content is dynamically divided into a core decision layer, a task process layer, and a redundant information layer. A fine-grained summary compression strategy based on a fine-tuning model is adopted for the core decision layer, a step merging and deduplication compression strategy is adopted for the task process layer, and a rule-based deletion strategy is adopted for the redundant information layer.

[0075] In this exemplary embodiment, dynamic compression is triggered when the context window usage rate reaches 85%; if the core decision-making layer information accounts for less than 60%, the task process layer and redundant information layer are compressed first; if the task enters the final stage, the weight of the core decision-making layer is increased to 80%, and only the "final conclusion related information" is retained.

[0076] In some instances, the dynamic management of the associative memory network includes:

[0077] A two-layer associative knowledge network is constructed, comprising a static memory layer and a dynamic interaction layer. The specific operation triggered by a selection action involves retrieving and injecting the Top-K most relevant memories of the current task into the context window based on the current task progress and dynamic association weights. The dynamic association weights are used to characterize the degree of association between the relevant memories and the current task.

[0078] The specific operation triggered by the write action is to write the tool feedback result or key interaction data as a new node into the two-layer associated knowledge network, and update the dynamic association weight between the current task and the existing memory nodes.

[0079] In this exemplary embodiment, the limitations of the existing three types of isolated memory storage are overcome, and a memory association architecture with "task goal" as the core is constructed to dynamically associate memory, tool feedback and user interaction data to achieve "precise retrieval on demand".

[0080] First, the memory network structure. A two-layer knowledge graph is used to construct an associative memory network. The first layer is the "static memory layer", where nodes are defined as contextual memory, procedural memory, and semantic memory, and edges are defined as "association weights" (initialized based on cosine similarity). The second layer is the "dynamic interaction layer", where nodes add tool feedback (such as API return results and search summaries) and real-time user input, and edges are defined as "temporal associations" (recording the task stage in which the interaction occurs).

[0081] Second, a dynamic update mechanism. Each time the agent completes a subtask, the memory network is updated. The specific logic is as follows:

[0082] The dynamic association weight between computational tool feedback and static memory nodes (such as the weight of "code compilation error feedback" and "syntax rules in program memory" is increased by 30%).

[0083] Delete redundant memory nodes that have not been associated for three consecutive task cycles to free up storage resources.

[0084] Thirdly, a precise retrieval method. Based on a two-dimensional retrieval of "task stage + association weight", for example, in code repair tasks, priority is given to retrieving "program memory associated with the current syntax error type", "contextual memory of similar historical errors", and "semantic memory associated with compilation logs returned by the tool". The retrieval results are sorted by "association weight × task stage matching degree", and only the top 3 results are injected into the context window.

[0085] In some instances, the dynamic management of the sub-agent cluster includes:

[0086] When the reinforcement learning scheduling model predicts and decides based on the task type, task requirements, and current task state, and outputs an isolation action intent for the context scheduling action at the current task stage, a dynamic sub-agent generation operation is triggered. The dynamic sub-agent generation operation includes dynamically allocating a dedicated context window for the generated sub-agent, transmitting sub-task result summaries, cross-task dependency information, and conflict warning signals between sub-agents on demand through a shared context bus, and arbitrating information conflicts during transmission by invoking an associative memory network based on evidence credibility.

[0087] In this exemplary embodiment, the generation of sub-agents is triggered based on a reinforcement learning model (the state space includes "task complexity, tool type, and context load"), and the specific logic is as follows:

[0088] When the single agent's context window usage rate is ≥90%, the task contains more than 3 types of tools, or there are "parallel subtasks" (such as "literature retrieval" and "data processing" can be performed in parallel), a sub-agent is automatically generated.

[0089] Each sub-agent is assigned a "dedicated context window" (containing only the associated memory and tool description of the sub-task it is responsible for), and the window size is dynamically allocated according to the complexity of the sub-task (e.g., the window capacity of the "code debugging sub-agent" is 2000 tokens, and the window capacity of the "system architecture design sub-agent" is 8000 tokens).

[0090] Design a lightweight bus module to achieve "non-redundant exchange of key information" between sub-agents. For example, only "subtask result summary, cross-subtask dependency information, and conflict warning signals" are transmitted (such as "data processing sub-agent" transmitting "data cleaning completion summary + outlier location" to "analysis sub-agent").

[0091] When there is a conflict in the context transmitted by two sub-agents (such as a contradiction between "Literature Conclusion A" and "Experimental Data B"), the bus automatically calls the "Associative Memory Network" to retrieve relevant evidence, sorts it by "Evidence Credibility × Task Relevance", and injects only the information with higher priority into the context of the target agent.

[0092] In this application, after each intelligent agent completes a task cycle, the feedback layer inputs the "task result accuracy, latency, and token consumption" into the scheduling model, updates the model parameters, and optimizes the next action selection (e.g., when the "tool call success rate is low", the model prioritizes triggering the "select" operation and retrieves the tool usage rules in the program's memory).

[0093] In this application, the sub-task objectives of the code assistant scenario differ significantly, and the priority needs to be matched by dynamically adjusting α (progress / time consumption weight), β (context redundancy weight), and γ (token cost weight). In all scenarios, α+β+γ=1, and the weights can be dynamically fine-tuned according to the real-time task status (such as time consumption exceeding expectations or token exceeding the limit).

[0094] I. Core Sub-Scenarios and Reward Function Weight Configuration

[0095] 1. Regarding "code debugging scenarios"

[0096] Objective: To quickly locate the cause of errors (such as Pandas CSV reading errors or syntax exceptions) and prioritize debugging efficiency;

[0097] Reward function weight configuration: (α=0.5, β=0.3, γ=0.2);

[0098] Because α is the highest, debugging needs are time-sensitive, and "short processing time" is the core user requirement; β is medium, and it is necessary to avoid redundancy that obscures key error information; γ is the lowest, and token costs can be moderately sacrificed for debugging efficiency.

[0099] 2. Regarding "Performance Optimization Scenarios"

[0100] Objective: Reduce code execution time (e.g., read a million-line CSV file in Pandas from 8 seconds to 2.5 seconds), while optimizing key information retention and token control;

[0101] Reward function weight configuration: (α=0.3, β=0.4, γ=0.3);

[0102] Because β is the highest: core information such as "optimization parameters and performance analysis data" must be accurately preserved; α / γ balance: optimization progress and token cost are equally important, and excessive compression should be avoided to prevent optimization failure.

[0103] 3. Regarding "Code Generation Scenarios"

[0104] Objective: To generate complete code that meets requirements (such as automated data cleaning scripts), balancing generation efficiency and code quality;

[0105] Reward function configuration: (α=0.4, β=0.35, γ=0.25);

[0106] Because α is relatively high: the generation task needs to be delivered on time; β is second highest: the context such as "user requirement details and library call specifications" needs to be preserved to avoid the generation deviating from the requirements; γ is relatively low: the token cost can be moderately compromised for the integrity of the generation.

[0107] 4. Regarding "Cross-session iteration scenarios"

[0108] Objective: To build upon past tasks (such as optimizing the Pandas code from the previous debugging session) and reduce redundant work and token waste.

[0109] Reward function configuration: (α=0.25, β=0.35, γ=0.4);

[0110] Since γ is the highest: cross-session token consumption needs to be controlled (to avoid repeatedly loading historical memories); β is the second highest: key historical information needs to be accurately retained; α is the lowest: the timeliness of iterative tasks is weaker than cost control.

[0111] II. Triggering logic rules for the action space (A) in each scenario:

[0112] 1. Regarding "Code debugging scenario (α=0.5, β=0.3, γ=0.2)";

[0113] Core triggering principle: Prioritize improving debugging progress (α) through "selection (retrieval of memory)" and "isolation (separation of subtasks)" and supplement it with "compression (de-redundancy)" to protect critical information (β).

[0114] 2. Regarding the "performance optimization scenario (α=0.3, β=0.4, γ=0.3)";

[0115] Core triggering principle: Prioritize the protection of core information (β) through "compression (precise preservation of optimized information)" and "writing (storage optimization scheme)" while taking into account the control of token (γ) through "isolation (parallel optimization)".

[0116] 3. Regarding "Code generation scenario (α=0.4, β=0.35, γ=0.25)";

[0117] Core triggering principle: Prioritize improving the generation progress (α) by "selecting (retrieving and generating templates)" and "isolating (separating subtasks)", and supplement it with "compression (removing redundancy)" to retain the required information (β).

[0118] 4. Regarding "Cross-session iteration scenario (α=0.25, β=0.35, γ=0.4)";

[0119] Core triggering principle: Prioritize controlling the token (γ) through "selection (retrieve historical memory)" and "compression (deduplication)", and supplement it with "writing (update memory)" to ensure continuity (β).

[0120] In this application, updating the decision parameters and / or execution conditions of the reinforcement learning scheduling model based on the multi-dimensional feedback signals to optimize the scheduling strategy for subsequent tasks is a closed-loop, data-driven, self-iterative optimization process. The system not only executes tasks but also learns from each task execution, continuously improving its decision-making capabilities.

[0121] This invention provides an adaptive closed-loop context engineering device based on an intelligent agent, wherein the intelligent agent includes a perception layer, a decision layer, an execution layer, and a feedback layer. Figure 2 This is a schematic diagram of an agent-based adaptive closed-loop context engineering device provided in an embodiment of the present invention. Figure 2 As shown, the device includes:

[0122] The action intent output unit 20 is used to collect the task type, task requirements and current task status related to the user task through the perception layer, and predict decisions based on the task type, task requirements and current task status through the reinforcement learning scheduling model in the decision layer, and output the context scheduling action intent for the current task stage; wherein, the context scheduling action intent for the current task stage is an execution action in a predefined action space.

[0123] The specific operation determination unit 21 is used to map the action intention to at least one specific operation that can be triggered and executed at the execution layer, and to set the execution conditions for triggering the specific operation based on the context scheduling action intention of the current task stage.

[0124] The specific operation execution unit 22 is used to trigger and execute the corresponding specific operation based on the execution conditions of the specific operation to obtain the task execution result; wherein, the specific operation includes dynamic management of at least one of the context window of the LLM agent, the associated memory network, and the sub-agent cluster;

[0125] The execution result feedback unit 23 is used to generate a multi-dimensional feedback signal containing task efficiency, resource consumption and information fidelity through the feedback layer based on the task execution result, and update the decision parameters of the reinforcement learning scheduling model and / or the execution conditions based on the multi-dimensional feedback signal to optimize the scheduling strategy of subsequent tasks.

[0126] In this exemplary embodiment, the current task may be editing input code. When editing the input code, the context scheduling action intent for the current task stage can be output based on the task type, task requirements, and current task state prediction decision, so as to adjust the specific operation on the input code in a timely manner.

[0127] This application utilizes a reinforcement learning scheduling model in the decision layer to predict decisions based on task type, task requirements, and current task state, outputting a context-based scheduling action intent for the current task stage. The context-based scheduling action intent for the current task stage is an execution action within a predefined action space. In the execution layer, the action intent is mapped to at least one specific operation that can be triggered and executed. Based on the context-based scheduling action intent for the current task stage, execution conditions for triggering the specific operation are set. Based on the execution conditions of the specific operation, the corresponding specific operation is triggered and executed, resulting in the task execution result. This allows the agent to adjust the context-based scheduling action intent in real time according to task type, task requirements, and current task state, enabling dynamic management of at least one of the LLM agent's context window, associative memory network, and sub-agent cluster, thereby improving the application efficiency of the agent.

[0128] Since the systems / devices described in the above embodiments of the present invention are systems / devices used to implement the methods of the above embodiments of the present invention, those skilled in the art can understand the specific structure and modifications of the systems / devices based on the methods described in the above embodiments of the present invention, and therefore will not be repeated here. All systems / devices used in the methods of the above embodiments of the present invention fall within the scope of protection of the present invention.

[0129] This invention provides a computer-readable storage medium, characterized in that it stores an agent-based adaptive closed-loop context engineering program thereon, which, when executed by a processor, implements the agent-based adaptive closed-loop context engineering method described in the above embodiments.

[0130] This invention provides an electronic device, characterized in that it includes a memory, a processor, and an agent-based adaptive closed-loop context engineering program stored in the memory and executable on the processor. When the processor executes the agent-based adaptive closed-loop context engineering program, it implements the agent-based adaptive closed-loop context engineering method described in the above embodiments.

[0131] In the description of this invention, it should be understood that the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. Therefore, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this invention, "a plurality of" means two or more, unless otherwise explicitly specified.

[0132] In this invention, unless otherwise explicitly specified and limited, the terms "installation," "connection," "linking," and "fixing," etc., should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral part; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; they can refer to the internal communication of two components or the interaction between two components. Those skilled in the art can understand the specific meaning of the above terms in this invention according to the specific circumstances.

[0133] In this invention, unless otherwise explicitly specified and limited, "above" or "below" the second feature can mean that the first and second features are in direct contact, or that they are in indirect contact through an intermediate medium. Furthermore, "above," "over," or "on top" the second feature can mean that the first feature is directly above or diagonally above the second feature, or simply indicates that the first feature is at a higher horizontal level than the second feature. "Below," "below," or "beneath" the second feature can mean that the first feature is directly below or diagonally below the second feature, or simply indicates that the first feature is at a lower horizontal level than the second feature.

[0134] In the description of this specification, the terms "one embodiment," "some embodiments," "embodiment," "example," "specific example," or "some examples," etc., refer to specific features, structures, materials, or characteristics described in connection with that embodiment or example, which are included in at least one embodiment or example of the present invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.

[0135] Although embodiments of the present invention have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present invention. Those skilled in the art can make modifications, alterations, substitutions and variations to the above embodiments within the scope of the present invention.

Claims

1. An agent-based adaptive closed-loop context engineering method, characterized in that, The intelligent agent includes a perception layer, a decision-making layer, an execution layer, and a feedback layer; the method includes: The perception layer collects the user's task type, task requirements, and current task status, and the reinforcement learning scheduling model in the decision layer predicts decisions based on the task type, task requirements, and current task status, outputting the context scheduling action intent for the current task stage; wherein, the context scheduling action intent for the current task stage is an execution action in a predefined action space. In the execution layer, the action intent is mapped to at least one specific operation that can be triggered and executed in the execution layer, and the execution conditions for triggering the specific operation are set based on the context of the current task stage. Based on the execution conditions of the specific operation, the corresponding specific operation is triggered and executed to obtain the task execution result; wherein, the specific operation includes dynamic management of at least one of the context window, associated memory network, and sub-agent cluster of LLM agent; Based on the task execution results, a multi-dimensional feedback signal containing task efficiency, resource consumption, and information fidelity is generated through the feedback layer. The decision parameters of the reinforcement learning scheduling model and / or the execution conditions are updated based on the multi-dimensional feedback signal to optimize the scheduling strategy of subsequent tasks.

2. The agent-based adaptive closed-loop context engineering method according to claim 1, characterized in that, The current task status includes the percentage of task progress completed per unit time in the current task stage, the context redundancy rate, and the ratio of actual token consumption to baseline consumption. The reinforcement learning scheduling model in the decision layer predicts decisions based on the task type, task requirements, and current task state, and outputs the contextual scheduling action intent for the current task stage, including: The reinforcement learning scheduling model in the decision layer adjusts the weights of the dynamic reward function corresponding to the task progress ratio completed per unit time in the current task stage, context redundancy rate, and the ratio of actual token consumption to baseline consumption based on the task type, task requirements, the proportion of task progress completed per unit time in the current task stage, context redundancy rate, and the ratio of actual token consumption to baseline consumption. Based on the weights of the proportion of task progress completed per unit time in the current task phase, the context redundancy rate, and the ratio of actual token consumption to baseline consumption, the context scheduling action intent for the current task phase is determined.

3. The agent-based adaptive closed-loop context engineering method according to claim 1, characterized in that, The context scheduling action intent includes at least one of the following: Select actions, write actions, compress actions, and isolate actions; The execution conditions include at least one of immediate execution conditions, event listening conditions, and state threshold conditions; wherein, the event listening conditions are used to trigger the operation when any of the following occurs: tool call completion, subtask completion, or user interaction; the state threshold conditions are used to trigger the operation when the context window usage rate exceeds a predetermined usage rate, the number of associated memory nodes exceeds a predetermined number, or the sub-agent load exceeds a predetermined load. The setting of execution conditions to trigger the specific operation based on the context scheduling action intent of the current task stage includes: Based on the selected action in the current task stage, set immediate execution conditions to trigger the specific operation corresponding to the selected action; Based on the write action in the current task phase, set an immediate execution condition to trigger the specific operation corresponding to the write action; Based on the compression action in the current task stage, set a state threshold condition to trigger the specific operation corresponding to the compression action; Based on the isolation action of the current task stage, set an event listener condition to trigger the specific operation corresponding to the isolation action.

4. The agent-based adaptive closed-loop context engineering method according to claim 3, characterized in that, The dynamic management of the context window of the LLM agent includes: When the usage rate of the context window exceeds a predetermined usage rate, a tiered compression operation is triggered; wherein, the tiered compression operation includes: Based on the current task progress, the context content is dynamically divided into a core decision layer, a task process layer, and a redundant information layer. A fine-grained summary compression strategy based on a fine-tuning model is adopted for the core decision layer, a step merging and deduplication compression strategy is adopted for the task process layer, and a rule-based deletion strategy is adopted for the redundant information layer.

5. The agent-based adaptive closed-loop context engineering method according to claim 3, characterized in that, The dynamic management of the associative memory network includes: A two-layer associative knowledge network is constructed, comprising a static memory layer and a dynamic interaction layer. The specific operation triggered by a selection action involves retrieving and injecting the Top-K most relevant memories of the current task into the context window based on the current task progress and dynamic association weights. The dynamic association weights are used to characterize the degree of association between the relevant memories and the current task. The specific operation triggered by the write action is to write the tool feedback result or key interaction data as a new node into the two-layer associated knowledge network, and update the dynamic association weight between the current task and the existing memory nodes.

6. The agent-based adaptive closed-loop context engineering method according to claim 3, characterized in that, The dynamic management of the sub-agent cluster includes: When the reinforcement learning scheduling model predicts and decides based on the task type, task requirements, and current task state, and outputs an isolation action intent for the context scheduling action at the current task stage, a dynamic sub-agent generation operation is triggered. The dynamic sub-agent generation operation includes dynamically allocating a dedicated context window for the generated sub-agent, transmitting sub-task result summaries, cross-task dependency information, and conflict warning signals between sub-agents on demand through a shared context bus, and arbitrating information conflicts during transmission by invoking an associative memory network based on evidence credibility.

7. The agent-based adaptive closed-loop context engineering method according to claim 2, characterized in that, The dynamic reward function R is: ;in, This represents the percentage of task progress completed per unit of time in the current task phase. For context redundancy; This is the ratio of actual token consumption to baseline consumption. This represents the progress of the current task phase. Time elapsed for the current task progress; The actual token consumption for the current task phase; This represents the baseline cost for traditional static strategies. These are all weighting coefficients corresponding to each quantity.

8. An agent-based adaptive closed-loop context engineering device, characterized in that, The intelligent agent includes a perception layer, a decision-making layer, an execution layer, and a feedback layer; the device includes: The action intent output unit is used to collect the task type, task requirements and current task status related to the user task through the perception layer, and predict decisions based on the task type, task requirements and current task status through the reinforcement learning scheduling model in the decision layer, and output the context scheduling action intent for the current task stage; wherein, the context scheduling action intent for the current task stage is an execution action in a predefined action space. The specific operation determination unit is used to map the action intent to at least one specific operation that can be triggered and executed at the execution layer, and to set the execution conditions for triggering the specific operation based on the context scheduling action intent of the current task stage. The specific operation execution unit is used to trigger and execute the corresponding specific operation based on the execution conditions of the specific operation to obtain the task execution result; wherein, the specific operation includes dynamic management of at least one of the context window of the LLM agent, the associated memory network, and the sub-agent cluster; The execution result feedback unit is used to generate a multi-dimensional feedback signal containing task efficiency, resource consumption and information fidelity through the feedback layer based on the task execution result, and update the decision parameters of the reinforcement learning scheduling model and / or the execution conditions based on the multi-dimensional feedback signal to optimize the scheduling strategy of subsequent tasks.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by a processor, it implements the steps of the method according to any one of claims 1 to 7.

10. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the method according to any one of claims 1 to 7.