A method for dynamic context cleaning and pollution suppression for long-range intelligent agents

By generating structured retention templates and semantic placeholders in long-range intelligent agents, the problem of accidental deletion of irrelevant information and loss of technical details in context management is solved, and accurate information recovery and secure compression are achieved.

CN123115334APending Publication Date: 2026-11-17XIDIAN UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611336072.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-31
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

In context management of long-range intelligent agents, existing technologies struggle to effectively prevent the accidental deletion of irrelevant information and the loss of technical details, especially during the exploration phase and when information needs are unclear. Existing methods may lead to the premature deletion of important information or the inability to accurately recover compressed content.

Method used

The main intelligent agent generates a structured retention template, stores the original observations and generates reference pointers, determines the fragments to be retained and discarded based on template verification, generates semantic placeholders, performs filtering and observation verification, and reloads the target original text when necessary to ensure accurate information recovery.

Benefits of technology

It achieves control before irrelevant information affects subsequent reasoning, avoids accidental deletion and loss of information, ensures the original text recoverability of technical details, and balances context compression and information security.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123115334A_ABST
    Figure CN123115334A_ABST
Patent Text Reader

Abstract

This invention provides a method for dynamic context cleanup and pollution suppression for long-range intelligent agents, comprising: generating tool actions and structured retention templates through the main intelligent agent; executing tool actions to obtain original observations and storing them to generate reference pointers; when the template verification passes, extracting retention fragments and determining discard fragments according to retention conditions or preset retention ranges based on the filtering mode, generating semantic placeholders and determining filtered observations; writing filtered observations into the activity context after passing verification, and determining safe observations based on retention fragments or original observations if the verification fails; when the template verification fails, using the original observations as safe observations; generating a reload request containing reference pointers and reload ranges based on the semantic placeholders, reading the target original text from the stored original observations and writing it into the activity context. This invention balances context compression and information security, not only avoiding accidental deletion of important information during the exploration phase, but also ensuring the recoverability of the original text of technical details.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of artificial intelligence technology, specifically relating to a method for dynamic context cleaning and pollution suppression for long-range intelligent agents. Background Technology

[0002] Large language model agents have been used for long-duration tasks such as software defect repair, web page manipulation, file processing, data analysis, and multi-tool collaboration. In the reasoning and action loop, the agent generates tool actions based on the current context. The tool or environment returns search results, code files, terminal logs, or web page content, which the system then appends to the context. As the number of interaction steps increases, tool observations typically occupy the majority of the context capacity, while the content that truly influences the next decision in a single return may only be a small number of function definitions, error lines, or configuration fields.

[0003] Existing context management typically employs sliding windows, historical summaries, observation masking, or proactive reconstruction. These processes mostly occur after the original observations have been written into the activity context and participated in at least one round of inference. Once irrelevant fragments in the original observations induce incorrect hypotheses, invalid tool calls, or intermediate conclusions, subsequent deletion or compression of the original fragments is unlikely to eliminate the established behavioral chains. Furthermore, the coarse-grained truncation or summarization of the entire round may alter file paths, line numbers, error codes, numerical values, and code symbols.

[0004] When exploring unfamiliar files or conducting broad searches, if strict target criteria are always used for filtering, important information that has not yet been identified may be deleted prematurely; if only compressed rewritten content is saved, it will be impossible to recover the technical details later according to the original text and the precise scope. Summary of the Invention

[0005] To address the aforementioned problems in the existing technology, this invention provides a method for dynamic context cleaning and pollution suppression for long-range intelligent agents. The technical problem to be solved by this invention is achieved through the following technical solution: In a first aspect, the present invention provides a method for dynamic context cleaning and pollution suppression for long-range intelligent agents, comprising: Based on the activity context, the main agent generates tool actions and their corresponding structured, preserved templates. Execute the tool action to obtain the original observation, store the original observation and generate the corresponding reference pointer; The structured retention template is validated. If the validation passes, a filtering mode and retention conditions are determined based on the structured retention template. Based on the filtering mode, retention fragments are extracted from the original observations according to the retention conditions or a preset retention range, and discard fragments are determined. Semantic placeholders are generated based on the discard fragments and the reference pointers. Filtered observations are determined based on the retained fragments and the semantic placeholders. Filtered observations are validated. If the validation passes, the filtered observations are written into the activity context. If the validation fails, safe observations are determined based on the retained fragments, or the original observations are determined as safe observations. If the template validation fails, the security observation is determined based on the original observation; the security observation is then written into the activity context. When the main agent determines that the discarded fragment needs to be recovered based on the semantic placeholder, the main agent generates a reload request including the reference pointer and the reload range, reads the target original text from the stored original observation according to the reload request, and writes the target original text into the activity context; The main agent continues to generate tool actions based on the updated activity context until the task result is obtained.

[0006] Secondly, the present invention provides a context dynamic cleanup and pollution suppression system for long-range intelligent agents, comprising: The tool generation module is used to generate tool actions and their corresponding structured preserved templates by the main intelligent agent based on the activity context. The tool interaction module is used to execute the tool actions and obtain the raw observations; The original observation storage module is used to store the original observations and generate corresponding reference pointers; A dual-mode filtering module is used to perform template validation on the structured retention template. When the template validation is passed, the filtering mode and retention conditions are determined based on the structured retention template. Based on the filtering mode, retention fragments are extracted from the original observations according to the retention conditions or a preset retention range, and discard fragments are determined. Semantic placeholders are generated based on the discard fragments and the reference pointers. Filtered observations are determined based on the retained fragments and the semantic placeholders. Filtered observations are validated. When the filtered observation validation is passed, the filtered observations are written into the activity context. When the filtered observation validation is not passed, safe observations are determined based on the retained fragments, or the original observations are determined as safe observations. When the template validation is not passed, safe observations are determined based on the original observations. The safe observations are written into the activity context. The target original text reading module is used to generate a reload request including the reference pointer and reload range through the main agent when the main agent determines that the discarded segment needs to be recovered according to the semantic placeholder, read the target original text from the stored original observation according to the reload request, and write the target original text into the activity context. The iterative control module is used to continue generating tool actions based on the updated activity context through the main agent until the task result is obtained.

[0007] Thirdly, the present invention provides an electronic device, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; The memory is used to store computer programs; When the processor executes the computer program stored in the memory, it implements the steps of the context dynamic cleaning and pollution suppression method for long-range intelligent agents provided in the first aspect.

[0008] Compared with the prior art, the beneficial effects of the present invention are as follows: The present invention provides a context dynamic cleanup and pollution suppression method for long-range intelligent agents. The main intelligent agent generates tool actions and their corresponding structured retention templates based on the activity context, moving the decision to retain or discard items forward to before the observations are written. By fully storing the original observations and generating reference pointers after the tool returns, and then performing filtering, the discarded content has the basis for accurate on-demand recovery, avoiding the loss of technical details caused by only saving compressed and rewritten content. Through template validation of the structured retention template, when it passes, the method extracts the retained fragments from the original observations according to the retention conditions or preset retention range based on the filtering mode, and determines the discard fragments. This ensures that filtering occurs before the original observations are written into the activity context. When the objective is clear, the target mode achieves accurate extraction based on conditions; when the information requirement is unclear, the exploration mode achieves conservative truncation. By analyzing the discard fragments... The invention generates semantic placeholders using reference pointers and combines them with retained fragments to determine filtered observations. These placeholders replace discarded content to achieve context compression while preserving memory cues and recovery paths. Filtered observations are validated; those that pass are written to the activity context, while those that fail are either confirmed as safe observations based on retained fragments or the original observations are confirmed as safe observations, preventing information loss due to erroneous filtering. When template validation fails, safe observations are confirmed based on the original observations and written to the activity context, avoiding silent information loss due to template anomalies. When the main agent determines that discarded fragments need to be recovered based on semantic placeholders, a reload request containing reference pointers and reload ranges is generated. The target original text is read from the stored original observations and written to the activity context, enabling subsequent recovery of technical details according to the original text and precise range without re-executing the tool. Ultimately, this invention controls information entry before irrelevant information affects subsequent reasoning, balancing context compression and information security. This not only avoids accidental deletion of important information during the exploration phase but also ensures the recoverability of the original text of technical details.

[0009] The present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description

[0010] Figure 1 This is a schematic diagram illustrating the implementation process of a context dynamic cleanup and pollution suppression method for long-range intelligent agents provided in an embodiment of the present invention; Figure 2 This is a schematic diagram of the structure of a context dynamic cleanup and pollution suppression system for long-range intelligent agents provided in an embodiment of the present invention; Figure 3 This is a schematic diagram of the hardware entity of an electronic device to which embodiments of the present invention are applied. Detailed Implementation

[0011] The present invention will be further described in detail below with reference to specific embodiments, but the implementation of the present invention is not limited thereto.

[0012] Example 1 Please see Figure 1 , Figure 1 This is a schematic diagram illustrating the implementation process of a context dynamic cleanup and pollution suppression method for long-range intelligent agents provided in an embodiment of the present invention. Figure 1 As shown, the context dynamic cleanup and pollution suppression method for long-range intelligent agents provided in this embodiment of the invention may include the following steps: Step S101: Based on the activity context, generate tool actions and their corresponding structured retention templates through the main agent.

[0013] In one possible implementation, the main agent can determine the current sub-goal based on the activity context, generate tool actions based on the current sub-goal, and determine the return content filtering conditions based on the current sub-goal and the tool actions. In the same output of generating the tool actions, a structured retention template is composed of a pattern identifier used to indicate the target mode or exploration mode, a purpose description used to describe the current sub-goal, and retention conditions used to characterize the return content filtering conditions.

[0014] The structured retention template is used to fix the local intent at the time of the tool call as parsable data, so that subsequent filtering does not have to deduce the purpose of the tool call from the already grown complete trajectory. The current sub-target is the local problem that needs to be solved at the moment. The retention condition field is used to characterize the filtering conditions of the returned content. The returned content filtering conditions can include the file path to be matched, function definition, error level, configuration field, return value, target string or adjacent line range.

[0015] For example, the structured retention template can be represented in formats such as JSON, XML, YAML, function call parameters, typed objects, or fixed field text. The pattern identifier can be either the targeted pattern or the exploratory pattern, the purpose description contains the current local problem, and the retention condition field contains the content to be matched corresponding to the filter conditions of the returned content.

[0016] In one possible implementation, the structured retain template can also include a discard hint field to mark noise such as test directory references, duplicate logs, import statements, or irrelevant call points. An example of the structured retain template is as follows: {"mode":"targeted|exploratory","purpose":"...","retain":["..."],"discard_hint":"..."}; Where mode is the mode identifier, purpose is the purpose description, retain is the retention condition, and discard_hint is the discard hint field.

[0017] Optionally, provided that the structured retention template is available before the corresponding original observation is written into the activity context and can express the pattern identifier, purpose description and retention conditions, the structured retention template can also be generated by a planner, rule system or independent intent model.

[0018] In the above implementation, the structured template and tool actions are output in the same round, which can avoid additional calls to the main agent.

[0019] Step S102: Execute the tool action to obtain the original observation, store the original observation and generate the corresponding reference pointer.

[0020] In one possible implementation, a reference pointer to the original observation can be generated based on at least one of the step identifier of the current processing step, the tool identifier corresponding to the tool action, and the session identifier of the current task.

[0021] For example, raw observations may include search hits, code content, test logs, web page nodes, table records, or API return fields, etc.

[0022] After obtaining the raw observations, the raw observations can be stored in a memory key-value store, disk file, database, object storage, or content-addressable storage, and a reference pointer corresponding to the raw observations can be generated based on at least one of the step identifier of the current processing step, the tool identifier corresponding to the tool action, and the session identifier of the current task.

[0023] The original observation, line offset index, and integrity check value can be stored in association with a reference pointer. This allows the original observation to be located using the reference pointer, the target text to be determined using the line offset index, and the target text to be verified using the integrity check value when reading the target text based on a reload request. Specifically, the line offset index is used to convert the line range into the original text position, and the integrity check value is used to detect whether the stored or reloaded content has changed.

[0024] The steps described above for storing the original observations are performed before filtering the original observations and updating the activity context, so that even if only a small number of literal fragments are retained in the activity context, the original text initially returned by the tool can still be recovered.

[0025] Step S103: Perform template validation on the structured retention template. If the template validation passes, determine the filtering mode and retention conditions based on the structured retention template. Based on the filtering mode, extract the retention fragments from the original observations according to the retention conditions or preset retention range and determine the discard fragments. Generate semantic placeholders based on the discard fragments and reference pointers. Determine the filtered observations based on the retained fragments and semantic placeholders. Perform filtered observation validation on the filtered observations. If the filtered observation validation passes, write the filtered observations into the activity context. If the filtered observation validation fails, determine safe observations based on the retained fragments, or determine the original observations as safe observations.

[0026] In one possible implementation, depending on the filtering mode, retainable segments are extracted from the original observations according to retention conditions or a preset retention range, and discardable segments are determined. This includes: when the filtering mode is target mode, based on the purpose description and retention conditions, identifying literal content in the original observations that meets the return content filtering conditions, and using the literal content that meets the return content filtering conditions and its adjacent content within a predetermined range (such as a predetermined number of adjacent lines) as retainable segments, and using other content as discardable segments; when the filtering mode is exploration mode, using the range between the beginning and end determined based on the length of the original observations and preset head retention amount (such as 30 lines, or other values ​​set according to actual conditions) and tail retention amount (such as 20 lines, or other values ​​set according to actual conditions) as a preset retention range, using the head literal content and tail literal content within the preset retention range as retainable segments, and using the middle content as discardable segments.

[0027] For example, the returned content filtering criteria are filtering logic derived from a combination of the purpose description and retention criteria. The beginning and end ranges can be the sum of the beginning retention amount and the end retention amount. When the sum of the beginning and end retention amounts is not greater than the length of the original observation, the beginning and end retention amounts do not need to be adjusted. When the sum of the beginning and end retention amounts is greater than the length of the original observation, the beginning and end retention amounts can be adaptively reduced until the sum of the beginning and end retention amounts is not greater than the length of the original observation. Then, the beginning and end ranges are determined based on the sum of the beginning and end retention amounts, and these ranges are used as the preset retention ranges. The beginning and end retention amounts can be adjusted according to the tool type, context margin, and the length of the original observation.

[0028] The target mode is suitable for calls with explicit information requirements, such as locating a specific function definition, extracting error lines, or reading a specific field from a configuration file. The lightweight filtering model (which can be a dual-mode filtering module) selects only literal substrings (i.e., literal content) from the original observations that meet the content filtering criteria as retained content (i.e., retained fragments), without interpreting, merging, or rewriting the retained content; a predetermined number of adjacent lines (e.g., 5, or other values ​​set according to actual conditions) can be attached before and after the hit line to maintain local semantic integrity.

[0029] The exploration mode is suitable for scenarios such as browsing unfamiliar files for the first time, broadly searching code structures, or reading unknown web pages. Since it is impossible to accurately list all retention conditions in the above scenarios, the initial and final literal content of the original observation can be retained based on a preset retention range, while the intermediate content is hidden, in order to reduce the probability of accidental deletion caused by strict screening.

[0030] Optionally, the target mode and exploration mode can be extended to multiple levels such as strict target mode, weak target mode, abnormal mode and complete retention mode, and the mode can be selected according to the confidence of the structured retention template, tool type, context margin or historical accidental deletion.

[0031] In the above process, the lightweight filtering model only receives the current structured retention template, the current original observation, the row number of the original observation, and the reference pointer, without reading the complete activity context. Optionally, provided that the output can distinguish between retained and discarded fragments, the lightweight filtering model can be replaced by keyword matching, regular expression matching, syntax tree analysis, similarity judgment, classifier, or multi-level filters.

[0032] In the above process, the granularity of extracting literal content can be lines, sentences, paragraphs, code blocks, syntax tree nodes, log events, structured fields, web page nodes, or database records.

[0033] In one possible implementation, semantic placeholders are generated based on discarded fragments and reference pointers, and filtered observations are determined based on retained fragments and semantic placeholders. This includes: determining the discard scale based on the number of rows or structured units of the discarded fragments; generating a semantic description to characterize the hidden content and its possible uses based on the content category and purpose description of the discarded fragments; combining the discard scale, semantic description, and reference pointers into semantic placeholders; and replacing the discarded fragments with semantic placeholders according to the order of the retained and discarded fragments in the original observations, while retaining the literal content of the retained fragments, to obtain filtered observations.

[0034] For example, semantic placeholders are used to mark that a section of content is hidden, the approximate category of the hidden content, and the location of the original text. An example format is "[Hidden: Line 193 | Summary: Test directory cross-references and irrelevant module call points | Reference: Step 12 - Tool 3]". In semantic placeholders, the semantic description serves only as an index hint and does not replace the original text.

[0035] If the original observation contains multiple discontinuous discarded segments, semantic placeholders can be generated for each discarded segment. Then, according to the order of the discarded segments in the original observation, the semantic placeholders corresponding to each discarded segment can be alternately combined with multiple retained segments. This can maintain the local order of the original observation and make it easier for the main agent to understand the relationship between the retained segments.

[0036] In one possible implementation, filtering observations are validated, including: parsing the filtering observations to obtain format validation results; performing string matching or offset matching between each retained segment and the original observations to obtain literal fidelity validation results; comparing each retained segment with the retention conditions to obtain retention condition coverage validation results; validating the discard scale, semantic description, and reference pointer in the semantic placeholders to obtain placeholder validation results; if the format validation results, literal fidelity validation results, retention condition coverage validation results, and placeholder validation results all indicate that the validation has passed, the filtering observation validation is deemed to have passed; if any one of the format validation results, literal fidelity validation results, retention condition coverage validation results, and placeholder validation results indicates that the validation has failed, the filtering observation validation is deemed to have failed.

[0037] For example, one can check whether the overall structure of the filtered observations conforms to the expected format, such as whether the placeholder fields are complete, whether the JSON structure is valid, and whether the components are arranged in a predetermined order, to obtain the format verification result; one can verify whether each retained fragment is directly taken from the original text of the original observation by means of exact string matching or position matching by line offset / byte offset, to obtain the literal fidelity verification result; one can verify whether the retained fragments completely cover the retention conditions specified in the structured retention template (such as whether the objective function definition is included, whether the error level matches, whether the specified configuration fields are extracted, etc.), to obtain the retention condition coverage verification result; one can verify whether the discard scale (the number of hidden rows or units) is accurate, whether the semantic description (the category and possible use of the hidden content) exists, and whether the reference pointer is resolvable (whether the original observation in external storage can be successfully located), to obtain the placeholder verification result.

[0038] In one possible implementation, when a filtered observation fails the validation, a safe observation is determined based on the retained fragments, or the original observation is determined as a safe observation. This includes: when the filtered observation fails the validation, expanding the range of the retained fragments and updating the discarded fragments; generating an updated placeholder based on the updated discarded fragments; combining the expanded retained fragments and the updated placeholder as a candidate safe observation; performing a filtered observation validation on the candidate safe observation; when the candidate safe observation passes the filtered observation validation, the candidate safe observation is determined as a safe observation; when the candidate safe observation fails the filtered observation validation, the original observation is determined as a safe observation.

[0039] For example, when a filtered observation fails the validation, the system can perform a conservative rollback: relax the retention criteria, expand the range of retained fragments (e.g., increase the number of preceding and following context lines, expand the matching range, or lower the matching threshold), and re-extract retained fragments from the original observations based on the expanded retained fragments, while simultaneously updating the discarded fragments; generate updated placeholders based on the updated discarded fragments, and combine the expanded retained fragments with the updated placeholders to form candidate safe observations; perform filtered observation validation again on the candidate safe observations. If the candidate safe observation passes the filtered observation validation, it is determined as a safe observation; if the candidate safe observation fails the filtered observation validation, the rollback is terminated, the original observation is determined as a safe observation, and the safe observation is written into the activity context to ensure that information is not silently lost due to filtering uncertainty.

[0040] In one possible implementation, when template validation fails, a safe observation is determined based on the original observation, including: when the structured preserved template fails to parse, a field is missing, or the structure does not match the original observation, the template validation fails, and the original observation is combined with the template anomaly marker into a safe observation.

[0041] Step S104: If the template validation fails, determine the safe observations based on the original observations; write the safe observations into the activity context.

[0042] For example, if the template validation fails, the original observation can be identified as a safe observation and marked as an anomaly, and the identified safe observation can be written into the activity context.

[0043] In one possible implementation, if the original observation is an error message or permission prompt, it can also be identified as a safe observation and marked as an exception.

[0044] Step S105: When the main agent determines that the discarded segment needs to be recovered based on the semantic placeholder, the main agent generates a reload request including a reference pointer and a reload range. Based on the reload request, the target original text is read from the stored original observations and written into the activity context.

[0045] In one possible implementation, the main agent can determine the hidden content related to the current sub-target based on the semantic description and the current activity context, determine the reload range corresponding to the hidden content, and generate a reload request. The reload range includes line range, byte offset range, structured fields, or record identifiers. The stored original observation is located based on the reference pointer, the target original text is extracted from the stored original observation based on the reload range, and the target original text is written into the activity context.

[0046] For example, during the subsequent reasoning process of the main agent based on the activity context, when the semantic summary in the semantic placeholder indicates that hidden content may resolve the current uncertainty, the current reasoning assumption depends on details that may have been filtered out and requires counterfactual verification, or subsequent tool actions malfunction and require backtracking to the most recently relevant placeholder, the main agent determines that the discarded fragment needs to be restored. At this time, the main agent can determine the hidden content related to the current sub-target in the hidden discarded fragment based on the semantic description in the semantic placeholder and the current activity context, and determine the specific location range of the hidden content in the original observation, generating a reload request containing a reference pointer and a reload range. The reload range specifies the specific range from which the original text is restored from the original observation; it can be a start and end line range, a byte offset range, a structured field identifier, or a record identifier. If the reload range is omitted, the reload request points to the complete original observation. The system performs a search in external storage based on the reference pointer in the reload request to locate the stored original observation; then, based on the reload range, it extracts the target original text from the original observation and appends the target original text to the activity context for the main agent to continue reasoning. The above reload process only involves local reading of the current observation. Its search cost is independent of the trajectory length, and technical details can be restored according to the original text and precise range without re-executing the tool actions.

[0047] Step S106: The main agent continues to generate tool actions based on the updated activity context until the task result is obtained.

[0048] For example, the main agent can generate the next inference, tool action, and corresponding structured retention template based on the current activity context. If the tool action is not a stopping action, the tool action is executed and the original observation is obtained. After updating the activity context through template verification, retention fragment extraction, filtered observation verification, writing to the activity context, and on-demand reload steps, the main agent generates subsequent inference and tool actions again based on the updated activity context, and iteratively executes the above steps. If the tool action generated by the main agent is a stopping action, or the number of iterations reaches the preset maximum number of steps (such as a value between 20 and 50, or other values ​​set according to the actual situation), the loop terminates, and the task result is output based on the current activity context.

[0049] Example 2 In one possible implementation, the method of this invention is applied to a code repair task, where the main agent needs to locate a function named `authenticate`. The main agent generates a recursive search action and produces a structured retention template of the target pattern in the same output. The target field is to find the definition of the `authenticate` function and exclude test files. Retention criteria include the line starting with the function definition statement and the five lines before and after it. Discard hints include test directories, import statements, and irrelevant modules.

[0050] The tool environment returns 200 lines of search results, which can be completely saved and reference pointers generated. The dual-mode filtering module extracts seven lines of original text containing function definitions based on retention criteria, identifying the remaining 193 lines as discarded segments. Semantic placeholders are generated to describe cross-references in the test directory and irrelevant module call points, recording the number of discarded lines and reference pointers within the placeholders. The activity context only receives the seven lines of original text and the semantic placeholders.

[0051] During subsequent diagnostics, if the main agent determines, based on semantic placeholders, that the test reference may involve a missing mock object, it generates a reload request containing a reference pointer and the corresponding line range. The on-demand reload module directly reads the original text of that line range from external storage and writes it into the activity context, without needing to perform a recursive search again.

[0052] Example 3 In one possible implementation, experiments cover four types of long-term task benchmarks: Software Engineering Benchmark Verification Set (SWE-benchVerified), General AI Assistant benchmark (GAIA), WebArena benchmark, and Tool-Agent-User Interaction Benchmark (τ-bench), to verify the applicability of the method of the present invention in different scenarios. Among them, SWE-benchVerified belongs to the software defect repair task, which requires the agent to solve real-world software problems on GitHub and has a high observation-inference ratio; GAIA belongs to the general information processing task, which involves search, file processing, and computation; WebArena belongs to the web interaction task, which is used to simulate web navigation, forms, and information retrieval; and τ-bench belongs to the tool interaction task, which involves structured interactions between tools, agents, and users.

[0053] The method in this invention employs a Just-In-Time Directed Forgetting (JIT-Forget) mechanism. The main agent is Claude Sonnet, and the lightweight filtering model is Claude Haiku. Neither the main agent nor the lightweight filtering model performs weight updates. Compared to a baseline without context management, the method of this invention improves the success rate of various tasks. The success rate of software defect repair tasks increases from 28.4% to 44.7%, and the peak active context tokens decrease from 84.3K to 36.2K.

[0054] In a comparison of keeping the main agent, lightweight filtering model, and structured retention template unchanged while only changing the timing of filtering, the success rate of filtering immediately after the original observations are returned is 44.7%; after delays of 5, 10, and 20 steps, it drops to 41.2%, 37.8%, and 33.1%, respectively. This result indicates that filtering at a time before the original observations are written into the activity context is more effective in blocking subsequent behavioral chains triggered by irrelevant observations.

[0055] In a single erroneous content injection test, without context management, 71.3% of subsequent steps proceeded in the direction of the error, averaging 8.4 steps. Using the method described in this invention, this proportion decreased to 16.8%, and the average duration decreased to 1.9 steps. Removing the structured template, implementing safe rollback, dual-mode differentiation, or semantic description all reduced the task success rate, indicating that these steps collectively support contamination suppression and information recovery during the observation ingestion phase.

[0056] The present invention provides a context dynamic cleanup and pollution suppression method for long-range intelligent agents. The main intelligent agent generates tool actions and their corresponding structured retention templates based on the activity context, moving the decision to retain or discard items forward to before the observations are written. By fully storing the original observations and generating reference pointers after the tool returns, and then performing filtering, the discarded content has the basis for accurate on-demand recovery, avoiding the loss of technical details caused by only saving compressed and rewritten content. Through template validation of the structured retention template, when it passes, the method extracts the retained fragments from the original observations according to the retention conditions or preset retention range based on the filtering mode, and determines the discard fragments. This ensures that filtering occurs before the original observations are written into the activity context. When the objective is clear, the target mode achieves accurate extraction based on conditions; when the information requirement is unclear, the exploration mode achieves conservative truncation. By analyzing the discard fragments... The invention generates semantic placeholders using reference pointers and combines them with retained fragments to determine filtered observations. These placeholders replace discarded content to achieve context compression while preserving memory cues and recovery paths. Filtered observations are validated; those that pass are written to the activity context, while those that fail are either confirmed as safe observations based on retained fragments or the original observations are confirmed as safe observations, preventing information loss due to erroneous filtering. When template validation fails, safe observations are confirmed based on the original observations and written to the activity context, avoiding silent information loss due to template anomalies. When the main agent determines that discarded fragments need to be recovered based on semantic placeholders, a reload request containing reference pointers and reload ranges is generated. The target original text is read from the stored original observations and written to the activity context, enabling subsequent recovery of technical details according to the original text and precise range without re-executing the tool. Ultimately, this invention controls information entry before irrelevant information affects subsequent reasoning, balancing context compression and information security. This not only avoids accidental deletion of important information during the exploration phase but also ensures the recoverability of the original text of technical details.

[0057] Please see Figure 2 , Figure 2 This is a schematic diagram of a context dynamic cleaning and pollution suppression system for long-range intelligent agents provided by an embodiment of the present invention. The context dynamic cleaning and pollution suppression system for long-range intelligent agents provided by the present invention includes a tool generation module 201, a tool interaction module 202, a raw observation storage module 203, a dual-mode filtering module 204, a target original text reading module 205, and an iteration control module 206.

[0058] Among them, the tool generation module 201 is used to generate tool actions and their corresponding structured retention templates by the main intelligent agent according to the activity context; Tool interaction module 202 is used to execute tool actions and obtain raw observations; The original observation storage module 203 is used to store the original observations and generate corresponding reference pointers; The dual-mode filtering module 204 is used to perform template validation on the structured retention template. When the template validation is passed, the filtering mode and retention conditions are determined according to the structured retention template. According to the filtering mode, the retention fragments are extracted from the original observations according to the retention conditions or preset retention range, and the discard fragments are determined. Semantic placeholders are generated based on the discard fragments and reference pointers. Filtered observations are determined based on the retained fragments and semantic placeholders. Filtered observations are validated. When the filtered observation validation is passed, the filtered observations are written into the activity context. When the filtered observation validation is failed, safe observations are determined based on the retained fragments, or the original observations are determined as safe observations. When the template validation is failed, safe observations are determined based on the original observations. Safe observations are written into the activity context. The target original text reading module 205 is used to generate a reload request including a reference pointer and a reload range through the main agent when the main agent determines that the discarded segment needs to be recovered based on the semantic placeholder. Based on the reload request, the target original text is read from the stored original observation and written into the activity context. The iterative control module 206 is used to continue generating tool actions by the main agent based on the updated activity context until the task result is obtained.

[0059] Please see Figure 3 , Figure 3 This is a schematic diagram of the hardware entity of an electronic device to which an embodiment of the present invention applies. The electronic device provided in this embodiment includes a processor 301, a communication interface 302, a memory 303, and a communication bus 304, wherein the processor 301, the communication interface 302, and the memory 303 communicate with each other via the communication bus 304. Memory 303 is used to store computer programs; When the processor 301 executes the program stored in the memory 303, it implements the steps in the above method embodiments.

[0060] The communication bus 304 mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus 304 can be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, it is represented by only one thick line in the figure, but this does not indicate that there is only one bus or one type of bus.

[0061] Communication interface 302 is used for communication between the above-mentioned electronic device and other devices.

[0062] The memory 303 may include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory 303 may also be at least one storage device located remotely from the aforementioned processor.

[0063] The processor 301 mentioned above can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0064] The method provided in this invention can be applied to electronic devices. Specifically, the electronic device can be a desktop computer, a portable computer, a smart mobile terminal, a server, etc. No limitation is made herein; any electronic device that can implement this invention falls within the protection scope of this invention.

[0065] The present invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps provided in the above-described method embodiments.

[0066] For system / electronic device / storage medium embodiments, since they are basically similar to method embodiments, the description is relatively simple. For specific content and beneficial effects, please refer to the description of the method embodiments.

[0067] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. In addition, those skilled in the art can combine and integrate the different embodiments or examples described in this specification.

[0068] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems (devices), or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects, all of which are collectively referred to herein as "modules" or "systems." Furthermore, this application can take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code. The computer program may be stored / distributed in a suitable medium, provided with or as part of other hardware, or may take other distribution forms, such as via the Internet or other wired or wireless telecommunications systems.

[0069] This application is described with reference to flowchart illustrations and / or block diagrams of methods, systems (devices), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0070] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0071] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0072] The above description, in conjunction with specific preferred embodiments, provides a further detailed explanation of the present invention. It should not be construed that the specific implementation of the present invention is limited to these descriptions. For those skilled in the art, various simple deductions or substitutions can be made without departing from the concept of the present invention, and all such modifications and substitutions should be considered within the scope of protection of the present invention.

Claims

1. A method for dynamic context cleaning and pollution suppression for long-range intelligent agents, characterized in that, include: Based on the activity context, the main agent generates tool actions and their corresponding structured, preserved templates. Execute the tool action to obtain the original observation, store the original observation and generate the corresponding reference pointer; The structured retention template is validated. If the validation passes, a filtering mode and retention conditions are determined based on the structured retention template. Based on the filtering mode, retention segments are extracted from the original observations according to the retention conditions or a preset retention range, and discard segments are determined. Semantic placeholders are generated based on the discarded segments and the reference pointers. Filtered observations are determined based on the retained segments and the semantic placeholders. Filtered observations are validated. If the validation passes, the filtered observations are written into the activity context. If the filtered observation fails the verification, a safe observation is determined based on the retained fragment, or the original observation is determined as the safe observation. If the template verification fails, the security observation is determined based on the original observation; Write the security observation into the activity context; When the main agent determines that the discarded fragment needs to be recovered based on the semantic placeholder, the main agent generates a reload request including the reference pointer and the reload range, reads the target original text from the stored original observation according to the reload request, and writes the target original text into the activity context; The main agent continues to generate tool actions based on the updated activity context until the task result is obtained.

2. The method according to claim 1, characterized in that, The step of generating tool actions and their corresponding structured retention templates through the main agent based on the activity context includes: The main intelligent agent determines the current sub-target based on the activity context, generates the tool action based on the current sub-target, and determines the return content filtering conditions based on the current sub-target and the tool action. The structured retention template consists of a pattern identifier used to indicate the target mode or exploration mode, a purpose description used to describe the current sub-target, and retention conditions used to characterize the return content filtering conditions.

3. The method according to claim 2, characterized in that, The step of extracting and discarding fragments from the original observations according to the filtering mode, the retention conditions, or the preset retention range includes: When the filtering mode is the target mode, based on the purpose description and the retention conditions, literal content that meets the return content filtering conditions is determined in the original observation. The literal content that meets the return content filtering conditions and its adjacent content within a predetermined range are taken as the retained fragments, and the other content is taken as the discarded fragments. When the filtering mode is the exploration mode, the range of the beginning and end determined according to the length of the original observation and the preset beginning retention amount and the preset end retention amount is used as the preset retention range. The literal content of the beginning and the literal content of the end within the preset retention range are used as the retained segments, and the middle content is used as the discarded segments.

4. The method according to claim 2, characterized in that, The step of generating semantic placeholders based on the discarded fragments and the reference pointers, and determining filtered observations based on the retained fragments and the semantic placeholders, includes: The discard size is determined based on the number of lines or structured units of the discarded fragment; a semantic description is generated to characterize the hidden content and its possible uses based on the content category of the discarded fragment and the purpose description; the discard size, the semantic description, and the reference pointer are combined into the semantic placeholder. According to the order of the retained fragments and the discarded fragments in the original observations, the discarded fragments are replaced with the semantic placeholders, and the literal content of the retained fragments is retained to obtain the filtered observations.

5. The method according to claim 4, characterized in that, When the main agent determines that the discarded segment needs to be recovered based on the semantic placeholder, the main agent generates a reload request including the reference pointer and the reload range, reads the target plaintext from the stored original observations according to the reload request, and writes the target plaintext into the activity context, including: The main intelligent agent determines the hidden content related to the current sub-target based on the semantic description and the current activity context, and determines the reload range corresponding to the hidden content, and generates the reload request; the reload range includes line range, byte offset range, structured fields or record identifiers; The stored original observation is located according to the reference pointer, the target original text is extracted from the stored original observation according to the reload range, and the target original text is written into the activity context.

6. The method according to claim 1, characterized in that, The filtering observation verification includes: The filtered observations are parsed to obtain format verification results; each retained segment is matched with the original observation using string matching or offset matching to obtain literal fidelity verification results; each retained segment is compared with the retention conditions to obtain retention condition coverage verification results; the discard scale, semantic description, and reference pointer in the semantic placeholders are verified to obtain placeholder verification results. When the format verification result, the literal fidelity verification result, the retention condition coverage verification result, and the placeholder verification result all indicate that the verification has passed, the filtering observation verification is determined to have passed; when any one of the format verification result, the literal fidelity verification result, the retention condition coverage verification result, and the placeholder verification result indicates that the verification has failed, the filtering observation verification is determined to have failed.

7. The method according to claim 1, characterized in that, The step of determining a safe observation based on the retained fragment when the filtered observation fails the verification, or determining the original observation as the safe observation, includes: If the filtered observation fails the verification, the range of the retained fragments is expanded and the discarded fragments are updated. An updated placeholder is generated based on the updated discarded fragments. The expanded retained fragments and the updated placeholders are combined to form a candidate safe observation. The candidate safe observation is then verified by a filtered observation. If the candidate safe observation passes the filtered observation verification, it is determined as the safe observation. If the candidate safe observation fails the filtered observation verification, the original observation is determined as the safe observation. When the template validation fails, determining the security observation based on the original observation includes: If the structured retention template fails to parse, has missing fields, or does not match the structure of the original observation, the template validation is deemed to have failed, and the original observation and the template anomaly marker are combined into the safe observation.

8. The method according to claim 1, characterized in that, The process of storing the original observations and generating corresponding reference pointers includes: The reference pointer corresponding to the original observation is generated based on at least one of the step identifier of the current processing step, the tool identifier corresponding to the tool action, and the session identifier of the current task.

9. A context-based dynamic cleanup and contamination suppression system for long-range intelligent agents, characterized in that, include: The tool generation module is used to generate tool actions and their corresponding structured preserved templates by the main intelligent agent based on the activity context. The tool interaction module is used to execute the tool actions and obtain the raw observations; The original observation storage module is used to store the original observations and generate corresponding reference pointers; A dual-mode filtering module is used to perform template validation on the structured retention template. When the template validation is passed, the filtering mode and retention conditions are determined based on the structured retention template. Based on the filtering mode, retention fragments are extracted from the original observations according to the retention conditions or a preset retention range, and discard fragments are determined. Semantic placeholders are generated based on the discard fragments and the reference pointers. Filtered observations are determined based on the retained fragments and the semantic placeholders. Filtered observations are validated. When the filtered observation validation is passed, the filtered observations are written into the activity context. When the filtered observation validation is not passed, safe observations are determined based on the retained fragments, or the original observations are determined as safe observations. If the template verification fails, the security observation is determined based on the original observation; Write the security observation into the activity context; The target original text reading module is used to generate a reload request including the reference pointer and reload range through the main agent when the main agent determines that the discarded segment needs to be recovered according to the semantic placeholder, read the target original text from the stored original observation according to the reload request, and write the target original text into the activity context. The iterative control module is used to continue generating tool actions based on the updated activity context through the main agent until the task result is obtained.

10. An electronic device, characterized in that, It includes a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; The memory is used to store computer programs; When the processor executes the computer program stored in the memory, it implements the steps of the context dynamic cleanup and pollution suppression method for long-range intelligent agents as described in any one of claims 1-8.