Session management for generative models, apparatus, electronic device, and storage medium

By using a generative model for session management and leveraging keep-alive events to maintain streaming connections, the problem of silent periods caused by the uncertainty of external tool execution is solved, avoiding wasted computing power and connection interruptions, and improving user experience and task continuity.

CN123185175APending Publication Date: 2026-11-27UC MOBILE CHINA CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611087594.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-21
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

Generative models experience a silent period due to the uncertainty of execution time when calling external tools, which leads to interruption of streaming connections and users giving up waiting, resulting in wasted computing power.

Method used

By generating keep-alive events corresponding to the execution status of external tools, streaming connections are maintained. This includes adaptive sending strategies and keep-alive events, dynamically adjusting sending intervals and conditions, and keeping the client aware of the execution progress.

Benefits of technology

It effectively avoids interruptions in streaming connections, reduces wasted computing power, improves user experience, and ensures the continuity and efficiency of generated tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123185175A_ABST
    Figure CN123185175A_ABST
Patent Text Reader

Abstract

The application discloses a session management of a generative model, an apparatus, an electronic device and a storage medium. The method comprises the following steps: establishing a long connection streaming connection for real-time data transmission with a client according to a user session request from the client; identifying whether a generative task corresponding to the user session request triggers a calling instruction of an external tool; if yes, generating a keep-alive event corresponding to an execution state of the external tool according to the execution state of the external tool; and sending the keep-alive event to the client one or more times through the long connection streaming connection, so that the keep-alive event can be perceived by a user of the client. The method can maintain the connection with the generative model during a silent period of tool calling, and effectively avoid the waste of computing power caused by the user giving up.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of artificial intelligence technology, specifically to a session management system for generative models; this application also relates to corresponding devices, equipment and storage media. Background Technology

[0002] As generative models have become more powerful, their applications have expanded from simple text generation to system architectures that can proactively invoke external tools based on user commands and generate responses based on the execution results. In this architecture, generative models need to leverage external tools such as external retrieval, database queries, or business interfaces to improve their response quality.

[0003] However, the execution time of external tools is often highly uncertain due to factors such as service response fluctuations and computational complexity. During tool execution, the generative model is in a waiting state and cannot produce formal content, resulting in a silent period without output data on the streaming transmission link. This silent period prevents client users from knowing the task execution status, causing them to give up waiting for the generated content, resulting in the abandonment of previous results and a waste of computing power.

[0004] To address the aforementioned issues, existing technologies typically maintain the connection by sending heartbeat packets or empty packets at fixed intervals over the streaming connection. However, this heartbeat cannot sustain the user's expectation of the generated content and will still cause the user to abandon the wait for the generated content output, for example, by actively disconnecting the connection or restarting the task. These actions will result in the computing power used for the initial content generation being wasted, exacerbating the computing power shortage.

[0005] Therefore, how to maintain a valid connection during the silent period of tool calls, prevent customers from abandoning the ongoing generation process, and thus reduce the waste of computing power, is a technical problem that urgently needs to be solved. Summary of the Invention

[0006] This application provides a session management method for generative models. This method can maintain the connection with the generative model during the quiet period of tool invocation, effectively avoiding the waste of computing power caused by user abandonment.

[0007] This application provides a session management system for generative models, comprising: establishing a streaming connection with a client for real-time data transmission based on a user session request from the client; identifying whether the generation task corresponding to the user session request triggers a call instruction from the generative model to an external tool; if so, generating a keep-alive event corresponding to the execution state of the external tool based on the execution state of the external tool; and sending the keep-alive event to the client once or multiple times through the streaming connection, wherein the keep-alive event can be perceived by the user of the client.

[0008] Optionally, the execution status of the external tool includes: the status of the internal execution progress output by the external tool, and information reflecting the execution process of the external tool that is actively perceived based on the execution progress of the external tool.

[0009] Optionally, generating a keep-alive event corresponding to the execution state of the external tool includes: during the execution of the external tool, obtaining the state of the internal execution progress output by the external tool; generating a real-time execution state corresponding to the state of the internal execution progress; and generating a keep-alive event corresponding to the real-time execution state based on the real-time execution state.

[0010] Optionally, the method further includes: during the execution of the external tool, acquiring link status parameters reflecting the external communication environment and tool execution parameters reflecting the internal execution progress of the external tool; generating an adaptive sending strategy based on the link status parameters and the tool execution parameters; wherein the adaptive sending strategy is used to dynamically adjust the sending interval and / or sending conditions of the keep-alive event; sending the keep-alive event to the client once or multiple times includes: sending the keep-alive event to the client once or multiple times according to the adaptive sending strategy.

[0011] Optionally, generating an adaptive sending strategy based on the link status parameters and the tool execution parameters includes: obtaining the historical execution time, current execution time, and link quality of the streaming connection of the external tool based on the link status parameters and the tool execution parameters; calculating the sending interval and / or sending conditions of the keep-alive event based on the relative relationship between the historical execution time and the current execution time and the link quality of the streaming connection; and using the sending interval and / or sending conditions as components of the adaptive sending strategy.

[0012] Optionally, the method further includes: stopping the sending of the keep-alive event in response to the completion of the external tool's execution; generating a tool completion event to reflect the completion of the external tool's execution; and sending the tool completion event to the client so that the client can perceive the end of the execution of the external tool and switch from the external tool's invocation state to the content display state of the generated task.

[0013] Optionally, the method further includes: obtaining the execution result of the external tool in response to the completion of the external tool's execution; generating formal answer content based on the execution result; generating a formal content event for display in the generation task based on the formal answer content; and sending the formal content event to the client.

[0014] Optionally, the method further includes: after the streaming connection is disconnected, receiving a reconnection request initiated by the client after the streaming connection is disconnected; restoring the streaming connection corresponding to the original user session request according to the reconnection request; identifying whether the generation task corresponding to the user session request has triggered an external tool invocation instruction according to the user session request; if so, obtaining the execution status of the external tool; and continuing to execute the generation task according to the execution status of the external tool.

[0015] Optionally, the reconnection request includes at least a session identifier and the latest received event sequence number; identifying whether the generation task corresponding to the user session request has triggered an external tool invocation instruction based on the user session request includes: querying the execution status of the generation task corresponding to the user session request related to the reconnection request based on the session identifier, and determining whether it has triggered an external tool invocation instruction; continuing to execute the generation task based on the execution status of the external tool includes one of the following: if the external tool is in the process of execution, then proceeding to the step of generating a keep-alive event corresponding to the execution status of the external tool, and sending the keep-alive event to the client once or multiple times through the streaming connection; if the external tool has completed execution but has not sent all event data to the client, then resending the undelivered event data to the client.

[0016] Optionally, the method further includes: after the streaming connection is disconnected, receiving a reconnection request initiated by the client after the streaming connection is disconnected; according to the reconnection request, attempting to restore the streaming connection corresponding to the original user session request; if restoring the streaming connection fails, sending result acquisition indication information to the client so that the client can obtain the execution result of the generation task.

[0017] Optionally, the method further includes: identifying whether the generation task corresponding to the user session request triggers a generative model's instruction to call external tools; if it is identified that the generation task triggers a batch call instruction for multiple external tools, then the following steps are performed: obtaining the execution status of each of the multiple external tools; aggregating the execution status of each of the multiple external tools according to a preset aggregation rule to generate an aggregated state reflecting the overall execution status of the multiple external tools; generating a keep-alive event corresponding to the execution status of the external tools based on the execution status of the external tools, including: generating a keep-alive event corresponding to the aggregated state of the external tools based on the aggregated state.

[0018] Optionally, the method is applied to a distributed system containing multiple service nodes for executing the generation task; the method further includes: during the execution of the external tool, writing the keep-alive event and the execution status of the external tool into a shared storage node; in response to a reconnection request initiated by the client after the streaming connection is disconnected, and the reconnection request is routed to a target service node different from the one before the client disconnected, reading the keep-alive event and the execution status of the external tool from the shared storage node through the target service node, so as to resume sending the keep-alive event to the client or continue transmitting the execution result of the external tool.

[0019] Optionally, the method is applied to a multi-regional operating environment, and the method further includes: obtaining cross-regional link quality parameters between the region where the client is located and the region where the service node used to execute the generation task is located; and adaptively adjusting the keep-alive event sending interval and timeout threshold according to the cross-regional link quality parameters to adapt to the cross-regional link quality parameters.

[0020] This application also provides a session management device for generative models, comprising: a session control unit, configured to establish a streaming connection with a client for real-time data transmission based on a user session request from the client; a model response control unit, configured to identify whether the generation task corresponding to the user session request triggers a call instruction from the generative model to an external tool; a keep-alive scheduling unit, configured to generate a keep-alive event corresponding to the execution state of the external tool; and to send the keep-alive event to the client once or multiple times through the streaming connection, wherein the keep-alive event can be perceived by the user of the client.

[0021] Optionally, the device further includes: a tool invocation identification unit, configured to acquire link status parameters reflecting the external communication environment and tool execution parameters reflecting the internal execution progress of the external tool during the execution of the external tool; a keep-alive strategy unit, further configured to generate an adaptive sending strategy based on the link status parameters and the tool execution parameters; wherein the adaptive sending strategy is used to dynamically adjust the sending interval and / or sending conditions of the keep-alive event; the sending of the keep-alive event to the client once or multiple times includes: sending the keep-alive event to the client once or multiple times according to the adaptive sending strategy.

[0022] Optionally, the keep-alive scheduling unit is further configured to stop sending the keep-alive event in response to the completion of the external tool; generate a tool completion event to reflect the completion of the external tool; and send the tool completion event to the client so that the client can perceive the end of the execution of the external tool and switch from the calling state of the external tool to the content display state of the generated task.

[0023] Optionally, the model response control unit is further configured to, in response to the completion of the external tool's execution, obtain the execution result of the external tool; generate formal answer content based on the execution result; generate a formal content event for display in the generation task based on the formal answer content; and send the formal content event to the client.

[0024] Optionally, the session control unit is further configured to receive a reconnection request initiated by the client after the streaming connection is disconnected; the device further includes: an exception recovery unit, configured to restore the streaming connection corresponding to the original user session request according to the reconnection request; the model response control unit is further configured to identify whether the generation task corresponding to the user session request has triggered an external tool invocation instruction according to the user session request; if so, obtain the execution status of the external tool; and continue to execute the generation task according to the execution status of the external tool.

[0025] This application also provides an electronic device, which includes a processor and a memory; the memory stores a computer program, and the processor executes the above-described method after running the computer program.

[0026] This application also provides a computer storage medium storing a computer program, which, when run by a processor, performs the above-described method.

[0027] Compared with the prior art, the embodiments of this application have the following advantages: This application provides a session management method for generative models, comprising the following steps: establishing a long-lived streaming connection with a client for real-time data transmission based on a user session request from the client; identifying whether the generation task corresponding to the user session request has triggered an external tool invocation instruction; if so, generating a keep-alive event corresponding to the execution state of the external tool based on the execution state of the external tool; and sending the keep-alive event to the client once or multiple times through the long-lived streaming connection, wherein the keep-alive event can be perceived by the user of the client. In the above session management for generative models, during the generation model's invocation of external tools, a corresponding keep-alive event is generated based on the execution state of the external tool, and the keep-alive event is sent to the client through the streaming connection. This keep-alive event serves two purposes: firstly, it maintains the validity of the streaming connection, preventing idle periods caused by silence, which could lead the AI ​​system to believe the task has timed out and disconnect; secondly, by providing the user of the client with perceptible progress information, the user is aware of the execution progress of the external tool and will not actively interrupt the connection due to unclear status. Through the above method, the problem of abandonment caused by excessively long execution time of generation tasks is largely solved, avoiding wasted computing power. Attached Figure Description

[0028] Figure 1 This is a schematic diagram of the overall application environment for session management of generative models provided in this application.

[0029] Figure 2 This is a schematic diagram of the process of the generative model provided in this application performing session tasks.

[0030] Figure 3 This is a flowchart of session management for generative models provided in the first embodiment of this application.

[0031] Figure 4 This is a flowchart illustrating the generation of formal content from the generative model provided in this application.

[0032] Figure 5 This is a schematic diagram of a session management device for generative models provided in the second embodiment of this application.

[0033] Figure 6 This is a schematic diagram of an electronic device provided in the third embodiment of this application. Detailed Implementation

[0034] Many specific details are set forth in the following description to provide a full understanding of this application. However, this application can be implemented in many other ways different from those described herein, and those skilled in the art can make similar extensions without departing from the spirit of this application; therefore, this application is not limited to the specific embodiments disclosed below.

[0035] This application provides a session management method for generative models. The technical solution provided by this application can maintain a valid connection for the client even when the client is in a silent period after the generative model calls external tools, thus avoiding wasted computing power.

[0036] Generative models are a class of artificial intelligence algorithms whose core capability is learning the inherent patterns, distribution characteristics, and logical relationships of massive amounts of data, thereby autonomously generating entirely new, original content (such as text, images, audio, video, or code). Unlike traditional discriminative models, which can only classify, identify, or predict existing information, generative models focus on creation "from scratch." They typically utilize deep learning techniques (such as autoregressive models, diffusion models, or generative adversarial networks) to predict and generate the most likely new data samples based on probability rules learned during training. Generative models are often referred to as large models due to their extremely large number of parameters and massive training data scale.

[0037] Although generative models have the ability to generate original content, they still have many shortcomings, such as being prone to illusions, insufficient mathematical computation capabilities, and the inability to directly implement external operational control. External tools (such as real-time information databases, various APIs, and function libraries) can help models obtain more reliable information and acquire more data. Therefore, existing generative models often need to call external tools. These external tools have different information processing functions and can cooperate with the use of generative models to solve problems that generative models cannot solve well, such as information authenticity, numerical computation processing, data computation, and sending control information to external systems.

[0038] However, some external tool calls may require a long execution time due to insufficient network bandwidth or the complexity of the task itself. During this time, no new content is generated. For the current session-based generative model, this can lead to two problems: firstly, users may lose patience due to the prolonged lack of updates; secondly, the streaming connection to the client may be disconnected by various connection devices (such as gateways and firewalls) based on their management mechanisms due to the lack of new information transmission. This application provides a feasible solution to these problems to achieve keep-alive streaming output.

[0039] The term "keep-alive" refers to a technical mechanism used to maintain the continuous active or live state of computer processes, network connections, or system services in the operating environment. In this application, it specifically refers to a technical mechanism that keeps the streaming connection between a client using a generative model and the generative model alive.

[0040] Please refer to Figure 1 The diagram illustrates the overall application environment of the technical solution provided in this application. The technical solution provided in this application is executed in an AI system centered on a generative model, and dedicated modules are set up for executing the technical solution provided in this application, or related tasks are assigned to some existing modules; the session management for generative models provided in this application... Figure 1 Execute in the system environment shown.

[0041] like Figure 1 As shown, the system environment in which the method provided in this application operates includes a client 11 and an AI server 12.

[0042] The client 11 can run on mobile devices such as smartphones and tablets, or on devices such as computers. Specifically, it can be a browser, an app, an executable program, or a mini-program. The client can send task requests to the AI ​​server 12 and establish a streaming connection. This streaming connection is used to receive content generated by the AI ​​server 12 corresponding to the task request. A streaming connection is a data transmission mode in which, after the two communicating parties establish a connection, data is sent and received continuously and in chunks in real time, without waiting for the entire data content to be processed or generated before being transmitted all at once. Streaming connections are an application layer concept, corresponding to persistent connections at the network or transport layer.

[0043] exist Figure 1 In the display box of the client 11, the display content of the client 11's display interface is shown, including: formal content, status prompts, connection awareness and other display content. These parts can adopt different layout forms according to the specific client form and interface layout requirements.

[0044] The "formal content" refers to the formal response content generated by the generative model sent by the AI ​​server 12 and received by the client 11 in response to the service request. For example, it may be a reply generated in response to a knowledge query. This content is generally displayed in the dialog box of the client 11's user interface, occupying the main part of the interface. The "status prompt" is used to provide information about the current status of the AI ​​server 12, and is generally displayed in the status bar of the user interface, such as the upper right corner. The "connection awareness" displays whether the current streaming connection is normal, and is generally displayed in the status bar of the user interface, such as the upper right corner, or it may be displayed side by side with the "status prompt".

[0045] In addressing the technical problem of a generative task request, the "formal content" may not generate new content for a considerable period due to execution time caused by calling external tools. Given the characteristics of streaming connections, the lack of real-time content during this time could lead to the connecting devices misjudging the streaming connection as interrupted and terminating it. It could also cause the client user to mistakenly believe that the AI ​​server 12 is in a state of task interruption or termination, thus abandoning the task request. This results in wasted computing power. To address this, the current task execution status can be displayed in the "status prompt" section. This solves the problem of user awareness of the current status, preventing them from manually abandoning the task. Furthermore, transmitting relevant information about the current status via the streaming connection avoids idle periods on the connection line, preventing the connecting devices from terminating the streaming connection.

[0046] The content displayed on client 11 depends on the content transmitted to client 11 via the streaming connection established between client 11 and AI server 12. Content transmitted via the streaming connection triggers changes to the content on client 11's interface, referred to as events. These events are categorized into formal content events, keep-alive events, status events, tool events (tool start events, tool completion events), and recovery events, depending on the type of change triggered. All these events originate from AI server 12, but the specific functional unit within AI server 12 from which they originate varies depending on the nature of each event.

[0047] The AI ​​server 12, relative to the client 11, is generally deployed on a remote server, or in the cloud. The core of the entire AI server 12 is the generative model it employs (i.e., a large model). Figure 1 The model includes LLM (Laser-Based Management Model), but it's not just a generative model. It also includes units that establish connections with clients, determine keep-alive strategies, resume and restart after interruption, and invoke and monitor external tools. These units can be implemented as processes, queues, or dedicated devices deployed on the server. Based on the general understanding of those skilled in the art, appropriate implementation methods can be adopted according to the specific functions they perform and the specific environment of the system. The following discussion focuses on functional units, combined with... Figure 1 Please provide an explanation.

[0048] In one specific implementation of this application, the AI ​​server 12 is functionally divided into a session control unit 121, a model response control unit 122, a generative model (LLM), a tool invocation unit 123, a tool invocation recognition unit 124, a keep-alive strategy unit 125, a keep-alive scheduling unit 126, and an anomaly recovery unit 127. These units can be implemented in software, hardware, or a combination of both, and each control unit can be deployed in a cloud server.

[0049] The session control unit 121 is used to implement connection establishment, session management, and event delivery. The connection establishment involves receiving user session requests from clients and establishing a streaming connection with the clients for real-time data transmission based on the user session requests. The session management includes managing long-lived connections (streaming connections) with the clients that issue user session requests, setting a session ID (session_id) for each session, and setting a sequence identifier (sequence_id) for each event during the session. The event delivery involves sending events generated by other units to the client 11.

[0050] The model response control unit 122 manages matters related to the invocation of the generative model, including model invocation, tool identification, and context management, and outputs the formal content of the generative model LLM to the session control unit 121. The model invocation involves the session control unit 121 invoking the generative model LLM to generate relevant content based on the task requirements provided in the user's session request. Tool identification occurs when the generative model LLM executes a generative task based on the user's prompts and the current context, determining whether an external tool is needed. The LLM selects the most suitable tool from a pre-set "tool list" (containing tool name, description, and parameter format), generating a structured tool invocation instruction, such as a JSON instruction specifying the tool to be invoked and the required parameters. The model response control unit 122 then issues this tool invocation instruction. Context management refers to generating content related to the client's historical information by cropping, retrieving, and compressing relevant historical information based on the client's prompts. This ensures that the generated content meets the user's needs, enabling AI to remember key background information and accurately understand the current question within its limited memory capacity, thus providing coherent and professional answers.

[0051] The tool invocation unit 123 is used to asynchronously invoke the execution of specific external tools according to the tool invocation command issued by the model response control unit 122. The external tools invoked may vary depending on the situation, including retrieval tools, databases, code tools, business interfaces, etc. In addition, it manages the progress and status of tool execution and provides the above information to the keep-alive scheduling unit 126. The tool invocation unit 123 is also responsible for receiving the execution results of external tools and injecting the execution results of external tools into the context of LLM model generation as an organic component of the formal content.

[0052] The tool call identification unit 124 is used to detect the tool call instructions issued by the LLM, and accordingly send a call instruction to the tool call unit 123 to the external tool, and provide the keep-alive event generation unit 126 with information on whether the generation task corresponding to the user session request has triggered the call instruction of the generative model LLM to the external tool, so that the keep-alive scheduling unit 126 can generate a corresponding keep-alive event accordingly.

[0053] The keep-alive strategy unit 125 receives input parameters related to the keep-alive scheme and generates a keep-alive strategy using a pre-set keep-alive strategy generation method based on the input parameters. The input parameters change dynamically with relevant circumstances and are called dynamic input parameters; the keep-alive strategy changes dynamically based on changes in the output parameters and is called a dynamic keep-alive strategy. The dynamic input parameters may include: client read timeout, gateway idle timeout, AI server timeout, proxy layer timeout, whether external tools are started, historical average execution time of external tools, P95 or P99 execution time of external tools, the execution time of the current external tool, whether the external tool provides phased progress, the time of the most recent formal content output, client type (browser, mobile, inter-service call), current node load, link quality, etc. The dynamic keep-alive strategy may include: keep-alive sending interval, keep-alive event type, status event sending conditions, keep-alive pause conditions, retry rules, recovery rules, and whether to degrade to an asynchronous task, etc.

[0054] The keep-alive scheduling unit 126 is used to generate relevant keep-alive events in real time according to the dynamic keep-alive strategy provided by the keep-alive strategy unit 125. The keep-alive events can be interpreted broadly and narrowly. Broadly, all events sent through a streaming connection of a session, excluding formal content events, are called keep-alive events. These events only maintain the link activity of the streaming connection and do not participate in text concatenation. Narrowly, only events specifically generated to prevent the streaming connection from being interrupted are called keep-alive events; other states and processes generated by the system itself are not considered keep-alive events in the narrow sense. Broadly defined keep-alive events include: keep-alive events (narrowly defined), status events, tool start events, tool completion events, recovery events, etc. The status events are used to characterize the current execution stage of the tool, such as "Pending execution," "Executing," "Result processing," "Execution completed," and "Abnormal interruption." These execution stage statuses can be transmitted to the client via streaming and displayed in the "Status Prompt" position on the client interface. The tool start event and tool completion event are used by the front-end and back-end to determine whether they are currently in the tool invocation process. When an external tool is started, a tool start event is issued, which can be displayed in the "Status Prompt" position. For example, when an external search tool is started, "Calling external search tool" can be displayed in the "Status Prompt" position. This allows the client, back-end, and all links in the streaming connection chain to understand the current status of the external tool being called, so as to anticipate any delays in subsequent content updates. Correspondingly, after the external search tool has completed its search task, a tool completion event is generated, which can be displayed in the "Status Prompt" position as "External search task completed," allowing the client, back-end, and all links in the streaming connection chain to understand the current status of the external tool being called. During tool execution, if the tool can output intermediate progress information, such as the number of search hits, database query stage, code execution steps, and file parsing progress, the system can encapsulate this information as a status event and send it to the client through the streaming connection. This allows the client to continuously perceive the execution progress and prevents the client or related devices on the streaming connection link from disconnecting the long-lived connection due to a lack of information updates for an extended period. If the tool cannot provide clear progress, the system will at least send a keep-alive event, which may include information such as session identifier, tool identifier, current stage, timestamp, execution duration, and remaining budget to prove that the session is still alive and the task is still in progress. Based on this information, the keep-alive event can generate appropriate content that is perceptible to the client, preventing the client user from actively closing the task. For example, appropriate status events can be generated. For instance, if the search tool is started, even if it does not provide new search progress information, but it is clear that the search is in progress, it can output "Search is in progress, please wait patiently" and display a blinking or dynamic icon.Even without a formal answer token output, the entire process doesn't become completely silent, and the client user can still perceive that the external tool is working, meaning the task on the AI ​​server is not interrupted. Once the external tool completes its execution, the system first stops sending keep-alive events, incorporates the external tool's output into the current dialogue context, model cache, or intermediate state storage, and then calls the LLM model to continue generating a formal answer based on the external tool's output. The subsequent text is then output to the client via a formal content event. During the switchover process, the keep-alive scheduling unit 126 can send a tool completion event to notify the front end to switch from the "external tool processing" state back to the normal content display state. The entire switchover process is continuous for the user, requiring no new session establishment, explicit polling, or re-initiating requests.

[0055] The anomaly recovery unit 127 is designed to handle various interference scenarios in a real network environment. When the streaming connection of client 11 is lost due to network jitter, browser refresh, mobile device switching to the background, or proxy layer connection recycling, client 11 can include the original session_id and the most recently successfully received sequence_id in the reconnection request to request the establishment of a connection related to the original streaming connection, thereby achieving effects such as session recovery, breakpoint resumption, and result resending. Specifically, after receiving the reconnection request, the AI ​​server queries the current session status and the status of the started external tool based on the session_id: if the external tool is still executing, it resumes sending keep-alive events or status events to achieve session recovery; if the external tool has completed but the subsequent formal content has not yet been fully delivered, it continues to resend the unsent events from the sequence_id onwards to achieve breakpoint resumption; if the external tool has finished executing but the original session's streaming connection cannot be recovered, it returns an asynchronous completion notification, a result retrieval address, or a polling flag for client 11 to obtain the final result after the subsequent task is completed. In this way, the user can avoid having to start the entire task from scratch due to a brief disconnection, significantly reducing the cost waste caused by repeated reasoning and repeated tool calls.

[0056] Please refer to Figure 2 This diagram illustrates the process of tool calls and session management architecture based on a streaming gateway and Large Language Model (LLM) after the client issues a user session request to the generative model. The flowchart includes the various stages of the process, specifically the client 21 and the session control unit 22 (which is essentially equivalent to...). Figure 1 The session control unit 121), generative model LLM, and tool engine 23 (basically equivalent to Figure 1 Tool calling unit 123), external tool 24, keep-alive manager 25 (equivalent to Figure 1This includes various stages such as the keep-alive strategy unit 125 and the keep-alive scheduling unit 126. Here, for ease of explanation of the entire workflow, the relevant stages for executing this process are shown. These stages are related to the above... Figure 1 Some functional units shown are consistent, while others are slightly different. These differences are merely a matter of division and do not affect the essence. The following, in conjunction with the diagram, illustrates the complete flow of the generative model provided in this application executing a session task; this session task includes tool calls.

[0057] like Figure 2 As shown, the entire process includes the following steps.

[0058] In step S201, client 21 sends a user session request and, after establishing a streaming connection, receives streaming events through that streaming connection.

[0059] In step S202, the streaming gateway 221 of the session control unit 22 receives the user session request, and the session state manager 222 connected to the streaming gateway 221 maintains a long connection through the streaming gateway 221, that is, maintains a streaming connection.

[0060] In step S203, the streaming gateway 221 forwards the user session request to the generative model LLM. In step S204, the generative model LLM returns a regular streaming response to the streaming gateway 221. This regular streaming response is sent to the client 21 through the streaming connection between the streaming gateway 221 and the client, which corresponds to receiving the streaming event in step S201.

[0061] In step S205, the generative model LLM triggers a tool invocation instruction, which is sent to the tool engine 23 (which undertakes the task of the tool invocation unit 123), and the tool invocation is initiated through the tool engine 23.

[0062] Step S206: The tool engine 23 sends a tool call command to the external tool 24 to execute the tool operation; the specific external tool may be a database, API, search engine, code sandbox, etc.

[0063] In step S207, the tool engine 23 synchronizes the execution status and characteristics of external tools to the keep-alive manager 25, and the keep-alive manager 25 undertakes the tasks of the keep-alive strategy unit 125 and the keep-alive scheduling unit 126.

[0064] In step S208, the keep-alive manager 25 sends keep-alive / status events to the streaming gateway 22 according to the policy, so that the streaming gateway 22 sends them to the client 21 as streaming events.

[0065] In step S209, the external tool 24 returns the execution result to the tool engine 23; the execution result page includes the status events of the external tool's task execution.

[0066] In step S210, the tool engine 23 returns the results to the generative model LLM, which integrates the generative model LLM into its own generated content as the content of the returned streaming response.

[0067] The above process reflects the relevant process of the generative model session management provided in this application running in the whole system. The following provides a specific embodiment of session management for generative models from the perspective of AI server 12 as the execution subject.

[0068] First Embodiment like Figure 3 As shown, the first embodiment of this application provides a session management system for generative models, applied to an AI server, including: Step S301: Based on the user session request from the client, establish a streaming connection with the client for real-time data transmission.

[0069] Streaming connections refer to long-lived connections established based on streaming protocols, enabling AI servers to send data to clients in blocks, time-sharing and chunk-by-chunk. Streaming connections can be implemented using the WebSocket protocol or the Server-Sent Events (SSE) protocol. WebSocket supports full-duplex real-time data transmission between the AI ​​server and client, while SSE supports one-way real-time push from the AI ​​server to the client.

[0070] In this application embodiment, a generative model refers to a deep learning model capable of autonomously generating new content such as text, code, images, or audio / video based on input data (such as user-generated questions, contextual information, etc.). Specific types of generative models include large language models and multimodal generative models. In this application embodiment, a large language model with external tool invocation capabilities is preferred, but this application is not limited to this. The generative model is deployed on the AI ​​server side of the AI ​​system. The AI ​​server side is the core inference function module of the AI ​​system. The AI ​​server side refers to the party in the AI ​​system that provides network access and interaction services to clients. It receives user session requests from clients through an access gateway, invokes the generative model to perform inference, and returns the inference results to the client through a streaming connection.

[0071] In this embodiment, a user session request refers to a request message actively triggered by a user through the client interface to initiate a dialogue interaction process. This request message carries at least the user's input content and optionally includes a session identifier, user identity credentials, and contextual data. For example, if a user enters "Help me analyze the sales data of the company's stores nationwide over the past five years and generate a PPT with trend charts and a summary report" in the input box on the client interface and clicks send, a user session request is triggered. This request is encapsulated as an HTTP request or a WebSocket message and sent to the AI ​​server.

[0072] In response to the user session request, the AI ​​server establishes a streaming connection with the client, serving as the communication channel for subsequent real-time data transmission. Real-time data refers to the intermediate generation results or status information produced sequentially by the generative model during the execution of the generation task corresponding to the user session request. Intermediate generation results include, but are not limited to, the formal content generated word-for-word by the generative model, and status information includes keep-alive events reflecting the tool's execution progress and used to maintain connection validity. After establishing a streaming connection and receiving the user session request, the AI ​​system first checks whether the user session request carries a session identifier. If the user session request does not carry a session identifier, a unique session identifier is generated for this session, and the context data related to this session is initialized using this session identifier as an index. If the user session request already carries a session identifier, the system does not regenerate the session identifier but instead restores the existing session context from the storage system based on the already carried session identifier. The session identifier is a unique identifier assigned by the AI ​​system to the current user session request, used to associate all requests, responses, and status data of the same session during subsequent interactions, ensuring that multiple data exchanges belong to the same session context. Context data refers to the set of structured information dynamically generated and maintained by an AI system when processing a current user session request, in order to maintain dialogue coherence, support model inference, and manage task execution status. The context data includes at least the session identifier itself, as well as structured information such as dialogue content, task execution status, and system configuration parameters parsed from the user session request.

[0073] Step S302: Identify whether the generation task corresponding to the user session request has triggered the generative model's instruction to call external tools.

[0074] After the streaming connection is established, the AI ​​system begins generating a response. During this process, it parses the generation task corresponding to the user session request and identifies whether the generation task triggers a call instruction to an external tool. A generation task refers to the specific work content that the AI ​​system determines needs to be completed by the generative model based on the user session request. It includes one or more operational steps required to achieve the final generation goal. An external tool refers to a service interface, application program, or computing resource that is independent of the generative model and can provide specific functions or data, such as a database query interface, a data analysis code execution environment, a file generation interface, or a third-party business system interface. A call instruction is a structured instruction output by the generative model during inference to request the invocation of a specific external tool. This call instruction at least includes the identification information of the invoked external tool and the input parameters required to execute the external tool.

[0075] Taking an example where the AI ​​server receives a user session request from a client: "Help me analyze the sales data of the company's stores nationwide over the past five years and generate a PPT with trend charts and a summary report," the AI ​​server establishes a streaming connection with the client and creates a unique session identifier, such as hy001, for this session request. After the streaming connection is established, the AI ​​system performs semantic parsing on the user session request, identifying that the corresponding generation task includes the following sub-tasks: data query task, data analysis task, and report generation task. The AI ​​system further determines that these sub-tasks cannot be completed independently using only the generative model's internal knowledge or general reasoning capabilities. For example, the generative model does not have direct access to the company's internal database, cannot independently execute program code for data aggregation calculations, and cannot directly call third-party application programming interfaces for presentation generation. Therefore, the AI ​​system determines that this generation task requires the use of external tools.

[0076] Specifically, the invocation instructions include: a first invocation instruction for invoking the database query tool, which includes database query parameters such as the time range "past five years", the statistical dimension "each store", and the indicator "sales revenue"; a second invocation instruction for invoking the data analysis tool, which specifies the statistical analysis operations to be performed, such as trend analysis; and a third invocation instruction for invoking the report generation tool, which specifies the output format as PPT and the content structure requirements as including trend charts and a summary report. After the above three invocation instructions are generated, the pre-set tool invocation recognition plugin (which performs...) is used... Figure 1Once the function of the tool calling the recognition unit 124 is recognized, the AI ​​system proceeds to step S303. It should be noted that the calling instructions of the external tools can be issued in parallel or sequentially according to their dependencies, depending on the data dependencies between the external tools. This application does not limit this.

[0077] It should be noted that during the execution of external tools, the AI ​​system continuously acquires and updates context data to record relevant data from the external tool invocation in this session. Context data includes, but is not limited to, parameters in the external tool invocation request, runtime logs of the external tool execution environment, or intermediate data generated by the external tool during processing. Context data is stored in association with the session identifier for subsequent querying and use.

[0078] Step S303: If yes, then generate a keep-alive event corresponding to the execution state of the external tool, based on the execution state of the external tool.

[0079] In this embodiment, during the process of generating a response to a user session request, if the generation task does not trigger an external tool invocation instruction, the AI ​​system continues to directly output the formal content generated by the generative model and continuously outputs it to the client via a streaming connection in the form of formal content events. If the generation task triggers an external tool invocation instruction, that is, the AI ​​system identifies the need to invoke one or more external tools during the inference process, the AI ​​system pauses the output of formal content and enters the tool execution phase. Since the execution time of external tools is affected by factors such as data volume, computational complexity, and external service response speed, it has considerable uncertainty. Therefore, during the execution of external tools, the AI ​​system obtains the execution status of the external tools and generates corresponding keep-alive events based on the execution status of the external tools to maintain the effectiveness of the streaming connection during the silent period.

[0080] In this embodiment, a keep-alive event refers to a data packet sent by the AI ​​system to the client via streaming connection during a silent period when the generative model cannot produce formal content. This packet is used to maintain connection validity and carries status information reflecting the execution status of the external tool. The keep-alive event differs from a pure heartbeat packet without business meaning; the status information it carries can be perceived by the client user. In an optional embodiment, the keep-alive event also includes context data related to the current session, so that the client can associate the received keep-alive event with the corresponding session and the execution instance of the external tool. Specifically, the keep-alive event may include one or more of the following information: a session identifier, an external tool identifier to uniquely identify the currently executing external tool instance, the current execution stage of the external tool, a timestamp recording the generation time of the keep-alive event, the accumulated execution time of the external tool from the start of execution to the current moment, and remaining budget information indicating the remaining available time in the link timeout budget for the current session. Based on this information, appropriate content perceptible to the client can be generated, preventing the client user from actively closing the task. It should be noted that the keep-alive event can selectively include the above information according to actual needs, and not every keep-alive event must carry all the information.

[0081] The execution status of an external tool refers to its operational status and progress information during execution. Specifically, the execution status of the external tool includes: the status of the internal execution progress output by the external tool, and information reflecting the execution progress of the external tool that is actively sensed based on its execution progress.

[0082] In an optional embodiment, generating a keep-alive event corresponding to the execution state of the external tool includes: during the execution of the external tool, obtaining the state of the tool's internal execution progress output by the external tool; generating a real-time execution state corresponding to the state of the tool's internal execution progress; and generating a keep-alive event corresponding to the real-time execution state based on the real-time execution state.

[0083] The execution process of an external tool refers to the complete operation from receiving a call request to returning an execution result. The duration of this process is uncertain, influenced by factors such as data volume, computational complexity, and the response speed of the external service. The internal execution progress status output by the external tool refers to the current execution progress information actively returned by the external tool, reflecting its current execution stage or completion percentage. For example, a database query tool might return "Query progress: 30% complete," or a report generation tool might return "PPT generation progress: 50%."

[0084] Furthermore, obtaining the status of the internal execution progress output by the external tool specifically includes: receiving the current execution progress information output by the external tool during execution according to a preset format or interface protocol.

[0085] Furthermore, generating a real-time execution status corresponding to the internal execution progress of the tool includes: generating user-understandable status description information based on the obtained internal execution progress status of the tool, and using this status description information as the real-time execution status corresponding to the internal execution progress status of the tool. The real-time execution status is a user-perceptible and understandable natural language or structured prompt converted from current execution progress information reflecting the current execution progress of the external tool. For example, when the AI ​​system receives "Query progress: 30% complete" returned by the database query tool, it generates a real-time execution status of "Querying sales data (30% complete)"; when it receives "Query progress: 60% complete", it generates a real-time execution status of "Querying sales data (60% complete)". These real-time execution states, as content perceptible to the client, ensure that the content carried by subsequently generated keep-alive events has a clear informational meaning for the client user.

[0086] The AI ​​system generates a keep-alive event based on the real-time execution status, and the keep-alive event includes at least the real-time execution status. Specifically, the AI ​​system encapsulates the real-time execution status and other relevant data into a data frame conforming to a streaming protocol (such as the SSE protocol) and sends it to the client through the streaming connection. After receiving the keep-alive event, the client parses and extracts the real-time execution status carried within it to display the current execution progress information of the external tool on the client interface.

[0087] In an optional embodiment, if the external tool does not have the function of actively outputting the status of its internal execution progress, a keep-alive event corresponding to the execution status of the external tool is generated. This includes: acquiring information reflecting the execution process of the external tool actively perceived based on its execution progress, as the current execution progress information; and generating a keep-alive event corresponding to the execution progress of the external tool based on the current execution progress information. The information reflecting the execution process of the external tool actively perceived based on its execution progress refers to the execution progress information of the external tool obtained by the AI ​​system through monitoring its running status (such as monitoring interface response status, detecting heartbeat signals, or polling task status). The AI ​​system generates a keep-alive event with corresponding content based on each acquired current execution progress information, so that the content of the keep-alive event is dynamically updated as the execution status of the external tool changes, thereby providing the user with continuously changing status feedback.

[0088] Specifically, the AI ​​system can perceive the current execution progress information of an external tool through at least one of the following methods: inferring the current execution progress based on relevant data called by the external tool during its execution; obtaining the current execution progress information by monitoring the interface response status of the external tool; obtaining the current execution progress information by polling the task status interface of the external tool; and obtaining the current execution progress information by detecting temporary files or output results generated by the external tool during its execution. Polling refers to the AI ​​system sending requests to the status query interface of the external tool at preset time intervals to obtain the current processing stage of the task. For example, when the external tool is a database query tool, the AI ​​system periodically calls the task status query interface provided by the tool to obtain the current query operation's status, such as "in execution," "completed," or "failed." When the AI ​​system detects that the task status interface returns "failed" or "timeout" during polling, it can also generate a keep-alive event carrying the text message "Query failed, retrying" and send it to the client so that the user is aware that the external tool's execution has encountered an anomaly.

[0089] It should be noted that the above methods can be used individually or in combination. When used in combination, the AI ​​system can integrate multiple methods to obtain current execution progress information and comprehensively judge the execution progress of the external tool, thereby improving the accuracy and reliability of the execution progress judgment.

[0090] Furthermore, if the external tool generates intermediate results during execution, the AI ​​system can detect the generation of these intermediate results during polling or monitoring. Upon detecting a new intermediate result, the system generates a keep-alive event carrying information related to that intermediate result and sends it to the client. For example, when the external tool is a data analysis tool, it generates an intermediate result file after completing trend analysis. After detecting the generation of this intermediate result file, the AI ​​system generates a keep-alive event carrying the text "Trend analysis completed, summary calculation in progress" and sends it to the client, allowing the user to obtain more granular execution progress information.

[0091] In an optional embodiment, the session management provided by this application further includes: identifying whether the generation task corresponding to the user session request triggers a generative model's instruction to call external tools; if it is identified that the generation task triggers a batch call instruction for multiple external tools, then the following steps are performed: obtaining the execution status of each of the multiple external tools; aggregating the execution status of each of the multiple external tools according to a preset aggregation rule to generate an aggregated state reflecting the overall execution status of the multiple external tools. Further, generating a keep-alive event corresponding to the execution status of the external tools includes: generating a keep-alive event corresponding to the aggregated state of the external tools based on the aggregated state.

[0092] Among them, batch invocation instructions for external tools refer to invocation instructions issued to two or more external tools in a single generation task, and their execution methods include concurrent, serial, or mixed invocation. Based on this, the situations that trigger concurrent invocation include, but are not limited to, the following two categories: first, multiple tool invocation instructions are generated simultaneously in a single inference; second, dependency analysis determines that there are no data dependencies between multiple external tools, thereby enabling concurrent execution to shorten the overall execution time.

[0093] The execution status of each external tool refers to the running status and progress information of each external tool during the execution process. Specifically, it includes the internal execution progress output by each tool and the information reflecting the execution process of each external tool actively perceived by the AI ​​system.

[0094] The preset aggregation rule refers to a predefined logic or algorithm used to merge the execution status of multiple external tools into overall status information. This aggregation rule can be flexibly configured according to the application scenario. For example, it can calculate the overall completion rate by weighted averaging the execution progress of multiple tools; take the status of the tool with the slowest progress as the overall progress; or, based on the execution order and dependencies, only display the status of tools currently executing, ignoring tools that have not yet started or have already been completed. The specific form of the aggregation rule can be preset according to the characteristics of the generated task; this application does not limit this.

[0095] Aggregated state refers to the comprehensive state information generated after merging the execution states of multiple external tools according to preset aggregation rules. The AI ​​system generates a unified keep-alive event based on the aggregated state and sends it to the client to avoid client information overload or user-perceived redundancy caused by sending the state information of multiple tools separately.

[0096] For example, if there are data dependencies between three external tools (e.g., tool B depends on the output of tool A, and tool C depends on the output of tool B), the three tools will be called sequentially. During the execution of tool A, if its internal execution progress is "Query Progress: 60%", and tools B and C have not yet started, the system will generate an aggregated status of "Data Querying (60% Completed)" according to the aggregation rules (e.g., only taking the status of the currently executing tool), and generate a corresponding keep-alive event to send to the client.

[0097] In another optional example, if there are no data dependencies between the three external tools, the system calls them concurrently. For example, the AI ​​system simultaneously obtains the progress of tool A as "Query Progress: 80%", the progress of tool B as "Calculation Progress: 50%", and tool C as not yet started. If the preset aggregation rule is to take the average progress of all executed tools, the generated aggregation status is "Overall Progress: 65%", and the corresponding keep-alive event sends the text message "Executing related tools, overall progress 65%" to the client.

[0098] Step S304: Send the keep-alive event to the client once or multiple times through the streaming connection, and the keep-alive event can be perceived by the client user.

[0099] In this context, the keep-alive event being perceptible to the client user means that it carries status description information corresponding to the execution status of the external tool. This status description information is presented in the client interface in the form of text, a progress bar, or other visual formats, allowing the user to intuitively understand the current execution status and specific progress of the external tool.

[0100] For example, in the example above, the AI ​​system first calls a database query tool to retrieve sales data from the past five years. After the database query tool begins execution, its internal execution progress status is "Query Progress: 30% Complete" and is returned to the AI ​​system. Upon receiving this internal execution progress status, the AI ​​system generates a corresponding real-time execution status: "Querying sales data (30% complete)". Subsequently, based on this real-time execution status, the AI ​​system generates a keep-alive event carrying the text information "Querying sales data (30% complete)" and sends it to the client via a streaming connection. This keep-alive event is displayed on the client's interface as a status indicator corresponding to the text information, allowing the user to know that the tool is currently executing and its progress is quantifiable. As the query continues, the database query tool successively returns internal statuses of "Query progress: 60% complete" and "Query progress: 90% complete." The AI ​​system accordingly generates keep-alive events carrying "Querying sales data (60% complete)" and "Querying sales data (90% complete)" respectively, and sends them sequentially to the client via streaming, allowing the client to continuously receive updates on the execution progress. After the query is completed, the AI ​​system obtains the query results and invokes the data analysis tool. The AI ​​system proactively detects the tool's execution status as "Calculating: Trend analysis completed" through polling, and accordingly generates a real-time execution status of "Analyzing data trends," then generates the corresponding keep-alive event and sends it to the client.

[0101] It should be noted that during the execution of the external tool, the AI ​​system continuously monitors whether the currently invoked external tool task has been completed: if the tool task has not been completed, the AI ​​system sends a keep-alive event to the client once or multiple times through the streaming connection; if the external tool has been completed, the AI ​​system stops sending keep-alive events, obtains the execution result returned by the external tool, and inputs the execution result into the generative model, so that the generative model can combine the execution result to continue generating formal content and restore the streaming output of the formal content.

[0102] Existing technologies typically use pure heartbeat packets or empty packets that only contain technical signals for maintaining network connectivity, without carrying business status information that users can understand. These packets are often invisible on the client interface or only displayed as static, unchanging waiting prompts, making it impossible for users to determine whether the tool is running and its progress. This application addresses this by sending keep-alive events. On one hand, it maintains continuous data transmission over the streaming connection, effectively preventing idle timeout disconnection mechanisms on the gateway, proxy layer, or AI server due to lack of data interaction during the silent period. On the other hand, the status information carried by the keep-alive events allows users to know the execution dynamics of external tools in real time, eliminating user anxiety caused by unknown status and preventing users from actively interrupting the connection due to lack of feedback.

[0103] In an optional embodiment, prior to step S304, the session management provided by this application embodiment further includes: During the execution of the external tool, link status parameters reflecting the external communication environment and tool execution parameters reflecting the internal execution progress of the external tool are acquired. An adaptive sending strategy is generated based on the link status parameters and the tool execution parameters. The adaptive sending strategy is used to dynamically adjust the sending interval and / or sending conditions of the keep-alive event. Sending the keep-alive event to the client once or multiple times includes sending the keep-alive event to the client once or multiple times according to the adaptive sending strategy.

[0104] Link status parameters refer to information reflecting the current status of the streaming link, including but not limited to client read timeout, gateway idle timeout, AI server timeout, proxy layer timeout, current node load, link quality, and the time of the most recent formal content output. These parameters reflect the idle tolerance of the streaming connection at each transmission stage and the current network condition. Tool execution parameters refer to information reflecting the internal execution progress of the external tool, including but not limited to historical average execution time, historical execution time, current execution time, whether the tool supports phased progress output, and the current internal execution progress status of the tool.

[0105] An adaptive transmission strategy is a strategy dynamically determined based on link state parameters and tool execution parameters to control the transmission behavior of keep-alive events. This adaptive transmission strategy defines at least the transmission interval and / or transmission conditions for keep-alive events, where the transmission interval refers to the time interval between two consecutive keep-alive events, and the transmission conditions refer to the conditions that must be met to trigger the transmission of a keep-alive event.

[0106] In practical implementation, an adaptive sending strategy is generated based on link state parameters and tool execution parameters. This includes: obtaining the historical execution time, current execution time, and streaming connection quality of the external tool based on the link state parameters and tool execution parameters; calculating the sending interval and / or sending conditions for keep-alive events based on the relative relationship between historical execution time and current execution time, and the streaming connection quality; and incorporating the sending interval and / or sending conditions as components of the adaptive sending strategy. According to the adaptive sending strategy, keep-alive events are sent to the client once or multiple times, including: determining the sending time interval according to the adaptive sending strategy; and sending keep-alive events to the client once or multiple times according to the sending time interval.

[0107] Historical execution time refers to the time required for the external tool to complete execution in historical calls. This can be the historical average execution time, or the historical P95 or P99 execution time (i.e., 95% or 99% of historical calls do not exceed this value). Current execution time refers to the cumulative time the external tool has taken from the start of this call to the current moment. The relative relationship between historical execution time and current execution time is used to predict how much longer the external tool will need to complete execution.

[0108] For example, if the current execution time is much shorter than the historical execution time, it indicates that the tool is still in the early stages of execution and is expected to take a long time to complete. In this case, a normal sending interval can be used. If the current execution time is close to the historical execution time, it indicates that the tool may be about to complete. In this case, the sending interval can be shortened to reflect the changes in the tool's execution progress in a timely manner. If the current execution time has significantly exceeded the historical execution time, it indicates that the tool's execution has encountered an anomaly or has taken longer than expected. In this case, the sending interval can be shortened and the frequency of keep-alive events can be increased to prevent idle timeout disconnection due to excessively long tool execution time.

[0109] Link quality is used to evaluate the stability and reliability of the communication link on which a streaming connection resides. Specific indicators include, but are not limited to, network latency, packet loss rate, and bandwidth utilization. When link quality degrades, the sending interval can be shortened to increase the number of keep-alive events sent, increasing the probability that at least one keep-alive event will successfully reach the client and reducing the risk of the connection being mistakenly judged as invalid due to network packet loss. When link quality is good, the sending interval can be extended to reduce unnecessary network overhead.

[0110] For example, when the link status parameter indicates that the gateway idle timeout is 30 seconds and the last time the formal content was output was 5 seconds ago, the AI ​​system determines the sending interval based on the remaining idle tolerance time of the current link (i.e., 25 seconds) and the historical average execution time of the tool (e.g., an average execution time of 20 seconds). If the tool has been executing for 5 seconds, the historical average execution time of the tool is 20 seconds, the tool is expected to complete in 15 seconds, and the remaining idle tolerance time is 25 seconds, then the AI ​​system can use a sending interval of sending a keep-alive event every 5 seconds. This ensures that the connection is maintained until the tool completes execution, while avoiding excessive network overhead caused by sending too frequently.

[0111] For example, when the tool execution parameters indicate that the current tool has been running for nearly the time required for tool P95, but the tool has not yet returned a result, the AI ​​system can shorten the sending interval and increase the frequency of keep-alive events to provide more frequent progress feedback when the tool is about to complete execution. At the same time, users can see more frequently updated progress prompts on the client interface, thereby enhancing their confidence that the system is running normally and preventing them from giving up due to waiting too long.

[0112] For example, when the link status parameter indicates that the most recent formal content output time is relatively recent (e.g., less than 2 seconds), and the tool execution parameter indicates that the tool has not yet generated a new internal execution progress status, the AI ​​system can appropriately postpone the sending of the next keep-alive event to reduce unnecessary data redundancy and system overhead.

[0113] In this way, keep-alive events are no longer sent at a fixed frequency. Instead, the adaptive sending strategy dynamically adjusts the sending behavior based on the link status and tool execution status. This allows the event to adapt to the time differences of different external tools without triggering idle timeouts. The sending frequency of keep-alive events changes adaptively with the execution process, avoiding the problems of excessive system overhead or untimely keep-alive caused by fixed-frequency sending.

[0114] The adaptive sending strategy also defines the sending conditions for keep-alive events. For example, when the tool execution parameters indicate that the current external tool supports phased progress output and new progress information is available, the AI ​​system sets the sending condition to "send whenever new progress information is detected," that is, it only sends keep-alive events when progress is updated, rather than sending them at fixed time intervals; when the tool execution parameters indicate that the current external tool does not support phased progress output, and the link status parameters indicate that the distance from the last data transmission has exceeded a preset threshold, the AI ​​system sets the sending condition to "send when idle time reaches a threshold," that is, it sends keep-alive events containing stateless content periodically at a low frequency.

[0115] In another optional embodiment, the AI ​​system further determines the maximum tolerable idle time for the streaming connection based on link state parameters. The maximum tolerable idle time refers to the maximum allowed idle time from the end of the most recent data transmission to when the gateway, proxy layer, or AI server determines the connection as failed and triggers an idle timeout disconnection. For example, when the gateway idle timeout is 30 seconds, the maximum tolerable idle time is 30 seconds; if the gateway idle timeout differs from the client read timeout, the smaller of the two is taken as the maximum tolerable idle time. After determining the maximum tolerable idle time, the AI ​​system sets the interval between keep-alive events to be less than the maximum tolerable idle time to ensure that at least one keep-alive event has been sent to the client before the maximum tolerable idle time is reached, thereby avoiding disconnection due to exceeding the idle timeout threshold.

[0116] Preferably, the sending interval can be dynamically adjusted according to changes in link status parameters and tool execution parameters, but it must always be less than the maximum tolerable idle time. For example, if the maximum tolerable idle time is 30 seconds, the AI ​​system can set the sending interval to 10 seconds; when the tool execution progresses quickly, the sending interval can be extended to 20 seconds; when the link quality deteriorates, the sending interval can be shortened to 5 seconds to increase the sending frequency of keep-alive events and reduce the probability of being mistakenly judged as idle timeout disconnection due to the failure of keep-alive events to arrive in time because of network packet loss.

[0117] It should be noted that during the execution of the external tool, the AI ​​system continuously monitors changes in link status parameters and tool execution parameters, and inputs the changed current link status parameters and tool execution parameters into the keep-alive strategy module. The keep-alive strategy module dynamically generates an adaptive sending strategy (i.e., the keep-alive strategy) that adapts to the current link status and tool execution status according to preset calculation rules, and adjusts the sending interval and / or sending conditions of keep-alive events based on the adaptive sending strategy. Through this method, the adaptive sending strategy not only achieves dynamic adaptation in sending frequency but also achieves fine-grained control in sending triggering conditions, ensuring that the sending behavior of keep-alive events maintains connection validity while avoiding unnecessary redundant sending.

[0118] Figure 3 From the perspective of AI server 12, the steps for generating and sending a corresponding keep-alive event based on the execution status of an external tool in session management for generative models are shown. Figure 4 Also from the perspective of AI server 12, the complete process of this method from receiving a user session request to generating the formal content of the response required for that request is shown, including... Figure 3 The steps are shown. Specifically, the method includes the following steps: S401: Receive user session requests and establish streaming connections; S402: Determine whether an external tool call command has been identified; if yes, proceed to steps S403 to S408; if no, proceed to step S409. S403: Generate a keep-alive event corresponding to the execution state of the external tool, based on the execution state of the external tool. S404: External tool that executes the call; S405: Determine whether the external tool has completed execution. If yes, proceed to step S406; otherwise, proceed to step S407. S406: Obtain the execution results of external tools; S407: Send keep-alive events to the client once or multiple times via streaming connection; S408: Generate formal response content based on the execution result; S409: Directly generate formal answer content; S410: Based on the formal answer, generate the formal content event to be displayed for the task generation.

[0119] In an optional embodiment, the session management further includes: stopping the sending of the keep-alive event in response to the completion of the external tool's execution; generating a tool completion event to reflect the completion of the external tool's execution; and sending the tool completion event to the client so that the client can perceive the end of the external tool's execution and switch from the external tool's invocation state to the content display state of the generated task.

[0120] In specific implementation, the session management further includes: obtaining the execution result of the external tool in response to its completion; generating formal response content based on the execution result; generating a formal content event for display in the generation task based on the formal response content; and sending the formal content event to the client. The formal content event generated based on the execution result of the external tool can be incorporated into already generated formal content events as part of the formal content of the complete streaming response.

[0121] External tool execution completion means that the external tool has completed all processing tasks and is ready to return execution results. For example, a database query tool has completed data query and returned the query result set, or a data analysis tool has completed analysis and calculation and returned the analysis results. In this case, the AI ​​system stops sending keep-alive events because after the tool execution phase ends, keep-alive events are no longer needed to maintain the connection validity during the silent period.

[0122] After ceasing to send keep-alive events, the AI ​​system generates a tool completion event. A tool completion event is a type of event generated by the AI ​​system upon detecting the completion of an external tool's execution. Its purpose is to notify the client of the end of the tool's execution phase, allowing the user to clearly know that the tool has finished executing. Tool completion events differ functionally from keep-alive events: keep-alive events maintain the connection and synchronize execution progress during tool execution, while tool completion events mark the end of the tool's execution phase. In terms of content, tool completion events carry notification information indicating execution completion (e.g., "data query complete" or "analysis complete"), rather than progress information.

[0123] After the AI ​​system sends the tool completion event to the client via streaming, the client can know that the external tool has completed its execution when it receives the event. It then switches the interface status from "tool in execution" (e.g., displaying "querying data...") to "content generation" or "content display" to prompt the user that the current stage has progressed to the next step.

[0124] During the process described above, the content sent on the streaming connection switches from keep-alive events to tool completion events. Since both are actual data packets, they can trigger the timeout timer reset on the gateway, proxy layer, or AI server at the time of transmission. Therefore, the transmission of tool completion events also serves to maintain the validity of the connection, that is, to ensure that the connection is not disconnected due to idle time before the model generates formal content while completing the state transition.

[0125] After the external tool completes its execution, the AI ​​system obtains the execution results returned by the tool and inputs these results into a generative model. The generative model then generates formal, user-facing responses based on the execution results. For example, it might understand and summarize sales data returned by a database query tool to generate a natural language response. Subsequently, the AI ​​system generates a formal content event to carry the final response based on the formal content produced by the generative model and sends it to the client via a streaming connection.

[0126] In an optional embodiment, session management further includes: receiving a reconnection request initiated by the client after the streaming connection is disconnected; restoring the streaming connection corresponding to the original user session request according to the reconnection request; identifying whether the generation task corresponding to the user session request has triggered an external tool invocation instruction according to the user session request; if so, obtaining the execution status of the external tool; and continuing to execute the generation task according to the execution status of the external tool.

[0127] In specific implementation, the reconnection request includes at least a session identifier and the latest received event sequence number. Identifying whether the generation task corresponding to the user session request has triggered an external tool invocation instruction based on the user session request includes: querying the execution status of the generation task corresponding to the user session request related to the reconnection request based on the session identifier, and determining whether it has triggered an external tool invocation instruction. Continuing to execute the generation task based on the execution status of the external tool includes one of the following: if the external tool is in the process of execution, then proceeding to generate a keep-alive event corresponding to the execution status of the external tool, and sending the keep-alive event to the client once or multiple times through the streaming connection; if the external tool has completed execution but has not sent all event data to the client, then resending the undelivered event data to the client.

[0128] In this application, the streaming connection may be disconnected due to various reasons such as client network switching (e.g., switching from Wi-Fi to 5G), network interruption, or gateway or proxy layer idle timeout. After the streaming connection is disconnected, the client initiates a reconnection request to the system. The reconnection request includes at least a session identifier and the latest received event sequence number. The session identifier is used to enable the system to identify the original session corresponding to the original user session request. Since the system has generated a unique session identifier for this session when the streaming connection is initially established and synchronized this session identifier with the client, the client carries this session identifier in the reconnection request, and the system can recover the context data corresponding to the original session based on this identifier. The latest received event sequence number refers to the number of the last data event received by the client before the connection was disconnected. During streaming transmission, the system assigns an incrementing event sequence number to each data event sent through the streaming connection. The client records the event sequence number when it receives each data event. The initial value of the event sequence number can be preset to 0 or 1, and the event sequence number is incremented by 1 after each data event is sent to the client through the streaming connection. The client can parse the event sequence number from each received data event to determine the current position of the received data. When the connection is re-established after being broken, the client sends the latest received event sequence number in the reconnection request to the system. The system can then determine which event the client has received based on the latest received event sequence number, and resume transmission from the event following the latest received event sequence number in subsequent event retransmissions.

[0129] The system restores the streaming connection corresponding to the original user session request based on the reconnection request. Then, it queries the execution status of the generation task corresponding to that session based on the session identifier to determine whether the generation task has triggered the external tool's invocation instruction. The execution status of this generation task is continuously maintained and updated by the system during the tool invocation process, and it can at least indicate what stage the current generation task is in.

[0130] If the generation task has triggered an external tool invocation command, the system will handle it in the following two ways, depending on the execution status of the external tool: If the external tool is still in execution (i.e., the tool has not yet completed execution), the system enters the keep-alive event generation and sending process. Based on the current progress status of the external tool, a corresponding keep-alive event is generated and sent to the client through the newly restored streaming connection. This maintains connection validity and synchronizes execution progress with the client during tool execution. Since the reconnection request carries the latest event sequence number received by the client, the system can determine which progress information the client has received and, accordingly, continue sending subsequent progress updates from the next event after the latest received event sequence number, preventing the client from repeatedly receiving already displayed progress content. If an external tool has completed execution, but the system has not yet sent all event data to the client before the connection is broken, the system will resend the undelivered event data to the client. Undelivered event data includes, but is not limited to, tool completion events generated when the external tool completes execution, and formal content events generated by the generative model based on the tool's execution results. The system determines which event data has been received and which has not been received by the client based on the latest received event sequence number carried in the client's reconnection request, and then resends the unreceived event data to the client in sequence. In this way, even if the client fails to receive some event data during a streaming connection interruption, the system can still resend the data based on the client's reported reception progress after reconnection, thus ensuring that the client receives a complete sequence of event data and avoiding data loss due to connection interruption.

[0131] Through the above reconnection and recovery mechanism, even if the streaming connection is abnormally disconnected during tool execution due to network or other reasons, the client user does not need to re-initiate the session or re-execute the tool call. The system can automatically restore the connection and resume data transmission through the session identifier and event sequence number in the reconnection request, thereby realizing the ability to resume streaming transmission from interruption.

[0132] In an optional embodiment, session management further includes: receiving a reconnection request initiated by the client after the streaming connection is disconnected; attempting to restore the streaming connection corresponding to the original user session request based on the reconnection request; and if restoring the streaming connection fails, sending a result acquisition indication message to the client so that the client can obtain the execution result of the generated task.

[0133] It should be noted that attempts to restore the streaming connection corresponding to the original user session request may fail for various reasons, including but not limited to: the AI ​​server being overloaded and unable to accept new connections; the AI ​​server restarting or malfunctioning, resulting in the loss of session context data; the client's network environment remaining unstable, causing the reconnection request to fail to reach the AI ​​server or to fail to complete the handshake; or the session identifier carried in the reconnection request having expired (e.g., exceeding the maximum session lifetime). In the above situations, the operation to restore the streaming connection will return a failure result.

[0134] If restoring the streaming connection fails, the system cannot continue pushing event data (such as keep-alive events, tool completion events, and formal content events) to the client via the streaming connection, because the streaming connection is the basic communication channel carrying real-time data transmission; without a connection, data cannot be pushed. In this case, the system sends a result retrieval instruction to the client.

[0135] Result retrieval instruction information refers to the information sent by the system to the client when the streaming connection cannot be restored, instructing the client to obtain the execution result of the generated task through other means. This instruction information includes at least the storage location or retrieval address of the execution result of the generated task, such as an accessible Uniform Resource Locator (URL) or file download address. After receiving this instruction information, the client can actively retrieve the execution result of the generated task through this address without relying on real-time push from the streaming connection. If the execution result of the generated task has not yet been completed, the result retrieval instruction information can also instruct the client to try to retrieve the execution result again after a preset time, or carry a status query address for checking the task progress.

[0136] In this way, even in the extreme case where the streaming connection cannot be restored, the system can still enable the client to obtain the final generated result by providing result acquisition instructions, thereby ensuring the reachability of the generation task execution result and avoiding the problem that the client cannot obtain the execution result at all due to the failure of the streaming connection to be restored.

[0137] In one alternative embodiment, the session management is applied to a distributed system comprising multiple service nodes for performing generation tasks; The session management also includes: during the execution of external tools, writing keep-alive events and the execution status of external tools to shared storage nodes; in response to a reconnection request initiated by a client after the streaming connection is broken, and the reconnection request is routed to a target service node different from the one before the client disconnected, the keep-alive events and the execution status of external tools are read from the shared storage node through the target service node, so as to resume sending keep-alive events to the client or resume transmitting the execution results of external tools.

[0138] In this context, a distributed system refers to a system architecture containing multiple service nodes for executing generation tasks. In a distributed deployment scenario, a distributed system typically includes multiple service nodes, each capable of handling user session requests, invoking external tools, and generating keep-alive events. Client-initiated requests (including initial requests and reconnection requests) are distributed to different service nodes by a load balancer or gateway based on factors such as the load and health status of each node. Therefore, when a client initiates a reconnection request after a connection is lost, the request may be assigned to a different target service node than the original node.

[0139] A shared storage node is a storage system independent of individual service nodes but accessible to multiple service nodes. Examples include distributed caches, distributed databases, or shared file systems. Shared storage nodes store state and event data generated by each service node during the processing of user session requests. Since shared storage nodes can be accessed by any service node in the distributed system, when a reconnection request is routed to the target service node, that service node can still read the data written by the original service node before the client disconnected from the shared storage node.

[0140] During the execution of the external tool, the original service node writes the session's context data, keep-alive events, and the execution status of the external tool to the shared storage node. The write operation can be performed in real-time, i.e., immediately upon generating a keep-alive event or updating the execution status; or it can be performed in batches according to a preset period, which is not limited in this application. Through this write operation, even if the original service node fails or restarts, the keep-alive events and execution status can still be persistently stored in the shared storage node.

[0141] When a client initiates a reconnection request after a streaming connection is broken, and this reconnection request is routed to a target service node different from the original service node, the target service node reads the session's context data, keep-alive events, and execution status of the external tool—previously written by the original service node—from the shared storage node. Based on the read execution status, the target service node can determine the current stage of the external tool; based on the read keep-alive event records, the target service node can determine which keep-alive events have been sent and which event data the client has received.

[0142] Subsequently, based on the read execution status and keep-alive event records, the target service node resumes sending keep-alive events to the client or continues transmitting the execution results of the external tool. Specifically, if the external tool is still in execution, the target service node continues to generate keep-alive events based on the current execution status and send them to the client to maintain connection validity and synchronize execution progress; if the external tool has completed execution, but the target service node determines based on the keep-alive event records that the client has not yet received all event data (e.g., tool completion event or formal content event has not been sent), the target service node will continue transmitting the unsent event data to the client from the breakpoint.

[0143] Through the aforementioned shared storage mechanism, even if a client's reconnection request is routed to a different service node, the node can still restore the execution state and keep-alive event records of the original session from the shared storage node. This enables cross-node session state recovery and streaming data continuation, avoiding the problem of being unable to restore the original session state due to reconnection requests being routed to different nodes. This improves the success rate of reconnection after disconnection and the fault tolerance of the system in distributed deployment scenarios.

[0144] In an optional embodiment, the method is applied to a multi-regional operating environment, and the method further includes: obtaining cross-regional link quality parameters between the region where the client is located and the region where the service node used to perform the generation task is located; and adaptively adjusting the keep-alive event sending interval and timeout threshold according to the cross-regional link quality parameters to adapt to the cross-regional link quality parameters.

[0145] In this context, a multi-regional operating environment refers to a system where service nodes are deployed across multiple geographical regions (e.g., North China, East China, South China, or China, Southeast Asia, Europe, etc.), and clients may initiate requests from different geographical regions. In cross-regional scenarios, network communication between the client and service nodes may traverse multiple network autonomous systems, increasing link length and resulting in significant differences in link quality parameters such as network latency and packet loss rate compared to access within the same region. Furthermore, link quality between different regions may also be affected by factors such as international egress bandwidth, transoceanic fiber optic cable transmission distance, and regional network congestion.

[0146] Cross-regional link quality parameters refer to indicators used to measure the quality of network communication between the region where the client is located and the region where the service node is located. These include, but are not limited to, network round-trip latency, packet loss rate, available bandwidth, and jitter. For example, when the client is located in Europe and the service node is deployed in North China, the round-trip latency of the cross-regional link may reach hundreds of milliseconds, and the packet loss rate may also be higher than that of access from the same region.

[0147] In this optional embodiment, the system obtains cross-regional link quality parameters between the region where the client is located and the region where the service node used to perform the generation task is located. This can be achieved through active probing during the session establishment phase (e.g., sending probe packets to measure round-trip latency), or by querying a regional link quality database maintained by the system, which is periodically updated with link quality data between different regions.

[0148] The system adaptively adjusts the sending interval and timeout threshold of keep-alive events based on the obtained cross-regional link quality parameters to adapt to the current cross-regional link quality.

[0149] When cross-region link quality parameters indicate poor link quality, such as high round-trip latency or high packet loss rate, the system can take at least one of the following adjustments: shorten the keep-alive event sending interval to increase the keep-alive event sending frequency, ensuring that at least one keep-alive event can successfully reach the client even with network packet loss, reducing the risk of the connection being mistakenly judged as invalid due to packet loss; and / or, extend the timeout threshold, such as extending the gateway idle timeout or client read timeout, to avoid normal communication being mistakenly judged as timeout due to the inherently high latency of cross-region links. When cross-region link quality parameters indicate good link quality, the system can appropriately extend the sending interval or shorten the timeout threshold to reduce unnecessary network overhead.

[0150] Through the above methods, the keep-alive strategy can adaptively adjust according to the actual quality of cross-regional links in a multi-regional operating environment, avoiding the failure of keep-alive events to arrive in time or to be misjudged as connection failures due to factors such as high latency and high packet loss rate of cross-regional links, thereby improving the reliability and stability of streaming connections in cross-regional scenarios.

[0151] Second Embodiment In the first embodiment described above, a session management method for generative models is provided. Correspondingly, the second embodiment of this application provides a session management apparatus for generative models. Since the apparatus embodiment is basically similar to the method embodiment, it is described simply; relevant details can be found in the description of the method embodiment. See also the description of... Figure 1 The following description of the apparatus embodiments is merely illustrative.

[0152] Please refer to Figure 5 This is a schematic diagram of a session management device for generative models provided in the second embodiment of this application.

[0153] The session management device includes: The session control unit 121 is used to establish a streaming connection with the client for real-time data transmission based on a user session request from the client. The model response control unit 122 is used to identify whether the generation task corresponding to the user session request has triggered a generative model to call an external tool. The keep-alive scheduling unit 126 is used to generate a keep-alive event corresponding to the execution state of the external tool based on the execution state of the external tool; and to send the keep-alive event to the client once or multiple times through the streaming connection, wherein the keep-alive event can be perceived by the client user.

[0154] Optionally, the session management device further includes: The tool call identification unit 124 is used to obtain link status parameters reflecting the external communication environment and tool execution parameters reflecting the internal execution progress of the external tool during the execution of the external tool. The keep-alive strategy unit 125 is further configured to generate an adaptive transmission strategy based on the link state parameters and the tool execution parameters; wherein the adaptive transmission strategy is used to dynamically adjust the transmission interval and / or transmission conditions of the keep-alive event; Sending the keep-alive event to the client once or multiple times includes: sending the keep-alive event to the client once or multiple times according to the adaptive sending strategy.

[0155] Optionally, the keep-alive scheduling unit 126 is further configured to stop sending the keep-alive event in response to the completion of the external tool execution; and generate a tool completion event to reflect the completion of the external tool execution. The tool completion event is sent to the client so that the client can perceive the completion of the external tool's execution and switch from the external tool's invocation state to the content display state of the generated task.

[0156] Optionally, the model response control unit 122 is further configured to, in response to the completion of the external tool, obtain the execution result of the external tool; generate formal answer content based on the execution result; generate a formal content event for the generation task based on the formal answer content; and send the formal content event to the client.

[0157] Optionally, the session control unit 121 is further configured to receive a reconnection request initiated by the client after the streaming connection is disconnected. The device further includes: an anomaly recovery unit 127, used to restore the streaming connection corresponding to the original user session request according to the reconnection request; The model response control unit 122 is further configured to identify, based on the user session request, whether the generation task corresponding to the user session request has triggered an external tool invocation instruction; if so, obtain the execution status of the external tool; and continue to execute the generation task based on the execution status of the external tool.

[0158] Third Embodiment Corresponding to the method embodiments described above, the third embodiment of this application also provides an electronic device. For example... Figure 6 As shown, Figure 6This is a schematic diagram of an electronic device provided in the third embodiment of this application. The electronic device includes: at least one processor 601, at least one communication interface, at least one memory 602, and at least one communication bus. Optionally, the communication interface can be an interface of a communication module, such as the interface of a GSM module. The processor 601 may be a CPU, an Application Specific Integrated Circuit (ASIC), or one or more integrated circuits configured to implement embodiments of the present invention. The memory 602 may include high-speed RAM and may also include non-volatile memory, such as at least one disk storage device. The memory 602 stores a program, and the processor 601 calls the program stored in the memory 602 to execute the methods provided in the above embodiments of this application.

[0159] Fourth embodiment Corresponding to the methods described above in this application, the fourth embodiment of this application also provides a computer storage medium. The computer storage medium stores a computer program, which is executed by a processor to perform the methods provided in the above embodiments of this application.

[0160] Although this application discloses preferred embodiments as described above, it is not intended to limit this application. Any person skilled in the art can make possible changes and modifications without departing from the spirit and scope of this application. Therefore, the scope of protection of this application should be determined by the scope defined in the claims of this application.

[0161] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.

[0162] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.

[0163] 1. Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information by any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include non-transitory computer-readable media, such as modulated data signals and carrier waves.

[0164] 2. Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0165] It should be noted that the embodiments of this application may involve the use of user data. In practical applications, user-specific personal data may be used in the scheme described herein within the scope permitted by applicable laws and regulations, provided that it complies with the applicable laws and regulations of the country (e.g., with the user's explicit consent, with the user being properly notified, etc.).

[0166] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, data stored, data displayed, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.

Claims

1. A session management method for generative models, characterized in that, include: Based on user session requests from the client, establish a streaming connection with the client for real-time data transmission; Identify whether the generation task corresponding to the user session request has triggered a generative model's instruction to call external tools; If so, then based on the execution state of the external tool, generate a keep-alive event corresponding to the execution state of the external tool; Through the streaming connection, the keep-alive event is sent to the client once or multiple times, and the keep-alive event can be perceived by the client user.

2. The session management according to claim 1, characterized in that, The execution status of the external tool includes: the status of the internal execution progress output by the external tool, and information reflecting the execution process of the external tool that is actively perceived based on the execution progress of the external tool.

3. The session management according to claim 1, characterized in that, The method further includes: During the execution of the external tool, link status parameters reflecting the external communication environment and tool execution parameters reflecting the internal execution progress of the external tool are acquired. An adaptive transmission strategy is generated based on the link state parameters and the tool execution parameters; wherein, the adaptive transmission strategy is used to dynamically adjust the transmission interval and / or transmission conditions of the keep-alive event; Sending the keep-alive event to the client once or multiple times includes: sending the keep-alive event to the client once or multiple times according to the adaptive sending strategy.

4. The session management according to claim 3, characterized in that, The step of generating an adaptive transmission strategy based on the link state parameters and the tool execution parameters includes: Based on the link status parameters and the tool execution parameters, obtain the historical execution time, current execution time, and link quality of the streaming connection of the external tool; Based on the relative relationship between the historical execution time and the current execution time, as well as the link quality of the streaming connection, the sending interval and / or sending conditions of the keep-alive event are calculated, and the sending interval and / or sending conditions are used as components of the adaptive sending strategy.

5. The session management according to claim 1, characterized in that, The method further includes: In response to the completion of the external tool's execution, the sending of the keep-alive event is stopped; Generate a tool completion event to reflect the completion of the external tool's execution; The tool completion event is sent to the client so that the client can perceive the completion of the external tool's execution and switch from the external tool's invocation state to the content display state of the generated task.

6. The session management according to claim 1, characterized in that, The method further includes: After the streaming connection is disconnected, the client initiates a reconnection request after the streaming connection is disconnected; Based on the reconnection request, restore the streaming connection corresponding to the original user session request; Based on the user session request, identify whether the generation task corresponding to the user session request has triggered the call instruction of the external tool; If so, then obtain the execution status of the external tool; The generation task continues to be executed based on the execution status of the external tool.

7. The session management according to claim 6, characterized in that, The reconnection request includes at least a session identifier and the most recently received event sequence number; The step of identifying whether the generation task corresponding to the user session request has triggered the external tool's invocation instruction based on the user session request includes: querying the execution status of the generation task corresponding to the user session request related to the reconnection request based on the session identifier, and determining whether it has triggered the external tool's invocation instruction. The step of continuing to execute the generation task based on the execution status of the external tool includes one of the following situations: If the external tool is in the process of execution, then the process of generating a keep-alive event corresponding to the execution state of the external tool, and sending the keep-alive event to the client once or multiple times through the streaming connection is initiated. If the external tool completes its execution but fails to send all event data to the client, it will resend the undelivered event data to the client.

8. The session management according to claim 1, characterized in that, The method further includes: identifying whether the generation task corresponding to the user session request has triggered a generative model to call an external tool; if it is identified that the generation task has triggered a batch call instruction for multiple external tools, then the following steps are performed. Obtain the execution status of each of the multiple external tools; The execution states of the multiple external tools are aggregated according to preset aggregation rules to generate an aggregated state that reflects the overall execution state of the multiple external tools. The step of generating a keep-alive event corresponding to the execution state of the external tool, based on the execution state of the external tool, includes: Based on the aggregation state, a keep-alive event corresponding to the aggregation state in which the external tool is located is generated.

9. The session management according to claim 1, characterized in that, The method is applied to a distributed system containing multiple service nodes for performing the generation task; The method further includes: During the execution of the external tool, the keep-alive event and the execution status of the external tool are written to the shared storage node; In response to a reconnection request initiated by the client after the streaming connection is disconnected, and the reconnection request is routed to a different target service node than before the client disconnected, the keep-alive event and the execution status of the external tool are read from the shared storage node through the target service node, so as to resume sending the keep-alive event to the client or resume transmitting the execution results of the external tool.

10. The session management according to claim 1, characterized in that, The method is applied to a multi-regional operating environment, and the method further includes: Obtain the cross-region link quality parameters between the region where the client is located and the region where the service node used to execute the generation task is located; Based on the cross-regional link quality parameters, the keep-alive event sending interval and timeout threshold are adaptively adjusted to suit the cross-regional link quality parameters.

11. A session management device for generative models, characterized in that, include: The session control unit is used to establish a streaming connection with the client for real-time data transmission based on the user session request from the client. The model response control unit is used to identify whether the generation task corresponding to the user session request has triggered the generative model's instruction to call external tools; The keep-alive scheduling unit is used to generate a keep-alive event corresponding to the execution state of the external tool, based on the execution state of the external tool. Through the streaming connection, the keep-alive event is sent to the client once or multiple times, and the keep-alive event can be perceived by the client user.

12. An electronic device, characterized in that, The electronic device includes a processor and a memory; The memory stores a computer program, and after the processor runs the computer program, it performs the method described in any one of claims 1-10.

13. A computer storage medium, characterized in that, The computer storage medium stores a computer program, which, when executed by a processor, performs the method described in any one of claims 1-10.