Long content bypass recovery method for large language model tool invocation

By using bypass capture and fault-tolerant field extraction, the parsing failure problem when generating long content from a large language model is solved, enabling disk recovery without regeneration, ensuring content consistency and continuity of user intent, reducing network and computing power consumption, and avoiding multiple rounds of interaction.

CN123137757APending Publication Date: 2026-11-20SIPPR ENG GROUP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611399842.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-10
Publication Date
2026-11-20

AI Technical Summary

Technical Problem

When generating long content, large language models encounter problems such as failure to parse tool call parameters, leading to user intent violations, generation delays, and high costs. They also face issues such as multiple rounds of interaction caused by failing to output text according to user intent and initiating tool calls.

Method used

By bypassing the capture of payload field content, content addressing is used to generate content identifiers, and the payload content is restored by fault-tolerant field extractor when parsing fails. The state is invoked using inter-process communication synchronization tools, and inhibitory hints are injected to complete disk write and avoid model regeneration.

Benefits of technology

When the tool fails to parse the parameters, it can complete the disk write without regenerating the model, ensuring content consistency and user intent continuity, reducing network and computing power consumption, and avoiding multiple rounds of interaction and repeated output.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123137757A_ABST
    Figure CN123137757A_ABST
Patent Text Reader

Abstract

The application discloses a long content bypass recovery method and device for large language model tool calling, establishes a bypass capture for a long file writing scene, recovers content completely consistent with content generated by a large language model for the first time from the bypass when tool calling parameter analysis fails, so that the large language model does not need to be regenerated, network and computing power are saved, and the continuity of a user intention is ensured. Meanwhile, aiming at the problem that the large language model only outputs long text and does not actively call tools to complete the intention generated and stored by the user, the application initiates tool calling by actively detecting an intention and automatically determining a target path as a tool calling parameter through a three-level backoff strategy to avoid completing the intention of the user through multiple rounds of interaction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of artificial intelligence technology, and is particularly applicable to a long content bypass recovery method for calling large language model tools. Background Technology

[0002] When Large Language Models (LLMs) interact with external systems via function calling, there exists a widely recognized but still unresolved failure pattern: When a user expects the LLM to generate a long file (such as source code, HTML pages, or Markdown documents) and write it to disk via a tool call, the arguments field of the function call may fail to resolve on the client side due to any of the following reasons: network interruption or server-side truncation during streaming; the LLM generating an unclosed JSON string in the arguments field (e.g., long text containing unescaped double quotes or newlines); truncation due to exceeding the token limit for a single output by the model; or client-side buffer overflow.

[0003] When parsing fails, the tool call is discarded. The large language model is unaware of the reason for the failure (it only receives a "parameter parsing failed" message), unaware that its recently generated content is partially lost, and even less aware of how to recover it. In traditional solutions, there are three known paths to handle this failure: 1. Have the model regenerate the complete JSON. Add system prompts to the dialogue history, requiring the model to re-output complete and valid arguments. The drawback is that for long content (tens of KB or more), the network and computing costs of regeneration are far higher than the initial generation, and the model may produce inconsistent content during regeneration, disrupting the continuity of user intent. 2. Truncate content to fit the limit. Arguments are truncated when their length exceeds a certain threshold. The drawback is that the content written to disk is incomplete, violating user intent. 3. Refuse to execute and ask the user to retry. Abandon immediately upon parsing failure. Its drawbacks include a poor user experience and the model's inability to recover from the generated content.

[0004] Furthermore, a structurally symmetrical failure mode exists within large language model agents: the user explicitly expresses the intention to "write XXX and save it," but the large language model only outputs long text without initiating any tool calls. Existing solutions either rely on the large language model to decide whether to call a tool or require multiple rounds of interaction to complete the tool call, resulting in high latency and context costs.

[0005] Therefore, a mechanism is needed that can recover long content that has already been generated from the bypass without requiring the model to be regenerated, while ensuring the user's intention to save the content to disk. Summary of the Invention

[0006] The purpose of this invention is to provide a long content bypass recovery method for large language model tool calls, which solves the problem that when the parameters of a large language model tool call fail during the client parsing stage, the model needs to be regenerated, resulting in violation of user intent, generation delay, and high cost. It also solves the problem that the large language model does not output text according to user intent and initiate tool calls, which requires multiple rounds of interaction to complete the large language model tool call.

[0007] To achieve the above objectives, the long content bypass recovery method for large language model tool calls described in this invention includes the following steps: S1, Bypass capture: When the agent's main loop receives the tool call stream returned by the large language model, before the parameters of the tool call are parsed, the predetermined payload field is identified from the original parameter stream of the tool call, and the content of the payload field is processed by content addressing independently of the formal parsing path to obtain the content identifier. The content of the payload field and the content identifier are associated and stored in the bypass cache. S2, Fault-tolerant field extraction; When the parameters called by the tool fail during the main loop parsing stage of the agent, the fault-tolerant field extractor is started to perform a linear scan on the original parameter stream, and searches for and extracts the corresponding string values ​​according to the predetermined load fields; The fault-tolerant field extractor records the closure state of each string value, and only when the closure state of all string values ​​is closed is the fault-tolerant field extraction determined to be successful; otherwise, the fault-tolerant field extraction is determined to be unsuccessful. S3, Bypass Recovery: When the fault tolerance field is successfully extracted and the content identifier associated with the tool call exists in the bypass cache, the client execution environment uses the content identifier and the path obtained from the fault tolerance field extraction as tool call parameters to call the predetermined disk-writing tool; the tool call status is synchronized to the user interface process through inter-process communication; the tool call result is injected into the agent's dialogue history; and an inhibitory prompt is appended to the dialogue history; the inhibitory prompt indicates that the tool call action of the large language model has been completed, prohibiting the re-output of the payload content, thereby enabling the long payload to be recovered from the bypass and disk-writing completed without the large language model regenerating when the tool call parameters of the large language model fail in the client parsing stage.

[0008] Furthermore, the tools include a set of tools capable of carrying long text, including the writeFile tool; the predetermined payload field is the content field; and the predetermined disk writing tool is the writeDraftArtifact tool.

[0009] Furthermore, the content addressing process employs the SHA-1 hash algorithm; the content identifier is formed by concatenating the timestamp with the first 6 characters of the SHA-1 hash algorithm.

[0010] Furthermore, the fault-tolerant field extractor searches for the predetermined payload field in the raw parameter stream; locates the colon character immediately following the quotation string of the predetermined payload field; skips the whitespace characters after the colon character; confirms that the current position is the starting double quote; starting from the position after the starting double quote, it reads character by character in a loop and records the backslash escape state with the escaped flag; when an unescaped double quote is encountered, it records the closure state as closed and returns the read string value; when the raw parameter stream is exhausted and no unescaped double quote is encountered, it records the closure state as unclosed and returns the read string value.

[0011] Furthermore, the step of synchronizing the tool call state to the user interface process through inter-process communication includes synchronizing the tool call object synthesized in the client execution environment, the instantiation state of each tool call, and the tool call result to the user interface process, so that the user interface process presents the recovery process indistinguishably from normal tool calls.

[0012] Furthermore, it also includes S4, where, when the agent's main loop detects that the current round's large language model response contains content that can be identified as a draft and is longer than a predetermined length, and there is no tool call initiated by the large language model in the current round's dialogue history, intent detection is performed on the current round's user message; when the intent detection is true, the client execution environment uses the content identifier in the bypass cache corresponding to the draft content and the target path inferred from the user message or context as tool call parameters to call the disk-writing tool; the disk-writing result is injected into the dialogue history as the tool call result; and an inhibitory prompt is appended to the dialogue history, the inhibitory prompt indicating to the large language model that the disk-writing action has been completed and prohibiting the re-output of the payload content, thereby realizing a mechanism that can automatically detect the mismatch between user intent and the large language model's tool call action when the large language model only outputs text and does not initiate a tool call, and the client actively synthesizes a tool call to close the loop of user intent.

[0013] Furthermore, in step S4, the target path is inferred from the user message or context using a three-level fallback strategy, which consists of: the absolute path or file path pattern explicitly appearing in the user message; the file name plus suffix pattern explicitly appearing in the user message; and the path parameter of the most recent tool call in the context.

[0014] Furthermore, the agent's main loop includes alternating steps of streaming generation and tool execution; the bypass capture is executed before the tool call parameters are parsed; and the bypass resumption execution does not block streaming generation of other tool calls.

[0015] Furthermore, the content of the inhibitory prompt is generated by interpolation from a predetermined prompt word template, and the interpolation variable includes at least the content identifier and the target path.

[0016] Furthermore, intent detection is performed on user messages; when the intent detection is true, quality retry determination for the streaming output of the large language model is disabled.

[0017] This invention provides a long content bypass recovery device for calling large language model tools, comprising: The bypass caching module is configured to temporarily store the payload content called by the large language model tool in a content-addressed manner; The bypass capture module is configured to write the payload field of a tool call that meets predetermined conditions into the bypass cache module before the tool call parameters are parsed. The fault-tolerant field extraction module is configured to perform a linear scan on the original parameter stream when the tool fails to parse the parameters, search for and extract the corresponding string values ​​according to the predetermined load fields, and record the closure state of each extracted string value. The bypass recovery execution module is configured to call the disk write tool when the fault tolerance field extraction module successfully extracts a string value and the corresponding string value exists in the bypass cache module. It then synchronizes the synthesized tool call status to the user interface process through inter-process communication and injects inhibitory prompts into the dialogue history. The intent and action mismatch detection and automatic disk placement module is configured to perform intent detection when the agent's response contains a long draft and no tool call, and automatically synthesize tool call parameters and execute the disk placement tool call when the detection is true.

[0018] The present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, is described as a long content bypass recovery method for large language model tools.

[0019] The present invention provides a computer device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the long content bypass recovery method for calling large language model tools.

[0020] The advantages of this invention are: 1. In long file writing scenarios, this invention can complete the disk writing process without regenerating a large language model (usually tens of KB or more) when the tool fails to parse the parameters, thus saving network and computing power.

[0021] 2. The content recovered from the bypass in this invention is completely consistent with the content initially generated by the large language model, avoiding inconsistencies that may occur during the regeneration process, ensuring the continuity of user intent, and maintaining the semantic consistency of the interactive interface.

[0022] 3. This invention solves the problem of multi-turn interactions caused by large language models only outputting long text without actively calling tools to complete the user's intention to generate and save the text to disk.

[0023] 4. This invention prevents large language models from repeatedly outputting long payloads in the same round of dialogue by injecting inhibitory prompts, thus avoiding the context being polluted by repeated long content. Attached Figure Description

[0024] Figure 1 is an overall flowchart of an embodiment of the present invention. Detailed Implementation

[0025] The technical solutions in the embodiments of the present invention will be clearly and completely described below. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present invention.

[0026] Example 1 This embodiment runs in the client execution environment (such as the Electron main process) of a large language model agent. The agent's main loop adopts alternating steps of streaming generation and tool execution. In each iteration, the client initiates a streaming request → the large language model incrementally returns a tool_call (tool call) incremental block → the client accumulates and attempts to parse the arguments field → if the arguments field is successfully parsed, the tool is executed and the process continues; if parsing fails, the long content bypass recovery method for large language model tool calls described in this invention is used to recover the content initially generated by the large language model from the bypass, avoiding inconsistencies that may result from regenerating the large language model and ensuring the continuity of user intent. Figure 1 As shown, the specific implementation steps are as follows: Step S1: Bypass Capture When the main loop of the agent receives the tool call stream returned by the large language model, for tool calls that meet the predetermined conditions, before the parameters of the tool call are parsed, the predetermined payload field is identified from the original parameter stream of the tool call, and the content addressing processing of the payload field is performed independently of the formal parsing path to obtain the content identifier. The content of the payload field and the content identifier are associated and stored in the bypass cache.

[0027] The predefined conditions are pre-configured filtering rules when activating the bypass recovery mechanism of the long content bypass recovery method for large language model tools described in this invention. Only when a rule is matched can bypass processing begin; otherwise, processing is performed only through the formal parsing path. Common filtering rule configurations include tool name whitelists or regular expression matching, tool name blacklists, parameter size thresholds (e.g., triggering when the cumulative number of arguments bytes exceeds 4KB), task or session stage markers (e.g., the current round is in the content output stage such as writing documents or generating reports), and parameter schema markers (the schema field in the tool definition is marked with x payload: true).

[0028] The original parameter stream is sent incrementally as string fragments from arguments called by streaming tools such as OpenAI. Before JSON.parse, it needs to be continuously concatenated to the argumentsBuffer string cache, including any intermediate fragments that are not completed during the concatenation process.

[0029] The payload field is a predefined field in the JSON-schema parameter of the tool used to carry large amounts of content. It is different from short text metadata fields such as path and mode. Typical examples are the content of write_file and the body of create_document. Its characteristics are that the numerical value is large and can be repeated, making it suitable for content addressing to achieve deduplication and on-demand retrieval.

[0030] The formal parsing path involves streaming fragments and concatenating them into a complete JSON, which is then processed by JSON.parse and schema validation before being executed by the tool.

[0031] Content addressing is the process of generating a fixed-length deterministic identifier from content using cryptographic hashing.

[0032] Specifically, when the main loop of the agent receives the tool call stream returned by the large language model, during the process of accumulating the tool call arguments stream (i.e., the window before parsing tool call parameters), for tool calls that can carry long text (such as write_file) and whose content field in the rawArguments raw parameter stream is of type string, the bypass cache interface is called to process the content in the arguments.content field in the following way: 1. Trim the blank spaces before and after to obtain standardized content; 2. If the normalized length is less than 200 characters, skip it (short content will not enter the bypass to avoid noise); 3. Calculate the SHA-1 hash value of the normalized content as the content identifier; 4. If the hash already exists in the bypass cache, reuse the existing entry and refresh the "recent content identifier" pointer; 5. Otherwise, generate a content identifier, which is formed by concatenating the timestamp with the first 6 characters of the SHA-1 hash algorithm, specifically: draft_{timestamp in base 36}_{first 6 characters of hash}, and simultaneously create an entry (containing id / kind / content / createdAt / hash) and add it to the bypass cache; 6. Create an inverted index from the tool call identifier (tc.id) to the content identifier.

[0033] This involves identifying the predetermined payload fields from the raw parameter stream of the tool call, and independently of the formal parsing path, performing content addressing on the payload fields to obtain content identifiers, and then associating the content of the payload fields with the content identifiers and storing them in the bypass cache.

[0034] Step S2: Extracting fault tolerance fields When the parameters invoked by the tool fail to be parsed during the main loop of the agent, the fault-tolerant field extractor is started to perform a linear scan on the original parameter stream, and searches for and extracts the corresponding string values ​​according to the predetermined load fields. The fault-tolerant field extractor records the closure state of each string value, and only when the closure state of all string values ​​is closed is the fault-tolerant field extraction determined to be successful; otherwise, the fault-tolerant field extraction is determined to be unsuccessful.

[0035] That is, when the agent's main loop fails to parse the arguments stream of the cumulative tool, a fault-tolerant field extractor is started on the rawArguments stream to extract string values ​​according to the predetermined field names (such as path).

[0036] The raw arguments and the arguments represent two states of the same data object at different processing stages. The raw arguments are unstructured hash data fragments that have not yet undergone serialization and assembly; while the arguments are standard JSON format strings generated by mapping key-value pairs and structurally encapsulating the raw arguments according to a predetermined communication protocol or data interface specification.

[0037] In this invention, the fault-tolerant field extractor is implemented using a finite state machine, which consists of a standard quintuple: a state set (Q), an input character set (Σ), a state transition function (δ: Q×Σ→Q), an initial state (q0), and a final state set (F). Given that JSON lexical rules are context-sensitive—meaning the same input characters have vastly different semantics under different grammatical depths or scenarios—the determination depends on the current context, making effective coverage impossible using conventional regular expressions. Therefore, this solution employs a finite state machine to track the context state in real time to accurately identify structural boundaries.

[0038] The specific steps for extracting fault-tolerant fields are as follows: S2.1, Field Name Lookup. The system searches for the target field name in the raw argument stream `rawArguments`, and then searches for the first occurrence of the substring of the target field name (`fieldName`) in the raw argument stream `rawArguments`. If not found, it returns null, and the fault-tolerant field extractor terminates.

[0039] S2.2, Locating the colon. Searches for the first ":" character after the target field name; if not found, returns null, and the fault-tolerant field extractor terminates.

[0040] S2.3, Skip whitespace. Skip consecutive whitespace characters after the colon until the first non-whitespace character is encountered.

[0041] S2.4, Validate the starting double quote. If the fault-tolerant field extractor confirms that the current position is a double quote, it will proceed to the actual string value extraction state; otherwise, it will return null and the fault-tolerant field extractor will terminate.

[0042] S2.5, Character-by-character scanning. Starting from the character after the double quote, the fault-tolerant field extractor performs a character-by-character cyclic scan of the raw parameter stream `rawArguments`. During the cyclic scan, the fault-tolerant field extractor uses an escape flag (`escaped`) to record whether the current character is in an escaped state. If the current character is an escape character, the escape flag is set and the escape character is discarded without being written to the buffer. If the current character is not an escape character, the state of the escape flag determines whether to write it as a normal character to the buffer, and the escape flag is reset after writing. The following operations are performed on each character: If the character preceding the current character is a backslash (i.e., escaped==true in the current processing loop), then the current character and the preceding backslash character are written together as part of the escape sequence into the buffer. Then, the escaped flag is reset to false, and the next character is processed.

[0043] If the current character is a backslash (\) and the current escaped flag is false, then the escaped flag is set to true, the backslash itself is not written to the buffer, and the next character is processed.

[0044] If the current character is a double quote (") and the current escaped flag is false, then the double quote is determined to be the end identifier of the field value, and the closed flag is set to true.

[0045] The accumulated character sequence in the buffer is used as the raw extraction result, which is then used in the subsequent decoding and normalization process (including JSON parsing rollback and preset replacement rules), and the final string value is returned.

[0046] The state machine terminates, and the fault-tolerant process ends.

[0047] If the current character does not fall under any of the above conditions (i.e., it is not a backslash, not a closing quote, and is not in an escaped state), then the character is written directly into the buffer, and the next character is processed.

[0048] S2.6, Stream reading complete.

[0049] If the character-by-character loop exits normally (i.e., it iterates through all characters in the original parameter string), but never encounters a non-escaped double quote end marker (i.e., the closed flag remains false), the extractor determines that the field value is not properly closed. In this case, the fault-tolerant field extractor does not return an empty value, but instead returns the accumulated character sequence in the buffer as a partial extraction result, and marks the closed flag as false, allowing the upper-level caller to decide whether to use this partial result based on business needs.

[0050] Specifically, for the writeDraftArtifact tool, fault tolerance and recovery require that both the path and artifactId fields be successfully extracted and closed==true.

[0051] Step S3: Bypass recovery When the fault tolerance field is successfully extracted and the bypass cache contains a content identifier associated with the tool call, the client execution environment uses the content identifier and the path field obtained from the fault tolerance field extraction as tool call parameters to call the predetermined disk-based tool; the tool call status is synchronized to the user interface process through inter-process communication; the tool call result is injected into the agent's dialogue history; and an inhibitory prompt is appended to the dialogue history; the inhibitory prompt indicates that the tool call action of the large language model has been completed and prohibits the re-output of the payload content.

[0052] Taking the writeDraftArtifact tool call recovery as an example, when step S2 successfully extracts the "path" field and closed == true; and the bypass cache in step S1 also retains the content identifier associated with the tool call, the following steps are executed: 1. The client execution environment synthesizes a new tool call identified as `fallbackToolCallId`, including a content identifier and a path field extracted from the fault tolerance field. The new tool call instruction is, for example, the disk write tool `writeDraftArtifact`, with parameters `{artifactId: cachedDraftArtifactId, path:fallbackPath}`. The tool call status (including running, completed, or error) is pushed sequentially to the user interface process (rendering process) via inter-process communication (e.g., using `ipcMain.on` and `webContents.send` in an Electron architecture).

[0053] 2. Execute the synthetic call using the normal protocol of the disk dump tool, and inject the execution result as the role:'tool' message into the dialog history.

[0054] 3. Add a suppressive hint with role: 'system'. The suppressive hint content is generated by interpolation from a predefined hint template, and the interpolation variables include at least the content identifier and the target path. Specifically, the suppressive hint content is: The previous `writeFile` operation failed due to corrupted parameters. The cached draft `{artifactId}` has now been automatically reused and written to `{path}`. Do not regenerate the entire content.

[0055] If the recovery execution itself fails, only the failed tool result and the "Do not resubmit corrupted parameters" message are appended to the dialogue history, and the model will re-initiate with a complete and valid JSON in the next round.

[0056] In this invention, the main loop of the intelligent agent includes alternating steps of streaming generation and tool execution; the bypass capture is executed before the tool call parameters are parsed; the bypass resumption execution does not block the streaming generation of other tool calls.

[0057] Step S4: Intent-Action Mismatch Detection and Automatic Disk Drop When the agent's main loop detects that the current round's large language model response contains content that can be identified as a draft and is longer than a predetermined length, and there is no tool call initiated by the large language model in the current round's dialogue history, intent detection is performed on the current round's user message. When the intent detection is true, the client execution environment uses the content identifier in the bypass cache corresponding to the draft content and the target path inferred from the user message or context as tool call parameters to call the disk-writing tool. The disk-writing result is injected into the dialogue history as the tool call result. An inhibitory prompt is appended to the dialogue history, indicating to the large language model that the disk-writing action has been completed and that the payload content should not be re-output.

[0058] When the agent's main loop detects that the current round's large language model response contains multiple lines of content longer than 600 characters, formatted as HTML, Markdown, source code, or long text, and there are no active tool calls in the current round's large language model response, the following actions are performed: 1. Proactively detect the user's intent to execute the message in this round; specifically, determine whether any combination of a predetermined action keyword and a target keyword or file path pattern appears simultaneously. If any combination of a predetermined action keyword and a target keyword or file path pattern exists, immediately determine that the user has the intent to "generate and persist to disk". Predetermined action keywords include update, modify, generate, write, save, persist to disk, export, submit, etc.; target keywords include script, file, code, page, document, etc.

[0059] 2. When it is determined that the user has the intent to "generate and write to disk," i.e., the intent detection is true, a three-level fallback strategy is used to determine the target path. Specifically, the first level uses the explicit absolute path or file path in the user message to determine the target path. The second level uses the filename and filename extension detected from the user input in the current round to determine the target path. The third level uses the path parameter of the most recent tool call in the context as the target path.

[0060] 3. The client execution environment synthesizes a tool call with the identifier draft-autowrite-{iteration}-{timestamp} and executes the disk write action, injecting the disk write result as the tool call result into the dialogue history.

[0061] 4. Add a suppressive prompt indicating to the large language model that the disk write operation has been completed and that the payload content should not be re-output. For example, the suppressive prompt could be: "The user request belongs to the 'automatic disk write after generation / update' scenario, and the latest draft artifactId has been automatically written to the path. Next steps: 1. Briefly state that the writing is complete; 2. Explicitly provide the file path; 3. If necessary, add only one sentence of the most valuable follow-up suggestion; 4. Do not output the entire draft content again."

[0062] To avoid misjudgment of "code intent recognition" in the intent detection and quality retry in step S4, this invention performs intent detection on the user message when the user message is simultaneously identified as having the intent to "generate and write to disk". When the intent detection is true, the "greeting script illusion" in the quality retry is judged as a short circuit (i.e., no quality retry is triggered), and the quality retry judgment for the streaming output of the large language model is disabled, thereby preserving tolerance for the code output of the user's explicit requests.

[0063] The present invention also provides a long content bypass recovery device for calling large language model tools, comprising: The bypass caching module is configured to temporarily store the payload content called by the large language model tool in a content-addressed manner; The bypass capture module is configured to write the payload field of a tool call that meets predetermined conditions into the bypass cache module before the tool call parameters are parsed. The fault-tolerant field extraction module is configured to perform a linear scan on the original parameter stream when the tool fails to parse the parameters, search for and extract the corresponding string values ​​according to the predetermined field names, and record the closure state of each extracted string value. The bypass recovery execution module is configured to call the disk write tool when the fault tolerance field extraction module successfully extracts the string value and the corresponding content identifier exists in the bypass cache module. It then synchronizes the synthesized tool call status to the user interface process through inter-process communication and injects inhibitory prompts into the dialogue history. The intent and action mismatch detection and automatic disk placement module is configured to perform intent detection when the agent's response contains a long draft and no tool call, and automatically synthesize tool call parameters and execute the disk placement tool call when the detection is true.

[0064] The present invention also includes a computer-readable storage medium having a computer program stored thereon. The computer program is used to implement the long content bypass recovery method for large language model tool calls described in this invention.

[0065] The present invention also includes a computer device comprising a memory and a processor, wherein the memory stores a computer program for implementing the long content bypass recovery method for large language model tool calls described in the present invention.

Claims

1. A method for bypassing and restoring long content for large language model tool calls, characterized in that, Includes the following steps: S1, bypass capture; When the main loop of the agent receives the tool call stream returned by the large language model, before the parameters of the tool call are parsed, the predetermined payload field is identified from the original parameter stream of the tool call, and the content addressing of the payload field is performed independently of the formal parsing path to obtain the content identifier. The content of the payload field and the content identifier are associated and stored in the bypass cache. S2, Fault-tolerant field extraction; When the parameters called by the tool fail during the main loop parsing stage of the agent, the fault-tolerant field extractor is started to perform a linear scan on the original parameter stream, and searches for and extracts the corresponding string values ​​according to the predetermined load fields; The fault-tolerant field extractor records the closure state of each string value, and only when the closure state of all string values ​​is closed is the fault-tolerant field extraction determined to be successful; otherwise, the fault-tolerant field extraction is determined to be unsuccessful. S3, Bypass Recovery: When the fault tolerance field is successfully extracted and the bypass cache contains a content identifier associated with the tool call, the client execution environment uses the content identifier and the path obtained from the fault tolerance field extraction as tool call parameters to call the predetermined disk-writing tool; the tool call status is synchronized to the user interface process through inter-process communication; the tool call result is injected into the agent dialogue history; An inhibitory prompt is added to the dialogue history; the inhibitory prompt indicates that the tool invocation action of the large language model has been completed and the re-output of the payload content is prohibited.

2. The long content bypass recovery method for calling large language model tools according to claim 1, characterized in that: The tools include a set of tools capable of carrying long text, including the writeFile tool; the predetermined payload field is the content field; and the predetermined disk writing tool is the writeDraftArtifact tool.

3. The long content bypass recovery method for calling large language model tools according to claim 1, characterized in that: The content addressing process uses the SHA-1 hash algorithm; the content identifier is formed by concatenating the timestamp with the first 6 characters of the SHA-1 hash algorithm.

4. The long content bypass recovery method for calling large language model tools according to claim 1, characterized in that: The fault-tolerant field extractor searches for the predetermined payload field in the raw parameter stream; locates the colon character immediately following the predetermined payload field; skips the whitespace characters following the colon character; and confirms that the current position is the starting double quote. Starting from the position after the initial double quote, read character by character in a loop and record the backslash escape status with the escaped flag; when an unescaped double quote is encountered, record the closure status as closed and return the read string value; when the original parameter stream is exhausted and no unescaped double quote is encountered, record the closure status as open and return the read string value.

5. The long content bypass recovery method for calling large language model tools according to claim 1, characterized in that: The step of synchronizing the tool call state to the user interface process via inter-process communication includes synchronizing the tool call object synthesized in the client execution environment, the instantiation state of each tool call, and the tool call result to the user interface process, so that the user interface process presents the recovery process indistinguishably from normal tool calls.

6. The long content bypass recovery method for calling large language model tools according to claim 1, characterized in that: It also includes S4, which performs intent detection on the current round user message when the agent's main loop detects that the current round's large language model response contains content that can be identified as a draft and is longer than a predetermined length, and there is no tool call actively initiated by the large language model in the current round's dialogue history; when the intent detection is true, the client execution environment calls the disk-writing tool using the content identifier in the bypass cache corresponding to the draft content and the target path inferred from the user message or context as tool call parameters; and injects the disk-writing result as the tool call result into the dialogue history; An inhibitory prompt is added to the dialogue history, indicating to the large language model that the disk placement action has been completed and that the payload content should not be re-output.

7. The long content bypass recovery method for calling large language model tools according to claim 6, characterized in that: In step S4, the target path is inferred from the user message or context using a three-level fallback strategy, which is as follows: the absolute path or file path pattern explicitly appearing in the user message; the file name plus suffix pattern explicitly appearing in the user message; And the path parameter of the most recent tool call in the context.

8. The long content bypass recovery method for calling large language model tools according to claim 1, characterized in that: The agent's main loop includes alternating steps of streaming generation and tool execution; the bypass capture is executed before the tool call parameters are parsed; the bypass resumption execution does not block streaming generation of other tool calls.

9. The long content bypass recovery method for calling large language model tools according to claim 1, characterized in that: The content of the inhibitory prompt is generated by interpolation from a predetermined prompt word template, and the interpolation variables include at least the content identifier and the target path.

10. The long content bypass recovery method for calling large language model tools according to claim 1, characterized in that: Perform intent detection on user messages; when intent detection is true, disable quality retry determination for the streaming output of the large language model.

11. A long content bypass recovery device for calling large language model tools, characterized in that, include: The bypass caching module is configured to temporarily store the payload content called by the large language model tool in a content-addressed manner; The bypass capture module is configured to write the payload field of a tool call that meets predetermined conditions into the bypass cache module before the tool call parameters are parsed. The fault-tolerant field extraction module is configured to perform a linear scan on the original parameter stream when the tool fails to parse the parameters, search for and extract the corresponding string values ​​according to the predetermined load fields, and record the closure state of each extracted string value. The bypass recovery execution module is configured to call the disk write tool when the fault tolerance field extraction module successfully extracts a string value and the corresponding string value exists in the bypass cache module. It then synchronizes the synthesized tool call status to the user interface process through inter-process communication and injects inhibitory prompts into the dialogue history. The intent and action mismatch detection and automatic disk placement module is configured to perform intent detection when the agent's response contains a long draft and no tool call, and automatically synthesize tool call parameters and execute the disk placement tool call when the detection is true.

12. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, it implements the method according to any one of claims 1 to 10.

13. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the method according to any one of claims 1 to 10.