End judgment method and device for multi-agent asynchronous session and related equipment

CN122554512APending Publication Date: 2026-08-11BEIJING TAIXIN TIANCHENG TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-04
Publication Date
2026-08-11

AI Technical Summary

Technical Problem

[0004]本发明实施例提供了面向多智能体异步会话的结束判断方法、装置及相关设备,旨在解决现有的会话结束判断方法难以准确判断会话结束的技术问题

Benefits of technology

[0009]This invention provides a method, apparatus, and related equipment for determining the end of multi-agent asynchronous sessions. The method receives user messages, records the session information of the current master agent, and initializes the state of the corresponding child agents; it receives asynchronous events and filters them according to session tree affiliation based on the session information to obtain events belonging to the same session tree; it verifies the identifier information of the events belonging to the same tree to obtain verified events that match the identifier information corresponding to the current master session; it monitors the states of the master session state machine and the child session state machines, and determines that the current master session has ended if the following conditions are met simultaneously: the master session is in an ended state, the number of child sessions is zero, and the silence time of the nearest valid event reaches a preset silence window. This application, through the collaborative determination of the master running state machine and the child session state machines, can significantly reduce the probability of premature termination in multi-agent asynchronous sessions. Single events such as the end of master agent operation, final message, or yielding will not directly lead to session completion.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122554512A_ABST
    Figure CN122554512A_ABST
Patent Text Reader

Abstract

This invention discloses a method, apparatus, and related devices for determining the end of asynchronous multi-agent sessions. The method receives user messages, records the session information of the current master agent, and initializes the state of the corresponding child agents; it receives asynchronous events and filters them according to session tree affiliation based on the session information to obtain events belonging to the same session tree; it verifies the identifier information of the events belonging to the same tree to obtain verified events that match the identifier information corresponding to the current master session; it monitors the states of the master session state machine and the child session state machines, and determines that the current master session has ended if the following conditions are met simultaneously: the master session is in an ended state, the number of child sessions is zero, and the silence time of the nearest valid event reaches a preset silence window. This application, through the collaborative determination of the master running state machine and the child session state machine, can significantly reduce the probability of premature termination in asynchronous multi-agent sessions. Single events such as the end of master agent operation, final message, or yielding will not directly lead to session completion.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to the field of artificial intelligence technology, and in particular to a method, apparatus and related equipment for determining the end of asynchronous sessions for multiple agents. Background Technology

[0002] With the development of large language models and intelligent agent technology, the task execution mode of intelligent agent systems has gradually evolved from single-turn question-and-answer to a complex process involving a main intelligent agent, sub-intelligent agents, tool invocation, file operations, asynchronous event pushing, and session resumption. In such systems, the front-end or business system typically receives model-generated content, tool invocation progress, lifecycle events, and session state change events through asynchronous communication channels such as WebSocket (a network protocol for full-duplex communication over a single TCP connection), and determines whether a user session has been completed based on this information.

[0003] Existing session completion detection schemes typically rely on a single completion event, the last message event, or a fixed timeout mechanism. In multi-agent collaborative scenarios, the master agent may create child agents through tool calls during execution and delegate subsequent tasks to child agents or wait for child agents to return results through a yielding mechanism. Due to the asynchronous and out-of-order nature of WebSocket events, the lifecycle start event of a child agent may arrive later than the tool result event of the master agent. If the system determines session completion solely based on the master agent's completion or the final message, it may send a completion signal to the front end prematurely before the child agent has finished executing, resulting in missing results. Summary of the Invention

[0004] This invention provides a method, apparatus, and related equipment for determining the end of asynchronous multi-agent sessions, aiming to solve the technical problem that existing session end determination methods are difficult to accurately determine the end of a session.

[0005] In a first aspect, embodiments of the present invention provide a method for determining the end of an asynchronous multi-agent session, comprising: Receive user messages, record the current session information of the main agent, and initialize the state of the corresponding sub-agent. The session information includes at least the corresponding session key and runtime ID. Receive asynchronous events and perform session tree affiliation filtering on the asynchronous events based on the session information to obtain events belonging to the same session tree; The relevant identification information of the aforementioned events is verified to obtain the verification events that match the identification information corresponding to the current main session; Monitor the state of the main session state machine and the sub-session state machine. If the following conditions are met simultaneously, the current main session is determined to have ended: the main session is in an ended state, the number of sub-sessions is zero, and the silence time of the nearest valid event reaches the preset silence window.

[0006] Secondly, embodiments of the present invention provide an end-determination device for multi-agent asynchronous sessions, comprising: The recording module is used to receive user messages, record the current session information of the main agent, and initialize the state of the corresponding sub-agent. The session information includes at least the corresponding session key and running ID. The attribution filtering module is used to receive asynchronous events and perform session tree attribution filtering on the asynchronous events according to the session information to obtain the same events belonging to the same session tree. The verification module is used to verify the identification information of the related events and obtain the verification events that match the identification information corresponding to the current main session. The state detection module is used to monitor the state of the main session state machine and the sub-session state machine. If the following conditions are met simultaneously, it is determined that the current main session has ended: the main session is in an ended state, the number of sub-sessions is zero, and the silence time of the nearest valid event has reached the preset silence window.

[0007] Thirdly, embodiments of the present invention provide a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the termination determination method for multi-agent asynchronous sessions described in the first aspect.

[0008] Fourthly, embodiments of the present invention provide a readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the processor performs the termination determination method for multi-agent asynchronous sessions described in the first aspect.

[0009] This invention provides a method, apparatus, and related equipment for determining the end of multi-agent asynchronous sessions. The method receives user messages, records the session information of the current master agent, and initializes the state of the corresponding child agents; it receives asynchronous events and filters them according to session tree affiliation based on the session information to obtain events belonging to the same session tree; it verifies the identifier information of the events belonging to the same tree to obtain verified events that match the identifier information corresponding to the current master session; it monitors the states of the master session state machine and the child session state machines, and determines that the current master session has ended if the following conditions are met simultaneously: the master session is in an ended state, the number of child sessions is zero, and the silence time of the nearest valid event reaches a preset silence window. This application, through the collaborative determination of the master running state machine and the child session state machines, can significantly reduce the probability of premature termination in multi-agent asynchronous sessions. Single events such as the end of master agent operation, final message, or yielding will not directly lead to session completion. Attached Figure Description

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

[0011] Figure 1 This is a flowchart illustrating an embodiment of the method for determining the end of asynchronous sessions for multiple agents provided in this invention. Figure 2 This is a schematic block diagram of an end-determination device for asynchronous multi-agent sessions provided in an embodiment of the present invention. Detailed Implementation

[0012] 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, not all, of the embodiments of 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.

[0013] It should be understood that, when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.

[0014] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.

[0015] It should also be further understood that the term "and / or" as used in this specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.

[0016] Please see Figure 1 This is a flowchart illustrating the method for determining the end of an asynchronous session for multiple agents provided in an embodiment of the present invention. The method includes steps S110 to S140.

[0017] Step S110: Receive user messages, record the current main agent's session information, and initialize the state of the corresponding sub-agent. The session information includes at least the corresponding session key and running ID. In this embodiment, the system operates on the client side or server proxy layer of the intelligent agent gateway connected via WebSocket or other asynchronous message channels. After receiving the server's acceptance confirmation frame for the request, the system sets the request state to "started" and records the unique identifier of the main session (main session identifier, i.e., session key) and the unique identifier of this run (main run identifier, i.e., run ID). The main run state is initialized to "running," the sub-session state set is cleared, and the yield flag, tool call flag, historical compensation flag, and final state callback flag are all reset to their initial values. This initialization ensures that each new request starts from a clean state, unaffected by the previous round's request state. Simultaneously, the system activates a global timeout guard and a heartbeat timeout guard. The former limits the maximum execution time of the entire session, while the latter detects abnormal situations with no consecutive valid events. Both force a completion callback before the final state callback is triggered, thus preventing the session from being permanently suspended due to server abnormalities, event loss, or network failures. The complete recording of the request context during the initialization phase allows all subsequent event processing to be based on a unified session tree and run identifier for attribution determination, laying the foundation for accurate completion determination.

[0018] Step S120: Receive asynchronous events and perform session tree affiliation filtering on the asynchronous events according to the session information to obtain events belonging to the same session tree; In this embodiment, session tree affiliation filtering for asynchronous events includes: determining whether an asynchronous event meets any of the following conditions; if it does, it passes the session tree affiliation filtering; otherwise, it is discarded: the session identifier of the asynchronous event is equal to the session key of the current main session; or, the derived source identifier of the asynchronous event is equal to the session key of the current main session; or, the parent session identifier of the asynchronous event is equal to the session key of the current main session; or, the session key of the asynchronous event already exists in the sub-session state set of the current main session. Specifically, the types of events pushed by the intelligent agent gateway through the asynchronous channel are diverse, including assistant message events, intelligent agent lifecycle events, tool call events, and session change events. In multi-session concurrent scenarios, events from other user sessions, historical sessions, or sibling sessions may be mixed in the same channel. Session tree affiliation filtering compares the session identifier, derived source identifier, and parent session identifier item by item, discarding events unrelated to the current request at the earliest stage, preventing irrelevant events from affecting the state maintenance of the current request. For sub-sessions that have been pre-registered, all subsequent events generated by them can be affiliated through the sub-session state set without re-comparing the derived source link, thus improving processing efficiency. By using multi-dimensional session tree attribution filtering, event crosstalk in multi-session concurrent scenarios can be effectively isolated, ensuring the accuracy of current request state maintenance.

[0019] Step S130: Verify the identification information of the related events to obtain the verification events that match the identification information corresponding to the current main session; In this embodiment, a runtime identifier correlation check is performed on the lifecycle events of the agent belonging to the main session, and only events whose runtime identifiers match the current main runtime identifier are processed. Specifically, when the main agent performs a yielding action and is restored by the completion result of a child agent, the main session generates a new runtime identifier. If runtime identifier verification is not performed, the lifecycle events generated by the old operation may affect the state of the new operation event. By strictly comparing runtime identifiers in the main session event processing, the system can distinguish between currently active operations and historical old operations, avoiding the mistaken setting the current main operation state to the final state prematurely by the end event of the old operation. By adopting the above technical solution, through runtime identifier correlation verification, accurate event attribution is achieved in multi-round operation scenarios, avoiding interference from old operation events on the new operation state, and improving the accuracy of session completion determination in session recovery scenarios.

[0020] Step S140: Monitor the state of the main session state machine and the sub-session state machine. If the following conditions are met simultaneously, it is determined that the current main session has ended: the main session is in an ended state, the number of sub-sessions is zero, and the silence time of the nearest valid event has reached the preset silence window.

[0021] In this embodiment, when a main running lifecycle end event is detected, it is determined whether the current run has called a yielding tool or whether there are still active sub-sessions. If so, the main running state is set to the yielding state; otherwise, the main running state is set to the truly ended state. When a running error event is detected, the main running state is set to the error state. Specifically, the yielding tool is a tool used by the main agent to actively end the current execution round and hand over the task to the sub-agent. The system listens for the tool name in the tool call event. Once the yielding tool is detected to be called, a yielding flag is immediately set. When a subsequent main running lifecycle end event arrives, the system reads this flag: if the flag indicates that the yielding tool has been called, or that there are still active sub-sessions in the current sub-session state set, it means that the end of the current run only represents the completion of this execution round, and the main agent will still be restored after the sub-tasks are completed. Therefore, the main running state is set to the yielding state, not the truly ended state; if the flag indicates that it has not been called and there are no active sub-sessions, it means that the main agent has completed all tasks, and the main running state is set to the truly ended state. Only when the main agent's running state is truly finished is the subsequent completion determination process allowed. By adopting the above technical solution, and distinguishing between the yielding state and the truly finished state, the problem of premature termination in multi-agent asynchronous collaboration scenarios is avoided, as the main agent's yielding in the middle is not mistakenly judged as the final completion of the session.

[0022] In one embodiment, monitoring the state of the sub-session state machine includes: registering the corresponding sub-session as active when a sub-agent lifecycle start event, a non-final session change event, or other events indicating that the sub-session has started are received; and registering the corresponding sub-session as final when a sub-agent lifecycle end event, an error event, or a final session change event is received. Specifically, the system maintains an independent state entry for each sub-session, using the sub-session identifier as the key and the active or final state as the value. Sub-session final states include completion, failure, termination, timeout, etc., and the specific enumeration values ​​can be extended and configured according to the protocol specifications of the agent platform. The system does not rely on the sub-session list contained in the main session snapshot to determine active sub-sessions, because the snapshot may simultaneously contain sub-sessions that are still running, sub-sessions with active descendants, and sub-sessions that have ended recently. If all sub-session identifiers present in the snapshot are directly marked as active, historical sub-sessions may be re-included in the active count, causing the session to never end. Therefore, the system strictly adheres to the independently maintained set of sub-session states and performs accurate state updates based on real-time events. By adopting the above technical solution, the current state of each sub-agent can be accurately tracked through an independently maintained sub-session state machine, avoiding misjudgment caused by relying on unreliable snapshot information and ensuring the accuracy of the "no active sub-session" condition in the judgment.

[0023] In one implementation, the silent window determination includes: updating the most recent event timestamp whenever a valid event related to the current session tree is received; scheduling a delayed completion check after each critical state change; canceling the old check and rescheduling if a new valid event is received within the delayed window; and allowing the final completion determination to be triggered only when the most recent event is more than a preset silent window away from the current time. Specifically, since the arrival order of lifecycle events, chat final message events, tool call events, and session change events in an asynchronous channel cannot be fully predicted, if a completion determination is performed immediately after one of these events arrives, the session may be mistakenly judged as completed before subsequent events arrive. The silent window mechanism introduces a waiting period to ensure that no new related events arrive during this period before performing the final completion condition check. The length of the silent window can be configured according to the business scenario and network latency, and can be dynamically adjusted during operation, generally set to a range of hundreds of milliseconds to several seconds to achieve a balance between response speed and determination accuracy. By adopting the above technical solution, the silent window mechanism serves as the last line of defense for multi-condition completion judgment, which can effectively prevent premature termination caused by out-of-order events and improve the robustness of completion judgment in complex network environments.

[0024] This method receives user messages, records the current master agent's session information, and initializes the state of the corresponding child agents; it receives asynchronous events and filters them according to session tree affiliation based on session information to obtain events belonging to the same session tree; it verifies the identifier information of the events belonging to the same tree to obtain verified events that match the identifier information corresponding to the current master session; it monitors the state of the master session state machine and the child session state machine, and determines that the current master session has ended if the following conditions are met simultaneously: the master session is in an ended state, the number of child sessions is zero, and the silence time of the nearest valid event reaches a preset silence window. This application, through the collaborative determination of the master running state machine and the child session state machine, can significantly reduce the probability of premature termination in multi-agent asynchronous sessions. Single events such as the end of master agent operation, final message, or yielding will not directly lead to session completion.

[0025] This invention also provides an end-of-session determination device for multi-agent asynchronous sessions. This device is used to execute any embodiment of the aforementioned end-of-session determination method for multi-agent asynchronous sessions. Specifically, please refer to... Figure 2 , Figure 2 This is a schematic block diagram of an end-of-session determination device for multi-agent asynchronous sessions provided in an embodiment of the present invention. This end-of-session determination device 100 for multi-agent asynchronous sessions can be configured in a server.

[0026] like Figure 2As shown, the termination determination device 100 for multi-agent asynchronous sessions includes a recording module 110, an attribution filtering module 120, a verification module 130, and a state detection module 140.

[0027] The recording module 110 is used to receive user messages, record the current session information of the main agent, and initialize the state of the corresponding sub-agent. The session information includes at least the corresponding session key and running ID. The attribution filtering module 120 is used to receive asynchronous events and perform session tree attribution filtering on the asynchronous events according to the session information to obtain the same events belonging to the same session tree. The verification module 130 is used to verify the identification information of the related events to obtain the verification events that match the identification information corresponding to the current main session. The state detection module 140 is used to monitor the state of the main session state machine and the sub-session state machine. If the following conditions are met simultaneously, it is determined that the current main session has ended: the main session is in an ended state, the number of sub-sessions is zero, and the silence time of the nearest valid event has reached the preset silence window.

[0028] This invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the termination determination method for multi-agent asynchronous sessions as described above.

[0029] In another embodiment of the invention, a computer-readable storage medium is provided. This computer-readable storage medium may be a non-volatile computer-readable storage medium. The computer-readable storage medium stores a computer program that, when executed by a processor, causes the processor to perform the termination determination method for multi-agent asynchronous sessions as described above.

[0030] Those skilled in the art will readily understand that, for the sake of convenience and brevity, the specific working processes of the devices, apparatuses, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this invention.

[0031] In the embodiments provided by this invention, it should be understood that the disclosed devices, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Units with the same function may be grouped into one unit. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. In addition, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interfaces, devices, or units, or it may be an electrical, mechanical, or other form of connection.

[0032] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of the embodiments of the present invention, depending on actual needs.

[0033] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0034] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), magnetic disks, or optical disks.

[0035] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and these modifications or substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A method for determining the end of an asynchronous multi-agent session, characterized in that, include: Receive user messages, record the current session information of the main agent, and initialize the state of the corresponding sub-agent. The session information includes at least the corresponding session key and runtime ID. Receive asynchronous events and perform session tree affiliation filtering on the asynchronous events based on the session information to obtain events belonging to the same session tree; The relevant identification information of the aforementioned events is verified to obtain the verification events that match the identification information corresponding to the current main session; Monitor the state of the main session state machine and the sub-session state machine. If the following conditions are met simultaneously, the current main session is determined to have ended: the main session is in an ended state, the number of sub-sessions is zero, and the silence time of the nearest valid event reaches the preset silence window.

2. The method for determining the end of asynchronous multi-agent sessions as described in claim 1, characterized in that, The session tree attribution filtering of the asynchronous events includes: Determine whether the asynchronous event meets any of the following conditions. If it does, filter it according to the session tree affiliation; otherwise, discard the asynchronous event: The session identifier of the asynchronous event is equal to the session key of the current main session; Alternatively, the source identifier of the asynchronous event is equal to the session key of the current main session; Alternatively, the parent session identifier of the asynchronous event is equal to the session key of the current main session; Alternatively, the session key for the asynchronous event already exists in the sub-session state set of the current main session.

3. The method for determining the end of asynchronous multi-agent sessions as described in claim 1, characterized in that, Monitoring the state of the main session state machine includes: When the end of the main runtime lifecycle event is detected, it is determined whether the current runtime has called the yielding tool or whether there is an active sub-session. If so, then set the main running state to the yielding state; If not, then set the main running state to the true terminated state; When a runtime error event is detected, the main runtime state is set to an error state.

4. The method for determining the end of asynchronous multi-agent sessions as described in claim 1, characterized in that, Monitoring the state of the sub-session state machine includes: When a sub-agent lifecycle start event, a non-final session change event, or other event indicating that a sub-session has been started is received, the corresponding sub-session will be registered as active. When a sub-agent lifecycle end event, error event, or final state session change event is received, the corresponding sub-session will be registered as final state.

5. A device for determining the end of an asynchronous multi-agent session, characterized in that, include: The recording module is used to receive user messages, record the current session information of the main agent, and initialize the state of the corresponding sub-agent. The session information includes at least the corresponding session key and running ID. The attribution filtering module is used to receive asynchronous events and perform session tree attribution filtering on the asynchronous events according to the session information to obtain the same events belonging to the same session tree. The verification module is used to verify the identification information of the related events and obtain the verification events that match the identification information corresponding to the current main session. The state detection module is used to monitor the state of the main session state machine and the sub-session state machine. If the following conditions are met simultaneously, it is determined that the current main session has ended: the main session is in an ended state, the number of sub-sessions is zero, and the silence time of the nearest valid event has reached the preset silence window.

6. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the termination determination method for multi-agent asynchronous sessions as described in any one of claims 1 to 4.

7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, causes the processor to perform the termination determination method for multi-agent asynchronous sessions as described in any one of claims 1 to 4.