Semantic shunting and persisting method of agent conversation item, transparent backfilling method and system

CN122674708BActive Publication Date: 2026-11-03NEZHA SMART TECHNOLOGY (SHANGHAI) CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202611160973.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-08-03
Publication Date
2026-11-03
Estimated Expiration
2046-08-03

AI Technical Summary

Technical Problem

Existing session data storage solutions suffer from problems such as database table bloat, index failure, retrieval difficulties, poor data consistency and recoverability when dealing with agent session items, especially when dealing with large fields, which limits performance and scalability.

Method used

A dynamic splitting mechanism based on the candidate semantic field matrix and byte length is adopted. Through semantic binding external processing, large-capacity semantic fields are migrated to external storage media, and structured external handles are recorded in the database to ensure data integrity and consistency.

Benefits of technology

It significantly reduces the I/O load and index maintenance overhead of relational databases, improves data storage performance and scalability, and ensures the recoverability of session item history and the stability of external interfaces.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122674708B_ABST
    Figure CN122674708B_ABST
Patent Text Reader

Abstract

The application provides a semantic shunting and persisting method, a transparent backfilling method and a system for an agent conversation item, which are applied to the fields of computer data storage and artificial intelligence technology, and realize the physical separation of large-capacity semantic data and structured metadata in the agent conversation item by establishing a candidate semantic field matrix and a dynamic shunting mechanism based on byte length: when the data size is small, it is directly stored in the database, and when it exceeds the threshold, it is automatically migrated to an external storage medium, and only the structured external handle encapsulating the storage path and abstract information is recorded in the original position of the database, thereby significantly reducing the I / O load and index maintenance overhead of the relational database under the premise of ensuring data integrity and traceability, providing storage transparency for the upper layer business, and effectively solving the bottleneck problem of data storage performance and scalability in large-scale agent applications.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the fields of computer data storage and artificial intelligence technology, specifically to a semantic splitting and persistence method, a transparent backfilling method, and a system for intelligent agent conversation items. Background Technology

[0002] With the development of large language models and intelligent agent technology, intelligent agent operation platforms now widely support capabilities such as multi-turn dialogue, tool invocation, function invocation, network retrieval, code execution, file analysis, and multimodal input / output. A single intelligent agent task may generate a large amount of conversational data with complex semantic structures, including user input, assistant output, tool invocation parameters, tool execution results, token (token or model usage unit) usage statistics, status fields, and timestamps. This type of data exhibits significant characteristics different from traditional business logs: it contains structured index fields (such as session identifiers and timestamps) and unstructured long text fields (such as tool outputs and code execution results), and has extremely high requirements for the recoverability of historical trajectories, reading consistency, and stability of external interfaces.

[0003] Current mainstream session data storage solutions all have significant limitations when facing the aforementioned new workloads: Full database storage solution: Store all fields directly in a relational database. Although the query path is simple, large fields cause the database table to bloat and the index to become invalid, which seriously affects the data query performance and increases the cost of backup, migration and operation and maintenance. Full file / object storage solution: Store all session content in files or object storage. It lacks fine-grained indexes and is only suitable for storing large objects. This makes it extremely difficult to search and locate data by user, session, time, etc. In addition, upper-layer business needs to determine whether the data is in a file or a database, which increases the development cost of upper-layer business. Traditional hot and cold tiered or archived migration solutions: These solutions migrate historical data to cold storage based on time or access frequency. However, the migration process often leads to inconsistent data access paths, disrupting the homogeneity of session items and making them unsuitable for real-time writing scenarios of agent session items.

[0004] Therefore, there is an urgent need for a method for splitting, persisting and transparently replenishing the semantic structure of conversation items for intelligent agents, which can reduce the pressure on large fields in the database while ensuring the stability of the external structure of conversation items, the recovery of historical running trajectories, and the verification of external data. Summary of the Invention

[0005] In view of this, embodiments of this specification provide a semantic splitting and persistence method, a transparent restoration method, and a system for intelligent agent conversation items. Without changing the form of the external conversation item interface, it splits and persists large-volume semantic fields and transparently restores them during reading, conversation memory restoration, or response serialization, while ensuring the consistency and integrity between external data and database records.

[0006] The embodiments in this specification provide the following technical solutions: This specification provides a semantic splitting persistence method for agent session items, applied to the write side, including: Receive a session item generated by the intelligent agent operation platform, wherein the session item includes at least a session identifier, a session item type, and at least one semantic field; Based on the session item type, a preset candidate semantic field matrix is ​​queried to determine the candidate semantic fields in the session item that participate in the traffic splitting judgment; The candidate semantic fields are serialized to obtain the corresponding byte sequence, and the byte length of the byte sequence is obtained. If the length of the bytes exceeds a preset threshold, then semantic binding external processing is performed; The semantic binding external processing includes: Determine the session item identifier of the session item; The target storage path is generated based on the session identifier, the session item identifier, the content summary information of the byte sequence, and the semantic role. Write the byte sequence into the external storage medium corresponding to the target storage path; Based on the session item identifier, a structured external handle is replaced and written in the original storage location of the candidate semantic field in the database to complete the persistence of the session item in the database; the structured external handle encapsulates the session identifier, the session item identifier, the semantic role, the target storage path, and the content summary information.

[0007] Further, determining the session item identifier of the session item includes: If the session item carries an initial session item identifier, then the initial session item identifier is validated by path security rules. If the validation passes, then the initial session item identifier is determined as the session item identifier of the session item. If the session item does not carry an initial session item identifier, or the initial session item identifier fails the verification, a session item identifier that satisfies the path security rules is generated.

[0008] Further, generating the target storage path includes: Perform a digest operation on the byte sequence to obtain an algorithm digest value, and extract the first N characters of the algorithm digest value as a path naming segment, where N is a preset positive integer; The session identifier, the session item identifier, the path naming fragment, and the semantic role are used to generate the target storage path according to a preset path naming rule; The content summary information in the structured external handle is the complete algorithm summary value, which is used for comparison during read-side verification.

[0009] Furthermore, the semantic splitting and persistence method for the agent session item also includes: Add the completed session items to the concurrent safe write queue with the session identifier as the key; When the length of the concurrent secure write queue reaches the preset batch disk flushing threshold, or when a timed disk flushing service instruction is received, the session items in the concurrent secure write queue are written to the database in batches. Furthermore, the semantic splitting and persistence method for the agent session item also includes: Upon receiving a shutdown signal, a flush operation is performed on the session item in the concurrent secure write queue to clear the concurrent secure write queue. If the byte sequence is successfully written to the external storage medium, but the session item fails to be persisted in the database, then an idempotent overwrite operation is performed on the target storage path based on the session identifier, the session item identifier, and the content summary information, or a periodic cleaning is performed through a cleaning service.

[0010] Furthermore, the semantic splitting and persistence method for the agent session item also includes: In response to a session item deletion command, the corresponding session item is deleted from the database, and the structured external handle associated with the session item is obtained. Based on the target storage path in the structured external handle, perform asynchronous cleanup on the external storage medium to delete the corresponding byte sequence; Based on the session identifier, delete the vector index or cache associated with the session item.

[0011] This specification also provides a transparent completion method for agent conversation items, applied to the reading side, including: Read session item records from the database; Iterate through the preset candidate semantic field matrix and identify each candidate semantic field in the conversation item: If the field content is a structured external handle, then parse the structured external handle to obtain the target storage path and content summary information; The byte sequence is read according to the target storage path, and the integrity of the byte sequence is performed using the content digest information; If the verification passes, the byte sequence is restored to the original data, and the corresponding field value in the session item is replaced; if the verification fails, the return of the session item is blocked. If the field content is not the structured external handle, then the data in the database is used directly; The processed session item is returned to the upper-layer interface in the same data format as before it was written.

[0012] Furthermore, the transparent completion method for the agent's conversation items also includes: setting a unified external completion entry point, and reusing the external completion entry point for at least one of the following scenarios: The return phase after reading session item records from the database; Restore historical session items to the agent's runtime context or memory session storage stage; The serialization and identification phase before outputting the session item list response.

[0013] Furthermore, the transparent completion method for the agent's conversation item also includes: If the external file corresponding to the target storage path does not exist or is unreadable, the read operation is deemed to have failed, and the session item is blocked from returning.

[0014] This specification also provides an embodiment of a semantic splitting persistence and transparent completion system for agent conversation items, including: The write processing module is used to execute the semantic splitting and persistence method for the aforementioned agent session item; The read-and-complete module is used to execute the transparent completion method for the aforementioned agent conversation items; The maintenance module is used to perform background asynchronous inspections of the consistency between the database and external storage media, and to clean up and reclaim orphan files caused by write transaction failures or abnormal interruptions.

[0015] Compared with the prior art, the technical effects that can be achieved by at least one of the above-mentioned technical solutions adopted in the embodiments of this specification include at least the following: By establishing a candidate semantic field matrix and a dynamic splitting mechanism based on byte length, the physical separation of large-capacity semantic data and structured metadata in agent session items is achieved: when the data scale is small, it is directly stored in the database; when it exceeds the threshold, it is automatically migrated to an external storage medium. Only the structured external handle encapsulating the storage path and summary information is recorded in the database. Thus, while ensuring data integrity and traceability, the I / O load and index maintenance overhead of relational databases are significantly reduced, and storage transparency is provided to upper-layer businesses without their awareness. This effectively solves the bottleneck problem of data storage performance and scalability in large-scale agent applications. Attached Figure Description

[0016] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0017] Figure 1 This is a flowchart of a semantic splitting and persistence method for an agent conversation item according to a specific embodiment of this application; Figure 2 This is a diagram of the intelligent agent conversation item semantic splitting and persistence system architecture in a specific embodiment of this application; Figure 3 This is a flowchart of the write-side semantic routing in a specific embodiment of this application; Figure 4 This is a structured diagram showing the binding relationship between external handles and external paths in a specific embodiment of this application; Figure 5 This is a lifecycle closed-loop timing diagram in a specific embodiment of this application; Figure 6 This is a flowchart of the reading and transparent completion process in a specific embodiment of this application; Figure 7 This is a schematic diagram of the three-path unified backfill in a specific embodiment of this application. Detailed Implementation

[0018] The embodiments of this application will now be described in detail with reference to the accompanying drawings.

[0019] The following specific examples illustrate the implementation of this application. Those skilled in the art can easily understand other advantages and effects of this application from the content disclosed in this specification. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. This application can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of this application. It should be noted that, in the absence of conflict, the following embodiments and features in the embodiments can be combined with each other. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0020] It should be noted that various aspects of embodiments within the scope of the appended claims are described below. It will be apparent that the aspects described herein can be embodied in a wide variety of forms, and any particular structure and / or function described herein is merely illustrative. Based on this application, those skilled in the art will understand that one aspect described herein can be implemented independently of any other aspect, and two or more of these aspects can be combined in various ways. For example, any number and aspects set forth herein can be used to implement the device and / or practice the method. Additionally, this device and / or method can be implemented using structures and / or functionalities other than one or more of the aspects set forth herein.

[0021] It should also be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of this application. The drawings only show the components related to this application and are not drawn according to the actual number, shape and size of the components in the actual implementation. In the actual implementation, the shape, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.

[0022] Additionally, specific details are provided in the following description to facilitate a thorough understanding of the examples. However, those skilled in the art will understand that practice can be carried out without these specific details.

[0023] In the agent runtime platform, session item data has significant unique characteristics: the data structure is highly semantically heterogeneous, with different types of session items such as message type, tool call request type, and tool call output type, and the field size shows obvious skew characteristics. The metadata is lightweight, while the tool output, multimodal content, and long context description can reach hundreds of KB or even larger.

[0024] Existing large-field externalization strategies typically involve simply transferring large text to files or object storage based on field size, and then saving the path in the database. However, this crude approach exposes serious architectural flaws in practical engineering applications: it cannot identify the type of agent session items and semantic fields, cannot distinguish between business JSON and key operational trajectories, and is prone to accidentally damaging important data or missing key link information, making it difficult to support the stringent auditing and traceability requirements of agents. During reading, it is easy to implement restoration logic in multiple paths, resulting in inconsistencies between front-end display, memory replenishment, and interface returns, which not only increases maintenance complexity but also undermines the credibility of agent operational trajectories.

[0025] After further investigation, the inventors discovered that traditional large-field external storage solutions lack state linkage between the storage layer and the application layer, which easily leads to the accumulation of zombie files. Moreover, if external data is corrupted or missing during reading, the system often cannot detect it and often returns error data or null values ​​while still feeding back the normal status to the application layer, which seriously affects the decision-making accuracy of the intelligent agent.

[0026] Based on this, the embodiments of this specification propose a semantic splitting and persistence scheme for agent conversation items: such as Figure 1 As shown, the overall approach is as follows: based on the type and field content of the agent's session items, it is determined in real time whether the capacity of the serialized semantic fields exceeds the limit. For fields that exceed the limit, semantic binding external processing is performed. A unique target storage path is generated through preset naming rules and the data is written to the external storage. At the same time, a structured handle encapsulating the session index, storage path, and integrity verification digest is written to the original database field position. Thus, while keeping the upper-layer business read interface logic completely transparent, it realizes the hierarchical storage of massive agent context data, effectively alleviating the IO performance bottleneck and index expansion risk of the main database.

[0027] The technical terms used in the embodiments of this specification are explained as follows: Intelligent agent session item: refers to a data unit formed by an intelligent agent runtime platform during a multi-round task, which can be arranged into a time-sequential runtime trajectory. It can be a user message, assistant message, tool call request, tool call result, system-generated status item, or other data item with recoverable context. This term is not limited to a specific software development kit (SDK), framework, or interface name.

[0028] Session item type: refers to the type identifier used to distinguish the technical semantics of a session item, such as message (message type), function_call (tool call request type), function_call_output (tool call output type), etc.; in different embodiments, it can also be referred to as first type session item, second type session item, and third type session item.

[0029] Semantic fields: These are fields in a session that carry the main text or recovery information of the agent's operational trajectory, such as message content, tool call parameters, tool call output, and usage statistics. They are distinct from structured index fields such as session identifiers, user identifiers, roles, states, and timestamps.

[0030] Candidate semantic field matrix: This refers to the mapping relationship between session item types and their semantic fields that can participate in traffic splitting. This matrix can be implemented in the form of a configuration table, code constants, rule engine, or model metadata.

[0031] Semantic splitting persistence refers to considering the session item type, semantic field role, and field byte length simultaneously during the write phase, selectively saving fields inline or externally, rather than mechanically processing all fields by size.

[0032] Transparent restoration: refers to restoring the structured handles in the database fields to their original semantic field content before reading, restoring the session context, or outputting external responses, so that the upper layer receives data consistent with the unexposed state.

[0033] Externally consistent output: This means that the field names, field levels, and field meanings seen by the external interface or the upper-level caller are consistent with those when they are not externally saved, and the internal structured handle is not exposed as an external contract.

[0034] Abnormal blocking: When external data is missing, unreadable, of inconsistent length, or fails digest verification, the session item is not returned as normal data, but the current output is stopped and an error is given.

[0035] The technical solutions provided by the various embodiments of this application are described below with reference to the accompanying drawings.

[0036] like Figures 1-3 As shown in the embodiments of this specification, a semantic splitting and persistence method for agent conversation items is provided, including: Step S10: Receive a session item generated by the intelligent agent operation platform. The session item includes at least a session identifier, a session item type, and at least one semantic field. The semantic field carries the text information of the intelligent agent's operation trajectory, such as message content, tool call parameters, tool call output, or usage statistics.

[0037] Step S20: Query the preset candidate semantic field matrix according to the session item type to determine the candidate semantic fields in the session item that participate in the traffic splitting judgment.

[0038] Specifically, based on the session item type of the current session item, a pre-established candidate semantic field matrix is ​​queried to determine the set of candidate semantic fields in the session item that need to participate in the traffic splitting judgment.

[0039] The candidate semantic field matrix maps and defines the semantic fields and their corresponding semantic roles contained in different types of session items (such as message type, tool call request type, tool call output type, etc.). This ensures that the traffic splitting operation only applies to fields that may form a large volume of execution trajectory text, and does not affect structured index fields such as status fields, identifier fields, and time fields. In other words, it does not mechanically measure the length of arbitrary fields. As an exemplary and not limiting implementation, the mapping matrix can be configured in the following form: For a message-type session item, its content field is mapped to a content semantic role, and its usage field is mapped to a usage semantic role. For session items of the function call request type, the parameter field (Arguments) is mapped to parameter semantic roles (arguments). For session items with the function call output type (function_call_output), their output field (Output) is mapped to the output semantic role (output). In addition to the above-mentioned session item types, we can also extend to planning step type, tool trace type, retrieval result type, code execution result type, or multimodal input / output item, etc. For other extended types of session items, their content field, argument field, output field, or usage field, etc., are mapped to semantic roles consistent with column semantics.

[0040] It should be noted that the Content field of the message type session item is preferably a JSON (JavaScript Object Notation) document representing an array of agent message content fragments, rather than a single piece of plain text. This array of content fragments can include structured fragments such as user input text, assistant output text, image descriptions, file references, and tool result references. Maintaining this array format is beneficial for front-end display, multimodal expansion, and agent context recovery.

[0041] Step S30: Serialize the candidate semantic fields to obtain the corresponding byte sequence, and obtain the byte length of the byte sequence.

[0042] Specifically, for each candidate semantic field, its current string value is encoded into a byte sequence according to a preset encoding method, and the byte length L of the byte sequence is obtained as the quantitative basis for the traffic splitting decision.

[0043] The preferred encoding method is UTF-8. It should be noted that the encoding method can be other character encodings such as UTF-16, GBK, or GB18030, depending on the actual application scenario, as long as the encoding and decoding rules are consistent on the writing side and the reading side. The choice of encoding method does not constitute a limitation on this embodiment.

[0044] Step S40: Determine whether the byte length exceeds the preset threshold.

[0045] For example, for the content field of a message session item, if its value is a JSON array document representing multiple fragments of content, then the entire JSON array document is treated as a serialized object for byte length determination, rather than being compressed into a single piece of plain text before determination.

[0046] Step S50: If the byte length L exceeds the preset threshold T, then perform semantic binding external processing, that is, enter the external writing process.

[0047] In conjunction with the above embodiments, if the content field exceeds the threshold, the system writes the byte sequence of the complete array JSON document to external storage and writes a structured handle to the Content field of the database, so that it can be restored to the original array JSON document when reading, and then enter the session item response normalization process, thereby ensuring that multi-fragment, multi-modal or structured content does not lose its structure due to external storage.

[0048] In some embodiments, the semantic splitting persistence method for the agent session item further includes step S60: if the byte length L is less than or equal to a preset threshold T, the original data in the candidate semantic field is written into the corresponding field in the database and stored inline; if the candidate semantic field is null, an empty string, or only blank, it is also stored inline and no external processing is performed.

[0049] In some embodiments, when the preset threshold is less than or equal to 0, or when external access is disabled, all candidate semantic fields are kept inline.

[0050] In some implementations, raw field values ​​stored in the database, such as those in the jsonb column, may be wrapped with EncodeLoose.

[0051] The specific steps for the semantic binding external processing are as follows: For candidate semantic fields that exceed the preset threshold T, determine the session item identifier itemId of the session item before external writing; A unique target storage path is generated based on the session identifier, the session item identifier, the content summary information of the byte sequence, and the semantic role; Write the original byte sequence of the external field to the external storage medium pointed to by the target storage path. The external storage medium can be selected from file system (such as local file system, network file system, distributed file system), object storage, key-value storage, database large object storage or other external storage media according to the deployment environment. Finally, a structured external handle is written to the original location of the candidate semantic fields in the database. This structured external handle encapsulates the session identifier, session item identifier, semantic role, target storage path, and content summary information in the form of a structured data object, thereby completing the persistent recording of the session item at the database level, while the actual large volume of data is stored in external storage. The structured handle can be implemented using JSON objects, Protocol Buffers, MessagePack, database composite types, or other parsable structures.

[0052] This embodiment introduces a candidate semantic field matrix driven by session item type, precisely limiting the scope of traffic splitting to the semantic fields that truly need to be externalized in the agent's operational trajectory. This avoids the overhead of invalid length measurement of non-load fields in traditional solutions. External storage paths are jointly generated using session identifiers, session item identifiers, summary information, and semantic roles, ensuring that each external file can be traced back to its specific session, session item, and semantic role, providing a complete binding relationship for subsequent location, verification, and auditing. Simultaneously, only compact structured handles are stored at the database level, while large volumes of data are placed in external storage, effectively reducing the storage space occupied by database tables and the risk of index bloat, thus improving the performance of querying and filtering based on structured fields. Furthermore, this embodiment does not change the original field structure and semantic meaning of session items, laying the foundation for subsequent transparent backfilling and homogeneous output.

[0053] Furthermore, the candidate semantic field matrix can be implemented using methods such as hard coding, configuration files, database storage, or dynamic interface registration, depending on the actual application scenario. The preset threshold can adopt various strategies such as a globally unified threshold, a threshold set by tenant, a threshold set by agent, a threshold set by session item type, or a threshold set separately by semantic role. Those skilled in the art should understand that the above-mentioned variations do not constitute a substantial limitation on the present invention.

[0054] In some embodiments, a session item identifier of the session item is generated or verified before external writing. If the session item carries an initial session item identifier, the initial session item identifier is verified by path security rules. If the verification passes, the initial session item identifier is determined as the session item identifier of the session item. If the session item does not carry an initial session item identifier, or the initial session item identifier fails verification, a new session item identifier that satisfies the path security rules is generated. This session item identifier is subsequently used simultaneously as a primary key and an external path fragment in the database record.

[0055] In some embodiments, the session item includes a session identifier, a session item identifier, a session item type, a role, a status, a creation time, and one or more semantic fields.

[0056] In some embodiments, for candidate semantic fields exceeding a threshold, a digest operation is first performed on the byte sequence of the candidate semantic field to obtain a unique content digest value. Then, a prefix string (e.g., the first 12 characters) is extracted from this digest value and combined with the session identifier, session item identifier, and semantic role, such as... Figure 4 As shown, relative paths are generated according to preset path naming rules.

[0057] As an example, the relative path can be in the following format: {conversationId} / {itemId} / {shaPrefix}_{logicalRole}.bin; Wherein, `conversationId` represents the session identifier, `itemId` represents the session item identifier, `shaPrefix` represents the content summary prefix, and `logicalRole` represents the semantic role of the field. Security checks are performed on the above path fragments, rejecting paths containing path traversal characters or illegal separators to prevent path injection security risks. The length of the summary prefix in the path in this embodiment can be flexibly configured according to actual deployment needs; the first 12 characters of the summary value can be extracted for naming, for example: `fileName` = `{contentSha256.Substring(0,12)}_{logicalRole}.bin` Alternatively, you can use the complete digest value (such as a 64-bit hexadecimal string). Alternatively, the summary prefix can be omitted from the filename, as long as it is associated with the session identifier, session item identifier, semantic role, or equivalent identifier.

[0058] The following example illustrates this using a tool call output type (function_call_output) session item generated by an agent when performing a data analysis task.

[0059] This session item contains an output field, the content of which is a string representing the tool's execution result. The length of this string is 512,000 bytes, which exceeds the preset threshold.

[0060] Based on the candidate semantic field matrix, the semantic role of the Output field is determined to be the output semantic role. Before external writing, a session item identifier (itemId) has been determined for this session item. Then, a 256-bit secure hash algorithm (SHA-256) digest is calculated from the byte sequence of the Output field. The prefix string of the digest is extracted, and the session identifier, session item identifier, prefix string, and semantic role are concatenated to generate the relative path as follows: conv_001 / item_009 / a1b2c3d4e5f6_output.bin.

[0061] After the target storage path is generated, the raw UTF-8 bytes of the output field are written to the external storage corresponding to that target storage path, and a structured external handle is written to the original position of the Output field in the database. This handle is in JSON format, as shown in the example below: { "v": 1, "kind": "agent_item_payload", "encoding": "utf-8", "conversationId": "conv_abc", "itemId": "item_xyz", "logicalRole": "output", "relativePath": "conv_abc / item_xyz / a1b2c3d4e5f6_output.bin", "byteLength": 512000, "contentSha256": "a1b2c3d4e5f6789012345678901234567890abcdef1234567890abcdef123456" } Wherein, v represents the handle version, kind represents the external data type, encoding represents the encoding method, conversationId represents the session identifier, itemId represents the session item identifier, logicalRole represents the semantic role of the field, relativePath represents the relative path, byteLength represents the byte length, and contentSha256 represents the SHA-256 digest value of the content; the above fields are used together for external object location, semantic binding, and verification on the read side.

[0062] The structured external handle records the complete algorithm digest value, not the digest prefix, to ensure that there is a complete digest comparison basis during verification.

[0063] It should be noted that in actual implementation, the hash algorithm can be selected from 256-bit secure hash algorithm (SHA-256), 384-bit secure hash algorithm (SHA-384), 512-bit secure hash algorithm (SHA-512), Black2 hash algorithm (BLAKE2), Black3 hash algorithm (BLAKE3), or other hash algorithms, depending on the system security strategy and performance requirements.

[0064] Additionally, structured external handles can contain version numbers, so that only supported versions are patched during reading, while other versions can be reported as errors or handled according to the upgrade strategy.

[0065] In some embodiments, such as Figure 3 and Figure 5 As shown, the semantic splitting and persistence method for the agent's session items also includes: enqueuing and batch flushing; Add the session item entity that has completed the traffic splitting process to the concurrent secure write queue with the session identifier as the key; When the length of the concurrent safe write queue reaches the preset batch flush threshold, or when the timed flush service detects that there are items to be written in the session, a transaction batch write is performed; if the write fails, the items of this batch of sessions are put back into the queue and retried when triggered later.

[0066] The following example illustrates the scenario where an agent continuously initiates multiple tool calls during a session.

[0067] In this scenario, the agent generates multiple session items of both function call request type (function_call) and function call output type (function_call_output). Each session item first undergoes parameter field (Arguments) or output field (Output) splitting based on the candidate semantic field matrix, and then is added to a write queue with the same session identifier as the key. When the queue reaches a preset batch flush threshold, a batch write is triggered, writing these session items to the database in batches and updating the session update time and message count. If the database commit fails, the batch of session items is put back into the queue, awaiting subsequent timed flushes or new write triggers.

[0068] The above embodiments can adapt to the characteristics of append-type, high-frequency, and session-aggregated writes during the operation of intelligent agents. By batch aggregation and submission, the number of database transaction interactions is effectively reduced, and the write throughput is improved. At the same time, the failure replay mechanism enhances the fault tolerance of write operations, avoids the risk of data loss due to momentary database failures, and improves reliability.

[0069] In some embodiments, the semantic splitting and persistence method for agent session items further includes: Upon receiving a shutdown signal, the current write session is flushed to disk, reducing the amount of uncommitted data in the memory queue.

[0070] In some implementations, data inconsistency arises between the system and the database when an external file is successfully written but the database transaction fails to commit. To address this anomaly, the following recovery strategies can be employed: The current batch of session items are put back into the write queue with the session identifier as the key, and will be automatically retried when the disk is flushed later. During subsequent retry writes, an idempotent overwrite operation is performed on the target storage path based on the session identifier, session item identifier, and digest prefix to ensure that the external content is consistent with the content pointed to by the database handle. Alternatively, the byte sequence corresponding to the target storage path can be marked as an orphan file to be cleaned, and a separate background cleaning service can perform regular cleaning during system off-peak hours.

[0071] The above strategies can be flexibly combined or selected individually based on the fault type, number of retries, and operation and maintenance strategies. For example, the system can set a maximum number of retries (e.g., 3 times), and after exceeding this number, it will switch to the orphan file cleanup process to avoid infinite retries blocking the write queue; or it can directly use idempotent overwrite when the first failure occurs.

[0072] In some embodiments, when an external write to a candidate semantic field fails, a handle to that external object should not be written to the database.

[0073] In some embodiments, multiple pending session items in the same session are organized by session identifier to avoid cross-session blocking; within the same session, they can be flushed to disk according to generation time or session item order.

[0074] In some embodiments, when a user deletes a historical session, the system first confirms that the session belongs to the current user or the current agent, and then deletes the session record and associated session items in the database. After successful database deletion, the system deletes the corresponding directory or object prefix in external storage based on the session identifier, and may further delete the vector index or cache associated with the session. If external file deletion fails, the system logs the error and can proceed to the subsequent cleanup process.

[0075] Correspondingly, such as Figure 2 and Figure 6 As shown in the embodiments of this specification, a transparent completion method for agent conversation items is also provided, applied to the reading side, including: Load database records: Read session item records from the database based on conditions such as session identifier, user identifier, and agent identifier.

[0076] Shallow Handle Identification for Candidate Semantic Fields: Shallow detection is performed only on fields within the candidate semantic field matrix. The preset candidate semantic field matrix is ​​traversed to determine whether each field is a structured external handle. Specifically, a JSON-formatted structured handle is used as an example: If a field is empty or does not appear in the form of a JSON object, it is determined to be ordinary inline content, and the original data in the database is used directly. If a field is a JSON object and contains necessary attributes such as handle version, type identifier, and relative path, it is determined to be a structured external handle.

[0077] It should be noted that no deep recursive scanning is performed on tool parameters or business JSON (JavaScript object notation) at this stage, in order to avoid misjudging legitimate business JSON as external handles.

[0078] External file reading and verification: For the identified structured external handle, read the corresponding external data according to the target storage path in the structured external handle. After reading, verify whether the byte length is consistent with the byte length in the handle. Recalculate the content digest using the same digest algorithm on the writing side, and then compare it with the integrity digest value stored in the handle.

[0079] Original text restoration: If the length and digest are consistent, i.e. the verification passes, the byte sequence is restored to the original string according to the encoding method in the handle, and the value of the corresponding field in the session item is replaced.

[0080] Anomaly blocking: If an external file does not exist, is unreadable, has an inconsistent length, or an inconsistent digest, the return of this session item will be blocked, and no unverified data will be output. This can handle HTTP errors, remote procedure call errors, returned error objects, thrown exceptions, or audit warnings, and can also simultaneously log structured data.

[0081] Under no circumstances should internal handles, empty fields, or unverified content be disguised as normal session items and returned. This solves the problem in traditional hybrid storage / large field external solutions where incomplete running traces are disguised as normal historical sessions when external files are missing, have inconsistent lengths, or fail digest verification.

[0082] After completing the above recovery process, the session item is returned to the upper-layer interface in the same data format as before writing. The front-end, the intelligent agent framework, and the business caller do not need to be aware of whether the field is external.

[0083] The following example illustrates the scenario of restoring historical sessions to the agent context after the agent platform restarts.

[0084] When the frontend requests a historical session item, after retrieving the session item from the database, it first calls the unified recovery entry point to expand the external handles in candidate fields such as Content, Arguments, Output, and Usage. It then reads the external files, verifies their length and summary, and restores each field to its original string (e.g., restoring the Output field to the original tool execution result string). Subsequently, the fully restored session item is written to the agent context or in-memory session storage. At this point, the frontend still receives the output field strings and is unaware of the externalization process.

[0085] Since the original semantic field content is entered into the context, rather than the external handle, the agent can obtain the historical running trajectory consistent with the state when it was not externalized during subsequent reasoning, ensuring the accuracy and reliability of context recovery.

[0086] In some embodiments, such as Figure 7 As shown, in order to ensure that the intelligent agent's session items are consistent with external formats, a unified external completion entry is set up, and the external completion entry is reused in at least one of the following scenarios: Main path backfill before database read return: After reading the session item from the database, immediately perform backfill on the candidate fields to produce a restored session item data transfer object (DTO). Main path restoration before agent session memory restoration: When it is necessary to restore historical session items to the agent running context or memory session storage, the unified restoration entry is also called to ensure that the original field content is entered into the context, rather than the external handle; Lightweight fallback buffer before external response serialization: Before outputting the session item list response, a shallow check is performed on the fields to be serialized; if an external handle is found, the unified buffer entry is called to expand it; if the buffer is successful, the output continues; if the buffer fails, the response is blocked, thus effectively preventing internal handles from entering the browser or software development kit (SDK), while avoiding deep recursive scanning of all business JSON.

[0087] The above three locations use a unified backup entry point to avoid the database read path, memory backup path and Hypertext Transfer Protocol (HTTP) response path each implementing their own set of parsing logic, thereby significantly reducing the risks of handle leakage, field form drift and unrecoverable historical sessions.

[0088] In some embodiments, the transparent completion method for agent session items further includes: If the external file corresponding to the target storage path does not exist or is unreadable, the read operation is deemed to have failed, and the session item is blocked from returning.

[0089] Let's take the example of an external file being corrupted.

[0090] If an output field in the database is stored as a structured handle, but the corresponding external file is accidentally deleted or its content is modified, resulting in inconsistent summaries, the system will detect an anomaly during reading. In this case, the system will not return an empty output, a structured handle, or display the session item as normal historical data. Instead, it will return an error and log it, ensuring the reliability of the agent's operational trajectory.

[0091] Furthermore, this embodiment requires that the externalization and recovery processes be transparent to the front-end, the intelligent agent framework, and the business caller. In other words, the session item fields returned externally remain in their original key and string form as when they were not externalized. For example: The arguments field of the tool call request type (function_call) still returns the tool call parameter string; The output field of the function call output type (function_call_output) still returns the string of the tool execution result; The content field of the message type still returns a JSON document or equivalent structure representing an array of content fragments, and the usage field still returns the original serialized content corresponding to the usage statistics.

[0092] Internal structured handles exist only in the server-side persistence layer and are not part of the external application programming interface (API) contract.

[0093] Based on the same inventive concept, this application also provides a semantic splitting persistence and transparent completion system for intelligent agent conversation items, including: A write processing module is used to execute the semantic splitting and persistence method for intelligent agent session items described in the embodiments of this application; The read-and-complete module is used to execute the transparent completion method for agent conversation items described in the embodiments of this application; The maintenance module is used to perform background asynchronous inspections of the consistency between the database and external storage media, and to clean up and reclaim orphan files caused by write transaction failures or abnormal interruptions.

[0094] like Figure 5 As shown, this embodiment not only focuses on writing and reading, but also covers the end-of-life stage of the intelligent agent's running trajectory data, solving the problem of inconsistency between the database and external files during lifecycle stages such as session deletion, service shutdown, and write failure.

[0095] In this specification, the same or similar parts between the various embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the descriptions of the embodiments described later are relatively simple, and relevant parts can be referred to the descriptions of the foregoing embodiments.

[0096] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A semantic splitting and persistence method for agent conversation items, characterized in that, Applied to the write side, including: Receive a session item generated by the intelligent agent operation platform, wherein the session item includes at least a session identifier, a session item type, and at least one semantic field; Based on the session item type, a preset candidate semantic field matrix is ​​queried to determine the candidate semantic fields in the session item that participate in the traffic splitting judgment; The candidate semantic fields are serialized to obtain the corresponding byte sequence, and the byte length of the byte sequence is obtained. If the length of the bytes exceeds a preset threshold, then semantic binding external processing is performed; The semantic binding external processing includes: Determine the session item identifier of the session item; The target storage path is generated based on the session identifier, the session item identifier, the content summary information of the byte sequence, and the semantic role. Write the byte sequence into the external storage medium corresponding to the target storage path; Based on the session item identifier, a structured external handle is replaced and written in the original storage location of the candidate semantic field in the database to complete the persistence of the session item in the database; the structured external handle encapsulates the session identifier, the session item identifier, the semantic role, the target storage path, and the content summary information.

2. The semantic splitting and persistence method for agent conversation items according to claim 1, characterized in that, The session item identifier for determining the session item includes: If the session item carries an initial session item identifier, then the initial session item identifier is validated by path security rules. If the validation passes, then the initial session item identifier is determined as the session item identifier of the session item. If the session item does not carry an initial session item identifier, or the initial session item identifier fails the verification, a session item identifier that satisfies the path security rules is generated.

3. The semantic splitting and persistence method for agent conversation items according to claim 1, characterized in that, The generation of the target storage path includes: Perform a digest operation on the byte sequence to obtain an algorithm digest value, and extract the first N characters of the algorithm digest value as a path naming segment, where N is a preset positive integer; The session identifier, the session item identifier, the path naming fragment, and the semantic role are used to generate the target storage path according to a preset path naming rule; The content summary information in the structured external handle is the complete algorithm summary value, which is used for comparison during read-side verification.

4. The semantic splitting and persistence method for agent conversation items according to claim 1, characterized in that, The semantic splitting and persistence method for agent session items also includes: Add the completed session items to the concurrent safe write queue with the session identifier as the key; When the length of the concurrent secure write queue reaches the preset batch disk flushing threshold, or when a timed disk flushing service instruction is received, the session items in the concurrent secure write queue are written to the database in batches. If the write fails, the session items in the current batch are rolled back to the concurrent safe write queue to wait for a retry.

5. The semantic splitting and persistence method for agent conversation items according to claim 4, characterized in that, The semantic splitting and persistence method for agent session items also includes: Upon receiving a shutdown signal, a flush operation is performed on the session item in the concurrent secure write queue to clear the concurrent secure write queue. If the byte sequence is successfully written to the external storage medium, but the session item fails to be persisted in the database, then an idempotent overwrite operation is performed on the target storage path based on the session identifier, the session item identifier, and the content summary information, or a periodic cleaning is performed through a cleaning service.

6. The semantic splitting and persistence method for agent conversation items according to claim 1, characterized in that, The semantic splitting and persistence method for agent session items also includes: In response to a session item deletion command, the corresponding session item is deleted from the database, and the structured external handle associated with the session item is obtained. Based on the target storage path in the structured external handle, perform asynchronous cleanup on the external storage medium to delete the corresponding byte sequence; Based on the session identifier, delete the vector index or cache associated with the session item.

7. A transparent completion method for agent conversation items, characterized in that, Applied to the read side, including: Read session item records from the database; Iterate through the preset candidate semantic field matrix and identify each candidate semantic field in the conversation item: If the field content is a structured external handle, then parse the structured external handle to obtain the target storage path and content summary information; The byte sequence is read according to the target storage path, and the integrity of the byte sequence is performed using the content digest information; If the verification passes, the byte sequence is restored to the original data, and the corresponding field value in the session item is replaced; if the verification fails, the return of the session item is blocked. If the field content is not the structured external handle, then the data in the database is used directly; The processed session item is returned to the upper-layer interface in the same data format as before it was written.

8. The transparent completion method for agent conversation items according to claim 7, characterized in that, The transparent completion method for agent conversation items further includes: setting a unified external completion entry point, and reusing the external completion entry point for at least one of the following scenarios: The return phase after reading session item records from the database; Restore historical session items to the agent's runtime context or memory session storage stage; The serialization and identification phase before outputting the session item list response.

9. The transparent completion method for agent conversation items according to claim 8, characterized in that, The transparent completion method for agent session items also includes: If the external file corresponding to the target storage path does not exist or is unreadable, the read operation is deemed to have failed, and the session item is blocked from returning.

10. A semantic splitting persistence and transparent completion system for intelligent agent conversation items, characterized in that, include: A write processing module is used to execute the semantic splitting and persistence method for agent session items as described in any one of claims 1-6; A read-and-paste module is used to execute the transparent read-and-paste method for agent session items as described in any one of claims 7-9; The maintenance module is used to perform background asynchronous inspections of the consistency between the database and external storage media, and to clean up and reclaim orphan files caused by write transaction failures or abnormal interruptions.

Citation Information

Patent Citations

  • Large model deployment method and system based on multi-level cache mechanism

    CN119739809A

  • Dialogue processing method and device based on historical session recognition, equipment and medium

    CN120450048A