Agent long-term task consistency maintenance method based on long-term memory
By generating memory snapshot feature vectors in long-term agent tasks and combining them with risk prediction models and state machine topologies, the problems of memory promiscuity and drift in long-term agent task recovery are solved, thereby achieving task consistency maintenance and improved execution stability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHENZHEN LAIDA SIWEI INFORMATION TECH CO LTD
- Filing Date
- 2026-05-12
- Publication Date
- 2026-06-09
AI Technical Summary
In existing technologies, when recovering long-term tasks of intelligent agents, historical memory and the current target node are easily mixed and drifted after external asynchronous interruption. This makes it difficult to accurately match the effective context during the recovery phase, and it can easily cause state judgment deviations and task execution deviations in complex scenarios, reducing the stability and reliability of long-term tasks of intelligent agents.
When an agent performs long-term tasks based on a hierarchical finite state machine, it responds to external asynchronous interruption events, obtains task execution logs and current state context to generate memory snapshots, converts them into snapshot feature vectors and stores them in a vector memory, retrieves historical memory snapshots through similarity, quantifies context drift entropy, and generates control instructions to maintain task consistency by combining risk prediction models and state machine topology.
It achieves unified retention and traceability of memory during the interruption recovery phase, quantitatively identifies memory hybridity and drift issues, and ensures the accuracy of state transitions through logical verification and cleaning processes, thereby improving the stability and reliability of long-term tasks.
Smart Images

Figure CN122174867A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of artificial intelligence and intelligent agent task control technology, specifically to a method for maintaining consistency in long-term tasks of intelligent agents based on long-term memory. Background Technology
[0002] Long-term task consistency maintenance for agents based on long-term memory refers to the management of task execution logs, state contexts, and historical memories during the execution of long-term tasks by agents, in order to maintain task continuity and execution consistency during interruption recovery and state transitions. Current long-term task consistency maintenance methods include state machine-based flow control methods, log recording-based recovery methods, and memory retrieval-based context-assisted methods. However, when performing long-term task recovery based on existing technologies, on the one hand, after encountering external asynchronous interruptions, historical memory and the current target node are prone to mixing and drift, making it difficult to accurately match the effective context during the recovery phase; on the other hand, existing solutions do not adequately consider the logical preconditions and risk levels of different state nodes, which can easily lead to state judgment deviations, erroneous state transitions, and task execution deviations in complex scenarios such as disaster recovery of enterprise-level core systems, thereby reducing the stability and reliability of the agent's long-term task execution. Summary of the Invention
[0003] To address the aforementioned technical problems, this invention provides a method for maintaining consistency in long-term tasks of intelligent agents based on long-term memory. Specifically, the technical solution of this invention includes: During the execution of long-range tasks by the agent based on a hierarchical finite state machine, in response to the received external asynchronous interruption event, the agent obtains the task execution log and current state context under the current state node of the hierarchical finite state machine and generates a current memory snapshot. The current memory snapshot is converted into a snapshot feature vector, and the snapshot feature vector is stored in the vector memory bank; When the agent recovers from an external asynchronous interruption event and triggers a state transition, it obtains the current transition target node of the agent in the hierarchical finite state machine, generates target retrieval features based on the current transition target node, and retrieves the historical memory snapshot sequence from the vector memory by calculating the similarity between the target retrieval features and the snapshot feature vectors in the vector memory. Semantic divergence calculation is performed on historical memory snapshot sequences to quantify context drift entropy; The context drift entropy is input into a preset risk prediction model for mapping processing, and the risk probability value of context failure is calculated and normalized to the interval of zero to one. The risk probability value is compared with the preset safety threshold and the preset danger threshold, respectively, wherein the preset danger threshold is greater than the preset safety threshold. When the risk probability value is lower than the preset safety threshold, a first control command is generated; when the risk probability value is greater than or equal to the preset safety threshold and lower than the preset danger threshold, a second control command is generated. When the risk probability value is greater than or equal to the preset danger threshold, a third control instruction is generated; in response to the first control instruction, the agent is driven to complete the state transition according to the preset default execution path; In response to the second control command, the agent is triggered to perform a local memory filtering operation on the historical memory snapshot sequence; In response to a third control command, long-running tasks are suspended, and a memory cleaning and logical alignment process is triggered to compress historical memory snapshots in the vector memory that cause increased context drift entropy.
[0004] Compared with the prior art, the present invention has the following beneficial effects: 1. This invention, during the execution of long-term tasks by an agent based on a hierarchical finite state machine, synchronously acquires the task execution log and current state context under the current state node and generates a memory snapshot when an external asynchronous interrupt event is received. Then, the memory snapshot is converted into a snapshot feature vector and written into a vector memory bank. This ensures that the execution trajectory, permission boundaries, resource consumption, target subtasks, and state machine hierarchical positions before and after the interruption are uniformly preserved, thereby providing a searchable and traceable long-term memory foundation for the recovery phase. 2. This invention forms local variance by the distance between adjacent snapshot feature vectors, forms logical conflict features by combining state parameters with the differences between the precondition parameters of the target node, and calculates context drift entropy according to preset weights, thereby quantitatively identifying the mixing, drift and logical incompatibility problems between historical memory and the current target node, avoiding the erroneous context mixing caused by restoring only by text similarity; 3. This invention forms multiple homogeneous snapshot clusters through cluster analysis, and performs feature dimensionality reduction and semantic fusion on each cluster to generate a single fused snapshot. The fused snapshot replaces the target conflict snapshot set in the vector memory. At the same time, it combines the initial target of the long-term task and the list of currently completed sub-tasks for logical verification. If the verification passes, the state transition to the current target node is re-initiated. If the verification fails, a manual intervention alarm is triggered and the process is suspended. This achieves targeted compression, logical alignment, and auditable traceability control of high-conflict historical memory. Attached Figure Description
[0005] Figure 1 The present invention provides a flowchart illustrating the long-term memory-based agent long-term task consistency maintenance method according to an embodiment of the present invention. Detailed Implementation
[0006] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to specific embodiments.
[0007] The long-term memory-based agent long-term task consistency maintenance method includes the following steps: during the process of the agent executing a long-term task based on a hierarchical finite state machine, in response to the received external asynchronous interruption event, the agent obtains the task execution log and current state context under the current state node of the hierarchical finite state machine, and generates a current memory snapshot. The current memory snapshot is converted into a snapshot feature vector, and the snapshot feature vector is stored in the vector memory bank; When the agent recovers from an external asynchronous interruption event and triggers a state transition, it obtains the current transition target node of the agent in the hierarchical finite state machine, generates target retrieval features based on the current transition target node, and retrieves the historical memory snapshot sequence from the vector memory by calculating the similarity between the target retrieval features and the snapshot feature vectors in the vector memory. Semantic divergence calculation is performed on historical memory snapshot sequences to quantify context drift entropy; The context drift entropy is input into a preset risk prediction model for mapping processing, and the risk probability value of context failure is calculated and normalized to the interval of zero to one. The risk probability value is compared with a preset safety threshold and a preset danger threshold, wherein the preset danger threshold is greater than the preset safety threshold. When the risk probability value is lower than the preset safety threshold, a first control command is generated; when the risk probability value is greater than or equal to the preset safety threshold and lower than the preset danger threshold, a second control command is generated. When the risk probability value is greater than or equal to the preset danger threshold, a third control instruction is generated; in response to the first control instruction, the agent is driven to complete the state transition according to the preset default execution path; In response to the second control command, the agent is triggered to perform a local memory filtering operation on the historical memory snapshot sequence; In response to the third control command, long-term tasks are suspended and a memory cleaning and logical alignment process is triggered to compress historical memory snapshots in the vector memory that cause increased context drift entropy. This embodiment provides a mechanism for maintaining consistency in long-term tasks by an intelligent agent based on long-term memory, such as... Figure 1 As shown; specifically, the disaster recovery process of an enterprise-level core system is modeled as a layered finite state machine. The top-level state may include resource takeover, database recovery, microservice recovery, network reconstruction, and end-to-end verification, while the sub-level state is further refined into operation nodes such as read-only mounting, backup volume replay, transaction log replay, starting core service instances, and refreshing routing tables. The autonomous intelligent agent executes tasks sequentially in this state machine, but during the recovery period, it will frequently encounter asynchronous alarms caused by the instability of the underlying hardware state. Therefore, it is necessary to maintain the consistency of memory and state before and after each external asynchronous interruption event is received. In the specific implementation process, when any state node is running, once an external asynchronous interrupt event is received, the system immediately freezes the current state's running trajectory and extracts two types of information to form a current memory snapshot. The first type of information is the task execution log, which records the executed actions, output results, and intermediate feedback. The second type of information is the current state context, which records the node's permission boundaries, resource usage, target subtasks, preconditions, and current state machine hierarchy. To facilitate machine retrieval, a snapshot can be organized into a structure of node identifier + timestamp + log summary + set of state parameters. Furthermore, in order to enable subsequent interruption recovery to quickly locate the memory related to the current target node in a medium-to-large-scale historical record, this embodiment performs vectorized encoding on the current memory snapshot; for example, the log text and status parameters can be concatenated first, and then a set of snapshot feature vectors with preset dimensions can be output through an embedded encoder. After that, the vector, together with the original snapshot text, node number and generation time, is written into the vector memory; the vector memory can be a vector database with metadata index, or it can be a combination of local cache and remote persistent storage. To avoid name confusion for the same technical object in subsequent descriptions, in this embodiment and subsequent embodiments, unless otherwise specified, the memory bank refers to the aforementioned vector memory bank, and the history record refers to the memory snapshot record written to the vector memory bank and retrieved through metadata or vector similarity; context failure is used to indicate the risky state in which the agent selects the wrong context during state transition due to the mixing of long-term memory fragments. Its typical manifestation at the runtime level is abnormal state consistency, that is, the agent incorrectly applies the state constraint that does not belong to the current transition target node as the current valid state constraint. The two are not two independent risk indicators. After the asynchronous interruption event subsides, the state machine will determine the current transition target node based on the current task flow relationship. At this time, instead of simply restoring the interrupt position, the transition target node is used as the retrieval anchor point to extract a sequence of historical memory snapshots from the vector memory. During retrieval, the target node identifier, state level label and semantic vector similarity can be used simultaneously for joint constraints to avoid returning snapshots that should not be logically mixed in based solely on text similarity. After obtaining the historical memory snapshot sequence, the system performs semantic divergence calculation on the sequence to quantify the context drift entropy. Here, the context drift entropy is used to characterize whether the historical memory is in a stable convergence state under the same transfer target, or whether it has been mixed with multiple fragmented contents containing different nodes, different permissions, and different resource states. If the value continues to rise, it indicates that the degree of mixing of related fragments in the vector memory has exceeded the predetermined data divergence baseline, and continuing to directly restore the execution is likely to cause inaccurate state judgment. The context drift entropy is input into a preset risk prediction model to obtain a risk probability value normalized to the interval between zero and one. For ease of explanation, it is assumed that the preset safety threshold is 0.35 and the preset danger threshold is 0.75. When the model output is 0.20, it indicates that the current historical memory is basically stable, and the first control instruction can be generated to continue the state transition along the default execution path. When the output is 0.58, it indicates that there is a certain degree of memory confusion, but it has not yet reached the point where it is necessary to stop and repair. At this time, the second control instruction is generated to filter only the retrieved local memory and then send the filtering result to the context window to assist the current state transition. When the output is 0.83, it indicates that the historical memory near the node has significant conflict. At this time, the third control instruction is generated to suspend the long-term task and enter the memory cleaning and logical alignment process, prioritizing the elimination of conflict snapshots that cause the drift entropy to increase. A simplified example can be used to illustrate its operation. Suppose that at a certain moment, the target node is the database recovery-replay transaction log. The system retrieves three snapshots from the vector memory: snapshot M1 corresponds to the database volume being mounted and write permissions being enabled; snapshot M2 corresponds to network blocking and database writes being prohibited; snapshot M3 corresponds to the database replay progressing to log segment L28. If evaluated solely based on semantic similarity, M1, M2, and M3 are all related to recovery. However, M2 belongs to the network isolation sub-process. If it is incorrectly concatenated into the database write scenario, it will cause subsequent control commands to deviate. The system uses semantic divergence calculation to find that the internal differences of the sequence exceed a preset divergence threshold, and then outputs a risk probability that is higher than a preset safety threshold. When the value is greater than or equal to a preset danger threshold, the system directly blocks further execution, instead of issuing action instructions without logical verification. In abnormal situations, if the task execution log cannot be fully obtained when the interruption occurs, for example, if some log buffers have not yet been written to disk, a degraded snapshot can be generated by using the log fragments from the most recent stable checkpoint and the current state registration information, and the log incompleteness can be marked in the snapshot metadata. If vector encoding fails, the original snapshot text and node labels are first written to the temporary storage area. Vectorization processing is then performed after the encoding service is restored. If no historical memory snapshot sequence that meets the conditions is found during restoration, the task is not restored directly. Instead, a conservative mode is triggered, and the state machine is rolled back to the nearest verified parent node and re-entered. If the risk probability value is exactly equal to a certain threshold, it is processed according to the higher risk level to avoid the risk of unexpected state transitions under boundary values. In the 31st hour of the enterprise-level core system disaster recovery task, the agent was in the index reconstruction sub-state under database recovery. At this time, the underlying storage array generated a secondary alarm, causing the task to be interrupted. The system recorded the currently reconstructed index shard number, database instance write lock status, available storage space, current node execution permissions, etc., forming a memory snapshot and writing it to the vector memory. Ten minutes later, the alarm was cleared, and the state machine planned to transfer to the transaction log replay completion verification node. When the system retrieved the historical snapshot, it found that some results came from the previous network reconstruction process. Although the text also contained words such as recovery completion verification passed, its resource context was not compatible with the database process. After semantic divergence calculation, a context drift entropy greater than or equal to the preset danger threshold was obtained, which finally triggered the third control instruction to suspend the recovery task and enter the memory cleaning process. The purpose of this step is to establish a control link for long-term tasks under conditions of high-frequency interruption and limited context window, which first assesses memory reliability and then decides whether to resume execution. This achieves coordinated constraints between state machine transition logic and long-term memory content, reducing execution deviations caused by erroneous memory splicing.
[0008] Furthermore, the step of performing semantic divergence calculation on the historical memory snapshot sequence to quantify the context drift entropy specifically includes: sorting the historical memory snapshot sequence according to the generation timestamp, and extracting the distance between the snapshot feature vectors of adjacent historical memory snapshots in the historical memory snapshot sequence as the feature vector distance; Based on the feature vector distance, determine the local variance of the historical memory snapshot sequence; obtain the precondition parameters required for the current transfer target node; Analyze the historical memory snapshot sequence to obtain the state parameters contained in each historical memory snapshot; By comparing the state parameters and precondition parameters contained in each historical memory snapshot in the historical memory snapshot sequence, the state parameters and precondition parameters are divided into discrete state parameters, numerical interval parameters, and sequential dependency parameters. The conflict level is quantified according to the matching rules corresponding to different parameter types to calculate the degree of difference, and the degree of difference is extracted as a logical conflict feature. The local variance and logical conflict features are weighted and summed according to preset weight coefficients corresponding to the degree of feature vector discreteness and logical incompatibility, respectively, to calculate the context drift entropy. The context drift entropy is used to characterize the degree of discreteness and conflict of memory data in the vector memory bank.
[0009] This embodiment provides a specific calculation mechanism for context drift entropy; specifically, when retrieving historical snapshots based solely on semantic similarity, it is easy to encounter the problem of similar texts but incompatible states. Therefore, it is necessary to simultaneously include the degree of discreteness at the vector level and the degree of conflict at the logical precondition level in the evaluation, so as to more realistically reflect whether the memory sequence can be safely used for the current state transition. In the specific implementation process, the system extracts the feature vector distance between adjacent snapshots in the historical memory snapshot sequence. This distance can be cosine distance, Euclidean distance, or other difference measurement methods suitable for the current encoder. For illustration purposes, it is assumed that four snapshots N1, N2, N3, and N4 are retrieved, and their pairwise adjacent distances are 0.12, 0.18, and 0.75, respectively. The first two distances are lower than the preset distance benchmark value, indicating that the local context is similar. The values of the three feature vector distances jump, indicating that snapshots with significant differences from the initial semantic distribution have been mixed into the historical memory snapshot sequence. Specifically, in the implementation process, the system extracts the feature vector distance between adjacent snapshots in the historical memory snapshot sequence; assuming the retrieved historical memory snapshot sequence contains... The set of distances between pairwise adjacent feature vectors of each snapshot is: Local variance characterizes the degree of dispersion of vectors within a sequence, and its quantized eigenvalues... The calculation formula is as follows: in, It is the arithmetic mean of the distances between all adjacent feature vectors, i.e. ; The summation index has a range of values. to ; The first in the historical memory snapshot sequence The feature vector distance between adjacent snapshot pairs; when An increase in the value indicates an increase in the dispersion within the historical memory snapshot sequence.
[0010] Based on this, the system fuses local variance and logical conflict features according to preset weight coefficients to obtain the context drift entropy; let the context drift entropy be... The calculation formula is as follows: in, The extracted logical conflict features are dimensionless normalized values. and These are preset weight coefficients corresponding to the degree of dispersion and logical incompatibility of the feature vectors, respectively, and satisfying the following conditions: ; obtained through this formula It also reflects the degree of dispersion of memory fragments and the degree of conflict between logical preconditions, ensuring that features of different dimensions are evaluated under the same dimensionless standard.
[0011] For example, the local variance weight can be set to 0.4 and the logical conflict feature weight to 0.6 to reflect that the state machine preconditions are more critical for safe recovery; if the current local variance is 0.30 and the logical conflict comprehensive value is 0.50, then the context drift entropy can be calculated as 0.4×0.30+0.6×0.50=0.42; the quantification result obtained in this way reflects both the degree of dispersion of memory fragments and the degree of conflict of logical preconditions. If the sequence length difference is further considered, the above results can be normalized. For example, when the number of historical snapshots is too small, the system can add a minimum sample correction term to avoid making an overly aggressive low drift judgment based on only 1 or 2 snapshots. When the number of samples in the historical memory snapshot sequence is greater than the second preset number threshold, a sliding window method can be used to calculate in segments to avoid early old snapshots causing too much interference to the current state transition. In abnormal situations, if there are missing items between adjacent snapshots, such as the status parameters of a snapshot not being fully collected, the snapshot can be handled in the logical conflict calculation by using the unknown parameter penalty value. For example, the unknown item can be recorded according to the preset default value of the conflict penalty, instead of being directly recorded as zero conflict. If the precondition parameters cannot be obtained from the target node configuration, the drift entropy calculation is paused and the conservative recovery mode is entered, allowing only a rollback to the parent node to reconfirm the preconditions; if the difference between the local variance and the logical conflict is greater than the preset deviation threshold, for example, if the vector distance is lower than the first preset threshold but the logical conflict feature value is higher than the second preset threshold, then the direction with higher logical conflict is prioritized to avoid misjudgment of the true state due to the consistency of surface semantics. In the aforementioned disaster recovery mainline, the system prepares to transfer from the database backup volume verification completion to the transaction log replay node; three historical snapshots are retrieved: P1 records that the database volume is mounted and the primary instance is writable; P2 records that the database volume is mounted but remains read-only; P3 records that the database instance is temporarily unreachable during network switching. Among them, the vector distance between P1 and P2 is only 0.10, and the vector distance between P2 and P3 is 0.48. If judged only by vector distance, P1 and P2 are relatively close to the target node, but in the logical preconditions, there is a key difference between writable and read-only, so P2 will show obvious conflict; based on this, the system calculates the context drift entropy greater than the preset risk judgment threshold, providing the basic input for subsequent risk mapping; Furthermore, to avoid insufficient accuracy in extracting logical conflict features, this embodiment can divide the precondition parameters into three categories: discrete state parameters, numerical range parameters, and sequential dependency parameters, and process them separately. Among them, for discrete state parameters, such as whether they are writable, whether they are mounted, and whether they are allowed to send external commands, when the historical snapshot is consistent with the target precondition, it is recorded as zero conflict; when they are inconsistent, it is recorded as complete conflict; and when the parameter is missing, it is recorded as medium conflict. For numerical range parameters, such as remaining memory, available storage space, and concurrent instance quotas, the degree of difference can be determined based on whether they fall within the target node's allowed range and the magnitude of deviation. For sequentially dependent parameters, such as log segment continuity, subtask completion order, and parent node completion markers, values can be assigned hierarchically based on correct order, missing order, and reversed order. The resulting single-parameter differences are then aggregated to form the logical conflict characteristics of a single historical snapshot, thus ensuring that logical conflicts are not directly given by fuzzy semantic judgments, but are obtained by comparing state parameters item by item. Furthermore, before calculating the adjacency distance and local variance, the historical memory snapshot sequence is preferably sorted according to the generation timestamp and then subjected to consistency screening based on the node label of the current transfer target node. That is, the snapshots entering the semantic divergence calculation are first ensured to be in the same target transfer neighborhood before the adjacency distance is calculated. This operation can avoid the misjudgment of non-temporally adjacent snapshots as adjacent samples due to similarity sorting caused by the disordered order of retrieval returns, which would lead to the calculation deviation of local variance. Furthermore, when the number of historical memory snapshots is less than two, the system does not simply treat the local variance as zero, but introduces a minimum sample conservative correction. Specifically, the local variance can be directly added according to the preset baseline value, or the calculation result can be marked as low confidence and the conservative level can be increased in subsequent risk mapping. The reason for this is that too few samples do not mean that the memory is stable, but are more likely to mean that the retrieval evidence is insufficient. If it is directly treated as zero variance, it is easy to misjudge the situation without sufficient evidence as highly stable context. Furthermore, the aggregation of logical conflict features at the sequence level can be achieved by weighting snapshot importance. This importance can be determined by the degree of node label matching, the recentity of the snapshot time, and the completeness of key state parameters in the snapshot. That is, the closer the snapshot is to the current transfer target node, the more recent it is, and the more complete its parameters are, the greater the impact of its logical conflict on the final context drift entropy. Conversely, snapshots with a generation timestamp span exceeding the preset duration threshold or with incomplete information still participate in the calculation, but their impact is moderately suppressed. This allows the context drift entropy to better align with the memory fragments that the current recovery decision truly relies on. The purpose of this mechanism is to improve the degree of disorder in memory sequences from a single semantic similarity judgment to a two-dimensional quantification of semantic distribution and state pre-condition logic, thereby achieving a more refined identification of the degree of memory contamination and enabling the generation process of context drift entropy to have clear parameter sources, comparison paths and conservative processing rules.
[0012] Furthermore, the step of inputting the context drift entropy into a preset risk prediction model for mapping processing and calculating the risk probability value of context failure normalized to the interval of zero to one includes, before: obtaining the global state machine topology of the agent in the hierarchical finite state machine; extracting the in-degree data and out-degree data of the current transfer target node in the global state machine topology; and determining the topological complexity of the current transfer target node based on the in-degree data and out-degree data. The steps of inputting context drift entropy into a preset risk prediction model for mapping processing and calculating risk probability value specifically include: inputting context drift entropy and topological complexity into a preset risk prediction model containing multi-dimensional feature input; performing nonlinear mapping processing on context drift entropy and topological complexity through the preset risk prediction model, and outputting a risk probability value of context failure normalized to the interval of zero to one. The risk probability value is used to indicate the probability of an agent experiencing state consistency anomalies.
[0013] This embodiment provides a risk prediction mechanism that incorporates the topological complexity of a state machine. Specifically, relying solely on context drift entropy to determine risk is not accurate enough in some scenarios. This is because different state nodes have varying sensitivities to memory confusion. Some nodes have only a single predecessor and a single successor, so even with slight memory deviations, the recovery path is relatively easy to converge. However, some nodes are located at the intersection of multiple branches, and any inconsistent historical memory may lead the state machine to the wrong branch. Therefore, this embodiment further introduces the topological complexity of the current transition target node in the global state machine to participate in risk mapping. In the specific implementation process, the system obtains the global topology of the hierarchical finite state machine; this topology can be abstracted as a directed graph, where each node represents a task state and each directed edge represents an allowed state transition relationship; for example, in the main disaster recovery process, the database recovery completion verification node may flow to microservice recovery, or it may fall back to database reconstruction when the check fails, or it may turn to manual review and other branches when external resources are abnormal, so its connection relationship is relatively complex; Based on this, the system extracts the in-degree and out-degree data of the current transition target node in the directed graph of the state machine. The in-degree indicates how many execution paths can flow into the node, and the out-degree indicates the number of possible successor branches after the node; let the topological complexity of the current transition target node be O(n). The calculation formula is as follows: in, This represents the in-degree value of the target node for the transfer. This represents the out-degree value of the target node for the transition; both are non-negative integers. Generally speaking, The larger the value, the more complex the process intersection, and the higher the requirement for consistency of historical memory. The topological complexity here always refers to the sum of the in-degree and out-degree of the current transfer target node in the same global state machine topology, and no longer refers to the number of task steps, execution time or resource consumption complexity; when complex nodes or complex node connection relationships are mentioned in the following description, they are all engineering descriptions of the state with high topological complexity. Furthermore, the context drift entropy and topological complexity are input into a pre-defined risk prediction model; this model can be a nonlinear mapping model trained on historical task data, such as a lightweight neural network model, a gradient boosting tree model, or a risk mapper constructed based on a piecewise nonlinear function; its output is a risk probability value normalized to the interval between zero and one. The significance of introducing nonlinear mapping is that the relationship between drift entropy and topological complexity is not a simple linear superposition. For example, when the drift entropy increases from 0.2 to 0.4, if the topological complexity of the target node is 2, the increase in the risk probability value is lower than the preset first growth rate threshold; when the topological complexity of the target node is 7, the increase in the risk probability value is greater than the preset second growth rate threshold. It should be noted that in this embodiment, the probability of context failure and the probability of state consistency anomaly correspond to the same model output value in the control link, and two independent probability variables are not set. The former describes the source of risk from the perspective of memory consistency, that is, the mixing of long-term memory snapshots and the destruction of the current context. The latter describes the consequences of risk from the perspective of system performance, that is, the agent may mistakenly locate the wrong state node or mistakenly adopt state constraints that do not belong to the current node. Therefore, the normalized value output by the risk prediction model is used to represent both the risk of context failure and the probability of state consistency anomalies induced by the context failure. Subsequent threshold comparison, control instruction generation, and suspension cleaning processes are all based on the same risk probability value. A numerical example illustrates this: Suppose there are two target nodes for transition. Node A has a context drift entropy of 0.42 and a topological complexity of 2; Node B also has a context drift entropy of 0.42, but a topological complexity of 6. After applying the same nonlinear mapping model, the risk probability value of node A may be 0.33, while the risk probability value of node B may be 0.71. This shows that in the latter scenario, although the degree of memory confusion appears to be the same, because this node has more state branches, once the wrong context is selected during recovery, the subsequent offset is more likely to be amplified. Therefore, a more conservative control strategy should be adopted. Interpretability can be further enhanced by using interval-based output; for example, the model output falling between 0 and 0.35 can be considered low risk, between 0.35 and 0.75 is medium risk, and greater than or equal to 0.75 is high risk; in this way, the control module can directly trigger default execution, local filtering, or task suspension based on the interval, without the need for complex rule combinations. In abnormal situations, if the global state machine topology is updated during operation, such as by adding an emergency rollback branch, the in-degree, out-degree, and topological complexity of the affected nodes should be recalculated, and the input configuration of the risk prediction model should be refreshed. If a node temporarily lacks topological information due to a version switch, it should be treated as a high-complexity node, and a conservative strategy should be adopted first. If the risk prediction model service is temporarily unavailable, a rule-based rollback method can be used, such as using a combination of drift entropy and standardized complexity to approximate the model output, so as to avoid the system losing its risk classification capability. During the 72-hour disaster recovery process, the system is currently preparing to transfer from the database recovery completion verification to the microservice batch restart node. This node receives inflows from the main database recovery line and is also affected by branches such as the rollback results from the configuration center and the preparation status of dependent services, resulting in a high in-degree. At the same time, this node may subsequently transfer to multiple branches such as the interface health check service rollback to continue starting the next batch of instances, resulting in a high out-degree. Even if the context drift entropy is between the preset safety threshold and the preset danger threshold at this time, the risk prediction model may still output a high risk probability value because the topological complexity of this node itself is greater than the preset complexity threshold, thus prompting the system to clear its memory before resuming execution. Furthermore, to prevent the risk prediction model from becoming a processing module that cannot be directly interpreted, the system can construct supervision labels based on historical recovery task samples before model deployment. Among these labels, whether erroneous branch jumps occur, whether manual takeover is triggered, and whether task rollback or repeated execution occurs can all serve as observations of context failure. Thus, the model input is not an arbitrary concatenation of variables, but rather uses context drift entropy and topological complexity as core features, while the output corresponds to the actual risk outcomes that occurred in historical tasks. This not only explains the training basis of the model but also establishes a traceable correlation between risk probability values and on-site consequences. Furthermore, nonlinear mapping processing preferably satisfies monotonicity constraints during runtime: with topological complexity remaining constant, the higher the context drift entropy, the lower the output risk probability value should be; with context drift entropy remaining constant, the higher the topological complexity, the lower the output risk probability value should also not be lower. If the original output of the model violates this constraint, it can be corrected through a post-processing correction table or piecewise mapping. This prevents anomalous results caused by accidental bias in training samples, where more confused memories are judged as safer. Furthermore, before inputting context drift entropy and topological complexity into the model, both can be standardized in terms of dimensions. Context drift entropy can be used in the aforementioned zero-to-one range or mapped to this range. Topological complexity can be standardized based on the maximum connection size of nodes in the current state machine version, or mapped to three levels (low, medium, and high) according to a preset complexity classification. The purpose of this is to avoid the same topological complexity value representing inconsistent risk meanings in different deployment environments due to large differences in the size of different state machines. Furthermore, if rule-based rollback is used instead of model output, it is preferable to maintain the same risk classification boundary as the model. That is, the approximate risk value obtained by the rollback rule is still mapped to the zero-to-one range, and the preset safety threshold and preset danger threshold are used to continue to perform graded control, rather than starting a separate set of control logic. This ensures that the interface form of the control link is consistent in both the available and unavailable states of the model, and avoids the system generating additional branch complexity in the downstream control module due to model anomalies. The purpose of this mechanism is to couple the modeling of whether the memory itself is chaotic with the sensitivity of the node position, so as to achieve a more realistic prediction of state transition risks, improve the reliability of hierarchical control, and make the source of risk probability values, constraint relationships and backoff paths have clear and verifiable engineering meanings.
[0014] Furthermore, in response to the third control command, the long-term task is suspended, and the memory cleaning and logical alignment process is triggered to compress the historical memory snapshots in the vector memory that cause the context drift entropy to increase. Specifically, this includes: in response to the third control command, blocking the operation of the agent to issue execution instructions to the external system; Calculate the contribution of each historical memory snapshot in the historical memory snapshot sequence to the context drift entropy, and extract historical memory snapshots with a contribution greater than a preset contribution threshold from the historical memory snapshot sequence to form a target conflict snapshot set; when the target conflict snapshot set is empty, terminate the current memory cleaning and logical alignment process; when the target conflict snapshot set is not empty, perform cluster analysis on the target conflict snapshot set to generate multiple homogeneous snapshot clusters; For each homogeneous snapshot cluster, feature dimensionality reduction and semantic fusion are performed to generate a corresponding single fused snapshot; The set of target conflict snapshots in the vector memory is replaced with all the single fused snapshots to complete the compression of historical memory snapshots; The method also includes the step of obtaining the global state machine topology of the agent in a hierarchical finite state machine; After replacing the set of target conflict snapshots in the vector memory with all the single fused snapshots and completing the compression step of historical memory snapshots, the method also includes: obtaining the initial set target from the global state machine topology of the long-term task and extracting the list of currently completed subtasks from the agent's running context. Using the initial target and the list of currently completed subtasks, a single fusion snapshot is logically verified to generate a verification result. When the verification result is passed, the long-term task is released from suspension and the agent is driven to re-initiate the state transition to the current target node. When the verification result is unsuccessful, a manual intervention alarm signal is triggered, and the long-term task remains suspended.
[0015] This embodiment provides a memory cleaning and logical alignment mechanism under high-risk conditions. Specifically, in the aforementioned scheme, when the risk probability value has exceeded the preset danger threshold, it is difficult to completely eliminate high-conflict snapshots in the memory bank if only local filtering is relied upon, since conflicting fragments may be distributed in multiple adjacent time periods and similar nodes. At this time, continuing to resume execution will cause the erroneous context to be repeatedly retrieved. Therefore, this embodiment adopts a processing route of first blocking outgoing actions, then cleaning conflicting snapshots, and then verifying logical consistency. In the specific implementation process, after receiving the third control command, the system blocks the operation of the intelligent agent to send execution commands to the external system. This blocking not only stops new database writing, service restart and routing adjustment, but also freezes the automatic retry module to avoid further expansion of state deviation due to the replay of old commands during the cleaning period. In other words, after freezing the execution control plane, the processing flow of the memory data plane is started synchronously. The system calculates the contribution of each snapshot in the historical memory snapshot sequence to the context drift entropy. The contribution consists of two parts: one part reflects how much the local variance is improved after a snapshot is added to the sequence; the other part reflects the degree of conflict between the snapshot and the preconditions of the target node. For ease of understanding, assuming there are five snapshots C1 to C5 in the sequence, with contributions to the drift entropy of 0.08, 0.11, 0.37, 0.34, and 0.06 respectively, and a preset contribution threshold of 0.20, then C3 and C4 will be extracted to form the target conflict snapshot set. This avoids including all snapshots in the cleaning process and reduces the scope of unnecessary data processing. Cluster analysis is performed on the target conflict snapshot set to generate multiple homogeneous snapshot clusters. Homogeneity here does not require that the content is completely identical, but rather that the sources of conflict are similar. For example, one type of snapshots all come from network isolation processes that were accidentally mixed into the database recovery flow, while another type of snapshots come from old version permission configuration remnants. Taking C3 and C4 as examples again, if both record states such as network blockage, database write prohibition, and route switching pending, they can be clustered into the same cluster. If several other snapshots show that the microservice recovery is complete but the database is not yet consistent, they should form another cluster. For each homogeneous snapshot cluster, the system performs feature dimensionality reduction and semantic fusion. Feature dimensionality reduction is used to compress redundant dimensions and retain the low-dimensional representation that best represents the core conflict features of the cluster. Semantic fusion combines multiple highly similar but slightly different conflict snapshots into a single fused snapshot. Specifically, feature dimensionality reduction uses principal component analysis or autoencoder-based dimensionality reduction mapping to extract low-dimensional representations. Semantic fusion uses weighted average pooling on the low-dimensional representation vectors within the homogeneous snapshot cluster to obtain a single fusion center vector, and then uses this fusion center vector to construct a single fused snapshot. This merged snapshot not only preserves common semantics, but also includes tags from conflict compression, so that its default priority can be reduced during subsequent retrieval. For example, if there are four original snapshots in a cluster that all indicate that database writing is not allowed during network isolation, a single snapshot F1 can be obtained after merging, which expresses the existence of the restriction and avoids four highly similar records repeatedly interfering with the retrieval. After fusion is completed, the system replaces the set of target conflict snapshots in the vector memory with all single fused snapshots to complete compression. This does not delete all historical traces, but organizes the repetitive or conflict fragments that cause the drift entropy to be increased into a more compact and manageable representation, thereby reducing the probability of false recall during subsequent retrieval. Furthermore, after compression, the system needs to perform logical verification based on the global state machine topology. Specifically, it retrieves the initial target and the list of completed subtasks from the topology and checks whether the single fusion snapshot is consistent with this information. For example, if the initial target is to start the core microservices after database recovery, and the list of completed subtasks shows that database volume mounting, primary instance recovery, and transaction log replay have all been completed, then if the fusion snapshot still retains the main semantics of database not being ready, it should be considered as failing. Conversely, if the constraints after fusion match the chain of completed tasks, it can be considered as passing. To illustrate with a simplified example: Suppose that before the batch restart of microservices, six conflicting snapshots are retrieved, three of which are from the old network isolation phase and have highly similar content; two are from the database read-only verification phase; and one is from the current target link. After filtering by contribution, the top five conflicting snapshots are selected and clustered into two clusters: cluster A is the network isolation cluster, and cluster B is the database read-only cluster. After merging cluster A, a single snapshot FA is obtained, and after merging cluster B, a single snapshot FB is obtained. After replacement, the vector memory no longer accumulates five mutually reinforcing conflicting records, but only retains two controlled fused representations. Afterwards, the system checks whether the FA and FB conflict with the fact that the database recovery has been completed. If the conflict still exists, the system will remain suspended and issue an alarm. If the conflict is resolved after logical alignment, the system will allow the state transition to be re-initiated. In abnormal situations, if the target conflict snapshot set is empty, it indicates that the increased risk may come from model anomalies or topology configuration changes. In this case, compression and replacement are not performed, but the snapshot is directly submitted for manual review. If cluster analysis finds that a conflict snapshot cannot be assigned to any cluster, it can be retained as an independent cluster to avoid forced erroneous merging. If the semantic information loss rate after feature dimensionality reduction exceeds the preset tolerance threshold, for example, if the fused snapshot can no longer distinguish the key permission status, it should be reverted to the single snapshot with the highest representativeness in the original cluster; if the logical verification result is in an uncertain state, such as some completed subtasks lacking confirmation information, it should remain suspended and not automatically resume execution. During the 47th hour of disaster recovery for the enterprise-level core system, the agent encountered multiple rounds of secondary hardware alarms while preparing to batch restart microservices. This resulted in a large accumulation of old snapshots in the memory, indicating network blocking and database read-only pending rollback. These snapshots were frequently retrieved because their text contained terms such as "recovery service verification." The system determined that the risk had exceeded the preset danger threshold, immediately blocked outgoing commands, extracted high-contribution conflicting snapshots, and clustered and compressed them. After compression, the system confirmed, based on the global state machine, that database recovery was complete, the network had been switched back to the production channel, and the current target was to start the service instance. If the merged snapshot matched this, the suspension was lifted and execution continued; otherwise, a manual intervention alarm was issued, and the system remained paused. Furthermore, to make the contribution assessment operable, this embodiment can break down the impact of a single historical memory snapshot on context drift entropy into two steps: first, while keeping other snapshots unchanged, temporarily remove the snapshot and recalculate the context drift entropy, and observe the magnitude of the decrease in drift entropy; then, combine the logical conflict characteristics of the snapshot itself for joint evaluation. If the drift entropy decreases significantly after a snapshot is removed, and its logical conflict is at a high level, then the snapshot should be identified as a high-contribution conflict snapshot. Conversely, if a snapshot is different from other snapshots, but the decrease in the overall drift entropy after removal is less than the preset decrease threshold, then it will not be preferentially included in the target conflict snapshot set. This method can avoid judging it as core conflict data based solely on the anomaly of a single feature vector distance. Furthermore, cluster analysis preferably incorporates several hard constraints in addition to similarity judgment. These hard constraints can include at least node label consistency, permission mode consistency, and resource status category consistency. That is, conflicting snapshots from network isolation nodes, even if their texts contain phrases such as "recovery completed and verification passed," should not be forcibly clustered into the same cluster as snapshots from database replay nodes. Read-only snapshots should also not be directly merged with write-enabled snapshots. By setting such hard constraints, new semantic mixing can be avoided during the clustering process. Furthermore, for each homogeneous snapshot cluster, the system preferably retains at least the following information: the common main semantics of the cluster, the list of source snapshot identifiers, the time intervals covered, the common state constraints, and the conflict source labels when compressed. In this way, during subsequent re-retrieval, the system can reduce interference by utilizing the concise representation of the fused snapshot, and can also trace back to the original record for auditing when necessary along the source snapshot identifiers. In other words, the retrieval representation in the vector memory is replaced, while the original conflicting snapshot can be transferred to the read-only archive area or audit storage area for preservation, and will no longer participate in the recovery decision as the default retrieval object, thus balancing compression effect and audit traceability; Furthermore, the logical verification does not only check whether the merged snapshot text is consistent with the initial target, but also performs a three-way cross-comparison of the initial target, the list of currently completed subtasks, and the preconditions of the current transfer target node. For example, if the list of completed subtasks clearly includes the database master instance being writable and the network recovery channel switching back to production, but the merged snapshot still retains the master constraints of database being write-prohibited or network still being isolated, then it should be directly judged as failing. If the merge snapshot only retains the controlled description of network isolation that has occurred but has now been lifted, it can be considered as not hindering the current state transition; this avoids the merging operation retaining historical alarm traces, which may be mistakenly regarded as currently valid restrictions. The purpose of this mechanism is to proactively sacrifice short-term task progress when the risk is extremely high in exchange for the purification of the memory structure and the reconvergence of the logical chain, so as to achieve targeted compression and pre-restoration verification of high-conflict historical snapshots, and to ensure that conflict identification, cluster fusion and post-compression traceability all have clear engineering processing boundaries.
[0016] Furthermore, in response to the second control instruction, the step of triggering the agent to perform a local memory filtering operation on the historical memory snapshot sequence specifically includes: in response to the second control instruction, obtaining the generation timestamp of each historical memory snapshot in the historical memory snapshot sequence; The generated timestamp is compared with the current system time of the agent's operating environment to obtain the time difference. Based on the preset exponential time decay function and the time difference, the decay weight of each historical memory snapshot is calculated. Historical memory snapshots with a decay weight lower than a preset weight threshold are removed from the historical memory snapshot sequence, while historical memory snapshots with a decay weight greater than or equal to the preset weight threshold are retained, generating a filtered memory snapshot sequence. The filtered sequence of memory snapshots is input into the agent's context window to assist in state transitions.
[0017] This embodiment provides a local memory filtering mechanism under medium-risk conditions. Specifically, when the risk probability value is between a preset safety threshold and a preset danger threshold, directly entering the full cleaning process will significantly reduce the efficiency of task progress. However, if no processing is performed, old snapshots may continue to interfere with the current state transition. Therefore, this embodiment introduces local memory filtering based on time decay, retaining only the newest snapshots that are most valuable for the current recovery. In the specific implementation process, after receiving the second control command, the system first obtains the generation timestamps of each snapshot in the historical memory snapshot sequence and compares them with the current system time to obtain the time difference; based on a preset exponential time decay function, it calculates the decay weight of each historical memory snapshot; the specific configuration of the mathematical expression of the exponential time decay function is as follows: in, Indicates the decay weight. Indicates the time difference. This represents the preset decay rate constant. The basic idea is that the closer the snapshot is to the current time, the more likely it is to reflect the state that is more closely related to the current target node. Although snapshots with a larger time span may be similar in text, their reference value should gradually decrease because the environment, resources, permissions, and process stages may have changed. For clarity, a simple example can be used. Assume the current time is 12:00, and four snapshots T1, T2, T3, and T4 are retrieved, generated at 11:58, 11:40, 10:30, and 09:00 respectively. The exponential time decay function is set to output weights of approximately 0.95, 0.70, 0.22, and 0.05 for time differences of 2 minutes, 20 minutes, 90 minutes, and 180 minutes, respectively. If the preset weight threshold is 0.30, then T1 and T2 are retained, while T3 and T4 are discarded. Thus, the input context window will primarily contain a set of snapshots from recent periods that closely align with the current state machine transition. Furthermore, the filtered sequence of memory snapshots is sent into the agent's context window to assist in the current state transition. This step does not require sending the entire original text of the snapshots word by word. Instead, it can be organized in chronological order into a compressed form of the most recent operation summary + current valid constraints + confirmed resource status to accommodate the limited capacity of the context window. For example, T1 and T2 can be integrated into a short summary of the database master instance being restored to writable state, the most recent index verification being passed, and the current target entering a microservice single-batch restart, and then provided to the state machine execution module for invocation. Compared with the aforementioned high-risk cleaning mechanism, this embodiment adopts a local filtering strategy with computational resource consumption in accordance with preset standards. It is applicable to situations where the difference between the timestamps generated by historical snapshots reaches a preset first time difference threshold, but its semantic divergence has not yet triggered the global danger threshold. This avoids frequent triggering of suspension and reduces the disruption to the main task timeline. In abnormal situations, if the decay weight of all historical snapshots is lower than the preset weight threshold, it indicates that the current search results are too old overall. In this case, instead of directly driving the state transition with an empty sequence, a new search limited to the neighborhood of the current node is initiated. If necessary, the search can be rolled back to the most recent checkpoint to regenerate the context. If the timestamps of multiple snapshots are abnormal, such as when the system clock drifts and future timestamps appear, these snapshots should be marked as clock anomalies and temporarily removed. If the number of remaining snapshots after filtering is too large and exceeds the capacity of the context window, the most recently generated subset that matches the target node label can be retained first. In the main disaster recovery process, the system has completed database recovery and is preparing to start the second batch of core microservices. Due to multiple secondary alerts encountered along the way, the retrieved historical snapshots include both newly generated service dependency verification records and older snapshots formed during the network isolation phase two hours ago. The system determines that the current risk is in the medium range, so it filters out older snapshots based on time decay weights and only sends records generated within the last twenty minutes that are still related to the service startup chain into the context window. Based on this, the agent completes the restart of the current batch of services without pausing the entire disaster recovery task. The purpose of this step is to suppress the interference of historical memory snapshots exceeding the generation time threshold on the current state transition under moderate risk conditions with limited computing resource consumption, thereby achieving a balance between execution efficiency and memory stability.
[0018] Furthermore, long-term tasks include enterprise-level core system disaster recovery tasks, external asynchronous interrupt events include secondary alarm events caused by underlying hardware instability, and intelligent agents are autonomous intelligent agents used to perform enterprise-level core system disaster recovery tasks; The task execution log includes at least one of the following: database reconstruction log, microservice restart log, and network route reconfiguration log. The current state context includes the agent's current node permission information and current resource allocation status in the enterprise core system disaster recovery task.
[0019] This embodiment provides a specific implementation method of the above mechanism in an enterprise-level core system disaster recovery scenario. Specifically, the long-term tasks in this scenario typically span tens of hours and include hundreds of steps such as database reconstruction, microservice restart, configuration rollback, network routing reconfiguration, and storage consistency verification. During the recovery process, secondary alarms from servers, storage arrays, switching devices, and virtualization platforms will be continuously received. These alarms may not directly cause the main task to fail, but they will cause frequent interruptions, making it very suitable as an application environment for long-term memory consistency control. In practical implementation, the autonomous intelligent agent can be deployed on the disaster recovery control plane and connected to the operation and maintenance orchestration system, database cluster controller, service mesh platform, and network management system. Its task execution logs can include at least one or more of the following: database reconstruction logs, used to record processes such as data volume mounting, instance recovery, log replay, and index repair; microservice restart logs, used to record service instance startup order, health check results, and dependency connection status; and network route reconfiguration logs, used to record operations such as route switching, access control list updates, and load balancer adjustments. The above logs together constitute the execution trajectory part of the memory snapshot. Meanwhile, the current state context is not limited to the text log itself, but also includes operational information closely related to state transition security; for example, the current node permission information can indicate whether the agent has database write permissions, whether it has network policy reconfiguration permissions, and whether it is only allowed to perform read-only checks; the current resource allocation status can indicate the available CPU and memory quotas, available storage space, the number of currently locked service instances, and the bandwidth margin after network link switching, etc.; after these contents are included in the snapshot, the accuracy of subsequent retrieval and logical conflict determination can be significantly improved; A micro-example can illustrate how snapshots are organized; suppose an agent is executing a database recovery-replay transaction log node. The current task execution log records that log segments L1-L28 have been replayed, L29 has passed verification, and L30 is waiting to be written. The current state context records that database write permissions are enabled, the recovery resource pool has 32 gigabytes of remaining memory, the network has been switched to the recovery channel, and the current node is only allowed to perform operations on the primary instance. When the underlying disk controller throws a secondary alarm, the system combines the above information into a snapshot and writes it to the memory. If a historical snapshot is retrieved during recovery, showing network isolation mode and database write permissions closed, the system can quickly identify that the snapshot does not match the logic of the current node. For example, in a microservice batch restart node, the task execution log can record that the third batch of order service instances has been started successfully, the health check pass rate is 80%, the connection to the dependency configuration center is successful, and the status context records that the current node's permissions only allow service start and stop, and do not allow modification of the database structure; the current central processor quota is 40% remaining; two recovery windows have been occupied; once a secondary alarm occurs and the interruption occurs, the service start and stop class context and the database write class context can be distinguished during subsequent recovery to avoid the snapshots of different operation planes being incorrectly mixed. In abnormal situations, if a certain type of log source is temporarily unavailable, such as when the network device log interface times out, an incomplete snapshot can be constructed using other acquired logs and state context, and the source of the missing log item can be marked in the metadata. If the current node's permission information cannot be read in real time, it should be conservatively treated as a low-permission state, and high-risk operations should be prohibited from being executed automatically. If the resource allocation status is inconsistent with the actual device status, such as when the remaining memory in the cache deviates too much from the real-time monitoring value, the real-time monitoring value should be used to overwrite the cached value, and a new snapshot should be generated before participating in subsequent retrievals. During the 52-hour enterprise-level core system disaster recovery process, the autonomous intelligent agent completed the recovery of the database primary instance and began to start the microservice cluster in batches. At this time, a storage node continuously reported secondary alarms due to controller jitter, forcing the task to be interrupted multiple times. At each interruption, the system recorded relevant content from the database reconstruction log, microservice restart log, and network routing reconfiguration log, and simultaneously collected the current node's permission information and resource allocation status. When the interruption subsided, the system re-retrieved historical snapshots based on the target node, and used log categories and status contexts to filter out irrelevant records, thereby only restoring memory fragments that matched the current service restart phase. The purpose of this step is to explicitly map the abstract long-term memory retention mechanism to the high-risk industrial scenario of enterprise-level disaster recovery, thereby achieving unified snapshotting of task logs, running permissions, and resource status, and providing a reliable data foundation for the aforementioned risk assessment, filtering, and cleaning processes.
[0020] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.
Claims
1. A method for maintaining consistency in long-term tasks by an intelligent agent based on long-term memory, characterized in that, Includes the following steps: During the execution of long-range tasks by the agent based on a hierarchical finite state machine, in response to the received external asynchronous interruption event, the agent obtains the task execution log and current state context under the current state node of the hierarchical finite state machine and generates a current memory snapshot. The current memory snapshot is converted into a snapshot feature vector, and the snapshot feature vector is stored in the vector memory bank; When the agent recovers from an external asynchronous interruption event and triggers a state transition, it obtains the current transition target node of the agent in the hierarchical finite state machine, generates target retrieval features based on the current transition target node, and retrieves the historical memory snapshot sequence from the vector memory by calculating the similarity between the target retrieval features and the snapshot feature vectors in the vector memory. Semantic divergence calculation is performed on historical memory snapshot sequences to quantify context drift entropy; The context drift entropy is input into a preset risk prediction model for mapping processing, and the risk probability value of context failure is calculated and normalized to the interval of zero to one. The risk probability value is compared with a preset safety threshold and a preset danger threshold, respectively. Based on the comparison result, a corresponding control command is generated to drive the agent to complete state transition, perform local memory filtering operation on the historical memory snapshot sequence, or suspend the long-term task to perform memory cleaning and logical alignment process.
2. The method for maintaining consistency of long-term tasks by an intelligent agent based on long-term memory according to claim 1, characterized in that, The steps of comparing the risk probability value with a preset safety threshold and a preset danger threshold, and generating a corresponding control command based on the result, specifically include: The risk probability value, the preset safety threshold, and the preset danger threshold are compared, wherein the preset danger threshold is greater than the preset safety threshold; When the risk probability value is lower than the preset safety threshold, a first control command is generated to drive the agent to complete the state transition according to the preset default execution path; When the risk probability value is greater than or equal to the preset safety threshold and lower than the preset danger threshold, a second control command is generated to trigger the agent to perform a local memory filtering operation on the historical memory snapshot sequence. When the risk probability value is greater than or equal to the preset danger threshold, a third control instruction is generated to suspend the long-term task and trigger a memory cleaning and logical alignment process to compress the historical memory snapshots in the vector memory that cause the context drift entropy to increase.
3. The method for maintaining consistency of long-term tasks by an intelligent agent based on long-term memory according to claim 1, characterized in that, The steps involved in calculating semantic divergence and quantifying context drift entropy from a sequence of historical memory snapshots include: The historical memory snapshot sequence is sorted according to the generation timestamp, and the distance between the snapshot feature vectors of adjacent historical memory snapshots in the historical memory snapshot sequence is extracted as the feature vector distance; Based on the eigenvector distance, the local variance of the historical memory snapshot sequence is determined; Obtain the prerequisite parameters required for the current transfer target node; Analyze the historical memory snapshot sequence to obtain the state parameters contained in each historical memory snapshot; By comparing the state parameters and precondition parameters contained in each historical memory snapshot in the historical memory snapshot sequence, the state parameters and precondition parameters are divided into discrete state parameters, numerical interval parameters and sequential dependency parameters. The conflict level is quantified according to the matching rules corresponding to different parameter types to calculate the difference degree, and the difference degree is extracted as a logical conflict feature. The local variance and the logical conflict features are weighted and summed according to preset weight coefficients corresponding to the degree of discreteness and logical incompatibility of the feature vectors, respectively, to calculate the context drift entropy. The context drift entropy is used to characterize the degree of discreteness and conflict of the memory data in the vector memory bank.
4. The method for maintaining consistency of long-term tasks by an intelligent agent based on long-term memory according to claim 1, characterized in that, The step of inputting the context drift entropy into a preset risk prediction model for mapping processing, and calculating the risk probability value of context failure normalized to the interval of zero to one, also includes: Obtain the global state machine topology of the agent in a hierarchical finite state machine; Extract the in-degree and out-degree data of the current transition target node in the global state machine topology; Based on the in-degree data and the out-degree data, the topological complexity of the current transfer target node is determined.
5. The method for maintaining consistency of long-term tasks by an intelligent agent based on long-term memory according to claim 4, characterized in that, The step of inputting the context drift entropy into a preset risk prediction model for mapping processing and calculating the risk probability value specifically includes: A pre-defined risk prediction model that incorporates context drift entropy and topological complexity as inputs to multi-dimensional feature inputs; The preset risk prediction model performs nonlinear mapping on context drift entropy and topological complexity, and outputs a risk probability value of context failure normalized to the interval of zero to one. The risk probability value is used to indicate the probability of the agent experiencing state consistency anomalies.
6. The method for maintaining consistency of long-term tasks by an intelligent agent based on long-term memory according to claim 2, characterized in that, In response to a third control command, long-running tasks are suspended, and a memory cleaning and logical alignment process is triggered to compress historical memory snapshots in the vector memory that cause increased context drift entropy. This process specifically includes: In response to a third control command, the operation of the intelligent agent in issuing execution commands to external systems is blocked; Calculate the contribution of each historical memory snapshot in the historical memory snapshot sequence to the context drift entropy, and extract historical memory snapshots with a contribution greater than a preset contribution threshold from the historical memory snapshot sequence, which is the target conflict snapshot set; When the target conflict snapshot set is empty, the memory cleaning and logical alignment process is terminated. When the target conflict snapshot set is not empty, cluster analysis is performed on the target conflict snapshot set to generate multiple homogeneous snapshot clusters; For each homogeneous snapshot cluster, feature dimensionality reduction and semantic fusion are performed to generate a corresponding single fused snapshot; The set of target conflict snapshots in the vector memory is replaced with all the single fused snapshots to complete the compression of historical memory snapshots.
7. The method for maintaining consistency of long-term tasks by an intelligent agent based on long-term memory according to claim 6, characterized in that, The method also includes the step of obtaining the global state machine topology of the agent in a hierarchical finite state machine; after replacing the set of target conflict snapshots in the vector memory with all the single fused snapshots and completing the compression step of the historical memory snapshots, the method further includes: The initial target is obtained from the global state machine topology of the long-term task, and the list of currently completed subtasks is extracted from the agent's runtime context. Using the initial target and the list of currently completed subtasks, perform logical verification on the single fused snapshot and generate verification results; When the verification result is passed, the long-term task is released from suspension and the agent is driven to re-initiate the state transition to the current target node. When the verification result is unsuccessful, a manual intervention alarm signal is triggered, and the long-term task remains suspended.
8. The method for maintaining consistency of long-term tasks by an intelligent agent based on long-term memory according to claim 2, characterized in that, In response to the second control command, the steps that trigger the agent to perform local memory filtering operations on the historical memory snapshot sequence specifically include: In response to the second control command, the generation timestamps of each historical memory snapshot in the historical memory snapshot sequence are obtained; The generated timestamp is compared with the current system time of the agent's operating environment to obtain the time difference. Based on the preset exponential time decay function and the time difference, the decay weight of each historical memory snapshot is calculated. Historical memory snapshots with a decay weight lower than a preset weight threshold are removed from the historical memory snapshot sequence, while historical memory snapshots with a decay weight greater than or equal to the preset weight threshold are retained, generating a filtered memory snapshot sequence. The filtered sequence of memory snapshots is input into the agent's context window to assist in state transitions.
9. The method for maintaining consistency of long-term tasks by an intelligent agent based on long-term memory according to claim 1, characterized in that, Long-term tasks include enterprise-level core system disaster recovery tasks, external asynchronous interrupt events include secondary alarm events caused by underlying hardware instability, and intelligent agents are autonomous intelligent agents used to perform enterprise-level core system disaster recovery tasks.
10. The method for maintaining consistency of long-term tasks by an intelligent agent based on long-term memory according to claim 9, characterized in that, The task execution log includes at least one of the following: database reconstruction log, microservice restart log, and network route reconfiguration log. The current state context includes the agent's current node permission information and current resource allocation status in the enterprise core system disaster recovery task.