Hierarchical memory and context management methods, devices, equipment, and storage media for long-term autonomous scientific experimental agents.
By employing hierarchical memory and context management methods, the problem of context exceeding capacity limits in long-term autonomous scientific experiments is solved. A three-layer collaborative architecture is constructed to ensure that the agent has complete context information at each step of decision-making, thereby achieving the reliability and security of the agent.
Patent Information
- Application Number
- CN202611576719.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-10-13
- Publication Date
- 2026-11-10
AI Technical Summary
In existing technologies, during long-term autonomous scientific experiments, the content of the context exceeds the capacity limit of the mainstream LLM context window, resulting in the truncation of key decision-making information and weakening the agent's long-term reasoning and adaptive decision-making capabilities.
By adopting a hierarchical memory and context management approach, a three-layer collaborative architecture is constructed by generating recent full-volume structured data, long-term structured summary data, and global progress overview data. This ensures the retrieval of long-term historical data and forms a complete context space by monitoring and constraining agent operations through an interception system.
It enables the agent to have an accurate snapshot of the current state, a complete causal chain of recent operations, and a searchable knowledge base of long-term history at each decision step, ensuring the reliability and safety of the agent in long-term autonomous scientific experiments.
Smart Images

Figure CN123068433A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the fields of artificial intelligence and scientific experiment automation, and in particular to a hierarchical memory and context management method, apparatus, device and storage medium for a long-term autonomous scientific experiment agent. Background Technology
[0002] Long-duration autonomous scientific experiments refer to experimental processes executed continuously by intelligent agents for several hours to tens of hours without human intervention. These experiments encompass multiple stages, including data acquisition, environmental modeling, parameter decision-making, operation execution, result verification, and anomaly handling. Typical long-duration autonomous scientific experiments include, but are not limited to: scanning tunneling microscopy (STM) atomic manipulation experiments, automated chemical synthesis and characterization experiments, high-throughput material screening experiments, autonomous data acquisition experiments at synchrotron radiation beamlines, long-term electron microscopy imaging experiments, and robot-assisted biological experiments. These experiments share common characteristics: a large number of operation steps (typically hundreds to thousands), irreversible single-step operations with strict process dependencies, and highly structured parameter spaces in the real-time generated experimental data.
[0003] In recent years, autonomous agents based on Large Language Models (LLMs) have been widely explored for automation in various scientific experiments. In this framework, the LLM acts as the decision-making core, responsible for receiving real-time experimental status, planning the next step, setting operational parameters, and handling anomalies, thus constructing a closed-loop control system of "observation-decision-execution-verification." However, applying LLM to long-term scientific experiments faces a bottleneck in context management: as the number of experimental steps accumulates, the length of the LLM's input context expands linearly, exceeding the context window capacity limit of mainstream LLMs and causing inference costs and latency to continuously increase with each step. More importantly, when the context exceeds the window limit and is forcibly truncated, crucial decision information from early experiments (such as the effectiveness of a parameter combination under certain conditions) is permanently lost, severely weakening the agent's long-term inference and adaptive decision-making capabilities.
[0004] It is evident that existing technologies still need improvement and enhancement. Summary of the Invention
[0005] In view of the shortcomings of the prior art, the purpose of this invention is to provide a hierarchical memory and context management method, device, equipment and storage medium for long-term autonomous scientific experimental agents. It aims to solve the technical problem in the prior art that in long-term scientific experiments, the content of the context exceeds the capacity limit of the mainstream LLM context window, resulting in the truncation and loss of key decision information in the context input to the agent, which seriously weakens the agent's long-term reasoning and adaptive decision-making capabilities.
[0006] To achieve the above objectives, the present invention adopts the following technical solution: The first aspect of this invention provides a hierarchical memory and context management method for a long-term autonomous scientific experimental agent, comprising the following steps: before each round of agent inference invocation, generating recent full-scale structured data of the most recent N steps of operation according to a preset number of steps N (N is greater than 0); for long-term operation steps exceeding the number of steps N, converting them into standardized long-term structured summary data through a deterministic rule function; traversing the global experimental state objects in real time and dynamically synthesizing structured global progress overview data; inputting the recent full-scale structured data, long-term structured summary data, and global progress overview data into the agent as context information used for agent inference; monitoring the agent's operations, using a preset interception system to intercept and structure the agent's inappropriate operations, archiving the interception records to long-term structured summary data, and simultaneously using the interception records as behavioral health indicators for statistical analysis; and before the next round of agent inference invocation, injecting the interception statistical results as constraint prompts into the context information used for inference, for feedback to the agent for learning.
[0007] The hierarchical memory and context management method for long-term autonomous scientific experimental agents, wherein the interception system includes parameter security verification, spatial and conditional constraint verification, process dependency chain mandatory verification, and target fidelity verification.
[0008] The hierarchical memory and context management method for long-term autonomous scientific experimental agents, wherein the process dependency chain forced verification specifically includes: setting the type of core operation, traversing backward from the historical tail operation data of the agent, locating the index of the most recent core operation from the historical tail, establishing Boolean judgments for each subsequent step, outputting corresponding forced instructions based on the true value combination of the Boolean judgments, and combining the proposed next operation with the Boolean judgment to determine whether the operation violates the preset interception rules. If it violates the rules, the operation is intercepted and the reason for rejection is fed back.
[0009] The hierarchical memory and context management method for long-term autonomous scientific experimental agents includes the following steps: obtaining a user-specified list of task objectives and extracting the target identifier of the operation proposed by the agent from the action parameter field of the structured operation request output by the agent in each round of decision-making; comparing the extracted target identifier with the list of task objectives and the record of completed objectives; if the target identifier does not belong to the list of task objectives or points to a completed objective, then the operation is intercepted and a rejection reason is fed back.
[0010] The hierarchical memory and context management method for long-term autonomous scientific experimental agents further includes: constructing an active injection channel and setting active injection trigger conditions, wherein the trigger conditions are that the previous operation step is verified as failed, the current process dependency chain is incomplete, or the previous operation is intercepted; setting corresponding mandatory instructions for the trigger conditions, and injecting the mandatory instructions into the context information when the context information obtained by the agent meets the trigger conditions.
[0011] The hierarchical memory and context management method for long-term autonomous scientific experimental agents further includes: constructing an autonomous query channel and setting up a historical query tool for the agent to actively invoke based on its own judgment to retrieve data from the long-term structured summary data; and setting recommended usage times and parameter templates for historical queries to trigger the agent to actively retrieve data.
[0012] The hierarchical memory and context management method for long-term autonomous scientific experimental agents, wherein the input of recent full-volume structured data, long-term structured summary data, and global progress overview data into the agent as context information for inference, further includes: assembling multiple information segments into context information according to a preset multi-segment splicing protocol, wherein the multi-segment splicing protocol specifies the sequential assembly of the following information segments: mandatory instruction segment, user instruction segment, global status overview segment, recent step segment, and system prompt segment; the mandatory instruction segment informs the agent of the specific operation that must be performed next; the user instruction segment is the original user instruction superimposed with the result of explicit parameter extraction; the global status overview segment includes the global progress overview data; the recent step segment includes the recent full-volume structured data and long-term structured summary; and the system prompt segment includes role definition, complete tool description, decision principles, safety boundary constraints, and suggestions on when to use historical query tools.
[0013] A second aspect of the present invention provides a hierarchical memory and context management device for a long-term autonomous scientific experimental agent, comprising: The first generation module is used to generate the recent full-scale structured data of the most recent N steps of operation before each round of agent inference call, based on a preset number of steps N, where N is greater than 0. The second generation module is used to transform long-term operation steps exceeding the number of steps N into standardized long-term structured summary data through deterministic rule functions. The third generation module is used to traverse the global experimental state object in real time and dynamically synthesize structured global progress overview data. The input module is used to input the recent full-volume structured data, the long-term structured summary data, and the global progress overview data into the agent as context information used by the agent for reasoning. The monitoring module is used to monitor the operations of the agent. It uses a preset interception system to intercept inappropriate operations of the agent and record them in a structured manner. The interception records are archived to long-term structured summary data. The interception records are also used as behavioral health indicators of the agent for statistical analysis. Before the next round of agent inference, the interception statistics are injected as constraint prompts into the context information used for inference and fed back to the agent for learning.
[0014] A third aspect of the present invention provides a hierarchical memory and context management device for a long-term autonomous scientific experimental agent, comprising a memory and at least one processor, wherein the memory stores computer-readable instructions; the at least one processor invokes the computer-readable instructions in the memory to execute the various steps of the hierarchical memory and context management method for a long-term autonomous scientific experimental agent as described above.
[0015] A fourth aspect of the present invention provides a computer-readable storage medium storing computer-readable instructions, which, when executed by a processor, implement the various steps of the hierarchical memory and context management method for long-term autonomous scientific experimental agents as described above.
[0016] Beneficial Effects: This invention provides a hierarchical memory and context management method for long-term autonomous scientific experimental agents. It constructs a three-layer collaborative architecture by building recent, fully structured data to ensure complete temporal context required for local decision-making; by generating persistent, long-term structured summary data from historical steps; and by automatically traversing global experimental state objects to synthesize real-time global progress overview data. This architecture constitutes a complete three-dimensional context space including global situation, local details, and long-term knowledge. This ensures the retrievability of long-term historical data without compromising context space as the number of steps increases. Furthermore, it allows the agent to simultaneously possess an accurate snapshot of the current state, a complete causal chain of recent operations, and a retrievable knowledge base of long-term history at each decision step. In addition, this invention monitors and constrains the agent's operations to ensure reliability in long-term autonomous scientific experiments. Attached Figure Description
[0017] Figure 1 The first flowchart for a hierarchical memory and context management method for long-term autonomous scientific experimental agents.
[0018] Figure 2 This is the second flowchart for a hierarchical memory and context management method for long-term autonomous scientific experimental agents.
[0019] Figure 3 This is a block diagram of the overall system structure of Example 1.
[0020] Figure 4This is a schematic diagram of a hierarchical memory and context management device for a long-term autonomous scientific experimental agent provided in an embodiment of the present invention.
[0021] Figure 5 A schematic diagram of the structure of a hierarchical memory and context management device for a long-term autonomous scientific experimental agent provided in an embodiment of the present invention. Detailed Implementation
[0022] This invention provides a hierarchical memory and context management method, apparatus, device, and storage medium for long-term autonomous scientific experimental intelligent agents. To make the objectives, technical solutions, and effects of this invention clearer and more explicit, the invention is further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only for explaining the invention and are not intended to limit the invention.
[0023] Please see Figure 1 The first aspect of this invention provides a hierarchical memory and context management method for a long-term autonomous scientific experimental agent, comprising the following steps: S101. Before each round of agent inference, generate recent full-scale structured data of the most recent N steps based on the preset number of steps N, where N is greater than 0. S102. For forward operation steps exceeding the number of steps N, transform them into standardized forward structured summary data through a deterministic rule function; S103. Real-time traversal of global experimental state objects, dynamic synthesis of structured global progress overview data; S104. Input the recent full-volume structured data, the long-term structured summary data, and the global progress overview data into the agent as context information used by the agent for reasoning; S105. Monitor the agent's operations, use a preset interception system to intercept improper operations of the agent and record them in a structured manner, archive the interception records to long-term structured summary data, and use the interception records as behavioral health indicators of the agent for statistical analysis, and inject the interception statistics as constraint prompts into the context information used for reasoning before the next round of agent inference calls, so as to feed back to the agent for learning.
[0024] This invention employs a three-layer collaborative design: Recent, Archive, and Synthetic Summary. Its core design idea is to hierarchically manage experimental data within the agent's context along a dual axis of "time decay × information granularity."
[0025] Step S101 is used to construct a sliding window real-time context layer (Recent Layer). By setting step N, the Recent Layer uses a fixed-length sliding window to ensure the complete temporal context required for local decision-making, and provides the agent with complete observability of the local temporal causal chain.
[0026] Step S102 is used to construct the structured archive layer. The archive layer compresses and persists historical steps in a structured format, ensuring the retrievability of long-term historical data and preventing it from crowding out the context space as the number of steps increases. When each step is completed, the system uses a set of deterministic rule functions to transform it into standardized structured archive entries (such as retaining only the step identifier, spatial context, key parameters, result and failure classification fields), which are then written to the archive layer in an additive manner.
[0027] Step S103 is used to construct the global state summary layer. The summary layer is automatically synthesized in real time by the system through the global experimental state objects before each round of agent inference. It forms compact structured data such as task completion degree, operation statistics, and condition availability matrix into key decision variables, which serve as the deterministic input for the top-level situational awareness of the agent.
[0028] In this invention, memory decay is not determined autonomously by the agent (to avoid accidentally discarding key experimental parameters), but is driven by a fixed deterministic state machine of "stepping, window overflow, and compressed archiving," ensuring the auditability and reproducibility of memory management. At the same time, the complementary information relationship between the Summary layer and the Recent / Archive layer constitutes a complete three-dimensional context space including global situation, local details, and long-term knowledge, enabling the agent to have an accurate snapshot of the current state, a complete causal chain of recent operations, and a searchable knowledge base of long-term history at each step of decision-making.
[0029] In terms of physical implementation, the Recent layer directly reuses the history list (a linear sequence of StepRecord objects in memory). Each StepRecord contains an operation name, complete call parameters, and a natural language description as the payload, along with a success flag, a structured result data dictionary, a timestamp, and observation text. The Archive layer persists structured files in the experiment directory in an incremental mode. Each archive entry is serialized into a unified mode, containing a step index, timestamp, operation name, agent decision reason, experimental condition identifiers (such as spatial coordinates, sample number, channel identifier, etc.), operation parameters, execution result, failure type, and verification comparison data.
[0030] Furthermore, this invention also ensures that the behavioral boundaries of the agent in long-term autonomous experiments are constrained by setting up an interception system, so that the agent will not make major mistakes in decision-making due to the accumulation of biases in long-term autonomous decision-making.
[0031] From a mechanistic perspective, this embodiment employs a global state real-time synthesis and operation-level tracking mechanism. The core innovation of this mechanism lies in its independent reliance on the LLM agent to parse the current experimental progress from historical dialogue text (which carries the risk of information extraction omissions and erroneous inferences). Instead, before each round of inference, the system uses a deterministic algorithm to traverse the experimental runtime objects and historical step sequences, automatically synthesizing a structured progress overview. The synthesis algorithm includes: (i) Task completion statistics: traversing the state history, counting the total number of executions of all operations (not grouped by operation type); and counting the number of successful and failed operations based on the verification judgment results, using the sum of successful and failed operations as the total judgment count, and calculating the global real-time success rate (the proportion of successful operations to the total judgment count); (ii) Operation-level statistics: using "where to do it" as the outer grouping key (such as experimental chamber number, sample batch, spatial coordinates, etc., depending on the specific experimental field) and "to whom to do it" as the inner sub-key (such as target atom number, reaction intermediate identifier, characterization index name, etc.), traversing all historical steps, independently tracking the number of operation attempts and verification failures for each target, and... The system reads the complete list of available targets from the current environment model and generates a complete state record including untried targets, making the availability and historical performance of each target clear to the LLM; (iii) Process dependency chain state determination: Set the type of core operation. Core operations refer to operations that change the physical state of the experimental object and whose effects must be confirmed by subsequent closed-loop steps (such as atomic manipulation actions in the STM atomic manipulation example; while observation, modeling, verification and other steps that do not change the state of the object are ordinary operations). Traverse backward from the end of the history, locate the core operation closest to the end of the history, check whether there are necessary subsequent steps such as observation, modeling, and verification after it, determine the missing links one by one and generate accurate mandatory constraint prompts. In addition, the global progress overview data also includes the record of intercepting improper operations. This record counts the number of times improper operations are intercepted as a behavioral health indicator of the agent.
[0032] Another key feature of this operation-level tracking mechanism is its complete cross-session recoverability. Because each StepRecord is persisted as an independent structured file, when an experiment is interrupted and resumed due to device failure, network outage, or user-initiated pause, the runtime state can be restored from the checkpoint. The entire history list and operation state dictionary can then be reconstructed from the step file directory, including the number of operations for each target, success / failure status, and recent operation parameters. This ensures that the progress overview seen by the LLM agent after resumption is completely consistent with that before the interruption, preventing context breakage issues such as "forgetting targets already attempted" or "repeating completed operations."
[0033] For the interception system, in practical implementation, an event-driven hook interception system can be introduced. This system constructs a set of registerable and composable lightweight interceptor pipelines between the agent's decision output and hardware execution. Each hook listens to a specific decision event (such as "before operation initiation" or "before hardware instruction is issued" `pre_dispatch`). When the agent proposes an operation, all hooks registered to that event are triggered sequentially, independently checking whether the proposed operation meets its assigned constraints. If it does, the hook silently passes; if not, the hook intercepts the operation, generates a structured interception reason, and feeds it back to the agent, which must then reselect. The hook pipeline itself does not participate in positive decision-making; it does not tell the agent what it should do, but only prevents the agent from doing what it shouldn't. The agent retains complete decision-making autonomy and operates only within a safe space constrained by the hook boundaries.
[0034] In a first implementation of the first aspect of this invention, the interception system includes parameter security verification, spatial and conditional constraint verification, process dependency chain enforcement verification, and target fidelity verification. This embodiment defines four standard hooks, covering four orthogonal dimensions: experimental process logic, operational scope, hardware security, and task boundaries. Hook I: Parameter Safety Hook (registered in the pre_dispatch event). This hook verifies that all numerical parameters are within hardware safety limits (such as voltage range ±10V, current limit, temperature limit, pressure limit, etc.). This is a standard safety check already present in most laboratory automation systems, and this invention incorporates it into the hook pipeline as a standard component.
[0035] Hook II: Spatial / Conditional Constraint Hook (registered in the pre_execute event). This hook checks whether the target of the proposed operation is within the currently observed valid range. In STM embodiments, it checks whether the coordinates of the manipulated target are within the current scan field of view (e.g., within a 20×20 nm range) to prevent "blind manipulation" of unscanned areas; in chemical synthesis experiments, it can check whether the target reactor is in a usable state and whether the required reagents are prepared.
[0036] Hook III: Process Dependency Chain Enforcement Verification Hook (registered in the pre_execute event). This hook maintains an operation dependency declaration, defining the causal preconditions for each operation. Let a complete "operation and verification" cycle be an ordered tuple M = (core operation, observation and acquisition, environment modeling, result verification). The dependency chain integrity constraint requires that for any two adjacent core operations in the history, the three verification steps of observation and acquisition, environment modeling, and result verification must be strictly included in sequence. The dependency chain state determination algorithm traverses backward from the end of the history, locates the index of the most recent core operation, establishes Boolean judgments for each subsequent step, outputs precise enforcement instructions based on the true value combination, and combines the proposed next operation with the Boolean judgment to determine whether the operation violates the preset interception rules. If it violates the rules, the operation is intercepted and the reason for rejection is fed back. For example, "for (has_scan, has_model, !has_compare), it is determined that result verification must be performed," and "for (has_scan, has_model, has_compare, compare_success), it is determined that the dependency chain is complete and the next operation can be performed." Meaning of each marker: has_scan indicates whether observation and data collection has been performed, has_model indicates whether environment modeling has been performed, has_compare indicates whether result verification has been performed, compare_success indicates whether the result verification was successful; the symbol "!" indicates logical negation, that is, this step was not performed.
[0037] Preferably, the interception rules also include six typical violation patterns: continuous core operations, core operations plus skipping observation and verification, continuous verification operations, repeated historical queries with the same parameters, ending the task before the dependency chain is complete, and modeling without observation after the core operation.
[0038] Hook IV: Target Fidelity Hook (registered in the pre_execute event). This hook compares the target identifier of the operation proposed by the agent with the user-specified list of task targets. If the agent attempts to operate on a target not in the task list (such as unspecified cell coordinates in the STM embodiment), or attempts to repeat an operation on a target already marked as "completed," the hook triggers an interception and returns to the current task state. This hook ensures that the agent cannot unilaterally expand, shrink, or deviate from the user-specified task scope. The agent has complete autonomy over "how to complete," but "what to complete" is defined by the user and cannot be modified by the agent.
[0039] In summary, this embodiment uses the method of hooking the pipeline to transform the physical constraint of scientific experiments—"the need to see the actual data after the operation before determining whether the operation was successful"—into an insurmountable hard boundary in the agent's decision space. Simultaneously, it covers behavioral boundary constraints across four dimensions—process, space, parameters, and objective—through hooking I-IV. This mechanism is the core guarantee for enabling the agent to operate safely and reliably during long-term (tens of hours or even days) autonomous experiments.
[0040] Please see Figure 2 In a second implementation of the first aspect of the present invention, the hierarchical memory and context management method for the long-term autonomous scientific experimental agent further includes: S201. Construct an active injection channel and set the triggering conditions for active injection. The triggering conditions are: the previous operation step is verified as failed, the current process dependency chain is incomplete, or the previous operation is intercepted. S202. Set a corresponding mandatory instruction for the triggering condition. When the context information obtained by the agent meets the triggering condition, inject the mandatory instruction into the context information. S203. Construct an autonomous query channel and set up a historical query tool for the intelligent agent to actively call based on its own judgment to retrieve data in the long-term structured summary data; S204. Set the recommended timing and parameter template for using historical queries to trigger the agent to actively retrieve data.
[0041] Existing LLM agents typically employ a single mode for memory access: either the system automatically injects a preset range of historical information before each round of inference (passive supply mode), or the LLM agent relies entirely on itself to call retrieval tools to obtain historical data (active query mode). The drawback of the passive supply mode is its fixed supply range, which cannot respond to the dynamic information needs generated by the LLM agent during operation. For example, after consecutive failures, the LLM agent might want to find out "which parameters succeeded in similar failure cases," but the system has not predefined such push rules. The drawback of the active query mode is its reliance on the LLM agent's retrieval intention; for example, the LLM agent may miss key information due to "retrieval laziness," which is particularly evident in long-term operation. This implementation integrates the two modes complementaryly into a dual-channel collaborative mechanism: (a) System-initiated injection channel: When the decision context of the LLM agent meets specific triggering conditions (such as the previous operation step being verified as a failure, the current process dependency chain being incomplete, or the previous operation being intercepted by a hook), the system automatically injects mandatory instructions into the context, clearly informing the LLM agent of the current state and the next operation that must be performed. The essence of this channel is rule-driven deterministic context injection: the triggering conditions are objectively determined by the system state and do not depend on whether the LLM agent remembers to retrieve them, thus serving as a safety net for information integrity at key decision nodes.
[0042] In this context, "the previous operation step was verified as a failure" means that after execution, following verification such as experimental result validation, target fidelity verification, or environmental status feedback, the operation was determined to have failed to achieve its preset target or produced abnormal results that did not comply with experimental safety or constraints. This failure determination is output by the system-side verification logic and is not subjectively judged by the LLM agent. For example, in the STM embodiment, "the previous operation step was verified" refers to the comparison verification after manipulation (compare_scan); "determined as a failure" means that the verification gave a determination that the expected effect was not achieved (atoms are still present and have not been removed).
[0043] (b) LLM Agent Autonomous Query Channel: The LLM agent can proactively retrieve Archive layer data at any time based on its own judgment using the historical query tool: querying historical response characteristics under the selected new target; querying similar failure cases after consecutive failures to obtain parameter adjustment references; and querying the effective parameter distribution in global successful cases when parameters are uncertain. The system prompt embeds recommended usage times and parameter templates for historical queries, guiding the LLM agent to proactively retrieve data at appropriate decision boundaries. The recommended usage times refer to decision node scenarios pre-written in the system prompt that are suitable for triggering historical retrieval in the Archive layer. These scenarios guide the LLM agent to autonomously determine when to call the historical query tool, and are not mandatory triggering conditions. The LLM agent autonomously chooses whether to initiate a retrieval at this time based on the current experimental context. For example, calling the tool to query the target manipulation history before first manipulating a target, or querying similar failure cases after multiple consecutive failures in manipulating a target.
[0044] Both channels share the same underlying structured filtering engine, ensuring semantic consistency and reproducible logic in the results regardless of which channel triggers the retrieval. System-initiated injection serves as a deterministic safety net, while autonomous querying by the LLM agent provides flexibility. The former ensures the LLM agent never misses necessary information at critical nodes, while the latter empowers the LLM agent to explore beyond predefined boundaries in a wider range of scenarios.
[0045] Furthermore, the autonomous query channel applicable to agents, combined with the aforementioned long-term structured summary data, can form a structured multi-layered filtering retrieval mechanism. This scheme differs from the general LLM agent's use of embedding vectors for semantic similarity retrieval. The general LLM agent has inherent limitations with parameterized experimental data: for example, in STM experiments, "bias2.0V" and "bias 2.1V" have low correlation in the semantic vector space, but are highly correlated in physical experiment decisions. This invention employs a structured multi-layered precise filtering strategy organized around experimental dimensions for historical data retrieval. Each archived entry in the Archive layer (long-term structured summary data) uses experimental condition identifiers, target identifiers, failure types, operation parameters, and execution results as queryable structured dimensions. The historical query tool, a read-only tool directly accessible to the LLM agent, supports any combination of the following precise filtering dimensions: precise matching of condition identifiers, prefix matching of target identifiers, precise string matching of failure types, binary filtering of results, filtering of operation types, step range constraints, and limitations on the number of results.
[0046] The advantages of this structured filtering strategy compared to embedding retrieval are as follows: the results are completely deterministic, and the same query conditions always return the same result set; the process is fully traceable, and the intermediate results of each layer of filtering can be reviewed and reproduced; no additional infrastructure is required, and it does not rely on vector databases or dedicated embedding models, with all filtering logic being pure memory operations; the domain adaptation is precise, and the equivalence of experimental conditions and the precise matching of failure types are more suitable for parameterized, structured, and deterministic scientific experimental data scenarios than semantic similarity.
[0047] In a third implementation of the first aspect of the present invention, the step of inputting the recent full-volume structured data, the long-term structured summary data, and the global progress overview data into the agent as context information used for agent inference further includes: According to a preset multi-segment splicing protocol, multiple information segments are assembled into context information. The multi-segment splicing protocol specifies that the following information segments are assembled in sequence, including: mandatory instruction segment, user instruction segment, global status overview segment, recent step segment, and system prompt segment. The mandatory instruction segment tells the agent the specific operation that must be performed next. The user instruction segment is the original user instruction superimposed with the result of explicit parameter extraction; The global status overview section includes the global progress overview data; The most recent step segment includes the recent full structured data and the long-term structured summary; The system prompts include role definitions, complete tool descriptions, decision-making principles, security boundary constraints, and suggestions on when to use the historical query tool.
[0048] In this implementation, the context assembly before each round of LLM agent inference follows a fixed multi-segment splicing protocol, and its assembly order and semantic layering are as follows: (a) Mandatory instruction segment: When the previous operation is intercepted by the system or the current process dependency chain is missing, the highest priority mandatory instruction is automatically generated, which clearly informs the LLM of the specific operation that must be executed next. The operation that must be executed next is not dynamically generated, but is a deterministic lookup table output with truth value combination as index, and the mapping rule of truth value combination corresponding to instruction is adopted; if multiple triggering conditions are met at the same time, priority mutual exclusion ensures that the instruction is uniquely determined; (b) User instruction segment: The original user instruction is superimposed with the explicit parameter extraction result (experimental condition identifier, target identifier, operation number automatically extracted by LLM from natural language). (c) Global Status Overview: The system traverses the experimental status objects in real time, extracting device connection status, recently acquired parameters, environmental model statistics, number of executed steps, and operation-level statistics grouped by conditions, including the number of attempts, failures, remaining available attempts, and abandonment status of each operation, presented in structured text; (d) Recent Steps: The most recent N steps are extracted from the end of the history record, and a dedicated formatted summary is generated according to the operation type, including the parameter values used, the target condition identifier, the observation text summary of the acquisition / verification type, and whether each step is successful or not; (e) System Prompt: Includes role definition, complete tool description, decision principles, security boundary constraints, and suggestions on when to use the historical query tool.
[0049] The following are more specific embodiments to illustrate this solution.
[0050] Example 1: Application of the present invention in long-duration autonomous scientific experimental agents in STM atomic manipulation experiments. STM atomic manipulation is an experimental technique for precisely manipulating individual atoms at the nanoscale, and it is widely used in cutting-edge fields such as surface science and quantum device fabrication. A complete STM atomic manipulation experiment typically involves multiple steps, including scanning imaging, model surface, target atom selection, probe movement (FolMe), bias pulse application, and post-manipulation verification (Compare Scan). The entire execution cycle can take several hours to tens of hours and involves hundreds of operational steps.
[0051] Please see Figure 3In this embodiment, the action space of the LLM agent includes eight tools: scan (scanning the surface to acquire images), model_surface (performing lattice modeling on the scanned image, locating cells and atoms), correct_drift (template matching to estimate and compensate for drift), manipulate_atom (complete manipulation pipeline: marking → probe movement → bias pulse), compare_scan (comparing and verifying local images before and after manipulation), query_history (querying historical experimental records), finish (task completed, ending the loop), and stop (unrecoverable error, requesting user intervention). Specific implementation details are as follows: (1) A global state real-time synthesis and operation-level tracking mechanism is adopted. Before each round of LLM agent inference, the system traverses the experimental state objects, extracts the hardware connection state, the most recent scan parameters (center coordinates, scan size), surface model statistics (number of cells and number of atoms), the total number of steps executed, and the atomic-level manipulation statistics matrix grouped by cell, the manipulation count, failure count, remaining available count, and abandoned state of each atom, and presents them in structured text. The operation-level retry constraint in the progress overview is a fixed upper limit for each atom granularity (max_attempts_per_atom, default value is 3). When the manipulation count of an atom reaches the upper limit, the system marks it as "abandoned" in the overview, and the LLM agent will naturally know that the atom can no longer be used. The process dependency chain state determination algorithm traverses backward from the end of the history, determines whether there are three verification operations after manipulation: scan, model_surface, and compare_scan, determines the missing link one by one and generates precise constraint prompts.
[0052] (2) A structured multi-layered filtering retrieval mechanism is adopted: Each archived entry in the Archive layer uses cell coordinates (cell, a binary integer tuple), atom identifier (atom_id, a structured string), failure type (failure_type, a controlled vocabulary enumeration with values such as "atom_not_removed", "hardware_disconnected", "move_failed", "pulse_failed", "tool_failed", etc.), manipulation parameters (params, including numerical fields such as bias_V and pulse_width_s), and execution result (result, a binary value of success / fail). The query history tool supports arbitrary Boolean combinations of six dimensions: exact cell matching, atom_id_prefix prefix matching, exact string matching of failure_type, binary filtering of result, tool name filtering, and step range constraints. The above identifiers are explained as follows: "atom_not_removed" (the atom was not removed, meaning the target atom still exists after verification), "hardware_disconnected" (hardware connection interrupted), "move_failed" (probe movement failed), "pulse_failed" (bias pulse application failed), "tool_failed" (tool execution failed), etc.
[0053] bias_V (bias voltage, in volts), pulse_width_s (pulse width, in seconds) and the execution result (result, a binary value of success / fail, i.e., success / failure) are used as queryable structured dimensions.
[0054] atom_id_prefix prefix matching (atomic identifier prefix matching, such as the prefix "(-1,0)" can match all atomic identifiers under cell (-1,0).
[0055] (3) Adopting a dual-channel memory access paradigm: When the Push channel is in the retry decision state after the LLM operation fails, the system rules constrain the automatic injection of a forced instruction into the context. The LLM tool calls the Pull channel to query the historical response characteristics of the cell before selecting a new target atom (e.g., query condition {"cell": [-1, 1], "result": "success"}), and after consecutive failures, it queries similar failure cases to obtain parameter adjustment references (e.g., query condition {"failure_type": "atom_not_removed"}).
[0056] (4) The event-driven Hook interception and process dependency chain forced verification mechanism are adopted: The specific implementation of the four standard hooks in the STM embodiment is as follows: Hook I (process dependency chain hook) defines the manipulation-verification cycle as an ordered quadruple M = (manipulate_atom, scan, model_surface, compare_scan), maintains the declarative dependencies of tools such as manipulate_atom / compare_scan / model_surface, registers them in the pre_execute event, and intercepts six typical violation patterns: continuous core operation (continuous manipulate_atom), core operation → skip observation → verification (skip scan and directly compare_scan), continuous verification operation (continuous compare_scan), repeated history query with the same parameters (repeated query_history with the same parameters), finish the task before the dependency chain is complete (finish before the dependency chain is complete), and model without observation after core operation (model_surface directly without scan after manipulation); Hook II (spatial constraint hook) checks whether the cell coordinates of the manipulated target are within the current scan field of view (20×20 Within a certain range (nm), "blind operation" attempts are intercepted; Hook III (parameter safety hook) verifies that parameters such as bias amplitude (±10V range), pulse width, and tunnel current are within hardware limits; Hook IV (target fidelity hook) compares the manipulation target proposed by the LLM with the user-specified target cell / atom list, intercepting manipulation requests for completed or non-specified targets. Hook interception events are written to the Archive in a structured format (including hook type, details of rejected operations, and LLM correction results), and the Synthetic Summary is injected with "interception counts of each hook type within the most recent M steps," providing real-time meta-aware feedback on the reliability of LLM behavior.
[0057] Example 2: Application of the present invention in automated chemical synthesis experiments using a long-duration autonomous scientific experimental agent. In automated chemical synthesis experiments, the core operations are chemical reaction steps (such as feeding, heating, and reflux), observation and acquisition correspond to online analysis (such as gas chromatography and mass spectrometry), environmental modeling corresponds to reaction system state modeling (temperature, pressure, concentration), and result verification corresponds to product separation and characterization. Experimental condition identifiers can be replaced with reactor number, batch number, etc. In high-throughput material screening experiments, the core operations are sample loading and parameter scanning, observation and acquisition correspond to characterization measurements (XRD, SEM, etc.), and experimental condition identifiers can be replaced with sample number, component ratio, etc. In synchrotron radiation beamline experiments, the core operations are beam alignment and energy scanning, observation and acquisition correspond to detector signal readings, and experimental condition identifiers can be replaced with beamline number, energy range, etc.
[0058] This technical solution can be extended to other scientific experimental scenarios. In each scenario, the architecture of the four-layer mechanism (state synthesis, structured retrieval, dual-channel access, and dependency chain verification) remains unchanged. Only the domain-specific tool definitions, condition identifier formats, and dependency chain structures need to be replaced.
[0059] In summary, the hierarchical memory and context management method for long-term autonomous scientific experimental agents of the present invention employs four mechanisms to achieve the four core objectives of context management for LLM agents in long-term autonomous scientific experiments, including: controllable token consumption, complete short-term temporal causal chain guarantee, searchable long-term structured knowledge persistence, and deterministic experimental process security guarantee.
[0060] The global state real-time synthesis and operation-level tracking mechanism has the following technical effects: Taking the STM atomic manipulation example, the operation-level statistical matrix eliminates the need for the LLM agent to infer the state of each target from historical dialogues before each round of inference, such as which has been tried, which has succeeded, which has remaining attempts, and which has been abandoned. All of this is presented in deterministic structured text. The LLM agent no longer suffers from cognitive biases such as "mistakenly believing a target has not been tried and retrying" or "not knowing a target has failed multiple times and continuing to retry ineffectively," significantly improving the quality of target switching decisions. In the chemical synthesis example, this mechanism can track the completion status, yield, purity, and other key indicators of each reaction step, enabling the LLM agent to accurately grasp the state of each intermediate in the synthesis path. Cross-session recoverability ensures that the progress overview seen by the LLM agent after the experiment is resumed is completely consistent with that before the interruption. This mechanism transforms the LLM agent's situational awareness from "self-understanding after reading historical text" to "reading the deterministic structured report generated by the system," which completely eliminates the risk of information extraction omissions and inference errors.
[0061] The structured multi-layer filtering retrieval mechanism offers the following technical advantages: Taking the STM atomic manipulation example, precise equivalence matching of spatial coordinates ensures that the retrieval results only include historical records related to the current target space, avoiding cross-regional noise interference. The failure type field of the controlled vocabulary makes the retrieval of failure patterns completely deterministic. The mechanism's zero external dependency characteristic (pure in-memory filtering, requiring no vector database or embedding service) allows for direct deployment in the constrained computing environment of experimental control computers. In the high-throughput materials screening example, this mechanism supports precise querying of historical experimental records by multiple dimensions such as material composition, synthesis conditions, and characterization results.
[0062] The dual-channel memory access paradigm has the following technical effects: the system rule constraint push channel acts as a deterministic safety net, ensuring that the LLM agent will always obtain the correct context constraints at key decision nodes, and will not miss key information even if the LLM agent does not actively search; the LLM agent tool call pull channel gives the agent the ability to autonomously acquire information in a wider range of scenarios, and the LLM agent can actively query history at any time according to current needs, rather than passively accepting the information push range predefined by the system.
[0063] The event-driven Hook interception and process dependency chain forced verification mechanism has the following technical effects: This mechanism, in the form of a hook interception pipeline, constructs four layers of deterministic safety boundaries between LLM agent decision-making and hardware execution, including: Hook I (process dependency chain) ensures that each operation follows physical causality, fundamentally eliminating the possibility of skipping critical verification steps; Hook II (spatial / conditional constraints) prevents "blind operation" of unobserved areas; Hook III (parameter safety) ensures that hardware operation parameters are within safety limits; and Hook IV (goal fidelity) ensures that the LLM agent does not deviate from the user-specified task scope. More importantly, the hook system transforms the behavior drift of the LLM agent from an unobservable hidden danger into an explicit, measurable, structured signal. Each interception event is recorded and archived to the Archive layer, and Hook interception statistics are injected into the Synthetic Summary as a meta-aware indicator of the LLM agent's "behavioral health," realizing a closed loop of "intercepting and recording behavior failures, followed by feedback learning." This mechanism internalizes the physical constraints of scientific experiments into the hard boundary of the LLM agent's decision space, which is the core pillar of the safety and reliability of the entire autonomous experimental system.
[0064] The hierarchical memory and context management method for long-term autonomous scientific experimental agents in this invention has been described above. The hierarchical memory and context management device for long-term autonomous scientific experimental agents in this invention is described below. Please refer to [link to relevant documentation]. Figure 4One embodiment of the hierarchical memory and context management device for long-term autonomous scientific experimental agents in this invention includes: The first generation module 10 is used to generate recent full-volume structured data of the most recent N steps of operation before each round of intelligent agent inference call, based on a preset number of steps N, where N is greater than 0. The second generation module 20 is used to transform long-term operation steps exceeding the number of steps N into standardized long-term structured summary data through a deterministic rule function. The third generation module 30 is used to traverse the global experimental state object in real time and dynamically synthesize structured global progress overview data. The input module 40 is used to input the recent full-volume structured data, the long-term structured summary data and the global progress overview data into the agent as context information used by the agent for reasoning. The monitoring module 50 is used to monitor the operation of the intelligent agent. It uses a preset interception system to intercept improper operations of the intelligent agent and record them in a structured manner. The interception records are archived to long-term structured summary data. The interception records are also used as behavioral health indicators of the intelligent agent for statistical analysis. Before the next round of intelligent agent inference, the interception statistics are injected as constraint prompts into the context information used for inference and fed back to the intelligent agent for learning.
[0065] The above describes in detail the hierarchical memory and context management device of the long-term autonomous scientific experimental intelligent agent in the embodiments of the present invention from the perspective of modular functional entities. The following describes in detail the hierarchical memory and context management device of the long-term autonomous scientific experimental intelligent agent in the embodiments of the present invention from the perspective of hardware processing.
[0066] Figure 5This is a schematic diagram of a hierarchical memory and context management device for a long-term autonomous scientific experimental agent provided in an embodiment of the present invention. The hierarchical memory and context management device 900 for the long-term autonomous scientific experimental agent can vary considerably due to different configurations or performance. It may include one or more central processing units (CPUs) 910 (e.g., one or more processors) and a memory 920, and one or more storage media 930 (e.g., one or more mass storage devices) for storing application programs 933 or data 932. The memory 920 and storage media 930 can be temporary or persistent storage. The program stored in the storage media 930 may include one or more modules (not shown in the diagram), each module may include a series of instruction operations on the hierarchical memory and context management device 900 for the long-term autonomous scientific experimental agent. Furthermore, the processor 910 may be configured to communicate with the storage media 930 and execute a series of instruction operations in the storage media 930 on the hierarchical memory and context management device 900 for the long-term autonomous scientific experimental agent to implement the steps of the hierarchical memory and context management method for the long-term autonomous scientific experimental agent provided in the above-described method embodiments.
[0067] The hierarchical memory and context management device 900 for long-duration autonomous scientific experimental agents may also include one or more power supplies 940, one or more wired or wireless network interfaces 950, one or more input / output interfaces 960, and / or one or more operating systems 931, such as Windows Server, Mac OS X, Unix, Linux, FreeBSD, etc. Those skilled in the art will understand that... Figure 5 The hierarchical memory and context management device structure shown for a long-term autonomous scientific experimental agent does not constitute a limitation on the hierarchical memory and context management device for a long-term autonomous scientific experimental agent. It may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0068] The present invention also provides a computer-readable storage medium, which can be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. The computer-readable storage medium stores instructions that, when executed on a computer, cause the computer to perform the steps of a hierarchical memory and context management method for a long-term autonomous scientific experimental agent.
[0069] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the device or apparatus described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0070] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0071] It is understood that those skilled in the art can make equivalent substitutions or modifications to the technical solution and inventive concept of the present invention, and all such substitutions or modifications should fall within the protection scope of the appended claims.
Claims
1. A hierarchical memory and context management method for a long-term autonomous scientific experimental agent, characterized in that, Includes the following steps: Before each round of agent inference, based on the preset number of steps N (N is greater than 0), the recent full-scale structured data of the most recent N steps of operation is generated. For long-term operational steps exceeding N steps, they are transformed into standardized long-term structured summary data through deterministic rule functions; Real-time traversal of global experiment status objects, dynamically synthesizing structured global progress overview data; The recent full-volume structured data, the long-term structured summary data, and the global progress overview data are input into the agent as context information used for agent reasoning. The system monitors the agent's operations and uses a pre-set interception system to intercept and record inappropriate actions. The interception records are archived to long-term structured summary data. The interception records are also used as behavioral health indicators of the agent for statistical analysis. Before the next round of agent inference, the interception statistics are injected as constraint prompts into the context information used for inference, and fed back to the agent for learning.
2. The hierarchical memory and context management method for long-term autonomous scientific experimental agents according to claim 1, characterized in that, The interception system includes parameter security verification, spatial and conditional constraint verification, process dependency chain mandatory verification, and target fidelity verification.
3. The hierarchical memory and context management method for long-term autonomous scientific experimental agents according to claim 2, characterized in that, The process dependency chain mandatory verification specifically includes: Set the type of core operation, traverse backwards from the end of the agent's historical operation data, locate the index of the most recent core operation from the end of the history, establish Boolean judgments for each subsequent step, output corresponding forced instructions based on the true value combination of the Boolean judgments, and combine the proposed next operation with the Boolean judgments to determine whether the operation violates the preset interception rules. If it violates the rules, the operation is intercepted and the reason for rejection is fed back.
4. The hierarchical memory and context management method for long-term autonomous scientific experimental agents according to claim 2, characterized in that, The target fidelity verification includes: Obtain the user-specified list of task objectives, and extract the target identifier of the operation proposed by the agent from the action parameter field of the structured operation request output by the agent in each round of decision-making; The extracted target identifier is compared with the task target list and the completed target record; if the target identifier does not belong to the task target list or points to a completed target, the operation is blocked and a rejection reason is reported.
5. The hierarchical memory and context management method for long-term autonomous scientific experimental agents according to claim 1, characterized in that, Also includes: Construct an active injection channel and set the trigger conditions for active injection. The trigger conditions are: the previous operation step is verified as failed, the current process dependency chain is incomplete, or the previous operation is intercepted. A corresponding mandatory instruction is set for the triggering condition. When the context information obtained by the agent meets the triggering condition, the mandatory instruction is injected into the context information.
6. The hierarchical memory and context management method for long-term autonomous scientific experimental agents according to claim 1, characterized in that, Also includes: An autonomous query channel is constructed, and a historical query tool is set up for the intelligent agent to actively call based on its own judgment to retrieve data from the long-term structured summary data; Set recommended usage times and parameter templates for historical queries to trigger the agent to actively retrieve data.
7. The hierarchical memory and context management method for long-term autonomous scientific experimental agents according to claim 1, characterized in that, The step of inputting the recent full-volume structured data, the long-term structured summary data, and the global progress overview data into the agent as context information for the agent's reasoning also includes: According to a preset multi-segment splicing protocol, multiple information segments are assembled into context information. The multi-segment splicing protocol specifies that the following information segments are assembled in sequence, including: mandatory instruction segment, user instruction segment, global status overview segment, recent step segment, and system prompt segment. The mandatory instruction segment tells the agent the specific operation that must be performed next. The user instruction segment is the original user instruction superimposed with the result of explicit parameter extraction; The global status overview section includes the global progress overview data; The most recent step segment includes the recent full structured data and the long-term structured summary; The system prompts include role definitions, complete tool descriptions, decision-making principles, security boundary constraints, and suggestions on when to use the historical query tool.
8. A hierarchical memory and context management device for a long-term autonomous scientific experimental intelligent agent, characterized in that, include: The first generation module is used to generate the recent full-scale structured data of the most recent N steps of operation before each round of agent inference call, based on a preset number of steps N, where N is greater than 0. The second generation module is used to transform long-term operation steps exceeding the number of steps N into standardized long-term structured summary data through deterministic rule functions. The third generation module is used to traverse the global experimental state object in real time and dynamically synthesize structured global progress overview data. The input module is used to input the recent full-volume structured data, the long-term structured summary data, and the global progress overview data into the agent as context information used by the agent for reasoning. The monitoring module is used to monitor the operations of the agent. It uses a preset interception system to intercept inappropriate operations of the agent and record them in a structured manner. The interception records are archived to long-term structured summary data. The interception records are also used as behavioral health indicators of the agent for statistical analysis. Before the next round of agent inference, the interception statistics are injected as constraint prompts into the context information used for inference and fed back to the agent for learning.
9. A hierarchical memory and context management device for a long-term autonomous scientific experimental intelligent agent, characterized in that, It includes a memory and at least one processor, wherein the memory stores computer-readable instructions; the at least one processor invokes the computer-readable instructions in the memory to perform the steps of the hierarchical memory and context management method for a long-term autonomous scientific experimental agent as described in any one of claims 1-7.
10. A computer-readable storage medium storing computer-readable instructions thereon, characterized in that, When the computer-readable instructions are executed by the processor, they implement the various steps of the hierarchical memory and context management method for long-term autonomous scientific experimental agents as described in any one of claims 1-7.
