A multi-agent based context sharing method, system, and medium

By generating metadata in multi-agent collaboration and storing it in a distributed cache, a topic set with a session identifier index is established, solving the problems of token consumption and semantic noise in context sharing, and achieving efficient and accurate context sharing and data management.

CN122086972BActive Publication Date: 2026-07-07XIAMEN YUANTING INFORMATION TECH CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
XIAMEN YUANTING INFORMATION TECH CO LTD
Filing Date
2026-04-23
Publication Date
2026-07-07

AI Technical Summary

Technical Problem

Existing context sharing methods in multi-agent collaboration lead to a surge in token consumption, semantic noise interference with model attention, and a lack of structured organization and indexing mechanisms, resulting in response delays and data redundancy.

Method used

Meta-information is generated by parsing contextual content, stored in a distributed cache, and a topic set indexed by session identifiers is established. A large language model is used to return semantically relevant topic identifiers, enabling precise sharing on demand. Version numbers and timestamps are introduced to manage concurrent conflicts, and a unified expiration time is set to clean up data.

Benefits of technology

It significantly reduces token consumption, filters semantic noise, improves the efficiency and accuracy of context sharing, and ensures data consistency and efficient management of storage resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122086972B_ABST
    Figure CN122086972B_ABST
Patent Text Reader

Abstract

A multi-agent-based context sharing method, system and medium, comprising: parsing context content output by a first agent to generate corresponding meta information; storing the context content and the corresponding meta information in a distributed cache; establishing a topic set indexed by a session identifier in the distributed cache, and adding a topic identifier to the topic set; in response to a task to be executed by a second agent, obtaining a topic set corresponding to a current session identifier, reading a topic description corresponding to each topic identifier in the topic set to generate a topic description list; inputting the task to be executed and the corresponding topic description list into a large language model, receiving a set of topic identifiers returned by the large language model as target topic identifiers related to the semantic of the task to be executed; reading corresponding context content from the distributed cache according to the target topic identifiers, and inputting the context content into the second agent after associating the context content with the task to be executed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of multi-agent collaboration technology, and in particular to a multi-agent context sharing method, system and medium. Background Technology

[0002] In multi-agent collaboration, agents with different functions need to share each other's outputs (i.e., context) to ensure the consistency and coherence of task execution. In existing technologies, context sharing among multiple agents mainly adopts linear transmission of dialogue history or full broadcasting. The system packages all agents' previous outputs, reasoning processes, and original instructions into a long text and transmits it completely to the agent currently performing the task.

[0003] However, existing context sharing methods cause the context length to grow exponentially with the number of collaborative steps, and a large amount of irrelevant information is repeatedly transmitted, which not only causes a surge in token consumption, but also easily reaches the upper limit of the model's context window. At the same time, the semantic noise formed by irrelevant information can interfere with the model's attention, which can easily lead to inference bias or illusion. In addition, existing methods lack a structured organization and indexing mechanism for the context, and cannot retrieve it accurately as needed, resulting in a response delay that grows linearly with the session duration.

[0004] In summary, existing technologies struggle to achieve efficient, accurate, and low-noise context sharing. Summary of the Invention

[0005] To address the aforementioned technical problems, this invention provides a multi-agent context sharing method, which includes the following steps:

[0006] The context content output by the first intelligent agent is parsed to generate corresponding metadata; the metadata includes a topic identifier to which the context content belongs and a topic description used to describe the semantics of the context content.

[0007] The context content is associated with the corresponding metadata and stored in a distributed cache; wherein the context content is stored in a string structure and an entity data key is generated, and the metadata is stored in a hash structure and associated with the entity data key;

[0008] In the distributed cache, a topic set indexed by session identifier is established, and the topic identifier is added to the topic set;

[0009] In response to the task to be executed by the second intelligent agent, obtain the topic set corresponding to the current session identifier, read the topic description corresponding to each topic identifier in the topic set, and generate a list of topic descriptions;

[0010] Input the task to be executed and the corresponding list of topic descriptions into the large language model, and receive the set of topic identifiers returned by the large language model as target topic identifiers that are semantically related to the task to be executed;

[0011] The corresponding context content is read from the distributed cache according to the target topic identifier, and then the context content is associated with the task to be executed and input into the second intelligent agent.

[0012] Optionally, the topic set is stored in the distributed cache as a set data structure, and the session identifier is used as the key name of the topic set.

[0013] Optionally, the metadata also includes a version number and a timestamp; the version number is used to identify the update order of context content under the same topic identifier, and the timestamp is used to record the generation time of the context content.

[0014] Optionally, the method further includes:

[0015] In response to multiple agents concurrently updating the context content corresponding to the same topic identifier, obtain the expected version number carried by each update request;

[0016] The expected version number is compared with the current version number currently stored in the distributed cache; if the expected version number matches the current version number, the update operation is allowed and the current version number is updated; if the expected version number does not match the current version number, the update operation is rejected and a conflict indication is returned.

[0017] Optionally, the method further includes:

[0018] In response to a session termination command, the set of topics corresponding to the session identifier is obtained, and the corresponding metadata and context content are deleted according to each topic identifier in the topic set, and the topic set is deleted.

[0019] Optionally, before parsing the context content output by the first agent and generating the corresponding metadata, the process further includes:

[0020] In response to the session initialization request, a globally unique session identifier is generated;

[0021] Create a set of topics named after the session identifier in the distributed cache.

[0022] Optionally, the topic set corresponding to the session identifier, the metadata and context content corresponding to each topic identifier are all set with a unified expiration time, and the corresponding storage space is automatically reclaimed by the distributed cache after the timeout.

[0023] Optionally, the step of associating the context content with the task to be executed and inputting it into the second intelligent agent specifically involves: formatting the read context content according to a preset prompt word template, and concatenating it before the task description of the task to be executed to form an enhanced input prompt word, which is then input into the second intelligent agent.

[0024] Corresponding to the aforementioned multi-agent-based context sharing method, the present invention provides a multi-agent-based context sharing system, comprising:

[0025] The metadata generation module is used to parse the context content output by the first intelligent agent and generate corresponding metadata; the metadata includes a topic identifier to which the context content belongs and a topic description used to describe the semantics of the context content;

[0026] A storage module is used to associate the context content with the corresponding metadata and store it in a distributed cache; wherein the context content is stored in a string structure and an entity data key is generated, and the metadata is stored in a hash structure and associated with the entity data key;

[0027] The topic set creation module is used to create a topic set indexed by the session identifier in the distributed cache, and add the topic identifier to the topic set;

[0028] The topic description list generation module is used to respond to the task to be executed by the second intelligent agent, obtain the topic set corresponding to the current session identifier, read the topic description corresponding to each topic identifier in the topic set, and generate a topic description list.

[0029] The target topic identifier acquisition module is used to input the task to be executed and the corresponding list of topic descriptions into the large language model, and receive the set of topic identifiers returned by the large language model as target topic identifiers that are semantically related to the task to be executed.

[0030] The context content enhancement module is used to read the corresponding context content from the distributed cache according to the target topic identifier, associate the context content with the task to be executed, and input it into the second intelligent agent.

[0031] Furthermore, to achieve the above objectives, the present invention also provides a computer-readable storage medium storing a multi-agent-based context sharing program, wherein the multi-agent-based context sharing program, when executed by a processor, implements the steps of the multi-agent-based context sharing method described above.

[0032] Compared with the prior art, the present invention has the following beneficial effects:

[0033] (1) By parsing the context content to generate meta-information, the context content and meta-information are associated and stored in the distributed cache, and a topic set indexed by the session identifier is established, which realizes the structured splitting and storage of the context, avoids the repeated transmission caused by full broadcast, and significantly reduces token consumption; after inputting the task to be executed and the list of topic descriptions into the large language model, the model returns the semantically related target topic identifier, and then accurately reads the corresponding context content based on this, realizing semantically based on on-demand accurate sharing, effectively filtering irrelevant information, eliminating the interference of semantic noise on the model's attention, and suppressing inference bias and illusion; with the help of the key-value storage structure of the distributed cache and the topic set indexing mechanism, the context is quickly located and read, avoiding the inefficient retrieval of long texts by linear traversal.

[0034] (2) The topic set is stored in a distributed cache as a set data structure and the session identifier is used as the key name. This realizes the deduplication of topic identifiers and efficient member judgment, avoids storage redundancy caused by repeated addition of topic identifiers, and supports fast topic set location and traversal based on session identifiers, thus improving the retrieval efficiency of topic level.

[0035] (3) Adding version number and timestamp to the metadata enables precise tracking of the update order of context content and accurate recording of generation time, providing a basis for version comparison for concurrent update conflict detection. It also supports time-series query based on timestamp and implementation of expiration policy, enhancing the lifecycle management capability of context content.

[0036] (4) When the expected version number is consistent with the current version number, the update is allowed and the version number is incremented. When they are inconsistent, the update is rejected and a conflict indication is returned. This effectively prevents data overwriting and state inconsistency when multiple agents update the same topic content concurrently, and ensures the integrity and consistency of the context content.

[0037] (5) When responding to the session termination command, the topic set corresponding to the session identifier and its associated metadata and context content are automatically cleaned up, realizing closed-loop management of the life cycle of session-level data, timely releasing the storage resources of the distributed cache, and avoiding storage expansion and resource waste caused by invalid data occupying cache space for a long time.

[0038] (6) When responding to the session initialization request, a globally unique session identifier is generated and a corresponding topic set is created, which establishes a namespace isolation foundation for the structured storage and indexing of subsequent context content, ensuring that the context data of different sessions are independent of each other and do not interfere with each other, and supports the scenario requirements of multiple sessions running in parallel.

[0039] (7) A unified expiration time is set for the topic set, meta information and context content corresponding to the session identifier, which realizes the automatic recycling mechanism of storage space. Expired session data can be cleaned up without manual intervention, reducing the complexity of system operation and maintenance. At the same time, it prevents "zombie" data from occupying cache resources for a long time and ensures the sustainable service capability of distributed cache.

[0040] (8) The read context content is formatted by using a preset prompt word template and then appended to the task description of the task to be executed to form an enhanced input prompt word. This achieves the standardized integration of context content and task description, ensuring that the input received by the second agent conforms to the expected format and improving the stability and output quality of the agent's task execution. Attached Figure Description

[0041] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this invention, illustrate exemplary embodiments of the invention and are used to explain the invention, but do not constitute an undue limitation of the invention. In the drawings:

[0042] Figure 1 This is a simplified flowchart of an embodiment of the context sharing method based on multiple agents according to the present invention;

[0043] Figure 2 This is a framework diagram of an embodiment of the multi-agent context sharing system of the present invention. Detailed Implementation

[0044] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0045] like Figure 1 As shown, the present invention provides a multi-agent context sharing method, which includes the following steps:

[0046] The context content output by the first intelligent agent is parsed to generate corresponding meta-information. The meta-information includes the topic identifier to which the context content belongs and the topic description used to describe the semantics of the context content. For example, if the context content is a "user requirements analysis" report, "user requirements" is parsed and generated as the topic identifier. At the same time, the text "user requirements document, containing functional, performance and non-functional requirements" is extracted from the report summary or key sentences as the topic description.

[0047] The context content is associated with the corresponding metadata and stored in the distributed cache; the context content is stored as a string structure and an entity data key is generated, and the metadata is stored as a hash structure and associated with the entity data key.

[0048] In the distributed cache, a topic set indexed by session identifiers is established, and topic identifiers are added to the topic set. For example, when a multi-agent collaborative session starts, a session identifier, such as "session:abc", can be assigned to the session. Subsequently, a storage structure associated with the session identifier, such as a list or key-value pairs, can be created in the distributed cache to store all registered topic identifiers in the session. Whenever a topic identifier is generated and stored, it is added to the topic set corresponding to the session identifier.

[0049] In response to the task to be executed by the second intelligent agent, obtain the topic set corresponding to the current session identifier, read the topic description corresponding to each topic identifier in the topic set, and generate a list of topic descriptions;

[0050] Input the task to be executed and the corresponding list of topic descriptions into the large language model, and receive the set of topic identifiers returned by the large language model as target topic identifiers that are semantically related to the task to be executed.

[0051] Based on the target topic identifier, the corresponding context content is read from the distributed cache, and then the context content is associated with the task to be executed and input into the second agent.

[0052] This invention generates meta-information by parsing context content, associates and stores the context content and meta-information in a distributed cache, and establishes a topic set indexed by session identifiers. This achieves structured splitting and storage of context, avoiding redundant transmission caused by full broadcast and significantly reducing token consumption. After inputting the task to be executed and the list of topic descriptions into a large language model, the model returns semantically relevant target topic identifiers, which are then used to accurately read the corresponding context content. This achieves semantically based on-demand and precise sharing, effectively filtering irrelevant information, eliminating semantic noise interference with model attention, and suppressing inference bias and illusion. With the help of the key-value storage structure of the distributed cache and the topic set indexing mechanism, it achieves fast context location and reading, avoiding the inefficient retrieval of long texts through linear traversal.

[0053] Preferably, when the first agent outputs new context content, it parses the topic to which it belongs. If it is a new topic, it creates an index tree branch; if it is an existing topic, it updates the corresponding metadata, thereby enabling fast data mounting and routing.

[0054] In this embodiment, the topic set is stored in a distributed cache as a set data structure, and the session identifier is used as the key name of the topic set.

[0055] Specifically, a set data structure is an unordered collection of unique elements. In distributed caches (such as Redis), set data structures can efficiently store and manage a set of unique elements. Using it to store topic sets means that all topic identifiers under each session will be stored as members of the set. This structure guarantees the uniqueness of topic identifiers, avoids duplicate storage, and enables efficient retrieval of the entire member list. This is crucial for scenarios that require fast management and traversal of all topics within a session. Simultaneously, the session identifier serves as the key name for the topic set. Key names are strings used in distributed caches to uniquely identify and access stored data. Using the session identifier as the key name for the topic set means that each session has an independent set data structure named after its session identifier. For example, if the session identifier is "session-abc", then there will be a set named "session-abc" in the distributed cache, containing all topic identifiers under that session. This naming convention clearly isolates topic sets from different sessions, facilitating direct location and manipulation of topic data for a specific session based on the session identifier, achieving session-level isolation and management.

[0056] This invention stores the topic set in a distributed cache using a set data structure and uses the session identifier as the key, thereby achieving deduplication of topic identifiers and efficient member judgment. This avoids storage redundancy caused by repeated addition of topic identifiers and supports fast topic set location and traversal based on session identifiers, improving the retrieval efficiency at the topic level.

[0057] In some of the above embodiments, although methods have been proposed for parsing, storing, and retrieving the context content output by the first agent based on topic identifiers, in multi-agent collaboration scenarios, the context content under the same topic identifier may be frequently updated by multiple agents. Without an effective mechanism to track the order and timing of these updates, it is difficult to ensure the historical traceability of the context content and to effectively manage data inconsistencies that may result from concurrent updates, thereby affecting the efficiency of agent collaboration and data reliability.

[0058] In this embodiment, the metadata also includes a version number and a timestamp; the version number is used to identify the update order of context content under the same topic identifier, and the timestamp is used to record the generation time of the context content. For new topics, the version number can be omitted or set to 0.

[0059] Specifically, the version number is used to identify the update order of context content under the same topic. The version number can be an incrementing integer value; each time context content under the same topic is updated, its corresponding version number increases. Through the version number, the system can clearly identify different historical states of context content, providing a foundation for subsequent data tracing, conflict detection, and concurrency control. The timestamp is used to record the generation time of the context content. A timestamp is typically a numerical value representing a specific point in time, such as a Unix timestamp or a string in a standard date and time format. When context content is generated or updated, the system records the current time as its timestamp. This allows the system to accurately understand the specific moment of creation or most recent update of each version of context content, facilitating the analysis of the timeliness of context content, time series analysis, and, when needed, backtracking to the context state at a specific point in time.

[0060] When multiple agents attempt to update the same context content, the version number serves as a crucial basis for determining the update order and detecting concurrent conflicts, thus laying the foundation for subsequent concurrency control mechanisms and avoiding the risk of data being overwritten or lost out of order. Simultaneously, the timestamp provides precise time information about the generation or update of the context content. This not only helps assess the timeliness of the context content but also allows for backtracking when needed, enhancing the granularity and reliability of context management. Combined with basic context storage and retrieval mechanisms, the addition of version numbers and timestamps significantly improves the consistency, traceability, and management efficiency of context data in multi-agent collaborative environments.

[0061] This invention adds version number and timestamp to the metadata, enabling precise tracking of the update order of context content and accurate recording of generation time. It provides a basis for version comparison for concurrent update conflict detection, and supports time-series query based on timestamp and expiration policy implementation, thereby enhancing the lifecycle management capability of context content.

[0062] However, in multi-agent collaboration scenarios, when multiple agents attempt to concurrently update the context content corresponding to the same topic identifier, the lack of an effective concurrency control mechanism may lead to problems such as data overwriting, update loss, or data inconsistency, thereby affecting the accuracy and reliability of collaboration. To address this, in this embodiment, the method further includes:

[0063] In response to multiple agents concurrently updating the context content corresponding to the same topic identifier, obtain the expected version number carried by each update request;

[0064] The expected version number is compared with the current version number currently stored in the distributed cache. If the expected version number matches the current version number, the update operation is allowed and the current version number is updated. If the expected version number does not match the current version number, the update operation is rejected and a conflict indication is returned.

[0065] Specifically, concurrent updates occur when multiple agents modify the context content of the same topic identifier stored in the distributed cache and submit update requests within the same time period. Before initiating an update operation, each agent typically reads the context content and its metadata corresponding to the topic identifier from the distributed cache, which includes the current version number. This version number obtained during the read is used by the agent as the "expected version number" carried in its update request, indicating that the agent expects to modify based on this specific version. When an update request is received from an agent, the system retrieves the metadata corresponding to the topic identifier from the distributed cache again and extracts the currently stored "current version number". Subsequently, the system compares the "expected version number" carried in the update request with the "current version number" retrieved from the cache in real time. This comparison is a key step in implementing the optimistic locking mechanism, used to determine whether other agents have modified the data during the time between an agent reading the data and submitting the update.

[0066] If the expected version number is exactly the same as the current version number, it indicates that the context content has not been modified by other agents since the agent last read the data. In this case, the system will allow the update operation to be executed, writing the new context content submitted by the agent to the distributed cache. Simultaneously, to reflect the data change, the system will atomically increment the current version number in the metadata corresponding to the topic identifier, for example, by 1, ensuring that subsequent update requests can be verified based on the latest version number. This operation is typically guaranteed by atomicity, ensuring that version verification and data update are completed as an inseparable whole. Conversely, if the expected version number is inconsistent with the current version number, it means that while the agent was reading data and preparing to update, other agents had successfully modified the context content, resulting in a currently stored version number higher than the agent's expected version number. To avoid overwriting valid updates from other agents, the system will reject the update operation. Simultaneously, the system will return a conflict indication to the agent that initiated the update, informing it that the update failed due to a version conflict. Upon receiving a conflict indication, the agent can process it according to a preset strategy, such as retrieving the latest context content, merging its own modifications with the latest content, and then attempting to submit the update again.

[0067] Through the above technical solution, this application introduces a version number-based optimistic locking mechanism in scenarios where multiple agents concurrently update shared context content. When multiple agents attempt to modify the context content corresponding to the same topic identifier, the system effectively detects and handles concurrent conflicts by comparing the expected version number carried in the update request with the current version number stored in the distributed cache. If the version numbers match, the update is allowed and the version number is atomically incremented, ensuring that each update is based on the latest data state; if the version numbers do not match, the update is rejected and a conflict indication is returned, avoiding the problem of "latest writer overwriting earlier writer," thereby ensuring the data consistency and integrity of the context content in the distributed cache. This mechanism enables multiple agents to safely and reliably share and update context information, significantly improving the stability and efficiency of multi-agent collaboration and avoiding data corruption and semantic noise caused by concurrent operations. However, in multi-agent collaboration, the lifecycle of a session is finite. If the generated context content, metadata, and topic sets are not promptly cleaned up after the session ends, a large amount of expired or useless data will accumulate in the distributed cache. This not only wastes storage resources but may also affect the overall system performance and data management efficiency. Therefore, in this embodiment, the method further includes:

[0068] In response to a session termination command, obtain the topic set corresponding to the session identifier, delete the corresponding metadata and context content based on each topic identifier in the topic set, and delete the topic set.

[0069] A session termination command is an externally sent signal that clearly indicates a specific session has been completed or is no longer needed. This command typically carries a unique session identifier so the system can accurately identify the session that needs to be cleaned up. This command can be received through various methods, such as API calls, message queue events, or internal system events, with the aim of triggering subsequent data cleanup processes.

[0070] Upon receiving a session termination command, the system retrieves the set of topics associated with that session identifier from the distributed cache, based on the session identifier contained in the command. This set of topics is pre-built in the distributed cache and indexed by the session identifier, storing all registered topic identifiers during that session. For example, in the distributed cache, the session index key (ctx:session:{SessionID}) stores all TopicIDs under that session in a Set structure; all topic identifiers can be quickly retrieved by reading this Set structure.

[0071] The system then iterates through each topic identifier in the topic set. For each topic identifier, the system constructs its corresponding metadata key (e.g., ctx:meta:{SessionID}:{TopicID}) and entity data key (e.g., ctx:data:{SessionID}:{TopicID}) in the distributed cache according to preset naming rules. Then, the system performs a deletion operation, removing this metadata and context content from the distributed cache. This deletion operation can be performed non-blockingly, such as using Redis's UNLINK command, to avoid blocking the main thread and thus improve system responsiveness.

[0072] After all session-related metadata and context content have been deleted, the system performs a final cleanup operation: deleting the set of topics corresponding to the session identifier itself. This means that the Set structure used to index all topics under this session (e.g., ctx:session:{SessionID}) will also be removed from the distributed cache. This operation signifies that all data for this session in the distributed cache has been completely cleaned up, freeing up the storage space it occupied.

[0073] When responding to a session termination command, this invention automatically cleans up the topic set corresponding to the session identifier and its associated metadata and context content, realizing closed-loop management of the lifecycle of session-level data, timely releasing the storage resources of the distributed cache, and avoiding storage expansion and resource waste caused by invalid data occupying cache space for a long time.

[0074] In some embodiments described above, the context content output by the first agent is parsed and metadata is generated to achieve context-related storage and retrieval. However, in practical applications, the lack of a unified management and initialization mechanism for sessions may lead to confusion of context data between different sessions, or the inability to effectively establish independent context storage spaces at the start of a session, thereby affecting the efficiency and data isolation of multi-agent collaboration. Therefore, in this embodiment, before parsing the context content output by the first agent and generating the corresponding metadata, the following steps are also included:

[0075] In response to the session initialization request, a globally unique session identifier is generated;

[0076] Create a collection of topics named after session identifiers in the distributed cache.

[0077] When responding to a session initialization request, this invention generates a globally unique session identifier and creates a corresponding topic set, establishing a namespace isolation foundation for the structured storage and indexing of subsequent context content. This ensures that the context data of different sessions are independent and do not interfere with each other, supporting the scenario requirements of multiple sessions running in parallel.

[0078] In some of the embodiments described above in this application, context sharing among multiple agents is achieved by storing the context content, metadata, and conversation topic set output by the first agent in a distributed cache. However, without effective lifecycle management of this stored data, as agent interactions continue and context data accumulates, the distributed cache may face problems such as data redundancy, excessive memory consumption, and performance degradation, affecting the stability and efficiency of the system.

[0079] In this embodiment, the topic set corresponding to the session identifier, the metadata and context content corresponding to each topic identifier are all set with a unified expiration time. After the expiration time, the corresponding storage space is automatically reclaimed by the distributed cache.

[0080] Specifically, the topic set corresponding to the session identifier is a collection of all topic identifiers under a specific session, indexed by the session identifier. As a session-level data index, it can quickly locate and manage all context topics belonging to the same session. In a distributed cache, this collection is typically stored as a Set structure, with the session identifier as the key and the members being the various topic identifiers under that session. The metadata corresponding to each topic identifier is data describing the attributes of the context content, including the topic identifier to which the context content belongs and a topic description used to describe the semantics of the context content. It does not directly contain the actual content of the context, but provides structured information about the context content, such as its semantics, version, generation time, and pointers to the actual context content. In a distributed cache, the metadata is typically stored as a hash structure to facilitate efficient reading and writing of individual fields. The context content refers to text data with actual business significance generated by the agent during task execution, such as task descriptions, code snippets, and analysis results. It is the basis for information sharing and collaboration between agents. In a distributed cache, the context content is typically stored as a string structure to accommodate the storage needs of large text data.

[0081] The unified expiration time refers to setting the same Time-To-Live (TTL) for the set of topics under the same session identifier, the metadata corresponding to each topic identifier, and the context content. For example, during session initialization, topic creation, or update, the EXPIRE command of a distributed caching system (such as Redis) can be used to set a unified absolute TTL (e.g., 24 hours) for all relevant keys, including session index keys (e.g., "ctx:session:{SessionID}"), metadata keys (e.g., "ctx:meta:{SessionID}:{TopicID}"), and entity keys (e.g., "ctx:data:{SessionID}:{TopicID}"). This unified setting ensures the consistency of the lifecycle of session-related data and avoids data incompleteness or logical errors caused by residual data. The automatic reclamation of the corresponding storage space by the distributed cache after timeout refers to the built-in expired key deletion mechanism typically provided by distributed caching systems (such as Redis). When a key's time-to-live expires, the caching system automatically removes it from storage and reclaims the memory it occupies, based on its internal policies (such as lazy deletion or periodic deletion). For example, when a uniform expiration time is reached, the distributed caching system will automatically delete the corresponding session index key, metadata key, and entity key, thus eliminating the need for explicit deletion operations by the application, simplifying data management, and effectively controlling the consumption of cache resources.

[0082] This invention sets a unified expiration time for the topic set, metadata, and context content corresponding to the session identifier, realizing an automatic storage space reclamation mechanism. Expired session data can be cleaned up without manual intervention, reducing the complexity of system operation and maintenance. At the same time, it prevents "zombie" data from occupying cache resources for a long time and ensures the sustainable service capability of distributed cache.

[0083] In this embodiment, the context content is associated with the task to be executed and then input to the second intelligent agent. Specifically, the context content is formatted according to a preset prompt word template and concatenated before the task description of the task to be executed to form an enhanced input prompt word, which is then input to the second intelligent agent.

[0084] The pre-defined prompt word template is a structured text framework used to guide the large language model in understanding the input structure and semantics. This template can contain specific markers, placeholders, or natural language instructions to clearly distinguish the context from the task description and instruct the large language model how to utilize this information. For example, the template can be defined as " <context topic="{TopicID}"> {content}< / context>The template, where "{TopicID}" and "{content}" represent the contextual topic identifier and the actual content to be filled, respectively, provides clear semantic boundaries and structured cues for large language models, enabling them to more accurately identify and utilize contextual information.

[0085] Formatting the retrieved context content refers to structuring the raw context content obtained from the distributed cache according to a preset prompt word template. Specifically, this includes embedding the raw text content into specific areas defined by the template, and potentially adding or modifying context-related metadata, such as topic identifiers, as needed. The purpose of formatting is to present the context content in a unified and standardized form that is easily parsed and understood by the large language model, thereby improving the usability of contextual information and the efficiency of the large language model in processing information.

[0086] Concatenating formatted contextual content before the task description means placing structured contextual information before the actual task instructions when constructing the prompts that are ultimately input to the second agent (usually a large language model). This concatenation order is strategic, aiming to provide the large language model with the necessary background knowledge and relevant information first, enabling it to establish a comprehensive understanding of the current situation before processing the core task description. This "context first, task later" input pattern helps the large language model better understand the intent and constraints of the task, reduces ambiguity, and guides it to generate responses that are more consistent with the context.

[0087] Ultimately, the enhanced input prompt refers to effectively combining the formatted contextual content with the original task description to generate a complete input text containing rich background information and clear task instructions. This enhanced prompt not only contains the core instructions needed for the second agent to complete the task, but also provides structured and relevant context, enabling the large language model to fully utilize this background information when processing tasks, thereby improving the accuracy and efficiency of task execution.

[0088] This invention formats the read contextual content using a preset prompt word template and appends it to the task description of the task to be executed to form an enhanced input prompt word. This achieves standardized integration of contextual content and task description, ensuring that the input received by the second agent conforms to the expected format and improving the stability and output quality of the agent's task execution.

[0089] like Figure 2 As shown, the present invention also provides a context sharing system based on multiple agents, which includes:

[0090] The metadata generation module 10 is used to parse the context content output by the first intelligent agent and generate corresponding metadata; the metadata includes the topic identifier to which the context content belongs and the topic description used to describe the semantics of the context content.

[0091] Storage module 20 is used to associate context content with corresponding metadata and store it in a distributed cache; wherein, the context content is stored in a string structure and an entity data key is generated, and the metadata is stored in a hash structure and associated with the entity data key;

[0092] The topic set creation module 30 is used to create a topic set indexed by the session identifier in the distributed cache and add the topic identifier to the topic set;

[0093] The topic description list generation module 40 is used to respond to the task to be executed by the second intelligent agent, obtain the topic set corresponding to the current session identifier, read the topic description corresponding to each topic identifier in the topic set, and generate a topic description list;

[0094] The target topic identifier acquisition module 50 is used to input the task to be executed and the corresponding list of topic descriptions into the large language model, and receive the set of topic identifiers returned by the large language model as target topic identifiers that are semantically related to the task to be executed.

[0095] The context content enhancement module 60 is used to read the corresponding context content from the distributed cache according to the target topic identifier, and input the context content into the second intelligent agent after associating it with the task to be executed.

[0096] Preferably, the storage module 20 is further configured to, in response to multiple agents concurrently updating the context content corresponding to the same topic identifier, obtain the expected version number carried by each update request; compare the expected version number with the current version number currently stored in the distributed cache; if the expected version number is consistent with the current version number, allow the update operation and update the current version number; if the expected version number is inconsistent with the current version number, refuse to execute the update operation and return a conflict indication.

[0097] Furthermore, the system also includes a topic set deletion module, which, in response to a session termination command, obtains the topic set corresponding to the session identifier, deletes the corresponding metadata and context content according to each topic identifier in the topic set, and deletes the topic set.

[0098] An initialization module, in response to a session initialization request, generates a globally unique session identifier; and creates a set of topics named after the session identifier in the distributed cache.

[0099] The following example will provide a more detailed explanation of the above technical solution:

[0100] In a multi-agent collaborative platform, user A initiates a software development task, such as "developing a payment function for an online shopping cart".

[0101] First, in response to user A's request, the system initialization module generates a globally unique session identifier, such as "sess-8f92a". In the distributed cache, an empty collection data structure is created using this session identifier "sess-8f92a" as the key, serving as the topic collection for this session. Simultaneously, a uniform expiration time is set for this topic collection, such as 24 hours, ensuring that related data is automatically reclaimed even if the session is not explicitly terminated.

[0102] Next, the requirements analysis agent (the first agent) receives the request from user A, processes it, and outputs contextual content about the "core requirements of the payment function." The metadata generation module 10 parses this contextual content and generates corresponding metadata. This metadata includes the topic identifier "Core_Req" to which the contextual content belongs, and a topic description that describes the semantics of the contextual content: "Describes the core business requirements of the online shopping cart payment function." In addition, the metadata also includes version number 1 and a current timestamp to identify the update order and generation time of the content.

[0103] Subsequently, storage module 20 stores the context content of "core requirements for payment function" in a string structure in the distributed cache and generates the entity data key "ctx:data:{sess-8f92a}:Core_Req". Simultaneously, it stores the metadata (including topic description, version number, timestamp, and pointer to the entity data key) in a hash structure in the distributed cache, with the key "ctx:meta:{sess-8f92a}:Core_Req". The topic set creation module 30 adds the topic identifier "Core_Req" to the topic set indexed by the session identifier "sess-8f92a".

[0104] Subsequently, the design agent (the second agent) is awakened, and its task to be executed is "designing the system architecture of the payment module". The topic description list generation module 40 responds to this task by obtaining the topic set corresponding to the current session identifier "sess-8f92a". The system reads the topic descriptions (e.g., "describe the core business requirements of the online shopping cart payment function") corresponding to each topic identifier (e.g., "Core_Req") in the topic set, and generates a topic description list.

[0105] The target topic identifier acquisition module 50 inputs the task to be executed, "Design the system architecture of the payment module," and the corresponding list of topic descriptions into the large language model. Based on the correlation between the task semantics and the topic descriptions, the large language model returns a set of topic identifiers, which includes "Core_Req," as target topic identifiers related to the semantics of the task to be executed.

[0106] The context content enhancement module 60 reads the corresponding context content "core requirements of payment function" from the distributed cache based on the target topic identifier "Core_Req". According to the preset prompt word template, the system formats the read context content and concatenates it before the task description of the task to be executed to form an enhanced input prompt word, which is then input to the design agent.

[0107] After the design agent completes its task, it generates context content about the "Payment Module Database Design" and attempts to update the topic "System_Design," with a desired version number of 1. Simultaneously, the test agent also attempts to update the "System_Design" topic, for example, by adding "Payment Interface Test Cases," and its desired version number is also 1. The design agent's update request arrives first at storage module 20. Storage module 20 retrieves the desired version number 1 it carries and compares it with the current version number 1 of the "System_Design" topic currently stored in the distributed cache. They match, allowing the update operation. The system writes the new context content and atomically updates the current version number to 2. Immediately following, the test agent's update request arrives. Storage module 20 retrieves the desired version number 1 it carries and compares it with the current version number 2 of the "System_Design" topic currently stored in the distributed cache. They do not match, the manager refuses to execute the update operation, and returns a conflict indication. Upon receiving a conflict indication, the test agent automatically triggers a retry strategy: it re-fetches the latest context content (version 2) of the "System_Design" topic, merges its own incremental modifications with the latest content, and then initiates another update request with the desired version number 2. This optimistic locking mechanism effectively solves the data inconsistency problem when multiple agents concurrently write to the same topic, ensuring data integrity, whereas existing technologies typically lack such fine-grained concurrency control.

[0108] When User A completes all software development tasks, the system receives a session termination command. The topic set deletion module retrieves the topic set corresponding to the session identifier "sess-8f92a". Based on the topic identifiers in this topic set, the system deletes the corresponding metadata and context content from the distributed cache, and finally deletes the topic set itself. Furthermore, because a uniform expiration time is set during session initialization, even without an explicit termination command, the distributed cache will automatically reclaim the corresponding storage space after the timeout, preventing "zombie" data from consuming memory.

[0109] This invention also provides a computer-readable storage medium, which may be a computer-readable storage medium included in the memory described in the above embodiments; or it may be a standalone computer-readable storage medium not assembled into a device. The computer-readable storage medium stores at least one instruction, which is loaded and executed by a processor to implement... Figure 1 The illustrated method is a context-sharing approach based on multiple agents. The computer-readable storage medium may be a read-only memory, a hard disk, or an optical disk, etc.

[0110] It should be noted that the various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For system embodiments and storage medium embodiments, since they are basically similar to method embodiments, the descriptions are relatively simple; relevant parts can be referred to the descriptions in the method embodiments.

[0111] Furthermore, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0112] The foregoing description illustrates and describes preferred embodiments of the present invention. It should be understood that the present invention is not limited to the forms disclosed herein and should not be construed as excluding other embodiments. It can be used in various other combinations, modifications, and environments, and can be altered within the scope of the inventive concept by means of the foregoing teachings or techniques or knowledge in related fields. Any modifications and variations made by those skilled in the art that do not depart from the spirit and scope of the present invention should be within the protection scope of the appended claims.

Claims

1. A multi-agent context sharing method, characterized in that, Includes the following steps: The context content output by the first intelligent agent is parsed to generate corresponding metadata. The metadata includes a topic identifier to which the context content belongs and a topic description used to describe the semantics of the context content. The metadata also includes a version number and a timestamp. The version number is used to identify the update order of the context content under the same topic identifier, and the timestamp is used to record the generation time of the context content. The context content is associated with the corresponding metadata and stored in a distributed cache; wherein the context content is stored in a string structure and an entity data key is generated, and the metadata is stored in a hash structure and associated with the entity data key; In the distributed cache, a topic set indexed by session identifier is established, and the topic identifier is added to the topic set; In response to the task to be executed by the second intelligent agent, obtain the topic set corresponding to the current session identifier, read the topic description corresponding to each topic identifier in the topic set, and generate a list of topic descriptions; Input the task to be executed and the corresponding list of topic descriptions into the large language model, and receive the set of topic identifiers returned by the large language model as target topic identifiers that are semantically related to the task to be executed; According to the target topic identifier, the corresponding context content is read from the distributed cache, and the context content is associated with the task to be executed and then input to the second intelligent agent. Specifically, according to the preset prompt word template, the read context content is formatted and concatenated before the task description of the task to be executed to form an enhanced input prompt word, which is then input to the second intelligent agent. Also includes: In response to multiple agents concurrently updating the context content corresponding to the same topic identifier, obtain the expected version number carried by each update request; The expected version number is compared with the current version number currently stored in the distributed cache; if the expected version number matches the current version number, the update operation is allowed and the current version number is updated; if the expected version number does not match the current version number, the update operation is rejected and a conflict indication is returned.

2. The multi-agent context sharing method according to claim 1, characterized in that, The topic set is stored in the distributed cache as a set data structure, and the session identifier serves as the key name of the topic set.

3. The multi-agent context sharing method according to claim 1, characterized in that, Also includes: In response to a session termination command, the set of topics corresponding to the session identifier is obtained, and the corresponding metadata and context content are deleted according to each topic identifier in the topic set, and the topic set is deleted.

4. The multi-agent context sharing method according to claim 1, characterized in that, Before parsing the context content output by the first agent and generating the corresponding metadata, the process also includes: In response to the session initialization request, a globally unique session identifier is generated; Create a set of topics named after the session identifier in the distributed cache.

5. The multi-agent context sharing method according to claim 1, characterized in that, The topic set corresponding to each session identifier, the metadata and context content corresponding to each topic identifier are all set with a unified expiration time. After the expiration time, the corresponding storage space is automatically reclaimed by the distributed cache.

6. A context-sharing system based on multiple agents, characterized in that, The step of performing the multi-agent-based context sharing method as described in any one of claims 1 to 5, wherein the multi-agent-based context sharing system comprises: The metadata generation module is used to parse the context content output by the first intelligent agent and generate corresponding metadata; the metadata includes a topic identifier to which the context content belongs and a topic description used to describe the semantics of the context content; A storage module is used to associate the context content with the corresponding metadata and store it in a distributed cache; wherein the context content is stored in a string structure and an entity data key is generated, and the metadata is stored in a hash structure and associated with the entity data key; The topic set creation module is used to create a topic set indexed by the session identifier in the distributed cache, and add the topic identifier to the topic set; The topic description list generation module is used to respond to the task to be executed by the second intelligent agent, obtain the topic set corresponding to the current session identifier, read the topic description corresponding to each topic identifier in the topic set, and generate a topic description list. The target topic identifier acquisition module is used to input the task to be executed and the corresponding list of topic descriptions into the large language model, and receive the set of topic identifiers returned by the large language model as target topic identifiers that are semantically related to the task to be executed. The context content enhancement module is used to read the corresponding context content from the distributed cache according to the target topic identifier, associate the context content with the task to be executed, and input it into the second intelligent agent.

7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a multi-agent-based context sharing program, which, when executed by a processor, implements the steps of the multi-agent-based context sharing method as described in any one of claims 1 to 5.