Document updating method and apparatus, computing device, storage medium, and program product

By performing structural parsing and pattern matching on the document, and using the target inference model to select a suitable structural pattern to generate updated content, the problem of inconsistent formatting caused by large language models in document updates is solved, ensuring the consistency and parsability of the updated document structure.

CN123178357APending Publication Date: 2026-11-27SWEET POTATO TECHNOLOGY (SHANGHAI) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611413563.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-11
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

When large language models update documents, the attention mechanism causes the generated results to tend to imitate the format of the most recently appearing content in the context. This results in the new content being inconsistent with the format of existing content of the same semantic type in the document, which undermines the consistency of the document structure and machine parsing.

Method used

By performing structural analysis on the initial document, multiple clustered content blocks and their candidate structural patterns and semantic adaptation features are identified. The target inference model is used to select the target structural pattern that semantically matches the updated description information, and the updated content is generated to ensure that the updated content is consistent with the existing content format of the same semantic class in the document.

Benefits of technology

Ensure that the structure of the updated content is determined based on the format rules derived from the document itself, avoid document structure chaos caused by attention mechanisms, and guarantee the consistency and parsability of the updated document structure.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123178357A_ABST
    Figure CN123178357A_ABST
Patent Text Reader

Abstract

The embodiment of the specification provides a document updating method and device, wherein the document updating method comprises the following steps: obtaining an initial document and update description information of the initial document; performing structural analysis on the initial document to determine a plurality of clustered content blocks of the initial document, a candidate structure mode corresponding to a document structure feature of each clustered content block, and a semantic adaptation feature corresponding to each candidate structure mode; determining, through a target reasoning model, a target structure mode that is semantically matched with the update description information from the candidate structure modes based on the initial document, the update description information and the semantic adaptation feature corresponding to each candidate structure mode, and generating an update content corresponding to the update description information based on the target structure mode to obtain an updated document. The target update content is ensured to be consistent with the existing content format of the same semantic category in the document, the document structure is prevented from being disordered due to the influence of the attention mechanism, and the document structure after the update is ensured to be uniform.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This specification relates to the field of artificial intelligence technology, and in particular to a document updating method. One or more embodiments of this specification also relate to a document updating apparatus, a computing device, a computer-readable storage medium, and a computer program product. Background Technology

[0002] With the widespread application of large language models in document processing, there is an increasing demand for directly updating existing documents using these models, such as adding content to structured documents like interface documents, configuration files, and user manuals. These structured documents typically contain multiple structural patterns; different semantic categories of content correspond to different structural patterns, while content within the same semantic category uses the same pattern. The readability and machine parsing capability of the document depend on maintaining this correspondence. Therefore, when adding content to a document, the semantic category of the new content should be matched with the existing structural patterns in the document to ensure that the format of the new content is consistent with existing content of the same semantic category.

[0003] However, when large models generate updated content based on document context, their attention mechanisms lead them to systematically assign higher weights to content in the context that is closer to the output position. This causes the generated results to tend to mimic the format of the most recently appearing content in the context, rather than selecting the corresponding structural pattern in the document based on the semantics of the content. When the semantic category of the new content is different from that of the most recently appearing existing content, but the same as that of the content in the document that is far from the output position, the new content will be incorrectly written in the format of the most recently appearing content, which is inconsistent with the format of the existing content in the same semantic category in the document, thus undermining the consistency of the document structure and machine parsingability. Summary of the Invention

[0004] In view of this, embodiments of this specification provide a document updating method. One or more embodiments of this specification also relate to a document updating apparatus, a computing device, a computer-readable storage medium, and a computer program product, to address the technical deficiencies existing in the prior art.

[0005] According to a first aspect of the embodiments of this specification, a document updating method is provided, comprising: Retrieve the initial document and its updated description; The initial document is structurally parsed to determine multiple clustered content blocks, candidate structural patterns corresponding to the document structural features of each clustered content block, and semantic adaptation features corresponding to each candidate structural pattern. Using the target reasoning model, based on the initial document, updated description information, and semantic adaptation features corresponding to each candidate structural pattern, the target structural pattern that semantically matches the updated description information is determined from each candidate structural pattern, and the updated content corresponding to the updated description information is generated based on the target structural pattern to obtain the updated document.

[0006] According to a second aspect of the embodiments of this specification, a document updating apparatus is provided, comprising: The acquisition module is configured to acquire the initial document and updated description information for the initial document; The parsing module is configured to perform structural parsing on the initial document, determine multiple clustered content blocks of the initial document, candidate structural patterns corresponding to the document structural features of each clustered content block, and semantic adaptation features corresponding to each candidate structural pattern. The generation module is configured to use a target inference model to determine the target structural pattern that semantically matches the updated description information from among the candidate structural patterns, based on the initial document, updated description information, and semantic adaptation features corresponding to each candidate structural pattern, and to generate updated content corresponding to the updated description information based on the target structural pattern, thereby obtaining the updated document.

[0007] According to a third aspect of the embodiments of this specification, a computing device is provided, comprising: Memory and processor; The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions, which, when executed by the processor, implement the steps of the document update method described above.

[0008] According to a fourth aspect of the embodiments of this specification, a computer-readable storage medium is provided that stores computer-executable instructions that, when executed by a processor, implement the steps of the document update method described above.

[0009] According to a fifth aspect of the embodiments of this specification, a computer program product is provided, including a computer program / instructions that, when executed by a processor, implement the steps of the document update method described above.

[0010] One embodiment of this specification involves performing structural analysis and clustering on an initial document to derive multiple structural patterns from the document itself, forming a representation of the document's own formatting rules. A target inference model is then invoked to determine the semantic adaptation features corresponding to each structural pattern. Based on these semantic adaptation features, a target structural pattern that semantically matches the updated descriptive information is determined, and updated content is generated based on the target structural pattern to obtain an updated document. Thus, the structure of the updated content is determined based on the formatting rules derived from the document itself, rather than mimicking recently occurring content in the context. This ensures that the updated content maintains consistency with the format of existing semantically similar content in the document, avoiding document structural chaos caused by attention mechanisms and guaranteeing a unified document structure after the update. Attached Figure Description

[0011] Figure 1 This is a flowchart illustrating a document update method provided in one embodiment of this specification; Figure 2 This is a schematic diagram of the architecture of a document update method in a multi-round editing scenario during the implementation of this specification; Figure 3 This is a flowchart illustrating a document update method in a tool scheduling scenario during the implementation of this manual; Figure 4 This is a schematic diagram of the structure of a document updating device provided in one embodiment of this specification; Figure 5 This is a structural block diagram of a computing device provided in one embodiment of this specification. Detailed Implementation

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

[0013] The terminology used in one or more embodiments of this specification is for the purpose of describing particular embodiments only and is not intended to be limiting of the one or more embodiments of this specification. The singular forms used in one or more embodiments of this specification and in the appended claims are also intended to include the plural forms, unless the context clearly indicates otherwise. It should also be understood that the terminology used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items.

[0014] It should be understood that although the terms first, second, etc., may be used to describe various information in one or more embodiments of this specification, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, first may also be referred to as second without departing from the scope of one or more embodiments of this specification, and similarly, second may also be referred to as first. Depending on the context, words used herein may be interpreted as when, when, or in response to a determination.

[0015] Furthermore, 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, stored data, displayed data, etc.) involved in one or more embodiments of this specification are all information and data authorized by the user or fully authorized by all parties. Moreover, the collection, use and processing of related 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.

[0016] First, the terms and concepts used in one or more embodiments of this specification will be explained.

[0017] Large Language Model (LLM): A large-scale pre-trained language model based on deep learning. It learns general knowledge and language rules from massive amounts of text data and possesses complex capabilities such as understanding, generation, and reasoning. The target reasoning model in this specification is the Large Language Model, used to perform reasoning tasks such as semantic attribute extraction, structural pattern matching, and content update generation.

[0018] Target inference model: An inference model used to perform semantic understanding and content generation tasks during document update. It can be a Large Language Model (LLM), a multimodal model, or other models with semantic understanding and generation capabilities. In the embodiments of this specification, multiple calls to the target inference model are independent calls, and each call uses an independent context.

[0019] Abstract Syntax Tree (AST): A tree-like representation of a document's content after parsing it according to its syntactic structure. Each node in the tree corresponds to a structural element in the document. Node types include headings, paragraphs, tables, lists, code blocks, quotation blocks, and separators. Parsing Markdown and other markup language documents into ASTs is a common method for structured processing.

[0020] Markdown: A lightweight markup language that uses simple tags (such as # for headings, | for tables, and ``` for code blocks) to describe the hierarchical structure of a document. It is widely used for writing skill definition documents, interface documents, technical documents, etc. The initial document in this specification may be, but is not limited to, a Markdown format document.

[0021] JSON (JavaScript Object Notation): A lightweight data-interchange format based on key-value pairs. It has a clear structure, is easy to parse, and is the most commonly used data format for front-end and back-end interface interactions and tool parameter definitions. Parameter definitions in tool definitions are typically described using JSON Schema format.

[0022] JSON Schema: A declarative language for describing JSON data structures. It describes the structural constraints of data through attributes such as field names, field types, descriptive text, constraints (such as enumeration values ​​and length limits), and required fields. It is a general representation format for tool parameter definitions.

[0023] Content Block: A content unit in a document that has independent structural semantics, such as a chapter, a table, a code block, a list, etc. A document can be represented as a sequence of content blocks, and each content block can have attributes such as block identifier, text content, belonging structure pattern identifier, semantic type label, hierarchy depth, parent content block identifier, and structural fingerprint.

[0024] A section tree is a tree-like structure that organizes document content according to heading levels. Each node in the tree represents a section, which includes a section title, heading level, a list of subsections, a list of non-heading content nodes under that section, and a section identifier. The section tree reflects the hierarchical relationship within the document.

[0025] Structural fingerprint: A feature sequence obtained by abstracting the structural skeleton of a content block sequence, ignoring the specific text content and retaining only structural information, composed of node types and their structural attributes. For example, the structural fingerprint of a chapter can be [Table(4, true, hash_A), Paragraph(true), Table(5, true, hash_B)], indicating that the chapter contains a sequence of structural elements consisting of 4 tables (including headers), bold paragraphs, and 5 tables (including headers). The structural attributes include the number of columns in the tables, whether they contain headers, column name hash values, the order of the lists, nesting depth, and range of the number of entries, the programming language and line count range of the code blocks, and the bolding, links, and length range of the paragraphs.

[0026] A structural template is the skeletal information in a candidate structural pattern used to constrain the organization of content. It is an abstract structural representation containing placeholders, such as a sequence of structural elements including table column numbers, column names, and chapter levels. The structural template defines the structural form that content using this structural pattern should have.

[0027] Expected Complexity: This term represents the number of structural elements required to generate the updated content. It can be understood as an estimate of the number of structural elements such as paragraphs, tables, lists, and code blocks needed to generate the updated content. Content complexity can be estimated using the target inference model based on the update description information, or it can be calculated based on rules such as the number of function points and parameters involved in the update description information.

[0028] Tool Identifier: Identification information used to uniquely identify a tool, which can be the tool name, tool number, etc. For example, the tool identifier can be the tool's name field.

[0029] Tool parameters: The compressed definition information of the tool's parameters. It is the parameter definition obtained by compressing the complete tool parameters (such as the original JSONSchema parameter definition) and still maintaining the parsable format of the model. It is used to enable the model to determine how to call the tool.

[0030] Schema Decision Log (SDL): A structured log recording the schema selection decision process. After each selection of a target schema, the semantic attributes of the decision, the matching scores of each candidate schema, the identifier of the selected schema, the matching score, the reason for selection, and the timestamp are recorded as a decision record. The schema decision log is used to implement explicit decision recording and anomaly detection across steps.

[0031] Normalized edit distance: The ratio of the edit distance between two sequences to the larger of their lengths. The edit distance represents the minimum number of edit operations required to transform one sequence into another. Edit operations include insertion, deletion, and replacement. The cost of a replacement operation is weighted according to the semantic similarity of the replaced element. Normalized edit distance is used to measure the degree of structural difference between two structural fingerprints.

[0032] Embedding Model: A model used to convert text into vector representations. It can be a pre-trained text embedding model. After text is vectorized using an embedding model, the semantic similarity between texts can be measured using the cosine similarity between vectors.

[0033] This specification provides a document updating method, and also relates to a document updating device, a computing device, a computer-readable storage medium, and a computer program product, which will be described in detail in the following embodiments.

[0034] The core concept of this embodiment is to break down the document update process into three independent stages: structure parsing, pattern matching, and constraint generation. Each stage is implemented through independent model calls, and the context of each call only contains the information required for that stage, thus severing the propagation link of the recency bias of the attention mechanism between consecutive editing steps at the architectural level. The structure parsing stage explicitly extracts structural patterns from the initial document, forming a structural pattern library independent of the editing process. The pattern matching stage, based on the semantic attributes of the update description information and the semantic adaptation features of each candidate structural pattern, explicitly calculates the matching score and makes interpretable and recordable pattern selection decisions. The constraint generation stage generates updated content under the constraints of the target structural pattern's structural template and instance content blocks, and performs structural consistency verification before writing. Simultaneously, the generation stage can also use tool hierarchy information from a preset tool library to help determine the target tools and their parameters required for generating updated content, reducing the context overhead of tool definition. This design transforms document editing from an implicit imitation paradigm to an explicit pattern-aware paradigm, improving the consistency and interpretability of document updates.

[0035] See Figure 1 , Figure 1 This is a flowchart of a document update method provided in one embodiment of this specification, which specifically includes the following steps.

[0036] Step 102: Obtain the initial document and updated description information for the initial document.

[0037] The initial document is a structured document with a hierarchical structure, comprising multiple levels of content blocks that can be parsed into a chapter tree containing chapter titles, chapter levels, and sub-chapter relationships. The initial document provides the structural carrier for the content to be updated; its structural information forms the basis for subsequent structural pattern extraction and pattern matching, and also serves as a reference source for maintaining structural consistency in the generated content. For example, the initial document could be a skill definition document SKILL.md, containing multiple command group chapters, each with a fixed structure of a 4-column overview table + bold paragraphs + a 5-column parameter table; or it could be a REST API interface document containing a fixed-structure interface chapter.

[0038] The update description information serves as an indication of the semantic description of the content to be updated. The update description information is not limited to the specific text content and structural form of the content to be updated; it can simply be a description of the functional semantics of the content. Alternatively, the update description information may include indications of the specific text content or structural form of the content to be updated. The update description information is used as input for semantic attribute extraction and structural pattern matching, providing a semantic basis for determining the target structural pattern of the content to be updated. For example, the update description information can be a new policy activation monitoring command, including three sub-commands: check-status, query-metrics, and render-chart; it can also be a new Apollo configuration query capability, implemented through the apollo-skill external skill.

[0039] The initial document and its updated description information can be obtained by receiving an edit request, which carries the document identifier of the initial document and the updated description information in natural language. The initial document is read according to the document identifier, and the updated description information and the initial document are used as semantic processing objects and structural processing objects, respectively, and then input into the subsequent process. This cuts off the interference of the editing history and the full text of the document on structural inference at the input level.

[0040] One optional implementation involves receiving an editing request sent by a Coding Agent client during the execution of an editing task. The editing request carries the document path of the target document and editing instructions in natural language form. Update description information is parsed from the editing instructions, and the initial document is read according to the document path.

[0041] One alternative implementation involves receiving an editing instruction input by a user through a document editing interface, wherein the editing instruction indicates the location of the document to be updated and a description of the updated content, the description of the updated content is determined as the update description information, and the document selected by the user is loaded from the document repository as the initial document.

[0042] One alternative implementation involves reading an editing task message to be processed from a message queue. The editing task message includes a document identifier and update description information. The document content of the initial document is read from the distributed storage system based on the document identifier. If the reading fails, the document is restored from backup storage.

[0043] In one implementation of this specification, within a skill definition document maintenance scenario for a coding agent, the user initiates an editing command via the client: a new policy activation monitoring command, comprising three subcommands: check-status, query-metrics, and render-chart. The client encapsulates this editing command, along with the target document's path, into an editing request and sends it to the document update service. The document update service parses the update description information from the editing request and, based on the document path, retrieves the skill definition document SKILL.md from the document repository as the initial document. This initial document contains three internal command groups: meta, CRUD, and batch, and two external skill reference sections: xray-log-query and dms-assistant. This completes the acquisition of the initial document and update description information.

[0044] In one implementation of this specification, in an scenario of automatic API documentation maintenance, a developer submits an edit command to add a GET / users / :id / followers interface to the / users resource, returning a list of followers for the specified user. The system parses the update description information from the edit command and loads the REST API documentation from the documentation repository as the initial document. This initial document contains defined interface sections such as GET / users (list query class) and POST / users (creation operation class), each with its own fixed structure. After retrieval, subsequent processes will determine the candidate structure pattern and the target structure pattern based on this initial document.

[0045] By separating the structural carrier and semantic requirements of the editing task, subsequent steps can independently establish intermediate representations in the structural and semantic dimensions, avoiding contextual interference caused by mixing the full text of the document and editing instructions into the same model call, thus laying the foundation for structure-aware document updates.

[0046] Step 104: Perform structural parsing on the initial document to determine multiple clustered content blocks of the initial document, candidate structural patterns corresponding to the document structural features of each clustered content block, and semantic adaptation features corresponding to each candidate structural pattern.

[0047] Clustered content blocks are groups of content blocks with the same or similar structural features in the initial document. The content blocks within each cluster have the same or similar structural forms. Clustered content blocks serve as the basic unit for summarizing structural patterns, aggregating recurring similar structures in the document to discover reusable structural patterns. For example, the three internal command groups (meta, CRUD, and batch) in a skill definition document can be clustered into a single content block, with each section having a structure of a 4-column overview table + bold paragraphs + a 5-column parameter table; similarly, the GET / users section in an interface document can be clustered into a single content block, with a structure of interface description + query parameter table + response example + pagination instructions.

[0048] Document structure features are feature information obtained by abstracting the structural skeleton of content blocks, ignoring the specific text content and retaining only structural information, including the node type sequence of the content block and the structural attributes of each node type. Document structure features are used to measure the degree of structural similarity between different content blocks and serve as the basis for content block clustering and structural pattern induction. For example, document structure features can be structural fingerprints.

[0049] Candidate structure patterns are structural templates derived from clustered content blocks, used to constrain the organizational structure of the updated content to be generated, ensuring consistency with the existing document structure. For example, a candidate structure pattern can be a command group table row pattern, with the structure template [Table(4, true, hash_A), Paragraph(bold), Table(5, true, hash_B)], and instance content blocks including three sections: meta, CRUD, and batch.

[0050] Semantic adaptation features are used to match the semantic attributes corresponding to the updated description information during the pattern matching stage to determine whether the candidate structural pattern is suitable for the content to be updated. Semantic adaptation features can be generated by the target inference model based on the semantic features of each content block in the clustered content blocks, or they can be pre-configured manually.

[0051] The initial document undergoes structural parsing, specifically by first parsing it into an abstract syntax tree and then constructing a chapter tree based on heading nodes. Document structural features are extracted from each sub-chapter under the same parent chapter, and clustering is performed based on the similarity of these features to obtain multiple clustered content blocks. These clustered content blocks are then summarized to obtain structural templates and instance content blocks for candidate structural patterns. Semantic adaptation features for each candidate structural pattern are generated through independent calls to the target inference model. Through this process, the initial document is transformed into a structural pattern library composed of multiple candidate structural patterns. This library serves as an intermediate representation, independent of subsequent matching and generation processes. Subsequent processes no longer directly access the full text of the initial document, eliminating the contamination sources of the full document and editing history for pattern matching and content generation.

[0052] One optional implementation involves caching the results of the structure parsing in the form of a structure pattern library. The cache key is the content hash of the initial document. When the content of the initial document remains unchanged, the cached structure pattern library is directly reused to avoid repeated parsing. For example, the structure pattern library may include a document identifier, a document content hash, all extracted structure patterns, a chapter tree, and an extraction timestamp.

[0053] One possible implementation is to first calculate the normalized edit distance between all pairs of structural fingerprints when clustering structural fingerprints, and then perform hierarchical clustering based on a preset distance threshold. The average connectivity method is used during the clustering process, that is, the distance between two clusters is the average of the pairwise distances between the elements of the two clusters. When the minimum inter-cluster distance is greater than the preset threshold, merging is stopped.

[0054] One optional implementation involves generating semantic adaptation features, where the input to the target inference model consists only of the titles and content summaries of each instance content block within the same cluster. The content summary can be a text digest of the first 200 characters of each instance content block. The output is a judgment rule in the form of this pattern when the content meets a certain condition. For example, the input could be the titles and content summaries of the meta, CRUD, and batch sections, and the output could be a pattern indicating that the content is an internal subcommand of the system with a clearly defined parameter list and CLI invocation method.

[0055] This manual describes an implementation scenario for maintaining a skills definition document. The SKILL.md file is parsed as follows: SKILL.md is parsed into an abstract syntax tree, and a chapter tree is constructed based on the title nodes, resulting in chapters such as meta, CRUD, batch, xray-log-query, and dms-assistant. Structural fingerprints are extracted from the sub-chapter chapters under the same parent chapter. The meta, CRUD, and batch chapters share the same structural fingerprint: [Table(4, true, hash_A), Paragraph(bold), Table(5, true, hash_B)]. The xray-log-query and dms-assistant chapters also share the same structural fingerprint: [Table(3, true, ...]. Based on normalized edit distance (distance threshold 0.3), hierarchical clustering is performed, with meta, CRUD, and batch clustered into cluster 1, and xray-log-query and dms-assistant clustered into cluster 2. Structural templates and instance content blocks are summarized for each cluster to form candidate structural pattern command group table rows and related Skill reference rows. The common semantic features of the two clusters are analyzed through independent calls to the target inference model, generating semantic adaptation features when the content is an internal sub-command of this system with a clear parameter list and CLI calling method, or when the content is a reference to an external system / Skill, and this system does not directly implement its function but only performs parameter mapping and forwarding. After structural parsing, a structural pattern library containing two candidate structural patterns is obtained and cached.

[0056] This specification describes an implementation scenario for API documentation maintenance. When parsing the REST API documentation, the GET / users and POST / users sections are extracted. The structural fingerprints of these two sections differ significantly, with the normalized edit distance exceeding a threshold of 0.3, resulting in two clustered content blocks. This leads to two candidate structural patterns: a list query endpoint section (with the GET / users section as an example content block) and a change operation endpoint section (with the POST / users section as an example content block). Semantic adaptation features are generated for each candidate structural pattern using a target inference model: when the API returns a data list supporting pagination, filtering, and other query operations, and when the API performs create / modify / delete operations requiring a request body and error handling.

[0057] By performing structural parsing on the initial document, the document is elevated from the full-text layer to the structural pattern layer, resulting in an explicit structural pattern library composed of clustered content blocks, candidate structural patterns, and semantic adaptation features. This enables subsequent pattern matching and content generation to be performed based on structural patterns rather than the full text of the document, avoiding the problem of nearest neighbor imitation caused by the influence of the nearest content in the context when directly inferring structural patterns from the full text of the document. This provides an intermediate layer foundation for the three-stage structure-aware document update.

[0058] In one optional embodiment of this specification, structural parsing is performed on the initial document to determine multiple clustered content blocks of the initial document, candidate structural patterns corresponding to the document structural features of each clustered content block, and semantic adaptation features corresponding to each candidate structural pattern, including: Perform structural analysis on the initial document to determine multiple content blocks with hierarchical relationships and the document structure characteristics of each content block; Based on the similarity of document structural features, content blocks at the same level are clustered to determine multiple clustered content blocks; Based on each content block in the first cluster content block, determine the first candidate structural pattern corresponding to the first cluster content block and the semantic adaptation feature corresponding to the first candidate structural pattern, wherein the first cluster content block is any one of multiple cluster content blocks.

[0059] Multiple content blocks with a hierarchical relationship are organized according to chapter levels. Each content block has a corresponding hierarchical position in the document's chapter tree. Content blocks at the same level are those that share the same parent chapter or the same chapter level in the chapter tree. For example, in the skill definition document, the three command group chapters meta, crud, and batch are child chapters under the same parent chapter and belong to the same level of content blocks; similarly, the GET / users chapter and the POST / users chapter in the interface document also belong to the same level.

[0060] To identify multiple content blocks with hierarchical relationships and their respective document structure features, the initial document can be parsed to obtain an abstract syntax tree, and then a chapter tree can be constructed based on the heading nodes. Each chapter node in the chapter tree and the non-heading content nodes under each chapter can be identified as a content block, and document structure features can be extracted for each content block.

[0061] Based on the similarity of document structural features, content blocks at the same level are clustered. Specifically, this can be done by calculating the pairwise similarity of document structural features between content blocks at the same level (such as similarity based on normalized edit distance), and grouping multiple content blocks with similarity reaching a preset threshold into the same cluster. For example, the structural fingerprints of the content blocks in the meta, CRUD, and batch sections are completely identical, and they are clustered into the same cluster.

[0062] Based on each content block in the first cluster, a first candidate structural pattern and its corresponding semantic adaptation features are determined. Specifically, this can be achieved by summarizing the structural templates of the candidate structural patterns based on the document structural features of each content block in the cluster, and by determining the corresponding semantic adaptation features based on the semantic features of each content block. For example, for a cluster of content blocks containing three sections: meta, CRUD, and batch, candidate structural patterns for command group table rows and their semantic adaptation features are summarized when the content is an internal subcommand of this system and has a clear parameter list and CLI calling method.

[0063] In one implementation of this specification, when performing structural analysis on the skill definition document, the document structure features of the three chapters, meta, CRUD, and batch, are the same and are clustered into a single content block. The candidate structural patterns of the command group table rows are then summarized, and the recurring structural patterns in the document are explicitly extracted to provide a structural basis for subsequent pattern matching.

[0064] Clustering content blocks at the same level based on the similarity of document structural features ensures that the clustering operation is performed within a range of comparable structures, avoiding mis-clustering caused by incomparable structures of content blocks across different levels, and guaranteeing the accuracy of the clustered content blocks and candidate structural pattern induction.

[0065] In one optional embodiment of this specification, based on each content block in the first clustered content block, a first candidate structural pattern corresponding to the first clustered content block and a semantic adaptation feature corresponding to the first candidate structural pattern are determined, including: Based on the document structure features of each content block in the first cluster, a target common subsequence is determined, and based on the target common subsequence, a first candidate structure pattern is determined, wherein the target common subsequence is the longest common subsequence among the document structure feature sequences of each content block in the first cluster. Based on the semantic features of each content block in the first cluster, semantic adaptation prompts are constructed, and the semantic adaptation features corresponding to the first candidate structural pattern are determined by the target inference model based on the semantic adaptation prompts.

[0066] The target common subsequence is the longest common subsequence among the document structure feature sequences of each content block in the first cluster. It reflects the common structural skeleton of each content block and serves as the basis for the structural template of the candidate structural pattern. For example, if the structural fingerprints of the meta, CRUD, and batch chapters are the same, the target common subsequence is this complete sequence.

[0067] Semantic adaptation prompts are information constructed based on the semantic features of each content block in a cluster, used to instruct the target inference model to determine semantic adaptation features. Semantic adaptation prompts can include semantic feature information such as the title and content summary of each content block, and instruct the target inference model to summarize the common semantic features of these content blocks and output the applicable conditions of the candidate structural patterns.

[0068] Determining the target common subsequence can specifically involve calculating the longest common subsequence of the document structure feature sequences of each content block in the first cluster, determining the calculation result as the target common subsequence, and generating a structural template for the first candidate structural pattern based on the target common subsequence. That is, the first candidate structural pattern includes the structural template corresponding to the target common subsequence.

[0069] Semantic adaptation prompts are constructed, and semantic adaptation features are determined through a target inference model. Specifically, this involves acquiring semantic features such as the titles and content summaries of each content block in the first cluster to construct semantic adaptation prompts, inputting them into the target inference model, which then summarizes the common semantic features of each content block and outputs the semantic adaptation features of candidate structural patterns. This call is independent, and its context only includes the semantic features of each content block in this cluster, without including other candidate structural patterns or update description information, thus ensuring that the semantic adaptation features only reflect the structural patterns of the document itself.

[0070] In one implementation of this specification, for a clustered content block containing three sections—meta, CRUD, and batch—the titles and content summaries of the three sections are obtained, and semantic adaptation prompts are constructed: Given the following document sections that share the same structural pattern, summarize the common semantic features of these sections and output, in the form of decision rules, what type of new content should adopt the same structure as them. This prompt is then input into the target inference model to obtain semantic adaptation features when the content is an internal sub-command of this system and has a clearly defined parameter list and CLI calling method.

[0071] The structure template is determined by the longest common subsequence, which accurately describes the common structural skeleton of all content blocks in the clustered content blocks, avoiding the randomness of using a single content block structure as a template and improving generalization ability. Semantic adaptation features are generated by the target inference model, which gives the candidate structure patterns a semantic dimension of applicable conditions description, providing a basis for subsequent semantic-based pattern matching.

[0072] Step 106: Using the target reasoning model, based on the initial document, updated description information, and semantic adaptation features corresponding to each candidate structural pattern, determine the target structural pattern that semantically matches the updated description information from each candidate structural pattern, and generate the updated content corresponding to the updated description information based on the target structural pattern to obtain the updated document.

[0073] The target structural pattern is a structural pattern determined from the candidate structural patterns that semantically matches the update description information. It is used to constrain the structural organization of the updated content, including a structural template and potentially instance content blocks. For example, when the update description information is a new policy activation monitoring monitor command, the target structural pattern can be a command group table row pattern; when the update description information is a new Apollo configuration query capability, the target structural pattern can be a related Skill reference row pattern.

[0074] The updated content is the content generated based on the update description information and to be written into the initial document. Its structure is constrained by the target structure pattern and maintains consistency in format with existing content in the initial document that uses the same structure pattern. The updated document is the document obtained after writing the updated content into the initial document. For example, when the target structure pattern is the relevant Skill reference row pattern, the updated content can be a reference table row for Apollo configuration query capabilities.

[0075] The target inference model determines the target structural pattern and generates updated content. Specifically, it provides candidate structural patterns obtained from parsing the initial document structure, updated descriptive information, and semantic adaptation features corresponding to each candidate structural pattern to the target inference model. Based on the semantics of the updated descriptive information, it matches the semantic adaptation features of each candidate structural pattern to determine the target structural pattern. Updated content is then generated based on the target structural pattern and written back to the initial document to obtain the updated document. In other words, the target inference model is based on the structural parsing results of the initial document, not the entire text of the initial document.

[0076] An alternative implementation involves arranging candidate structural patterns in the context of model calls in the form of an equally weighted list to eliminate positional bias in the candidate structural patterns and prevent the model from making selection biases due to the arrangement of candidate structural patterns in the context.

[0077] One possible implementation is to separate the determination of the target structural pattern and the generation of updated content into two independent model calls. The first model call determines the target structural pattern based on the pattern adaptation prompt, and the second model call generates updated content based on the content generation prompt. The contexts of the two calls are independent of each other, and the context of the second call does not include the output of the first call, thereby cutting off the transmission influence of the previous generation result on the pattern selection.

[0078] An optional implementation is to present each candidate structural pattern and its semantic adaptation features to the user when none of the candidate structural patterns match the updated description information, and receive the target structural pattern specified by the user, or generate a new structural pattern based on the updated description information as the target structural pattern.

[0079] This manual describes an implementation scenario for maintaining the skill definition document. The updated description information includes a new policy activation monitoring command (monitor command), comprising three sub-commands (check-status, query-metrics, and render-chart), two candidate structural patterns, and their semantic adaptation features. This information is provided to the target inference model. The target structural pattern is determined to be a command group table row pattern. Based on this pattern's structural template and instance content blocks, a monitor command group section is generated as the updated content and written to the initial document, resulting in the updated SKILL.md.

[0080] This specification describes an implementation scenario for API documentation maintenance. The update description information includes a new GET / users / :id / followers interface, which returns a list of followers for the specified user, two candidate structural patterns (a list query endpoint section and a change operation endpoint section), and their semantic adaptation features. These are provided to the target inference model. The target structural pattern is determined to be the list query endpoint section pattern. Based on this pattern, an interface section is generated as the update content, written into the initial document, and the updated document is obtained.

[0081] By determining the target structural pattern and generating updated content based on semantic adaptation features, the structure of the updated content is determined by the structural rules summarized by the document itself, rather than by the most recently appearing content in the context. This mechanism avoids document structure chaos caused by neighbor imitation and ensures the structural consistency of the updated document.

[0082] In one optional embodiment of this specification, a target structural pattern that semantically matches the updated description information is determined from among the candidate structural patterns using a target inference model based on the initial document, updated description information, and semantic adaptation features corresponding to each candidate structural pattern. The updated content corresponding to the updated description information is then generated based on the target structural pattern to obtain the updated document, including: Based on the updated description information and the semantic adaptation features corresponding to each candidate structural pattern, pattern adaptation prompt words are constructed. Based on the pattern adaptation prompt words, the target inference model is called to determine the target structural pattern that semantically matches the updated description information from each candidate structural pattern. Based on the target structural pattern and updated description information, content generation prompts are constructed. Based on the content, prompts are generated, the target inference model is invoked, and updated content corresponding to the updated description information is generated based on the target structural pattern. Based on the updated content and the initial document, the updated document is obtained.

[0083] Pattern adaptation prompts are used to enable the target inference model to match the semantics of the updated description information with the applicable conditions of each candidate structural pattern, thus making a pattern selection decision. For example, pattern adaptation prompts could be: Description of content to be added: {Updated description information}. Candidate structural patterns and applicable conditions: {Each candidate structural pattern and its semantic adaptation features}. Please determine the appropriate pattern for the content to be added.

[0084] Content generation prompts are used to constrain the target inference model to generate updated content within the structural framework defined by the target structural pattern. For example, the content generation prompts could be: Description of content to be added: {Update description information}. It must strictly adhere to the structural template: {Structure template of the target structural pattern}. Referencing existing similar content: {Instance content block}. Requirements: The output structure must be consistent with the template; only placeholders should be filled; no structural elements should be added or deleted; output the content directly, without explanations.

[0085] The process involves constructing pattern adaptation prompts and calling the target inference model to determine the target structural pattern. Specifically, this can involve acquiring updated description information and semantic adaptation features corresponding to each candidate structural pattern to construct pattern adaptation prompts, inputting them into the target inference model, and outputting the identifier or name of the target structural pattern. This call is an independent model call, and its context includes the structural pattern library, updated description information, and historical decision records. It does not include the results generated in the previous step, nor does it include the full text of the initial document, thus ensuring that the pattern selection is not affected by the text format of the previous step, nor is it interfered with by the full text of the document.

[0086] The process involves constructing content generation prompts and then calling the target inference model to generate updated content. Specifically, this can involve obtaining the structural template and instance content blocks of the target structural pattern, combining them with update description information to construct content generation prompts, and inputting these prompts into the target inference model. The target inference model then generates updated content based on the target structural pattern. This call is an independent model call; its context includes the structural template and instance content blocks of the selected pattern, as well as update description information. It does not include other candidate patterns, and the degree of freedom in generation is limited by the structural template. Even with attention mechanism biases, it cannot deviate from the target structural pattern.

[0087] This manual describes an implementation process that addresses a scenario involving the maintenance of skill definition documents. During the target structure pattern determination phase, the pattern adaptation prompt is: Description of content to be added: Add a new strategy activation monitoring command. Candidate Pattern 1: Command group table row, applicable when the content is an internal sub-command of this system with a clear parameter list and CLI calling method; Candidate Pattern 2: Related Skill reference row, applicable when the content is a reference to an external system / Skill. The pattern adaptation prompt is input into the target inference model, and the model outputs the target structure pattern as a command group table row. During the update content generation phase, the content generation prompt is: Description of content to be added is the same as above, and must strictly follow the structure template | Command Group Overview Table (4 columns) | Bold Paragraph | Parameter Table (5 columns) |, referring to the complete Markdown in the meta and CRUD sections as an example, only filling in placeholders, and directly outputting the Markdown content. The model generates the monitor command group section as the update content, writes it into the initial document, and obtains the updated document.

[0088] In one implementation of this specification, in an API documentation maintenance scenario, the build pattern adaptation prompt provides the target inference model with the semantic adaptation features of the newly added GET / users / :id / followers interface and two candidate structural patterns in the updated description information, determining the target structural pattern as the list query endpoint section. Subsequently, the build content generation prompt provides the target inference model with the structural template of the target structural pattern (interface description + query parameter table + response example + pagination description) and instance content block (the complete Markdown of the GET / users section) as well as the updated description information, generating the GET / users / :id / followers interface section with the same format as the GET / users section.

[0089] By splitting pattern selection and content generation into two independent calls with isolated contexts—the pattern selection call does not include the result of the previous generation step, and the generation call does not include other candidate patterns—the propagation link of recency bias between successive editing steps is severed at the architectural level. At the same time, pattern selection decisions can be explicitly recorded and traced back, improving the interpretability of document updates.

[0090] In one optional embodiment of this specification, based on pattern adaptation prompts, a target inference model is invoked to determine the target structural pattern that semantically matches the updated description information from among the candidate structural patterns, including: Based on pattern adaptation prompts, the target inference model is invoked to determine the semantic attributes and content complexity of the updated description information indicating the content to be updated. The first semantic vector of the updated description information is determined based on the semantic attributes, where the content complexity is used to characterize the number of structural elements required for the content to be updated. Based on the semantic features of the clustered content blocks corresponding to each candidate structural pattern, the second semantic vector corresponding to each candidate structural pattern is determined. The first matching result between semantic attributes and semantic adaptation features corresponding to each candidate structural pattern is determined by the target reasoning model. Determine the second matching result between content complexity and structural capacity of each candidate structural pattern, and the third matching result between the first semantic vector and the second semantic vector; Based on the first matching result, the second matching result, and the third matching result, the target structural pattern is determined from each candidate structural pattern.

[0091] Semantic attributes are a set of attributes obtained by semantically describing the content to be updated, and are determined by the target inference model based on pattern adaptation prompts.

[0092] Content complexity is used to characterize the number of structural elements required to generate the updated content, and is determined by the target inference model based on pattern adaptation prompts. Content complexity can be a numerical estimate of the number of structural elements, or it can be in tier form (such as a single-function tier or a multi-function tier), then mapped to an estimated number of structural elements according to a preset mapping rule. For example, the content complexity of the monitor command (multi-function) can be a value of 5 or a multi-function tier, while the content complexity of the apollo-skill reference (single-function) can be a value of 1 or a single-function tier.

[0093] The first semantic vector is the semantic vector corresponding to the updated description information, determined based on semantic attributes. One implementation involves combining each field of the semantic attributes with the updated description information to construct an embedded input, and then vectorizing it through an embedding model to obtain the first semantic vector. Another implementation involves vectorizing the text of each field of the semantic attributes separately, and then concatenating or weighting the vectorized result of the updated description information.

[0094] The second semantic vector is the semantic vector corresponding to the candidate structural pattern, determined based on the semantic features of the clustered content blocks corresponding to each candidate structural pattern. One implementation involves constructing text based on the title and content summary of each content block in the clustered content blocks and quantizing it, then using the semantic vector corresponding to each content block as the second semantic vector of the candidate structural pattern. Another implementation involves merging the titles and content summaries of each content block in the clustered content blocks to construct text and quantizing it, thus obtaining the second semantic vector of the entire candidate structural pattern.

[0095] The first matching result is the matching result between the semantic attribute and the semantic adaptation feature corresponding to each candidate structural pattern, which is determined by the target inference model. Specifically, the semantic attribute is compared with the semantic adaptation feature of a candidate structural pattern, and the target inference model determines whether it meets the conditions it describes and outputs the matching probability.

[0096] The second matching result is the matching result between the content complexity and the structural capacity of each candidate structural pattern, determined through deterministic calculation. Structural capacity is the number of structural elements in the structural template. The second matching result can be calculated as: Second matching result = 1 - |Content complexity - Structural capacity| / max(Content complexity, Structural capacity), where the closer the content complexity and structural capacity are, the higher the second matching result.

[0097] The third matching result is the matching result between the first semantic vector and the second semantic vector, which is determined through deterministic calculation. The calculation method can be the cosine similarity between the two. When the second semantic vector is the semantic vector corresponding to multiple content blocks, the maximum value of the cosine similarity between the first semantic vector and the semantic vectors of each content block is taken; when the second semantic vector is the semantic vector of the candidate structure pattern as a whole, the cosine similarity between it and the semantic vector of the whole is taken.

[0098] The target structural pattern is determined based on the first, second, and third matching results. Specifically, this can be achieved by calculating the comprehensive matching score of each candidate structural pattern, which is a weighted sum of the three matching results. For example, the comprehensive matching score = α × first matching result + β × second matching result + γ × third matching result, where α, β, and γ are preset weights, such as α = 0.5, β = 0.2, and γ = 0.3. The candidate structural pattern with the highest comprehensive matching score is then determined as the target structural pattern. When the highest comprehensive matching score is lower than a preset threshold (e.g., 0.4), it is determined to be a no-match pattern. In this case, a new structural pattern can be created based on updated description information, or the user can be asked to specify the target structural pattern.

[0099] This specification describes an implementation scenario for maintaining skill definition documents. For the updated description information q1 = "Add strategy activation monitoring monitor" command, which includes three sub-commands: check-status, query-metrics, and render-chart: The target inference model determines semantic attributes based on pattern adaptation prompts (content belongs to internal function, interaction method is command, content complexity is composite function, has parameter list, has sub-commands, does not depend on external systems), with a content complexity of 5 (the number of structural elements in the composite level mapping), and determines the first semantic vector. For candidate pattern command group table rows, the second semantic vector is determined based on the semantic features of their instance content blocks. The first matching result is 0.95, the second matching result for content complexity 5 and pattern structure capacity 3 is 0.6, the third matching result is 0.82, and the overall matching score is 0.841. For candidate pattern related Skill reference rows, the three matching results are 0.15, 0.2, and 0.20 respectively, with an overall matching score of 0.175. The highest overall matching score of 0.841 is greater than the preset threshold of 0.4, so the target structure pattern is determined to be the command group table row pattern.

[0100] This manual uses the maintenance of skill definition documents for an enterprise-level AI programming assistant as an example to illustrate the complete implementation process of the document update method in a scenario of continuous multi-round editing. The skill definition document serves as the skill catalog for the AI ​​programming assistant. It includes three internal command group sections (meta, CRUD, and batch) and two external skill reference sections (xray-log-query and dms-assistant). Command group sections uniformly employ four structural elements: title, overview table, bold paragraph, and parameter table. Reference sections uniformly use only two structural elements: title and reference table. In traditional solutions, document maintainers submit editing requests to the large model round by round. The large model generates modified documents based on the dialogue context. Due to recency bias in the attention mechanism, the model tends to mimic the format of recently output content. For example, if a command group table was added in the previous round, the current round will still generate documents in the command group table format when adding skill references, leading to a chaotic document structure and requiring multiple rounds of revisions. This solution breaks down the document update process into three independent stages: structure parsing, pattern matching, and content generation. Each stage uses an independent model call context, without containing information from the others. This architecturally severs the propagation link of recency bias between consecutive editing steps. Figure 2 This is a schematic diagram of the architecture of a document update method in a multi-round editing scenario during the implementation of this specification. Specifically: The first stage is structural analysis. Using the skill definition document as the initial document, step 102 is executed to obtain the initial document and its updated description information. Step 104 then performs structural analysis on the initial document. First, the initial document is parsed into an abstract syntax tree, and a chapter tree is constructed based on the heading nodes. Document structural features are extracted from each sub-chapter under the same parent chapter. For example, the structural fingerprints of the three internal command group chapters (meta, CRUD, and batch) are all structural sequences of 4-column tables (including headers), bold paragraphs, and 5-column tables (including headers). Clustering is performed based on the similarity of structural features. Normalized edit distances are calculated pairwise for all structural fingerprints, and hierarchical clustering is performed based on a preset distance threshold to obtain multiple clustered content blocks. For example, the three chapters (meta, CRUD, and batch) are clustered into a command group table row clustered content block, and the two chapters (xray-log-query and dms-assistant) are clustered into a related skill reference row clustered content block. For each clustered content block, candidate structural patterns are summarized: using the longest common subsequence of the document structural feature sequences of each content block in the clustered content block as the structural template, and using the content blocks in the clustered content block as instance content blocks, two candidate structural patterns are obtained: command group table rows and related skill reference rows. Semantic adaptation features are generated for each candidate structural pattern: the target inference model is called, with the input consisting only of the titles and content summaries of each instance content block in the same clustered content block, and the output is the judgment rule for using the pattern when the content meets certain conditions. For example, the semantic adaptation feature of the command group table row pattern is that this pattern is used when the content is an internal subcommand of this system and has a clear parameter list and CLI calling method; the semantic adaptation feature of the related skill reference row pattern is that this pattern is used when the content is a reference to an external system or skill. The parsing results are cached in the form of a structural pattern library, with the cache key being the content hash of the initial document. The context of this stage only includes the initial document and structural parsing prompts, and does not include any editing history. The structural pattern library serves as an intermediate representation independent of the subsequent matching and generation processes, and subsequent processes no longer directly access the full text of the initial document.

[0101] The second stage is pattern matching. This involves executing the sub-process for determining the target structural pattern in step 106. The first round of editing updates the description information q1 to a new strategy activation monitoring command, which includes three sub-commands: check-status, query-metrics, and render-chart. Based on the updated description information and the semantic adaptation features corresponding to each candidate structural pattern, pattern adaptation prompts are constructed. The target inference model is then invoked to determine the semantic attributes of q1: content belongs to internal functions, interaction method is command, content complexity is composite function, it has a parameter list, it has sub-commands, it does not depend on external systems, and its content complexity is the number of structural elements in the composite level mapping, which is 5. A first semantic vector is determined based on these semantic attributes, and a second semantic vector is determined based on the semantic features of the clustered content blocks corresponding to each candidate structural pattern. For the candidate pattern command group table row, the first matching result between semantic attributes and semantic adaptation features is 0.95, the second matching result between content complexity 5 and pattern structure capacity 3 is 0.6, and the third matching result between the first semantic vector and the second semantic vector is 0.82. Calculated by multiplying the first matching result by 0.5, the second matching result by 0.2, and the third matching result by 0.3, the overall matching score is 0.841. For the candidate pattern related Skill reference rows, the three matching results are 0.15, 0.2, and 0.20 respectively, with an overall matching score of 0.175. The highest overall matching score of 0.841 is greater than the preset threshold of 0.4, thus the target structure pattern is determined to be the command group table row pattern. In the second round of editing, the description information q2 was updated to include the newly added Apollo configuration query capability, implemented through the apollo-skill external skill. The target inference model determined that the semantic attributes of q2 are: content belonging to external reference, interaction method being reference, content complexity being single function, no parameter list, no sub-commands, dependent on external systems, and content complexity being a single-level mapping with 1 structural element. For the command group table row pattern, the three matching results were 0.10, approximately 0.33, and 0.15, with a comprehensive matching score of 0.161. For the related skill reference row pattern, the three matching results were 0.92, 1.0, and 0.88, with a comprehensive matching score of 0.924. The highest comprehensive matching score of 0.924 is greater than the preset threshold of 0.4, confirming the target structural pattern as the related skill reference row pattern. The context of this stage includes the structural pattern library, updated description information, and historical decision records, but does not include the parsing results of the first stage or the generation results of the third stage. Therefore, the pattern selection of q2 is not affected by the chapter format of the first round monitor command group, correctly avoiding neighbor imitation. Furthermore, in scenarios with no matching candidate structure patterns, when the overall matching score of all candidate structure patterns is lower than the preset threshold of 0.4, it is determined to be a no-match pattern.For example, the updated description information is a new WebSocket / ws / notifications real-time push interface. The target inference model determines the semantic attributes as streaming interaction mode, WebSocket protocol, and high real-time requirements. A comprehensive matching score is calculated for the interface description block pattern and error code table block pattern. The highest comprehensive matching score is 0.15, which is lower than the preset threshold of 0.4. Therefore, no matching candidate structure pattern is determined. A new template is generated based on the characteristics of the WebSocket interface. The new template includes an interface description, connection parameter table, message format table, push event example code block, and reconnection strategy paragraph. Corresponding semantic adaptation features are also generated. When the interface uses the WebSocket protocol for real-time bidirectional communication, the new pattern is determined as the target structure pattern, so that the structure type appearing for the first time in the document can also obtain the correct format guidance. The structure pattern library is continuously expanded as the document content evolves.

[0102] Decision recording and anomaly detection. After each target structural pattern is determined, the decision information for this pattern selection is recorded in the structural pattern decision log. This decision information includes the updated description information corresponding to the selection, semantic attributes, the comprehensive matching score of each candidate structural pattern, the identifier of the selected target structural pattern, the comprehensive matching score of the target structural pattern, the reason for selection, and a timestamp. Anomaly detection is performed based on the structural pattern decision log: when the updated description information is edited twice consecutively, selecting the same candidate structural pattern, and the semantic distance between the two updated description information is greater than a preset anomaly threshold (e.g., 0.6), a pattern selection review process is triggered. Review prompts are appended to the pattern adaptation prompts, and the matching calculation is re-executed. For example, if the previous editing step selected the command group table row mode, and the current updated description information also selected the command group table row mode, and the semantic vector cosine similarity between the two is 0.15 and the semantic distance is 0.85, which is greater than the preset anomaly threshold of 0.6, then a review prompt is added to the mode adaptation prompt words to prompt the target inference model to re-evaluate whether the current updated description information is indeed suitable for the mode. After re-executing the matching calculation, the current updated target structure mode is corrected to the relevant Skill reference row mode, which suppresses the continuous nearest neighbor imitation caused by recency bias.

[0103] The third stage is content generation. This involves executing the sub-process of generating updated content in step 106. Following the first round of editing, content generation prompts are constructed based on the target structural pattern and update description information q1. The structural template and instance content blocks of the command group table row pattern, along with q1, are provided to the target inference model. The model generates a monitor command group chapter as the updated content, which has the same format as instance content blocks such as meta, CRUD, and batch. The degree of matching between the structural features of the updated content and the structural features of the target structural pattern is determined. For example, the complement of the normalized edit distance between the structural fingerprint of the updated content and the structural fingerprint of the target structural pattern is used as the degree of matching. After verification, the updated content is written into the corresponding chapter of the command group table row pattern, resulting in the updated document after the first round of editing. Following the second round of editing, content generation prompts are constructed based on the structural template of the relevant Skill reference row pattern, instance content blocks, and q2. The model generates a reference table row for Apollo configuration query capabilities. After verification, this row is written into the corresponding chapter, resulting in the updated document after the second round of editing. The context in this stage only includes the target structural pattern, the instance content block of that pattern, and the update description information. It does not include other candidate structural patterns, the parsing results of the first stage, or the matching process of the second stage. The degree of freedom of generation is limited by the structural template, and even if there is a bias in the attention mechanism, it cannot deviate from the target structural pattern. If the verification fails, the updated content is regenerated based on the difference information between the updated content and the target structural pattern until the matching degree meets the preset conditions.

[0104] Through the above implementation process, the traditional solution requires about 6 rounds of communication and revision to achieve the correct structure. However, this solution, through three-stage context isolation and structural pattern matching, only requires one generation in two rounds of editing, reducing the number of editing rounds from 6 to 2, improving editing efficiency by about 67%. Moreover, the updated content generated in the two rounds is strictly consistent with the existing content in the document that is semantically similar. The pattern selection is made by explicit three-dimensional matching calculation, and each decision is fully recorded and traceable, providing a data foundation for decision auditing and anomaly detection, making the document update process interpretable and structurally consistent.

[0105] By explicitly matching and calculating the three dimensions of semantic attributes, content complexity and structural capacity, and semantic vectors, and making pattern selection decisions through weighted fusion, the pattern selection process becomes interpretable and reproducible, no longer relying on the model's implicit inference of the context, and fundamentally avoiding the problem of nearest neighbor imitation. At the same time, the matching results of each dimension can be fully recorded, providing a data foundation for decision auditing and anomaly detection.

[0106] In one optional embodiment of this specification, prompt words are generated based on content, a target inference model is invoked, updated content corresponding to the updated description information is generated based on the target structural pattern, and an updated document is obtained based on the updated content and the initial document, including: Based on the content, prompt words are generated, the target reasoning model is invoked, and updated content corresponding to the updated description information is generated based on the target structural pattern. Determine the degree of matching between the structural features of the updated content and the structural features of the target structural pattern; If the matching degree does not meet the preset conditions, the updated content is regenerated based on the difference information between the updated content and the target structure pattern until the matching degree of the regenerated updated content meets the preset conditions. Write the updated content into the initial document to obtain the updated document.

[0107] Content generation prompts are natural language instructions that guide the target inference model to generate updated content. They are constructed from three parts: a structural template corresponding to the target structural pattern, exemplary instance content blocks, and update description information. The structural template specifies the structural skeleton that the updated content should follow, the instance content blocks demonstrate to the model the actual presentation style of this structural skeleton in the existing document, and the update description information indicates the semantics of the content to be generated. The combination of these three elements ensures that the model has both structural constraints and style references during generation, and does not depend on the generation results of other steps in the dialogue history. For example, in the skill definition document maintenance scenario, the target structural pattern is a command group table row pattern, whose structural template is a sequence of overview table, bold paragraph, and parameter table. The instance content blocks are command group table rows in the meta, CRUD, and batch sections. The update description information is the "Add Policy Effectiveness Monitoring Monitor" command, which includes three sub-commands: check-status, query-metrics, and render-chart. The combination of these three elements yields the content generation prompts for this update.

[0108] Based on content generation prompts, the target inference model is invoked. Updated content corresponding to the updated description information is generated based on the target structural pattern. Specifically, the content generation prompts are input into the target inference model, which generates lexical units one by one in an autoregressive manner until a terminator is generated or a preset maximum length is reached. The lexical unit sequence is then decoded into text to obtain the updated content. The content generation prompts only contain the target structural pattern and its corresponding instance content blocks, excluding the generation results from other steps in the current session. This achieves context isolation during the generation phase, preventing the model output from being affected by the format of neighboring content. One optional implementation for constructing content generation prompts is to concatenate the structural template, each instance content block, and the updated description information into a single natural language prompt text, which is then input into the target inference model. Another optional implementation is to input the structural template and instance content blocks as system-level instruction text, and the updated description information as user-level input text, respectively, into the target inference model, and add output format constraints to the prompts, such as requiring the output to be in Markdown format and prohibiting the output of explanatory text.

[0109] The matching degree is a measure of the structural consistency between the structural features of the updated content and the structural features of the target structural pattern. A higher matching degree indicates that the structure of the updated content is more consistent with the target structural pattern. The structural features of the updated content are the actual structural skeleton presented by the updated content under the constraints of the target structural pattern, which can be obtained by performing structured parsing on the updated content. For example, the structural features of the updated content can be a sequence of structural element types [title, overview table, bold paragraph, parameter table], and the matching degree is highest when it is completely consistent with the structural features of the target structural pattern. The preset condition is the criterion for judging whether the matching degree is qualified. For example, the preset condition can be that the structural difference rate is not greater than a preset verification threshold, where the structural difference rate can be calculated by normalized edit distance, and the preset verification threshold can be 0.2; the preset condition can also be that the updated content contains all the necessary structural elements of the target structural pattern.

[0110] Determining the degree of matching between the structural features of the updated content and the structural features of the target structural pattern can be achieved through one optional approach: performing structured parsing on the updated content, such as parsing Markdown headings, tables, paragraphs, and code blocks to obtain the actual sequence of structural elements. This sequence is then compared with the sequence of structural element types corresponding to the structural features of the target structural pattern, and the structural difference rate is calculated. The degree of matching can be the complement of the structural difference rate; the smaller the structural difference rate, the higher the degree of matching. Another optional approach is to verify whether the updated content contains all the necessary structural elements of the target structural pattern, such as whether the heading or table is missing. If any necessary structural element is missing, the degree of matching is determined to be unsatisfactory.

[0111] The difference information describes the structural differences between the updated content and the target structural pattern. For example, it describes the difference between the expected sequence of structural elements and the actual sequence of structural elements, and may include missing structural elements, redundant structural elements, and element order deviations. For instance, when the updated content is missing bolded paragraphs and parameter tables, the difference information indicates that the missing structural elements are the bolded paragraphs and parameter tables; when the updated content contains additional code blocks that are not present in the target structural pattern, the difference information indicates that the redundant structural elements are the code blocks. The difference information is used to instruct the target inference model to correct structural deviations when regenerating the updated content.

[0112] If the matching degree does not meet the preset conditions, the updated content is regenerated based on the difference information until the matching degree of the regenerated updated content meets the preset conditions. One optional implementation is to add difference information to the content generation prompt, instructing the target inference model to correct the structural bias and regenerate. Another optional implementation is to concatenate the updated content and the difference information as new input, instructing the model to output the corrected updated content. The number of regenerations can be set to a preset threshold. For example, the preset threshold can be 2. If the matching degree still does not meet the preset conditions after reaching the threshold, a structural anomaly report is generated for user confirmation and processing, avoiding resource consumption caused by infinite retries.

[0113] The updated document is obtained by writing the updated content into the initial document. This involves merging the updated content into the initial document to obtain the updated document. One possible implementation is to write the updated content into the initial document at the position corresponding to the target structural pattern. This position is the location of the chapter containing the instance content block of that structural pattern in the initial document. It can be the end, beginning, or a specified insertion point of the chapter. Specifically, the updated content can be appended to the end of the instance content block to ensure continuous presentation of content with the same pattern in the document. Alternatively, the insertion position can be located based on anchor points specified in the update description information, such as chapter titles or table names. Formatting adjustments, such as consistent list indentation and heading levels, can be performed before writing to ensure consistency with the context. Another possible implementation is to append the updated content as a new chapter to the end of the initial document and establish an association record between the updated content and the target structural pattern in the chapter tree.

[0114] This manual describes an implementation scenario for maintaining a skills definition document. It addresses the update description information as a new strategy activation monitoring command (monitor), containing three sub-commands: check-status, query-metrics, and render-chart, with a target structure pattern of command group table rows. Based on this pattern's structure template (overview table, bold paragraph, parameter table), instance content blocks (command group table rows in the meta, CRUD, and batch sections), and the update description information, content generation prompts are constructed. These are input into the target inference model, which generates updated content including monitor command descriptions, sub-command function tables, and parameter descriptions. The updated content is then structurally parsed to obtain a sequence of structural elements [title, overview table, bold paragraph, parameter table], which is completely consistent with the structural features of the target structure pattern, with a structural difference rate of 0. The matching degree meets preset conditions, eliminating the need for regeneration. The updated content is then written into the monitor command-related instance content blocks within the command group sections of the initial document. Before writing, format adaptation is performed to maintain consistency between the title hierarchy and table style with the existing document content, resulting in an updated document.

[0115] This manual describes an implementation scenario for maintaining a skill definition document. For an update where the description information is a newly added `deploy` command, supporting environment switching, the initial update content generated by the target inference model is missing bolded paragraphs and parameter tables. The actual structural element sequence is compared with the expected structural element sequence [title, overview table, bolded paragraph, parameter table], and the structural difference rate is 0.5, which is greater than the preset verification threshold of 0.2, indicating that the matching degree does not meet the preset conditions. After adding the difference information (the missing structural elements are bolded paragraphs and parameter tables) to the content generation prompts and regenerating, the second generated update content contains all four structural elements, the structural difference rate is 0, and the matching degree meets the preset conditions. The second generated update content is then written into the initial document to obtain the updated document.

[0116] After generating updated content, the degree of matching between it and the target structural pattern is determined. If the preset conditions are not met, the content is regenerated based on the difference information until the conditions are met, and then written into the initial document to obtain the updated document. This provides a quantitative fallback mechanism for the generated results, avoiding the direct writing of content with missing structures into the document. At the same time, the retry overhead is controlled by a preset number of thresholds, balancing quality and efficiency.

[0117] In one optional embodiment of this specification, content is generated to produce prompt words based on the target structural pattern and updated description information, including: Based on the updated description information, the target tool group is determined from multiple tool groups in the preset tool library. The preset tool library includes tool summaries for each tool. Each tool is clustered into multiple tool groups based on the degree of functional correlation. The tool summary is used to describe the function and invocation conditions of the tool. Based on the tool summary, target structure pattern, and updated description information of the target tool group, content generation prompts are constructed.

[0118] The default tool library is a pre-built database containing the definition information of each tool. Each tool's definition includes a tool identifier, a tool summary, and tool parameters. Tools are clustered into multiple tool groups based on their functional relevance. For example, the default tool library for an enterprise-level AI programming assistant contains 60 tools, which are clustered into 8 tool groups based on their functional relevance, such as the core editing group, Git operation group, requirement management group, and compilation and deployment group. The core editing group includes file reading, writing, editing, and search tools, while the Git operation group includes branching, merging, and committing tools.

[0119] A tool summary is a concise description of a tool's function and invocation conditions, enabling the model to determine whether to invoke the tool. The tool summary may include a tool identifier, a compressed function description, and invocation conditions. It may also include core parameter information, such as the names and types of required parameters. For example, the tool summary for the file reading tool `read` would be: the tool identifier is `read`, the compressed function description is "read the contents of a file at a specified path," and the invocation condition is "a file path must be provided." The target tool group is the tool group determined from multiple tool groups based on the update description information and that is relevant to the current update content. For example, if the update description information is "view the current Git branch status," the target tool group would be the Git operation group.

[0120] Based on the update description information, the target tool group is determined from multiple tool groups in the preset tool library. That is, it is determined which tool capabilities are involved in the generation of this update content, and the corresponding tool group is determined as the target tool group.

[0121] An optional implementation involves classifying intent based on the updated description information to obtain the intent classification result corresponding to the updated description information. Then, based on the intent classification result and the semantic features of each tool group in the preset tool library, a target tool group is determined. The intent classification result is the recognition result of the intent expressed by the updated description information, used to map the updated description information to one or more tool groups. The semantic features of the tool group include group labels and keyword sets. When performing intent classification, an optional implementation involves keyword matching: the updated description information is segmented into words, and the matching score with the keyword set of each tool group is calculated. Tool groups with scores greater than a preset matching threshold, such as 0.15, are considered active tool groups. Another optional implementation is based on semantic similarity: calculate the cosine similarity between the updated description information semantic vector and the semantic vector of each tool group label. If the similarity is greater than a preset similarity threshold, such as 0.4, the tool group is activated. Alternatively, the two methods can be combined, and if keyword matching does not activate any tool group, it can fall back to semantic similarity matching.

[0122] Another optional implementation is to determine the target tool group by combining the structural template corresponding to the target structural pattern and / or the current context state of the target inference model, in addition to updating the description information. For example, when the target structural pattern is a code block example pattern, it can be inferred that generating updated content may require code editing tools, and the code editing tool group is determined as the target tool group. When the current context state indicates that the target inference model has called document reading tools in multiple rounds, it can be inferred that this type of tool may still be needed in this round, and the corresponding tool group is activated first. This extension method provides supplementary judgment basis when the intent classification signal is insufficient.

[0123] In the process of determining the target tool group, state management can also be performed on each tool group. One optional implementation is that each tool group maintains a three-state state machine, including an index state, a summary state, and a complete state, which respectively represent residing only in the index layer, residing in the summary layer, and at least one tool in the group residing in the complete layer. The state update rules are as follows: when the intent classification result matches a tool group, the state switches from the index state to the summary state; when the target inference model selects a tool in the group, the state switches from the summary state to the complete state; when the tool call is completed or the current round ends, the state switches back from the complete state to the summary state; if there is no match after a preset number of rounds, such as 3 rounds, the state switches back from the summary state to the index state.

[0124] In addition, the classification error between the intent classification result and the subsequent actual tool call can be recorded. When the cumulative number of classification errors reaches a preset threshold, the semantic features of each tool group in the preset tool library are updated based on the classification error. The classification error is a record where the intent classification result is inconsistent with the actual tool call. For example, the updated description information is mapped to tool group A, but the actual tool called belongs to tool group B. The classification error includes two categories: missed match (should be activated but not activated) and mismatch (should not be activated but activated). The preset threshold can be 100 records. A semantic feature update is triggered once every 100 records.

[0125] Based on the classification error, the semantic features of each tool group are updated. One possible implementation is to count the user words that cause missed matches and add the high-frequency words to the keyword set of the corresponding tool group. Another possible implementation is to count the keywords that cause mismatches and remove them from the keyword set, and adjust the matching threshold according to the missed match rate. When the missed match rate is greater than 5%, the matching threshold is reduced by 0.02 to expand the activation range.

[0126] Based on the tool summaries, target structure patterns, and update description information of the target tool group, content generation prompts are constructed. This involves incorporating the tool summaries of each tool within the target tool group into the content generation prompts, enabling the target inference model to determine whether to invoke a tool and which tool to invoke when generating updated content.

[0127] An optional implementation involves concatenating the tool summary of the target tool group, the structural template and instance content block corresponding to the target structural pattern, and the update description information into a natural language prompt text, which is then input into the target inference model. Another alternative implementation involves using the structure template, instance content blocks, and tool summaries of the target tool group as system-level command text, and update description information as user-level input text, which are then input into the target inference model. For example, in an agent-assisted editing scenario, given the update description information is "Help me fix this bug," and the target tool group is identified as the core editing group, the tool summaries of each tool within the core editing group, along with the structure template in the command group's table row pattern and the update description information, are used to construct content generation prompts. During generation, the model can both adhere to structural constraints and determine whether tools like `read` need to be called to retrieve file content.

[0128] In one implementation of this manual, in an agent-assisted editing scenario, the pre-defined toolkit contains 60 tools, divided into 8 tool groups, such as the core editing group, Git operation group, and requirement management group. For updates with the description "Help me fix this bug," a matching score is calculated with the keyword sets of each tool group. The highest matching score is with the core editing group, thus identifying the core editing group as the target tool group. For updates with the description "Check the current Git branch status," the target tool group is identified as the Git operation group. When the update description is "What do you think of this solution?", keyword matching does not activate any tool group. It reverts to semantic similarity matching; the cosine similarity with the tags of each tool group is below 0.4, therefore no tool group needs to be activated, and no tool definitions are loaded, achieving zero tool lexical consumption in a pure question-and-answer scenario. After identifying the target tool group, the tool summary corresponding to the target tool group is injected into the context. When generating updated content based on the tool summary of the target tool group, the tool parameters corresponding to the target tools in the target tool group are injected into the context. For example, for the update description information "Help me fix this bug", after activating the core editing group, the summary layers of the 6 tools in the group are injected into the context, consuming approximately 257 tokens. The target inference model decides to call the read tool, replacing the summary layer of the read tool with the complete layer (including file path, reading range, etc.), consuming approximately 207 tokens. After the call is completed, the complete layer is replaced back with the summary layer. During the entire process, the peak token consumption of the tool definition is 1504, which saves 95.3% compared to the 31,710 tokens of the full injection of 60 tool definitions.

[0129] The target tool group is determined based on the updated description information, and the tool summary of the target tool group is incorporated into the content to generate prompt words. This allows the tool definition loading to be automatically driven by the semantics of the updated description information, without the need for manual configuration by the user. The tool group is activated on demand, avoiding the waste of context caused by full injection. At the same time, the tool summary and tool parameters are injected in stages, so that the stage of determining whether to call only consumes the summary layer words, and the stage of how to call only consumes the full layer words. The tool definition usage dynamically scales up and down according to actual needs, significantly reducing the context usage while ensuring calling capability.

[0130] In one optional embodiment of this specification, the preset tool library further includes tool parameters for each tool; generating prompts based on content, calling the target inference model, and generating updated content corresponding to the updated description information based on the target structural pattern, including: Based on the content-generated prompts, the target inference model is invoked. Based on the summaries of each tool and the target structural pattern, the target tool required to generate the updated content corresponding to the updated description information is determined, and the tool identifier of the target tool is obtained from the summaries of each tool. Based on the tool identifier, obtain the target tool parameters from the preset tool library; The target inference model is invoked, and based on the target tool parameters and the target structural pattern, the updated content corresponding to the updated description information is generated.

[0131] Tool parameters are the compressed definitions of a tool's parameters. They represent the complete tool parameters, such as the original JSON Schema parameter definitions, compressed to maintain a model-parseable format. These parameters enable the model to determine how to invoke the tool. The preset tool library also includes tool parameters for each tool; that is, in addition to the tool summary, the preset tool library stores the parameter-level definitions for each tool used during the invocation phase. The target tool is the tool used to assist in generating updated content, as determined by the target inference model. For example, when it's necessary to organize all chapter titles in the current document into a table of contents, the target tool could be the `grep` tool. The tool identifier is a unique identifier for a tool in the preset tool library, which can be the tool name, tool number, etc. For example, the tool identifier could be the tool's name field, such as `grep`. Target tool parameters are the tool parameters corresponding to the target tool, including parameter name, parameter type, parameter description, required fields, constraints, etc. They are stored separately from the tool summary in the preset tool library and are retrieved based on the tool identifier only after the target tool is determined.

[0132] Based on the content generation prompts, the target inference model is invoked. Based on the tool summaries and the target structure pattern, the target tool required to generate the updated content corresponding to the updated description information is determined, and the tool identifier of the target tool is obtained from the tool summaries. That is, the target inference model determines whether a tool needs to be called and which tool needs to be called based on the tool summaries in the content generation prompts, and extracts the tool identifier of the target tool from the tool summaries.

[0133] One possible implementation is to input content-generated prompts into the target inference model, and have the model output the tool identifier of the target tool. Another alternative implementation involves semantically comparing the tool summary of each tool with the updated description information, selecting the tool with the highest semantic similarity as the target tool, and obtaining the tool identifier from its tool summary.

[0134] After determining the target tool, the tool identifier can be invalidated. If the tool identifier does not exist in the preset tool library, the target tool is re-determined based on the content-generated prompt words and the tool summary of each tool in the preset tool library. One possible implementation is to perform a semantic comparison between the tool summary of each tool and the updated description information, and select the tool with the highest semantic similarity as the re-determined target tool. Another alternative implementation is to concatenate the content generation prompts with the summaries of each tool and input them into the target inference model, so that the model can reselect the target tool; if none of them can be determined, then it falls back to the path of directly generating updated content.

[0135] Based on the tool identifier, the target tool parameters of the target tool are obtained from the preset tool library. That is, the target tool parameters corresponding to the target tool are retrieved from the preset tool library using the tool identifier, and the target tool parameters are provided to the target inference model as the basis for invocation.

[0136] One optional implementation is to store the tool parameters of each tool in a preset tool library using the tool identifier as the primary key, and to directly retrieve the target tool parameters by using the tool identifier; Another optional implementation is to pre-organize and store tool parameters in a tool library according to tool groups. When obtaining target tool parameters, the tool identifier of the target tool is first located in the target tool group, and then the corresponding target tool parameters are read.

[0137] The target inference model is invoked, and based on the target tool parameters and the target structural pattern, updated content corresponding to the updated description information is generated. Specifically, the target inference model constructs tool call data based on the data interface capabilities constrained by the target tool parameters, and generates updated content based on the structure constrained by the target structural pattern. Unlike paths where the target inference model directly generates updated content, this implementation provides a tool-assisted generation path: the target inference model is responsible for semantic-level tool selection and updated content generation, while the target tool parameters are provided by a preset tool library according to tool identifiers, separated from the model's generation process, thus avoiding content mismatch caused by the model guessing tool parameters.

[0138] This specification describes an implementation scenario for Agent-assisted editing. The target structure pattern is a document structure overview pattern, and the update description information is to organize all chapter titles in the current document into a table of contents. After generating prompts for the content, the target inference model is invoked. Based on the tool summaries of each tool in the core editing group and the target structure pattern, the model determines that the required target tool is the grep tool and obtains the tool identifier grep from its tool summary. Based on the tool identifier, the target tool parameters of the grep tool are obtained from the preset tool library, including parameter definitions such as regular expressions and file paths. The target inference model is invoked, and based on the target tool parameters and the structure template of the document structure overview pattern, the retrieval data is constructed according to the parameter definition format, where the pattern is ^#{1,3} and the path is docs / skill-definition.md. Based on the retrieval data, updated content in the form of a table of contents is generated and written to the initial document.

[0139] In one implementation of this specification, the above scenario is addressed. If the tool identifier grep obtained from the tool summary of the grep tool does not exist in the preset tool library, or if the tool has been taken offline, the content-generated prompt words and the tool summaries of each tool in the preset tool library are input into the target inference model to re-determine the target tool. The model selects the findtext tool, whose functional semantics are consistent with the searched text. Based on the tool identifier of findtext, the target tool parameters of findtext are obtained from the preset tool library. Updated content is generated based on the target tool parameters and the structure template of the document structure overview mode.

[0140] By determining the target tool and obtaining the tool-assisted generation path by the identifier, the generation of updated content can refer to the data interface capabilities constrained by the target tool parameters, thus expanding the capability boundary of the generation method. The target tool parameters are uniformly provided by the preset tool library according to the tool identifier, ensuring the authority and consistency of the parameter source. The re-determination mechanism when the tool identifier fails ensures the robustness of the tool-assisted generation path in the scenario of dynamic changes in the tool library, and avoids the interruption of the generation process due to tool missing.

[0141] In one optional embodiment of this specification, the preset tool library is constructed in the following manner: Obtain the original tool definitions for each tool; Feature extraction is performed on multiple original tool definitions to obtain tool features for each original tool definition. The tool features are used to characterize the structural form and functional semantics of each original tool definition. Based on the similarity of the features of each tool, the tools are clustered to obtain multiple tool groups; Based on the original tool definitions and features, the tool summary and tool parameters for each tool are determined.

[0142] The original tool definition is a complete definition of the tool, including the tool name, function description, and parameter definitions. The parameter definitions can be in JSON Schema format, containing parameter names, types, descriptions, required fields, and enumeration values. For example, the original tool definition for the tool `create_mr` (create merge request) includes the tool name `create_mr`, the function description "create merge request and associate source and target branches", and parameter definitions including `workspace`, `repo_path`, and `source_branch`. Tool features are characteristics used to characterize the structural form and functional semantics of each original tool definition. The structural form refers to the organizational structure of the parameter definitions in the original tool definition, and the functional semantics refers to the semantics expressed by the tool's function description.

[0143] For example, structural form can be characterized by obtaining a field tree and structural complexity through structured parsing of parameter definitions. The field tree is a hierarchical representation of fields obtained after parsing the parameter definitions into a tree structure. Each node corresponds to a field, including attributes such as field name, field type, field description, constraints (e.g., enumeration values, regular expressions, minimum length), and whether it is required. Structural complexity is a metric defined by the characterization tool to measure the degree of structural complexity. For example, structural complexity can be equal to the sum of the products of the nesting depth of each field and the field type weight. The type weight is assigned according to the field type, such as the object type having the highest weight and basic types having the lowest weight. Functional semantics can be characterized by embedding and vectorizing the functional description to obtain a functional embedding vector.

[0144] Obtaining the original tool definitions for each tool involves retrieving the complete definition information of each tool from the tool registration system, tool list, or runtime environment. One optional implementation is to read the tool definitions of all registered tools from the tool registry of the Agent system; another optional implementation is to parse the tool definitions of each tool from configuration files or plugin lists. For example, when building the default tool library for an enterprise-level AI programming assistant, the original tool definitions of 60 tools are retrieved from the tool registry, including the definitions of tools such as create_mr, get_session_id, and executeDataCreateSkill.

[0145] Feature extraction is performed on multiple original tool definitions to obtain tool features for each original tool definition. One optional implementation is to perform structured parsing on each tool definition to obtain the field tree and structural complexity of each tool, and calculate the function embedding vector based on the function description, using the field tree, structural complexity, and function embedding vector as tool features. Another optional implementation is to extract only the structural complexity as structural morphological features and only the function embedding vector as functional semantic features, in order to reduce the feature extraction overhead. For example, the parameter definition of the tool create_mr includes parameters such as workspace, repo_path, and source_branch, with a maximum nesting depth of 2 levels, belonging to medium-complexity tools; the tool get_session_id only contains one parameter, session_id, and has the lowest structural complexity.

[0146] Based on the similarity of the features of each tool, the tools are clustered to obtain multiple tool groups, that is, tools with similar functional semantics and similar structural forms are grouped together. One optional implementation is to perform hierarchical clustering based on the semantic similarity of the tool function embedding vectors, with a distance threshold of a preset value, such as 0.5. The clustering results constitute tool groups. For example, the 60 tools of the enterprise-level AI programming assistant are divided into 8 tool groups based on hierarchical clustering of function embedding vectors. Another optional implementation is to group the tools according to the calling frequency and call co-occurrence relationship, with tools that are frequently called in the same session being grouped into the same tool group.

[0147] Based on the original tool definitions and features, the tool summary and tool parameters for each tool are determined. That is, based on the original tool definitions and features, a tool summary for invocation judgment and tool parameters for invocation execution are generated for each tool.

[0148] One possible implementation is to use the tool name as the tool identifier, perform structured compression on the function description, extract the required parameter names and types from the parameter definitions as a core parameter list, and construct a tool summary from the tool name, the compressed function description, and the core parameter list; and perform structured compression on the parameter definitions to obtain the tool parameters.

[0149] Another optional implementation is to determine the information content of the tool summary for each tool based on the structural complexity of each tool. When the structural complexity is higher than a threshold, a tool summary with more information is generated, retaining more descriptive information. When the structural complexity is lower than the threshold, a tool summary with less information is generated, preventing excessive loss of summary information for highly complex tools.

[0150] After identifying each tool group, group tags can be determined based on the functional descriptions of the tools within each tool group. Furthermore, a set of keywords for each tool group can be determined based on the names and functional descriptions of the tools within each tool group. The group tags are short tags that summarize the semantics of the tool group's functions and are used for semantic similarity matching and user understanding. The set of keywords is a set of functional words for the tool group and is used for keyword matching-based intent classification.

[0151] One possible implementation is to concatenate the names and function descriptions of each tool in the group and input them into a lightweight language model to generate group labels of no more than 5 words. Using the names and function descriptions of each tool in the group as corpus, word weights are calculated using TF-IDF, and the top 20 words with the highest weights are taken as the keyword set.

[0152] Another alternative implementation is to extract high-frequency semantic words from the functional descriptions of the tools within the group to form group tags, and to count the high-frequency words that have been triggered by the tools in the group from the user's historical call logs and add them to the keyword set.

[0153] This specification describes an implementation scenario for Agent-assisted editing. The tool definitions of 60 tools are structurally parsed to obtain the field tree, structural complexity, and functional embedding vector for each tool. Based on hierarchical clustering of the functional embedding vectors, the 60 tools are divided into 8 tool groups. The names and functional descriptions of tools within each group are concatenated and input into a lightweight language model to generate group labels: the core editing group is labeled as file reading / writing and command execution, the Git operation group is labeled as Git / MR operation, and the requirement management group is labeled as requirement management, etc. Simultaneously, the top 20 keywords are extracted based on TF-IDF, and high-frequency trigger words are supplemented from historical call logs to form the keyword set for each tool group. For example, the parameter definition of the tool `create_mr` includes parameters such as `workspace`, `repo_path`, and `source_branch`, with a maximum nesting depth of 2 levels, classifying it as a medium-complexity tool. A tool summary containing the name, compressed functional description, and a list of core parameters is generated for it. The tool `get_session_id` contains only one parameter, `session_id`, and has the lowest structural complexity; a tool summary containing only the tool name and a one-sentence functional description is generated for it.

[0154] A pre-defined tool library is constructed by acquiring the original tool definition, feature extraction, clustering, and summary parameter determination process. This makes the tool library construction process structured and reusable. The amount of tool summary information is configured differently according to the structural complexity. While ensuring the compression effect, this avoids inaccurate call judgments due to insufficient summary information in highly complex tools. The group label and keyword set provide two types of basis for intent classification: keyword matching and semantic matching, making tool group activation judgment both fast and accurate.

[0155] In one optional embodiment of this specification, based on the original tool definitions and tool characteristics, the tool summary and tool parameters of each tool are determined, including: Based on the original tool definitions, obtain the tool description text and complete tool parameters for each tool; By comparing the description texts of each tool, redundant information in each tool description text is identified and removed from each tool description text to obtain the description text of each compressed tool. Based on the characteristics of each tool, the calling conditions of the tool to which each tool characteristic belongs are determined. Based on the invocation conditions and the description text of each compression tool, determine the tool summary for each tool; Based on the characteristics of each tool, the parameters of each complete tool are compressed to determine the tool parameters defined in the original tool definition.

[0156] Tool description text refers to the text information in the original tool definition used to describe the tool's functionality, such as function descriptions and usage instructions. Complete tool parameters are all parameter definitions in the original tool definition, such as complete JSON Schema parameter definitions. Redundant information refers to information that appears repeatedly in the tool description text, including repeated parameter descriptions across tools, repeated metadata fields, repeated sentence structures, and repeated skill lists. Detecting and removing redundant information can reduce the lexical overhead of the tool description text.

[0157] For example, if the `userEmail` parameter appears repeatedly in 28 tools and has the same description, then the description text for this parameter is redundant information. Compressed tool description text is the simplified tool description text obtained by removing redundant information from the tool description text. Invocation conditions describe the conditions that must be met to invoke the tool, such as the applicable business scenario of the tool, the user intent characteristics that trigger the tool, etc. Invocation conditions are used by the model to determine under what circumstances the tool should be invoked. For example, the invocation conditions for the file reading tool `read` are that it needs to read file content and requires a file path.

[0158] Based on the original tool definitions, the tool description text and complete tool parameters for each tool are obtained; that is, the tool description text and complete tool parameters are parsed from the original tool definitions. One optional implementation is to organize the original tool definitions by fields, directly reading the function description field to obtain the tool description text, and reading the parameter definition field to obtain the complete tool parameters. Another optional implementation is to perform structured parsing on the original tool definitions, locating the description fields and parameter fields based on the field tree, and extracting the tool description text and complete tool parameters respectively.

[0159] By comparing the description texts of each tool, redundant information in each tool's description text is identified and removed, resulting in compressed tool description texts. This involves pairwise comparison of the description texts of each tool to identify and remove duplicate content across tools. Redundancy detection is performed at three levels: parameter level, description text level, and functional semantic level. One optional implementation is as follows: At the parameter level, for any two parameters in any two tools, if the parameter name similarity is greater than a preset threshold (e.g., 0.8), and the parameter types are the same, and the cosine similarity of the embedding vectors of the parameter description texts is greater than a preset threshold (e.g., 0.85), then the two parameters are determined to belong to the same parameter pattern. This pattern is then registered as a global parameter pattern, retaining only one standard description, with the rest replaced by reference tags. Another optional implementation involves calculating a 64-bit SimHash fingerprint for each pair of tool description texts at the text level. Tool pairs with a Hamming distance of no more than 3 are further aligned at the sentence level and ROUGE-L scores are calculated. Sentence pairs with scores greater than a preset threshold, such as 0.7, are marked as redundant. Shared text segments are extracted, and only one copy is retained. The SimHash fingerprint is a fingerprint vector obtained by performing Local Sensitive Hashing on the text. The Hamming distance of the fingerprint is smaller if the texts are similar, which is used to quickly filter candidate redundant pairs and avoid the computational overhead of pairwise full-text comparison. Alternatively, at the functional semantic level, a functional embedding vector can be calculated for each tool, and the cosine similarity between each pair of tools can be calculated. Tool pairs with similarity greater than a preset threshold are marked as functionally overlapping, and an overlap report is output for manual review and merging.

[0160] Based on the characteristics of each tool, the calling conditions of the tool to which each tool characteristic belongs are determined. One possible implementation is to extract elements such as required parameters and parameter constraints from the field tree of the tool characteristics and generate calling conditions in combination with the business scenario description of the tool function. Another possible implementation is to summarize the user intent characteristics that trigger the tool as calling conditions based on the user input and context when the tool is called in historical sessions.

[0161] Based on each invocation condition and each compression tool description text, a tool summary for each tool is determined, which is a combination of the invocation conditions and the compression tool description text.

[0162] An optional implementation involves a tool summary comprising index information and summary information. The index information is determined based on the tool's tool identifier and function tags. Function tags are category tags obtained by classifying tool functions, such as git, database, deploy, and log, and are obtained by classifying the tool's function descriptions through text. The index information is the tool's most basic identification information, including the tool name and function tags, used to index all tools in the context with minimal overhead. The summary information is obtained by compressing the tool's function description. The summary information, together with the core parameter list (which only lists the required parameter names and types, excluding descriptions), constitutes the tool summary. For example, the index layer of the tool `create_mr` consists of the name `create_mr` and the function tag `git`, approximately 8 terms. The summary layer consists of the name `create_mr`, the compressed function description (30% of the original text), and the core parameters `workspace`, `repo_path`, and `source_branch`, approximately 50 terms. The compression process involves lossy compression of the function description. An optional implementation involves removing sentences marked as redundant. One possible implementation is to remove sentences with low information density, where information density is the ratio of the number of non-repeating content words after removing stop words to the total number of lexical units; another possible implementation is to remove supplementary explanations and examples within parentheses; if the compressed length still exceeds the target, such as 30% of the original text, remove sentences one by one from low to high information density, and mark descriptive text with strong instructions as to be retained.

[0163] Based on the characteristics of each tool, the parameters of each complete tool are compressed to determine the tool parameters defined in the original tool definition. That is, the complete tool parameters are compressed in a structured manner based on the tool characteristics.

[0164] Structured compression is a process of performing lossless and / or lossy compression on parameter definitions. Lossless operations include: removing metadata declarations that the model does not depend on; removing ref reference definitions and expanding them inline; and eliminating descriptive text that is highly repetitive with parameter names. Lossy operations include: retaining only the first 3 enumeration values ​​for parameters with too many enumeration values; compressing deep subfields of object parameters with excessive nesting depth into a single sentence description; and removing usage examples from parameter descriptions.

[0165] To ensure the security of compression, the optimal compression level can be determined through call testing. One possible implementation is to obtain the parameter definitions of the tool under multiple candidate compression levels for each tool based on the tool definition, and then perform call testing on the tool based on the parameter definitions under each candidate compression level to obtain the call accuracy of the tool under each candidate compression level. Based on the call accuracy under each candidate compression level, the optimal compression level of the tool is determined from multiple candidate compression levels. Based on the parameter definition corresponding to the optimal compression level of the tool, the complete parameter definition of the tool is determined.

[0166] The candidate compression levels are multiple pre-defined compression levels, such as: L0 original complete definition, 0% compression, as the baseline; L1 only lossless operation, about 10-15% compression; L2 lossless operation plus removal of examples and supplementary descriptions, about 25-35% compression; L3 lossless operation plus functional description compressed to 50%, about 40-55% compression; L4 only retain the summary layer, about 70-85% compression.

[0167] Invocation testing serves as a benchmark test to verify the effectiveness of tool invocation at various compression levels. For example, an invocation test set is constructed for each tool, including a positive example set (50 user inputs that should invoke the tool and their expected parameter outputs), a negative example set (20 user inputs that should not invoke the tool), and a parameter completeness set (30 invocation scenarios with different parameter combinations). The test set is executed at each compression level to evaluate selection accuracy, parameter completeness rate (the ratio of generated parameters containing all required parameters), and parameter format correctness. The overall accuracy can be calculated as 0.5 × selection accuracy + 0.3 × parameter completeness rate + 0.2 × parameter format correctness rate. The optimal compression level can be determined as follows: provided the invocation accuracy is not lower than 95% of the full injection benchmark, select the candidate compression level with the highest compression degree; if the invocation accuracy at all candidate compression levels is lower than the 95% threshold, the tool is marked as uncompressible, and the L0 original complete definition is always used.

[0168] When a tool definition changes, recalibration can be performed only on the changed tool. One possible implementation is to store the optimal compression level of each tool in a cache and set an expiration period, such as 7 days. The cache is read directly within the expiration period, and automatic recalibration is performed after the expiration period. When a tool definition changes, recalibration is triggered immediately, while the optimal compression level of the other tools remains unchanged.

[0169] This specification describes one implementation process that follows the aforementioned Agent-assisted editing scenario. Redundancy removal and three-level splitting are performed on the tool definitions of 60 tools: In parameter-level redundancy removal, the `userEmail` parameter appears repeatedly in 28 tools with identical descriptions; it is registered as a global parameter mode, and only one standard description is retained. The parameter definitions of the remaining tools are replaced with reference tags. In description text-level redundancy removal, SimHash fingerprints are calculated for each pair of tool function description texts. Tool pairs with a Hamming distance of no more than 3 undergo sentence-level alignment and ROUGE-L scores are calculated. Sentence pairs with scores greater than 0.7 are marked as redundant, and only one shared text segment is retained. In functional semantic-level redundancy detection, tool pairs with a functional embedding vector cosine similarity greater than 0.8 are output as overlap reports for manual review and merging. After removing redundancy, create_mr is split into three layers: the index layer consists of the name create_mr and the function tag git, approximately 8 terms; the summary layer consists of the name create_mr, the compressed function description (30% of the original text), and the core parameters workspace, repo_path, and source_branch, approximately 50 terms; the complete layer consists of the structured compressed parameter definitions, where the user_email parameter uses a citation tag instead of an inline description, and the title parameter omits descriptive text that overlaps with the parameter name. After removing redundancy and splitting into three layers, the index layer of 60 tools, the summary layer of each active tool group, and the complete layer of all tools occupy approximately 480, 3555, and 22197 terms, respectively.

[0170] This manual uses an enterprise-level AI programming assistant tool scheduling scenario as an example to illustrate the complete implementation process of the layered progressive injection and structured simplification method for tool definitions in a real system. The AI ​​programming assistant registered 60 tools and 15 skill definitions, totaling 75 definition items. The 60 tools are distributed across more than ten MCP servers, and the parameter definitions of each tool are described in JSON Schema format. The context window has 200,000 vocabularies. In the traditional full injection mode, the 60 tool definitions occupy approximately 31,710 vocabularies, and the behavior specifications and skill descriptions occupy approximately 15,000 vocabularies. Adding the duplicate injection of the Skill list and parameter redundancy, the system prompts occupy approximately 60,000 vocabularies in total. 30% of the available window is consumed before the user has even entered any content. In a typical dialogue, the user actually triggers only 3 to 5 tools, accounting for 5% to 8% of the total registered tools, meaning over 90% of the tool definition vocabularies are completely wasted. After adopting this solution, the management and loading process of tool definitions is divided into five stages: redundancy removal, three-layer splitting, tool grouping, intent-driven state machine injection, and compression-accuracy Pareto calibration. The first four stages complete the tool library construction offline, and only intent classification and state machine switching are performed at runtime. Figure 3This is a flowchart illustrating a document update method in a tool scheduling scenario during the implementation of this manual. Specifically: The first step is redundancy removal. All 75 defined items undergo structured parsing and a three-level redundancy detection. Parameter-level redundancy detection compares any two parameters from any two tools. If the parameter name similarity is greater than a preset threshold (e.g., 0.8), the parameter types are the same, and the cosine similarity of the embedding vectors of the parameter description text is greater than a preset threshold (e.g., 0.85), the two parameters are determined to belong to the same parameter pattern. For example, the `userEmail` parameter appears repeatedly in 28 tools with identical descriptions. After detecting this parameter pattern, it is registered as a global parameter pattern, retaining only one standard description, and replacing the remaining 27 with reference markers. Description text-level redundancy detection calculates a 64-bit SimHash fingerprint for the functional descriptions of any two tools. Tool pairs with a Hamming distance of no more than 3 undergo sentence-level alignment and ROUGE-L scores. Sentence pairs with scores greater than a preset threshold (e.g., 0.7) are marked as redundant. Shared text segments are extracted and retained only once to eliminate duplication caused by multiple tools sharing the same capability description sentence patterns. Functional semantic redundancy detection calculates the functional embedding vector for each tool. Tool pairs with a cosine similarity greater than a preset threshold (e.g., 0.8) are marked as functionally overlapping, and an overlap report is output for manual review and merging. After three levels of redundancy detection and removal, approximately 4,435 redundant tokens are eliminated.

[0171] The second step involves a three-layer decomposition. Each tool definition, after redundancy removal, is divided into three layers with increasing information density: an index layer, a summary layer, and a complete layer. The index layer contains only the tool name and function label, with each tool occupying 5 to 10 tokens. This layer is used to retain the index information of all tools in the context with minimal overhead. The summary layer contains the tool name, a compressed function description, and a list of core parameters. The core parameter list only lists the names and types of required parameters, with each tool occupying 30 to 80 tokens. This layer enables the target inference model to determine whether to call the tool. The complete layer is the structured and compressed complete parameter definition, preserving the model's parsability in JSON Schema format. Its size is 50% to 70% of the original definition. This layer enables the target inference model to correctly call the tool according to the parameter constraints. Lossless operations in structured compression include removing metadata declarations, inline expansion of reference definitions, and eliminating descriptive text that duplicates parameter names. Lossy operations include retaining only the first three enumeration values, compressing deep subfields into a one-sentence description, and removing usage examples. After the three-layer split, the index layer of 60 tools occupies approximately 480 tokens, the summary layer of all tools occupies approximately 3,555 tokens, and the complete layer of all tools occupies approximately 22,197 tokens. The index layer resides in the context, while the summary and complete layers are not preloaded and are injected as needed by subsequent stages.

[0172] The third step is tool grouping. All tools are hierarchically clustered based on their function embedding vectors, with a preset clustering distance threshold (e.g., 0.5). The 60 tools are divided into 8 tool groups, each with a group label and a keyword set. Group labels are generated by concatenating the tool names and function descriptions within the group and inputting them into a lightweight language model. Each group label contains no more than 5 words. For example, the core editing group's label is "file read / write and command execution," the Git operation group's label is "Git / MR operation," the requirements management group's label is "requirements management," and the compilation and deployment group's label is "compilation and deployment." The keyword set is constructed using the names and function descriptions of each tool within the group as corpus. Word weights are calculated using TF-IDF, and the top 20 words with the highest weights are selected. Additionally, high-frequency words that triggered the tools in that group are added to the keyword set from user history call logs.

[0173] The fourth step is intent classification. Intent classification is performed on the update description information for each edit. First, keyword matching is performed based on the keyword set. Then, the semantic similarity between the semantic vector of the update description information and the semantic features of each tool group is calculated. Tool groups with a keyword matching score greater than 0.15 or a semantic similarity greater than 0.4 are activated as target tool groups. For example, when a user inputs "Please fix this bug," the keyword set matches words like "read," "modify," and "execute," and the core editing group is activated; when a user inputs "Put this request in PingCode," the request management group is activated. The difference between the intent classification result and the subsequent actual tool call is recorded as classification error. When the accumulated classification error reaches 100, high-frequency words that cause missed matches are added to the keyword set of the corresponding tool group, keywords that cause mismatches are removed, and the matching threshold is adjusted based on the missed match rate, so that the mapping accuracy between intent and tool group continuously improves with data accumulation.

[0174] Step 5: On-demand injection of the three-state machine. Each tool group maintains a three-state machine consisting of an index state, a summary state, and a complete state. In the index state, the tool group only resides in the index layer; after the intent classification activates the tool group, the group switches from the index state to the summary state, injecting the summary layers of all tools in the group into the context; after the target inference model selects a tool in the group, the group switches from the summary state to the complete state, replacing the summary layer of that tool with the complete layer; when the tool call is completed and the current round ends, the group switches back from the complete state to the summary state; if there is no match for 3 consecutive rounds, the group switches back from the summary state to the index state and removes the summary layer. For example, in the first round of the session, the user inputs "Help me fix this bug," the intent classification activates the core editing group, injecting the summary layers of the 6 tools in the group into the context, consuming approximately 257 tokens; the target inference model decides to call the read tool, replacing the summary layer of the read tool with the complete layer (including file path, read range, and other parameter definitions), consuming approximately 207 tokens; after the target inference model completes the file read call according to the parameter definitions in the complete layer, it replaces the complete layer back with the summary layer. Throughout the process, the peak lexical consumption for tool definitions was 1,504 lexical units, a 95.3% saving compared to the 31,710 lexical units injected in full. In non-tool usage scenarios, intent classification did not activate any tool groups, and tool definitions occupied only 480 lexical units in the resident index layer, a 98.5% saving compared to full injection. The saved 31,230 lexical units can support longer dialogue contexts. If the user suddenly switches to an operation requiring tools, the corresponding tool group is activated through intent classification in this round, loading only about 350 lexical unit definitions as needed, rather than restoring all 75 definition items at once.

[0175] Compression-Accuracy Pareto Calibration Phase. During the full layer generation phase, a quantitative relationship is established between the compression level and the invocation accuracy for each tool. Five candidate compression levels are set: L0 represents the original full definition with a compression ratio of 0%, serving as the baseline for full injection; L1 performs only lossless operations, with a compression ratio of approximately 10% to 15%; L2 removes examples and supplementary descriptions from L1, with a compression ratio of approximately 25% to 35%; L3 compresses the functional description to 50% from L2, with a compression ratio of approximately 40% to 55%; L4 retains only the summary layer, with a compression ratio of approximately 70% to 85%. For each tool, a test suite is constructed, including 50 positive examples of user inputs and expected parameter outputs that should be used to invoke the tool, 20 negative examples of user inputs that should not be used to invoke the tool, and 30 parameter integrity sets of invocation scenarios with different parameter combinations. Invocation tests are performed at each candidate compression level to evaluate selection accuracy, parameter integrity rate, and parameter format correctness rate. The overall accuracy is calculated as 0.5 times the selection accuracy, 0.3 times the parameter integrity rate, and 0.2 times the parameter format correctness rate. Provided that the invocation accuracy is not lower than 95% of the full injection baseline, the candidate compression level with the highest compression degree is selected as the optimal compression level for the tool. If the invocation accuracy at all candidate compression levels is lower than the 95% threshold, the tool is marked as incompressible, and the L0 original integrity definition is always used. For example, when calibrating the tool `create_mr`, the overall accuracy rates for the five levels (L0 to L4) are 0.96, 0.955, 0.94, 0.91, and 0.87, respectively. The target accuracy rate is the product of 0.96 and 0.95, which is 0.912. The L3 level's accuracy of 0.91 is lower than the target, while the L2 level's accuracy of 0.94 is higher. Therefore, the optimal compression level for `create_mr` is determined to be L2. For the tool `executeDataCreateSkill`, the overall accuracy rates for all five levels are below 0.912, indicating it is not compressible, and the original, complete L0 definition is always used. When the tool definition changes, only that tool is recalibrated. For example, after adding the required parameter `reviewers` to `create_mr`, the parameter completeness rate at level L2 decreases. After recalibration, the optimal compression level is adjusted to L1, while the optimal compression levels for the other 59 tools remain unchanged. The optimal compression levels for each tool are stored in a cache with a 7-day validity period. Within this period, the cache is directly accessed, and recalibration is triggered immediately when the tool definition changes.

[0176] Through the above implementation process, the tool definition overhead was reduced from 31,710 lexical units in full injection to 480-1,040 lexical units, a reduction of 96.7%; the total initial context overhead was reduced from 60,000 lexical units to approximately 16,000 lexical units, a reduction of 73.3%, providing sufficient context margin for long dialogues; tool invocation accuracy was improved by 8.0%, tool coverage was improved by 31.4%, and compression-accuracy Pareto calibration ensured that the compression level of each tool met the safety boundary that the invocation accuracy was not lower than 95% of the full injection benchmark, significantly reducing context overhead without sacrificing tool invocation capabilities.

[0177] By comparing and eliminating redundant information from the description texts of various tools, determining tool summaries based on invocation conditions and compressed tool description texts, and compressing complete tool parameters based on tool features, the overhead of the tool definition's resident context is reduced from a linear increase in the full definition to a minimal overhead at the index layer. Only one copy of text repeated across tools is retained, compressing context occupancy from both structural and textual dimensions. The optimal compression level is determined through invocation testing, establishing a quantitative relationship between compression degree and invocation accuracy. This ensures that the complete parameter definitions of each tool achieve maximum compression within safe boundaries, and only incremental calibration is performed on the changed tool when tool definitions change, avoiding the computational overhead of repeated calibration for all tools.

[0178] This specification also provides a document updating device, see [link to documentation]. Figure 4 , Figure 4 This is a schematic diagram of a document updating device according to one embodiment of this specification. The document updating device includes: an acquisition module 402, a parsing module 404, and a generation module 406.

[0179] The acquisition module 402 is configured to acquire the initial document and updated description information of the initial document; The parsing module 404 is configured to perform structural parsing on the initial document, determine multiple clustered content blocks of the initial document, candidate structural patterns corresponding to the document structural features of each clustered content block, and semantic adaptation features corresponding to each candidate structural pattern. The generation module 406 is configured to use a target inference model to determine the target structural pattern that semantically matches the updated description information from each candidate structural pattern based on the initial document, updated description information and semantic adaptation features corresponding to each candidate structural pattern, and generate updated content corresponding to the updated description information based on the target structural pattern to obtain the updated document.

[0180] Optionally, the parsing module is further configured to perform structural parsing on the initial document, determine multiple content blocks with hierarchical relationships in the initial document and the document structural features of each content block; based on the similarity of the document structural features, cluster the content blocks at the same level to determine multiple clustered content blocks; based on each content block in the first clustered content block, determine the first candidate structural pattern corresponding to the first clustered content block and the semantic adaptation features corresponding to the first candidate structural pattern, wherein the first clustered content block is any one of the multiple clustered content blocks.

[0181] Optionally, the parsing module is further configured to determine a target common subsequence based on the document structure features of each content block in the first cluster, and to determine a first candidate structural pattern based on the target common subsequence, wherein the target common subsequence is the longest common subsequence among the document structure feature sequences of each content block in the first cluster; to construct semantic adaptation prompts based on the semantic features of each content block in the first cluster, and to determine the semantic adaptation features corresponding to the first candidate structural pattern based on the semantic adaptation prompts through a target inference model.

[0182] Optionally, the generation module is further configured to construct pattern adaptation prompts based on the updated description information and the semantic adaptation features corresponding to each candidate structural pattern, and based on the pattern adaptation prompts, call the target inference model to determine the target structural pattern that semantically matches the updated description information from each candidate structural pattern; construct content generation prompts based on the target structural pattern and the updated description information, and based on the content generation prompts, call the target inference model to generate updated content corresponding to the updated description information based on the target structural pattern, and obtain the updated document based on the updated content and the initial document.

[0183] Optionally, the generation module is further configured to, based on pattern adaptation prompts, invoke the target inference model to determine the semantic attributes and content complexity of the updated content to be generated by the update description information, and determine the first semantic vector of the update description information based on the semantic attributes, wherein the content complexity is used to characterize the number of structural elements required for the updated content to be generated; determine the second semantic vector corresponding to each candidate structural pattern based on the semantic features of the clustered content blocks corresponding to each candidate structural pattern; determine the first matching result between the semantic attributes and the semantic adaptation features corresponding to each candidate structural pattern through the target inference model; determine the second matching result between the content complexity and the structural capacity of each candidate structural pattern, and the third matching result between the first semantic vector and the second semantic vector; and determine the target structural pattern from each candidate structural pattern based on the first matching result, the second matching result, and the third matching result.

[0184] Optionally, the generation module is also configured to generate prompt words based on content, call the target inference model, generate updated content corresponding to the updated description information based on the target structural pattern; determine the degree of matching between the structural features of the updated content and the structural features of the target structural pattern; if the degree of matching does not meet the preset conditions, regenerate the updated content based on the difference information between the updated content and the target structural pattern until the degree of matching of the regenerated updated content meets the preset conditions; write the updated content into the initial document to obtain the updated document.

[0185] Optionally, the generation module is further configured to determine a target tool group from multiple tool groups in a preset tool library based on updated description information. The preset tool library includes tool summaries for each tool, and each tool is clustered into multiple tool groups based on the degree of functional relevance. The tool summaries are used to describe the functions and invocation conditions of the tools. Based on the tool summaries of the target tool group, the target structural pattern, and the updated description information, content generation prompts are constructed.

[0186] Optionally, the preset tool library also includes tool parameters for each tool. The generation module is further configured to generate prompt words based on content, call the target inference model, determine the target tool required to generate the updated content corresponding to the updated description information based on the summary of each tool and the target structural pattern, and obtain the tool identifier of the target tool from the summary of each tool; based on the tool identifier, obtain the target tool parameters of the target tool from the preset tool library; call the target inference model, and generate the updated content corresponding to the updated description information based on the target tool parameters and the target structural pattern.

[0187] Optionally, the document updating device further includes a tool group determination module, configured to obtain the original tool definitions of each tool; extract features from multiple original tool definitions to obtain tool features of each original tool definition, wherein the tool features are used to characterize the structural form and functional semantics of each original tool definition; cluster each tool based on the similarity of each tool feature to obtain multiple tool groups; and determine the tool summary and tool parameters of each tool based on each original tool definition and each tool feature.

[0188] Optionally, the tool group determination module is further configured to: obtain the tool description text and complete tool parameters of each tool based on each original tool definition; compare each tool description text to identify redundant information in each tool description text and remove the redundant information from each tool description text to obtain each compressed tool description text; determine the calling conditions of the tool to which each tool feature belongs based on each tool feature; determine the tool summary of each tool based on each calling condition and each compressed tool description text; and compress each complete tool parameter based on each tool feature to determine the tool parameters of each original tool definition.

[0189] The modules described above can be computer program modules running on computing devices or logic modules implemented in hardware. The functions of each module can be implemented by the processor executing corresponding computer-executable instructions, or by dedicated integrated circuits, field-programmable gate arrays, or other hardware circuits. This specification does not limit the embodiments in this way.

[0190] This specification also provides a computing device, see [link to documentation]. Figure 5 , Figure 5 This is a structural block diagram of a computing device provided in one embodiment of this specification. The computing device 500 may include a memory 510, a processor 520, a bus 530, a database 550, an access device 540, and a network 560.

[0191] Memory 510 stores computer-executable instructions. Memory 510 can be RAM, non-volatile memory, or a combination of both. Exemplary examples include read-only memory (ROM), random access memory (RAM), a disk, or an optical disk. Processor 520 executes the computer-executable instructions stored in memory 510. Processor 520 can be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), etc. Bus 530 connects memory 510 and processor 520. It can be an Industry Standard Architecture (ISA) bus, a PCI bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Database 550 stores initial documents, updated documents, preset tool libraries, structural pattern libraries, structural pattern decision logs, etc. It can be located inside computing device 500 or in other storage devices connected to computing device 500 via network 560. Access device 540 interacts with external devices, including but not limited to input / output devices such as keyboards, mice, displays, and touchscreens. Network 560 is used for communication between computing device 500 and external servers and tool execution environments, and can be a local area network, wide area network or Internet.

[0192] When the computer-executable instructions are executed by the processor 520, they implement the steps of the document update method described above. Optionally, when executing the document update method, the processor 520 may invoke a target inference model deployed on other computing devices via the network 560, or it may invoke a locally deployed target inference model. The target inference model may access a preset tool library and execute target tools via the network 560, and this embodiment of the specification does not limit this.

[0193] This specification also provides a computer-readable storage medium storing computer-executable instructions that, when executed by a processor, implement the steps of the document update method described above. The computer-readable storage medium can be any available medium or data storage device capable of storing a program, including but not limited to magnetic storage devices (such as floppy disks, hard disks, and magnetic tapes), optical discs (such as CD-ROMs and DVDs), and semiconductor memories (such as solid-state drives).

[0194] This specification also provides a computer program product, including a computer program / instructions that, when executed by a processor, implement the steps of the document update method described above. The computer program / instructions may be stored in a computer-readable storage medium in the form of source code, object code, or an executable file, or may be obtained by downloading from a network via wired or wireless means; this specification does not limit this.

Claims

1. A document updating method, characterized in that, include: Obtain the initial document and updated description information for the initial document; The initial document is subjected to structural parsing to determine multiple clustered content blocks of the initial document, candidate structural patterns corresponding to the document structural features of each clustered content block, and semantic adaptation features corresponding to each candidate structural pattern. Using a target reasoning model, based on the initial document, the updated description information, and the semantic adaptation features corresponding to each candidate structural pattern, a target structural pattern that semantically matches the updated description information is determined from each candidate structural pattern, and updated content corresponding to the updated description information is generated based on the target structural pattern to obtain an updated document.

2. The method according to claim 1, characterized in that, The step of performing structural parsing on the initial document to determine multiple clustered content blocks of the initial document, candidate structural patterns corresponding to the document structural features of each clustered content block, and semantic adaptation features corresponding to each candidate structural pattern includes: The initial document is subjected to structural parsing to determine multiple content blocks with hierarchical relationships in the initial document and the document structure features of each of the multiple content blocks; Based on the similarity of the document structural features, content blocks at the same level are clustered to determine multiple clustered content blocks; Based on each content block in the first clustered content block, a first candidate structural pattern corresponding to the first clustered content block and a semantic adaptation feature corresponding to the first candidate structural pattern are determined, wherein the first clustered content block is any one of the plurality of clustered content blocks.

3. The method according to claim 2, characterized in that, The step of determining the first candidate structural pattern corresponding to the first clustered content block and the semantic adaptation features corresponding to the first candidate structural pattern based on each content block in the first clustered content block includes: Based on the document structure features of each content block in the first clustered content block, a target common subsequence is determined, and based on the target common subsequence, the first candidate structure pattern is determined, wherein the target common subsequence is the longest common subsequence among the document structure feature sequences of each content block in the first clustered content block; Based on the semantic features of each content block in the first cluster, semantic adaptation prompts are constructed, and the semantic adaptation features corresponding to the first candidate structural pattern are determined by the target inference model based on the semantic adaptation prompts.

4. The method according to claim 1, characterized in that, The step involves using a target inference model to determine a target structural pattern that semantically matches the updated description information from among the candidate structural patterns, based on the initial document, the updated description information, and the semantic adaptation features corresponding to each candidate structural pattern. Then, based on the target structural pattern, updated content corresponding to the updated description information is generated to obtain an updated document. This includes: Based on the updated description information and the semantic adaptation features corresponding to each candidate structural pattern, a pattern adaptation prompt word is constructed. Based on the pattern adaptation prompt word, the target inference model is invoked to determine the target structural pattern that semantically matches the updated description information from each candidate structural pattern. Based on the target structural pattern and the updated description information, content is generated to generate prompt words. Based on the content, prompt words are generated. The target inference model is called to generate updated content corresponding to the updated description information based on the target structural pattern. Based on the updated content and the initial document, the updated document is obtained.

5. The method according to claim 4, characterized in that, The step of invoking the target inference model based on the pattern adaptation prompt words to determine the target structural pattern that semantically matches the updated description information from the candidate structural patterns includes: Based on the pattern adaptation prompt words, the target reasoning model is invoked to determine the semantic attributes and content complexity of the updated content to be generated indicated by the updated description information, and the first semantic vector of the updated description information is determined based on the semantic attributes, wherein the content complexity is used to characterize the number of structural elements required for the updated content to be generated; Based on the semantic features of the clustered content blocks corresponding to each candidate structural pattern, the second semantic vector corresponding to each candidate structural pattern is determined. The target reasoning model is used to determine the first matching result between the semantic attribute and the semantic adaptation feature corresponding to each candidate structural pattern; Determine the second matching result between the content complexity and the structural capacity of each candidate structural pattern, and the third matching result between the first semantic vector and the second semantic vector; Based on the first matching result, the second matching result, and the third matching result, the target structural pattern is determined from each candidate structural pattern.

6. The method according to claim 4, characterized in that, The process of generating prompt words based on the content, invoking the target inference model, generating updated content corresponding to the updated description information based on the target structural pattern, and obtaining the updated document based on the updated content and the initial document includes: Based on the content, a prompt word is generated, the target reasoning model is invoked, and the updated content corresponding to the updated description information is generated based on the target structural pattern. Determine the degree of matching between the structural features of the updated content and the structural features of the target structural pattern; If the matching degree does not meet the preset conditions, the updated content is regenerated based on the difference information between the updated content and the target structural pattern until the matching degree of the regenerated updated content meets the preset conditions. The updated content is written into the initial document to obtain the updated document.

7. The method according to claim 4, characterized in that, The step of generating prompt words based on the target structural pattern and the updated description information includes: Based on the updated description information, a target tool group is determined from multiple tool groups in a preset tool library. The preset tool library includes tool summaries for each tool. The tools are clustered into the multiple tool groups based on the degree of functional correlation. The tool summaries are used to describe the functions and invocation conditions of the tools. Based on the tool summary of the target tool group, the target structural pattern, and the updated description information, the content generation prompt words are constructed.

8. The method according to claim 7, characterized in that, The preset tool library also includes tool parameters for each tool; the step of generating prompt words based on the content, calling the target inference model, and generating updated content corresponding to the updated description information based on the target structural pattern includes: Based on the content, prompt words are generated, the target inference model is invoked, and based on the tool summaries and the target structure pattern, the target tool required to generate the updated content corresponding to the updated description information is determined, and the tool identifier of the target tool is obtained from the tool summaries. Based on the tool identifier, the target tool parameters of the target tool are obtained from the preset tool library; The target inference model is invoked, and based on the target tool parameters and the target structural pattern, the update content corresponding to the update description information is generated.

9. The method according to claim 8, characterized in that, The preset tool library is constructed in the following manner: Obtain the original tool definitions for each tool; Feature extraction is performed on the multiple original tool definitions to obtain tool features for each original tool definition, wherein the tool features are used to characterize the structural form and functional semantics of each original tool definition; Based on the similarity of the features of each tool, the tools are clustered to obtain the multiple tool groups; Based on the original tool definitions and the characteristics of each tool, the tool summary and tool parameters of each tool are determined.

10. The method according to claim 9, characterized in that, The process of determining the tool summary and tool parameters for each tool based on the original tool definitions and the tool characteristics includes: Based on the original tool definitions, obtain the tool description text and complete tool parameters for each tool; By comparing the description texts of each tool, redundant information in each tool description text is identified and removed from each tool description text to obtain the description texts of each compressed tool. Based on the features of each tool, the calling conditions of the tool to which each tool feature belongs are determined. Based on each invocation condition and the description text of each compression tool, determine the tool summary of each tool; Based on the features of each tool, the parameters of each complete tool are compressed to determine the tool parameters defined in the original tool definitions.

11. A document updating device, characterized in that, include: The acquisition module is configured to acquire an initial document and updated description information of the initial document; The parsing module is configured to perform structural parsing on the initial document, determine multiple clustered content blocks of the initial document, candidate structural patterns corresponding to the document structural features of each clustered content block, and semantic adaptation features corresponding to each candidate structural pattern. The generation module is configured to use a target inference model to determine a target structural pattern that semantically matches the update description information from the candidate structural patterns based on the initial document, the update description information, and the semantic adaptation features corresponding to each candidate structural pattern, and to generate updated content corresponding to the update description information based on the target structural pattern to obtain an updated document.

12. A computing device, characterized in that, include: Memory and processor; The memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions, which, when executed by the processor, implement the steps of the document update method according to any one of claims 1-10.

13. A computer-readable storage medium, characterized in that, It stores computer-executable instructions that, when executed by a processor, implement the steps of the document update method according to any one of claims 1-10.

14. A computer program product, characterized in that, Includes a computer program / instructions that, when executed by a processor, implement the steps of the document update method according to any one of claims 1-10.