A Method for Implementing AI Agents Based on Large Language Models and Knowledge Graphs

By combining semantic feature embedding and structural embedding alignment in the construction of the agent, the problem of the knowledge graph structure information not being explicitly organized is solved, the logical consistency and high knowledge accuracy of the response text are achieved, and the interaction stability and user experience of the agent are improved.

CN120822537BActive Publication Date: 2026-02-24SHANGHAI INTERNATIONAL STUDIES UNIVERSITY
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202510957832.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-07-11
Publication Date
2026-02-24
Estimated Expiration
2045-07-11

AI Technical Summary

Technical Problem

In existing methods for constructing intelligent agents, the structural information of knowledge graphs is not explicitly organized into controllable reasoning paths. This results in a lack of structural dependence on knowledge paths when language models generate responses, leading to prominent semantic biases and logical inconsistencies that affect the accuracy and reliability of the responses.

Method used

By collecting natural language instructions and performing semantic encoding to generate semantic feature embedding vectors, and combining them with knowledge graphs to obtain entity nodes and relationship paths, structural embedding encoding is performed. Dual-channel semantic structure alignment is then performed to generate a path candidate set, which is then structured and fused with a large language model. Path consistency verification and a fallback mechanism are implemented to ensure the logical consistency of the response text.

Benefits of technology

It effectively avoids semantic bias and logical inconsistency, improves the quality and credibility of response text, and enhances the interaction stability and user experience of the intelligent agent.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120822537B_ABST
    Figure CN120822537B_ABST
Patent Text Reader

Abstract

The application discloses an AI Agent intelligent agent implementation method based on a large language model and a knowledge graph, relates to the technical field of artificial intelligence, and comprises the following steps: embedding a semantic feature embedding vector as a query basis, acquiring entity nodes and relationship paths in a knowledge graph, and performing structural embedding coding to generate a structural embedding vector; performing double-channel semantic structure alignment on the semantic feature embedding vector and the structural embedding vector, performing alignment processing on the entity nodes and the relationship paths in the knowledge graph, and generating a path candidate set; performing structural coding on the path candidate set, generating prompt information, and inputting the prompt information to a large language model after being combined with a natural language instruction to generate a response draft; and performing path consistency verification on the response draft, executing rollback and generating a new response text draft again if the response draft is inconsistent, and outputting a final response text if the response draft is consistent. The application significantly improves the quality and reliability of the response text and enhances the interaction stability of the intelligent agent and the user experience.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of artificial intelligence technology, and in particular to an AIAgent implementation method based on a large language model and knowledge graph. Background Technology

[0002] With the continuous development of natural language processing technology, current mainstream methods for constructing intelligent agents are typically based on large-scale pre-trained language models, such as GPT and T5. These models primarily rely on neural language models to understand natural language input and generate corresponding responses. In practical applications, to improve the reliability of the agent's knowledge and its semantic response capabilities, a common approach is to introduce external knowledge bases or knowledge graphs through knowledge enhancement mechanisms to assist the language model in reasoning and answering. These mechanisms typically include: using keyword matching or entity recognition techniques to extract entities or relationships from user input; then performing queries in the knowledge graph based on keywords to retrieve relevant entity nodes or triplet information; and finally, feeding the retrieval results into the large language model in a way that supplements the context or embeds features for response generation.

[0003] The structural information of the knowledge graph is not explicitly organized into controllable reasoning paths, resulting in a lack of structural dependence on these knowledge paths when the language model generates responses. Specifically, while the model possesses the ability to generate natural language from knowledge fragments, the lack of structural modeling and semantic alignment of entities, relationships, and combinatorial paths within the graph makes it difficult for the language model to precisely control whether the reasoning process unfolds along the logical chains within the graph during response generation. This leads to semantic discrepancies or logical jumps between the final generated text content and the actual knowledge graph, thus affecting the accuracy and reliability of the response. Summary of the Invention

[0004] In view of the aforementioned existing problems, the present invention is proposed.

[0005] Therefore, this invention provides an AI Agent implementation method based on a large language model and knowledge graph to solve the problem of deviations in the semantic accuracy and logical consistency of response content.

[0006] To solve the above-mentioned technical problems, the present invention provides the following technical solution:

[0007] In a first aspect, the present invention provides a method for implementing an AI Agent based on a large language model and a knowledge graph. The method includes: collecting natural language commands and performing semantic encoding to generate semantic feature embedding vectors; using the semantic feature embedding vectors as a query basis to obtain entity nodes and relational paths in the knowledge graph, and performing structural embedding encoding to generate structural embedding vectors; performing dual-channel semantic structure alignment on the semantic feature embedding vectors and structural embedding vectors, and performing alignment processing on the entity nodes and relational paths in the knowledge graph to generate a path candidate set; performing structured encoding on the path candidate set to generate prompt information, and merging it with the natural language commands before inputting it into the large language model to generate a response draft; performing path consistency verification on the response draft, and if inconsistent, performing a rollback and regenerating a new response text draft, and if consistent, outputting the final response text; outputting the final response text to the user interface, and recording the semantic feature embedding vectors, structural embedding vectors, and path candidate sets to generate an agent behavior log.

[0008] As a preferred embodiment of the AI ​​Agent implementation method based on a large language model and knowledge graph described in this invention, the specific steps for collecting natural language instructions, performing semantic encoding, and generating semantic feature embedding vectors are as follows:

[0009] Collect task intent descriptions, entity names, operation verbs, limiting conditions, contextual constraints, and question expressions to obtain natural language instructions;

[0010] The natural language instructions are segmented and standardized to obtain a normalized word sequence. Then, a pre-trained language model encoder is used to perform context aggregation operations to generate a sentence-level semantic context representation.

[0011] The sentence-level semantic context representation is input into the embedding mapping network for feature compression and semantic mapping to generate semantic feature embedding vectors.

[0012] As a preferred embodiment of the AI ​​Agent implementation method based on a large language model and knowledge graph described in this invention, the steps of using semantic feature embedding vectors as the query basis to obtain entity nodes and relationship paths in the knowledge graph, and performing structural embedding encoding to generate structural embedding vectors are as follows.

[0013] The semantic feature embedding vector is used as the retrieval vector to calculate the semantic similarity with entity nodes in the knowledge graph and obtain a preliminary set of matching entity nodes.

[0014] Starting with the initially matched set of entity nodes, traverse the connections in the knowledge graph to obtain the set of entity nodes and relationship paths;

[0015] Each entity and its connection relationship in the entity node and relation path set is vectorized to generate a structure embedding encoding sequence, which is then input into the embedding compression network to generate a structure embedding vector.

[0016] As a preferred embodiment of the AI ​​Agent implementation method based on a large language model and knowledge graph described in this invention, the steps of performing dual-channel semantic structure alignment on semantic feature embedding vectors and structural embedding vectors, aligning entity nodes and relational paths in the knowledge graph, and generating a path candidate set are as follows.

[0017] The semantic feature embedding vector and the structural embedding vector are input into a dual-channel alignment network, and the matching score between each structural embedding vector and the semantic feature embedding vector is calculated.

[0018] The structural embedding vectors are sorted according to the matching scores, and the entity nodes with high scores are selected and combined with the relational paths to generate a preliminary path candidate set.

[0019] The initial path candidate set is mapped to a knowledge graph, path sequence information is extracted, and normalized encoding is performed to generate a normalized path candidate set.

[0020] As a preferred embodiment of the AI ​​Agent implementation method based on a large language model and knowledge graph described in this invention, the following steps are taken: The structural embedding vectors are sorted according to the matching scores, and entity nodes with high scores are selected and combined with relational paths to generate a preliminary path candidate set.

[0021] Sort the matching scores in descending order and output a sequence of structured embedding vectors arranged from highest to lowest score.

[0022] Calculate the mean and standard deviation of the matching scores, and use the combination of entity nodes and relationship paths with matching scores higher than the statistical threshold as candidates, and set the selection rules;

[0023] From the sorted sequence of structural embedding vectors, select entity nodes and relational path combinations that meet the selection rules to generate a preliminary path candidate set.

[0024] As a preferred embodiment of the AI ​​Agent implementation method based on a large language model and knowledge graph described in this invention, the steps of performing structured encoding on the path candidate set, generating prompt information, merging it with natural language instructions, and inputting it into the large language model to generate a response draft are as follows.

[0025] The entity nodes and relational path combinations in the path candidate set are structured and encoded to generate prompt information;

[0026] The prompts and natural language instructions are combined and integrated to form joint input data;

[0027] By leveraging a pre-trained large language model, deep semantic understanding and contextual analysis are performed on the joint input data, triggering a semantic reasoning and response text generation process to generate a response draft.

[0028] As a preferred embodiment of the AI ​​Agent implementation method based on a large language model and knowledge graph described in this invention, the following steps are taken: The path consistency check is performed on the response draft; if inconsistent, a rollback is executed and a new response text draft is regenerated; if consistent, the final response text is output.

[0029] The response draft and the path candidate set are semantically matched and logically consistent, the results are output and evaluated to generate a consistency judgment.

[0030] If the consistency judgment is inconsistent, the rollback mechanism is triggered, and the path candidate set and natural language instructions are re-input into the large language model to generate a new response text draft;

[0031] If the consistency judgment is consistent, the draft response will be used as the final response text.

[0032] As a preferred embodiment of the AI ​​Agent implementation method based on a large language model and knowledge graph described in this invention, the steps of outputting the final response text to the user interface and recording the semantic feature embedding vector, structural embedding vector, and path candidate set to generate an agent behavior log are as follows.

[0033] The final response text is sent to the user interface to output natural language results, and is then aggregated and processed together with semantic feature embedding vectors, structural embedding vectors, and path candidate sets to construct log data content.

[0034] The log data content is formatted and indexed to generate a behavior log containing semantic reasoning process and path reference information, and written to a specified storage area to generate an agent behavior log.

[0035] In a second aspect, the present invention provides a computer device, including a memory and a processor, wherein the memory stores a computer program, wherein: when the computer program is executed by the processor, it implements any step of the AI ​​Agent implementation method based on a large language model and knowledge graph as described in the first aspect of the present invention.

[0036] Thirdly, the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein: when the computer program is executed by a processor, it implements any step of the AI ​​Agent implementation method based on a large language model and knowledge graph as described in the first aspect of the present invention.

[0037] The beneficial effects of this invention are as follows: by integrating the structured encoding of the path candidate set with the original instructions, the response generated by the large language model is closely combined with the structural information of the knowledge graph, which effectively avoids semantic deviation and logical inconsistency, and ensures that the output text conforms to the user's intent and has high knowledge accuracy and logical rationality; at the same time, the path consistency verification and backoff mechanism constructs a closed-loop optimization process, which significantly improves the quality and credibility of the response text, and enhances the interaction stability of the intelligent agent and the user experience. Attached Figure Description

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

[0039] Figure 1 This is a flowchart of the AI ​​Agent implementation method based on a large language model and knowledge graph in this invention.

[0040] Figure 2 This is a flowchart of the semantic feature embedding vector generation process in this invention.

[0041] Figure 3 This is a flowchart of the structure embedding generation and alignment in this invention.

[0042] Figure 4 This is a flowchart of the response generation and verification process in this invention. Detailed Implementation

[0043] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, the specific embodiments of the present invention will be described in detail below with reference to the accompanying drawings.

[0044] Many specific details are set forth in the following description in order to provide a full understanding of the invention. However, the invention may also be practiced in other ways different from those described herein, and those skilled in the art can make similar extensions without departing from the spirit of the invention. Therefore, the invention is not limited to the specific embodiments disclosed below.

[0045] Secondly, the term "one embodiment" or "embodiment" as used herein refers to a specific feature, structure, or characteristic that may be included in at least one implementation of the present invention. The phrase "in one embodiment" appearing in different places in this specification does not necessarily refer to the same embodiment, nor is it a single or selective embodiment that is mutually exclusive with other embodiments.

[0046] Reference Figures 1-4 This is one embodiment of the present invention, which provides a method for implementing an AI Agent based on a large language model and knowledge graph, including the following steps:

[0047] S1. Collect natural language instructions, perform semantic encoding, and generate semantic feature embedding vectors.

[0048] S1.1 Collect task intent description, entity name, operation verb, limiting conditions, contextual constraint information and question expression to obtain natural language instructions.

[0049] Specifically, the input multi-turn interactive text or single-sentence command is segmented into sentences, and text fragments containing task intent description, entity names, operation verbs, limiting conditions, contextual constraints, and question expressions are identified and extracted. Part-of-speech tagging and named entity recognition are performed on the extracted text fragments to filter out fields that match the categories. The fields are then merged in the order of task intent description, entity names, operation verbs, limiting conditions, contextual constraints, and question expressions to form structured natural language commands.

[0050] S1.2. Perform word segmentation and standardization on the natural language instructions to obtain a normalized word sequence, and use a pre-trained language model encoder to perform context aggregation operation to generate a sentence-level semantic context representation.

[0051] Specifically, for natural language instructions, a word segmentation algorithm is used to segment the language into word sequences. The word sequences are then standardized, including unifying capitalization, removing meaningless stop words, and normalizing synonyms to form a normalized word sequence. The normalized word sequence is then input into a pre-trained language model encoder, which uses a multi-layer self-attention mechanism to capture the contextual dependencies between the normalized word sequences and perform context aggregation operations to output a sentence-level semantic context representation.

[0052] It should also be noted that the pre-training process of the pre-trained language model encoder is as follows: a large-scale corpus is constructed, covering diverse text data from multiple domains; a self-supervised learning method is used, based on a masked language model or an autoregressive language model, such as the GPT task, to train the input text; some words in the text are randomly masked or predicted sequentially, and the language model learns contextual semantic representations through a multi-layer Transformer structure, optimizing the loss function to make the prediction results as consistent as possible with the real words; after multiple rounds of iterative training, the language model parameters are gradually updated to obtain a pre-trained language model encoder with rich language understanding and generation capabilities.

[0053] S1.3 Input the sentence-level semantic context representation into the embedding mapping network, perform feature compression and semantic mapping, and generate semantic feature embedding vectors.

[0054] Specifically, each dimension vector in the sentence-level semantic context representation is used as the input feature of the embedding mapping network. Dimension compression is performed through a fully connected neural network, specifically by sequentially passing through multiple linear transformation layers, each containing an activation function, such as the ReLU function, to introduce non-linear transformation capabilities. Based on the compressed features, a semantic mapping layer is used to map the compressed sentence-level semantic context representation to the semantic embedding space. The semantic mapping layer consists of a set of linear transformation parameters with fixed dimensions, generating semantic feature embedding vectors.

[0055] S2. Using the semantic feature embedding vector as the query basis, obtain the entity nodes and relationship paths in the knowledge graph, and perform structural embedding encoding to generate structural embedding vectors.

[0056] S2.1. Use the semantic feature embedding vector as the retrieval vector, calculate the semantic similarity with entity nodes in the knowledge graph, and obtain a preliminary set of matching entity nodes.

[0057] Specifically, the semantic feature embedding vector is used as the input query vector; the existing knowledge graph entity node semantic vector index is called to read the semantic vector of each entity node; the cosine similarity function is used to calculate the similarity score between the semantic feature embedding vector and the semantic vector of each entity node, where the formula for calculating the cosine similarity function is:

[0058] ;

[0059] in, Representing vectors and Cosine similarity score between them Represents the semantic feature embedding vector. Represents the semantic vector of an entity node. Represents the vector dot product. Indicates the magnitude of the vector;

[0060] Sort all the calculated similarity scores in descending order to obtain a sequence of entity nodes with similarity scores from high to low; select a number of entity nodes with the highest similarity scores from the sorted entity node sequence, for example, select the first 20, as the initial set of matched entity nodes.

[0061] It should also be noted that the data source for the constructed knowledge graph entity node semantic vector index library is as follows: All entity node text information in the knowledge graph is obtained, specifically including entity name, alias, definitional description, hypernym and hyponym class names, and associated annotations; the text information is segmented and stop word removed to generate a standardized word sequence; then, the standardized word sequence is input into the same pre-trained language model encoder as the semantic feature embedding vector training to obtain the contextual semantic vector representation corresponding to each entity node; finally, the semantic vector representations of all entity nodes are uniformly normalized, and the unique identifier of the entity node is used as the index key to construct the knowledge graph entity node semantic vector index library.

[0062] S2.2 Starting with the initially matched set of entity nodes, traverse the connection relationships in the knowledge graph to obtain the set of entity nodes and relationship paths.

[0063] Specifically, starting with the initially matched set of entity nodes, the unique identifier of each entity node in the knowledge graph is read sequentially, and all triples with direct connections to the entity node are searched in the knowledge graph. The target entity node and its corresponding relation type are extracted to form a triple path of the starting entity, relation type, and target entity. The next level of connection is searched in the same way among the extracted target entity nodes, with the path depth limited to the maximum step size, for example, three steps. The sequence of entity nodes and relation types traversed by all paths is recorded, and finally, the set of entity nodes and relation paths is formed.

[0064] S2.3. Vectorize each entity and connection relationship in the entity node and relation path set, generate a structure embedding encoding sequence, and input it into the embedding compression network to generate a structure embedding vector.

[0065] Specifically, for each entity node, the entity name, superordinate and subordinate class names, and defining descriptive text are input into the pre-trained language model encoder, which outputs the entity node semantic vector. The relation type text and semantic annotation information of the semantic vector connections of each entity node are obtained and input into the pre-trained language model encoder, which outputs the relation type semantic vector. Each set of entity node semantic vectors and adjacent connection semantic vectors are concatenated in the order of the path to form a structure embedding encoding sequence. The structure embedding encoding sequence is input into the embedding compression network, and dimensionality reduction mapping is performed through multi-layer linear transformation and activation function to generate structure embedding vectors.

[0066] S3. Perform dual-channel semantic structure alignment on the semantic feature embedding vector and the structural embedding vector, and align entity nodes and relation paths in the knowledge graph to generate a path candidate set.

[0067] S3.1 Input the semantic feature embedding vector and the structural embedding vector into the dual-channel alignment network, and calculate the matching score between each structural embedding vector and the semantic feature embedding vector.

[0068] Specifically, the semantic feature embedding vector is input into the first channel and linearly transformed to obtain the semantic channel representation result; the structural embedding vector is sequentially input into the second channel and linearly transformed in the same dimension to obtain the structural channel representation result; the semantic channel representation result and each structural channel representation result are respectively multiplied by a dot product to obtain the matching score between the structural embedding vector and the semantic feature embedding vector; and the matching score corresponding to all structural embedding vectors is output.

[0069] S3.2 Sort the structural embedding vectors according to the matching scores, select the entity nodes with high scores and combine them with the relationship paths to generate a preliminary path candidate set.

[0070] S3.2.1 Sort the matching scores in descending order and output the structure embedding vector sequence arranged from high to low scores.

[0071] Specifically, the matching scores are bound one-to-one with the corresponding structure embedding vectors to form a set of matching score-structure embedding vector pairs; a sorting algorithm is used to sort the set of matching score-structure embedding vector pairs in descending order according to the matching scores to obtain a sequence of structure embedding vectors sorted from high to low; finally, the sorted sequence of structure embedding vectors is output.

[0072] S3.2.2 Calculate the average and standard deviation of the matching scores, and use the combination of entity nodes and relationship paths with matching scores higher than the statistical threshold as candidates, and set the selection rules.

[0073] Specifically, based on the matching score, the average matching score is calculated using the following formula:

[0074] ;

[0075] in, This represents the average score of all matches. This represents the total number of matching scores. Indicates the first Each match score Indicates the sequence number of the matching pair;

[0076] The standard deviation of the matching score is calculated using the following formula:

[0077] ;

[0078] in, This represents the standard deviation of all matching scores;

[0079] Based on the calculated average and standard deviation, the selection rule is set as follows: entity nodes with matching scores higher than the statistical threshold are combined with relationship paths as candidates.

[0080] It should also be explained that the process of setting the statistical threshold involves: collecting matching scores corresponding to all structural embedding vectors to construct a matching score set; performing distribution analysis on the matching score set to calculate basic statistics, such as median, quantiles, and standard deviation; determining the target location of highly relevant candidates based on specific needs, for example, using the 75th percentile as a reference for the upper bound of the distribution, or setting a dynamic deviation range, such as a matching score higher than the statistical mean plus a fixed deviation margin; finally, generating a statistical threshold value based on the selected criteria, and using the statistical threshold as the basis for subsequent path selection. The basis for setting the statistical threshold may include the task's accuracy requirements, the optimal interval distribution range in historical validation results, or the score interval corresponding to correctly labeled samples in manually labeled data.

[0081] S3.2.3 Filter the entity nodes and relational path combinations that meet the selection rules from the sorted structure embedding vector sequence to generate a preliminary path candidate set.

[0082] Specifically, the matching score corresponding to each group of structure embedding vectors in the sorted structure embedding vector sequence is read sequentially. It is determined whether the matching score is greater than the sum of the average matching score and the standard deviation. If the condition is met, the entity node and relation path combination corresponding to the structure embedding vector are extracted. The judgment process is repeated until the entire structure embedding vector sequence is traversed. All entity nodes and relation path combinations that meet the condition are collected and summarized to generate a preliminary path candidate set.

[0083] S3.3 Map the initial path candidate set to the knowledge graph, extract path sequence information, and perform normalized encoding to generate a normalized path candidate set.

[0084] Specifically, the system indexes and matches each combination of entity nodes and relational paths in the preliminary path candidate set to locate the corresponding entity nodes and connections in the knowledge graph; it reads the entity node identifiers and relational types in the order of connection to construct path sequence information; it performs a unified format conversion operation on each path sequence information, including entity node naming standardization, relational type label standardization, and path structure format organization, to obtain a data format that conforms to the standard; and it outputs the standardized path sequence information as a standardized path candidate set.

[0085] S4. The path candidate set is structured and encoded to generate prompt information. This information is then merged with natural language instructions and input into the large language model to generate a response draft.

[0086] S4.1 Perform structured encoding on the combination of entity nodes and relational paths in the path candidate set to generate prompt information.

[0087] Specifically, character-level word segmentation is performed on the entity node names and relation path labels contained in each set of path candidates. A fixed vocabulary mapping method is used to map each word to a corresponding word vector representation. The word vector representations are concatenated in the order of "entity name – relation type – entity name" to form the path encoding input sequence. The path encoding input sequence is input into the position encoding network, and the position index encoding of each word vector in the path is added. Average pooling is performed on the position encoded vector sequence to obtain the path encoding representation vector. The path encoding representation vector is mapped to a fixed-length prompt information vector, and the output is used as the final prompt information.

[0088] S4.2. Combine the prompts with the natural language instructions to form joint input data.

[0089] Specifically, the normalized word sequence in the natural language instruction is used as the starting part of the input, and the path encoding representation vector in the prompt information is reconstructed into text to generate structured prompt text. Then, the natural language instruction text and the structured prompt text are concatenated at the string level in a fixed order, and a connector such as "[SEP]" is used as the boundary identifier between the two parts. The concatenated text is used as the joint input data, and word segmentation is performed on the joint input data to generate a joint input sequence.

[0090] S4.3 Utilize a pre-trained large language model to perform deep semantic understanding and contextual analysis on the joint input data, triggering the semantic reasoning and response text generation process to generate a response draft.

[0091] Specifically, the normalized word sequence of the joint input data is input into a pre-trained large language model, such as the GPT model using the Transformer architecture. In the encoding stage, a self-attention mechanism is used to calculate the weights of each word and all other words in the context to obtain a globally context-dependent encoded representation. In the decoding stage, the generated sequence is initialized based on the encoding results, and combined with the historical generated word vectors and the joint input data, iterative calculations are performed through a multi-layer causal self-attention network and a positional feedforward network. When the word with the highest generation probability meets the termination condition, the generation process ends, and the generated response draft is output.

[0092] It should also be noted that the pre-training process of the pre-trained large language model includes: constructing a large-scale corpus, including encyclopedia articles, question-and-answer dialogue texts, programming code, and text data; then, the text data is segmented and encoded into corresponding word vector input sequences; during the training phase, an autoregressive language modeling task is used to predict the probability distribution of the next word based on the current context, specifically by updating parameters by minimizing the cross-entropy loss function between the predicted word and the real word; in each iteration, the input is propagated forward and backward through a multi-layer Transformer encoder and decoder, and the parameters of the large language model are updated using an optimizer such as Adam; training continues until the loss function of the large language model converges on the validation set, ultimately yielding a large language model that can be used for natural language generation and understanding tasks.

[0093] S5. Perform path consistency check on the response draft. If it is inconsistent, roll back and regenerate a new response text draft. If it is consistent, output the final response text.

[0094] S5.1 Perform semantic matching and logical consistency verification between the draft response and the candidate path set, output the verification results, evaluate them, and generate a consistency judgment.

[0095] Specifically, key entity nodes and their relationships are extracted from the response draft to form a semantic structure representation of the response; secondly, the corresponding entity nodes and relationship paths are combined from the path candidate set to form a semantic structure representation of the candidate path; a vectorized semantic matching method is used to calculate the similarity score between the semantic structure representation of the response and the semantic structure representation of the candidate path, and logical consistency is judged by combining the connection order and logical relationship of the entity nodes; a verification result is generated based on the similarity score and the logical consistency result; finally, the verification result is evaluated according to the set consistency threshold, and a consistency judgment result is output.

[0096] It should also be explained that the specific steps for setting the consistency threshold are as follows: The threshold is calculated using the mean and standard deviation based on statistical analysis of historical semantic matching scores and logical consistency judgment results. For example, the consistency threshold can be set as the mean of historical matching scores minus 0.5 times the standard deviation, serving as the critical value for judging whether the draft response and the candidate path set are consistent. Using the consistency threshold, the real-time calculated semantic matching score is compared with the consistency threshold. If the score is higher than the consistency threshold, it is judged as consistent; otherwise, it is considered inconsistent.

[0097] S5.2 If the consistency judgment is inconsistent, the rollback mechanism is triggered, and the path candidate set and natural language instructions are re-inputted into the large language model to generate a new response text draft.

[0098] Specifically, if the consistency judgment is inconsistent, the entity node and relation path combination corresponding to the next high-scoring and unused structural embedding vector is selected from the sorted structural embedding vector sequence to update the path candidate set. Then, the updated path candidate set and the current natural language instruction are input into the pre-trained large language model to perform the response text generation process based on the path candidate set, and a new response text draft is obtained. Then, the path consistency check is performed again on the new response text draft. If it is still inconsistent, the operation is repeated until a response text that satisfies the consistency judgment is consistent or the preset maximum number of backtracking times is reached.

[0099] S5.3 If the consistency judgment is consistent, then the draft response will be used as the final response text.

[0100] Specifically, if the consistency judgment is consistent, the current response draft is extracted from the output of the large language model, and then the format of the response draft is validated to ensure that the text content conforms to the preset text specifications and encoding requirements. Then, the response draft that has passed the format validation is saved as the final response text and output to the user interface for display. Finally, the generation time of the final response text and the corresponding path candidate set version information are recorded to complete the confirmation and release process of the final response text.

[0101] S6. Output the final response text to the user interface, and record the semantic feature embedding vector, structural embedding vector and path candidate set to generate an agent behavior log.

[0102] S6.1. The final response text is sent to the user interface to output the natural language result, and then aggregated and processed together with the semantic feature embedding vector, structural embedding vector and path candidate set to construct the log data content.

[0103] Specifically, the final response text is transmitted to the user interface in natural language output format, while semantic feature embedding vectors, structural embedding vectors, and path candidate sets are extracted. The natural language output, semantic feature embedding vectors, structural embedding vectors, and path candidate sets are then uniformly formatted and integrated to form a log data structure containing the response content, corresponding vector features, and path information. Finally, the log data structure is structured to ensure data fields are complete and standardized, generating the log data content.

[0104] S6.2. Organize and index the log data content to generate a behavior log containing semantic reasoning process and path reference information, and write it to the specified storage area to generate the agent behavior log.

[0105] Specifically, the log data content is formatted, including standardizing field naming, timestamp format, and data types. Next, the semantic feature embedding vectors, structural embedding vectors, path candidate sets, and associated information of the response text are structurally indexed to clarify the steps of the semantic reasoning process and corresponding path reference information, forming structured behavioral log data. This structured behavioral log data is then converted to a storage format and written to a designated storage area to generate the agent's behavioral log.

[0106] This embodiment also provides a computer device applicable to the implementation method of AI Agent based on large language models and knowledge graphs, including: a memory and a processor; the memory is used to store computer-executable instructions, and the processor is used to execute the computer-executable instructions to implement the AI ​​Agent implementation method based on large language models and knowledge graphs as proposed in the above embodiment.

[0107] The computer device can be a terminal, comprising a processor, memory, communication interface, display screen, and input devices connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores the operating system and computer programs. The internal memory provides an environment for the operation of the operating system and computer programs stored in the non-volatile storage media. The communication interface is used for wired or wireless communication with external terminals; wireless communication can be achieved through Wi-Fi, carrier networks, NFC (Near Field Communication), or other technologies. The display screen can be an LCD screen or an e-ink screen. The input devices can be a touch layer covering the display screen, buttons, a trackball, or a touchpad on the computer device's casing, or an external keyboard, touchpad, or mouse.

[0108] This embodiment also provides a storage medium storing a computer program. When executed by a processor, the program implements the AI ​​Agent implementation method based on a large language model and knowledge graph as proposed in the above embodiments. The storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as Static Random Access Memory (SRAM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Erasable Programmable Read Only Memory (EPROM), Programmable Red-Only Memory (PROM), Read-Only Memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.

[0109] In summary, this invention, through the fusion of structured encoding of the path candidate set and the original instructions, enables the response generated by the large language model to be closely integrated with the structural information of the knowledge graph, effectively avoiding semantic bias and logical inconsistency, ensuring that the output text conforms to the user's intent and possesses high knowledge accuracy and logical rationality; at the same time, the path consistency verification and backoff mechanism constructs a closed-loop optimization process, significantly improving the quality and credibility of the response text, enhancing the interaction stability of the intelligent agent and the user experience.

[0110] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.

Claims

1. An AI Agent agent implementation method based on a large language model and a knowledge graph, characterized by: Comprising, The natural language instruction is collected and semantically encoded to generate a semantic feature embedding vector, and the specific steps are as follows, Collect task intention description, entity name, operation verb, limitation condition, context constraint information and question expression to obtain natural language instruction; The natural language instruction is subjected to word segmentation and standardization processing to obtain a standardized word sequence, and a pre-trained language model encoder is used for context aggregation operation to generate a sentence-level semantic context representation; The sentence-level semantic context representation is input into an embedding mapping network for feature compression and semantic mapping to generate a semantic feature embedding vector; The semantic feature embedding vector is used as a query basis to obtain entity nodes and relationship paths in the knowledge graph, and structure embedding encoding is performed to generate a structure embedding vector, and the specific steps are as follows, The semantic feature embedding vector is used as a retrieval vector to calculate the semantic similarity with the entity nodes in the knowledge graph, and a preliminary matched entity node set is obtained; Starting from the preliminary matched entity node set, the connection relationship in the knowledge graph is traversed to obtain an entity node and relationship path set; Each entity and connection relationship in the entity node and relationship path set is vectorized to generate a structure embedding encoding sequence, which is input into an embedding compression network to generate a structure embedding vector; The semantic feature embedding vector and the structure embedding vector are subjected to double-channel semantic structure alignment, and the entity nodes and relationship paths in the knowledge graph are aligned to generate a path candidate set; The path candidate set is structured and encoded to generate prompt information, which is combined with the natural language instruction and input into a large language model to generate a response draft; The response draft is subjected to path consistency verification, if inconsistent, a rollback is performed and a new response text draft is generated, if consistent, a final response text is output; The final response text is output to the user interface, and the semantic feature embedding vector, structure embedding vector and path candidate set are recorded to generate an agent behavior log.

2. The AI Agent agent implementation method based on a large language model and a knowledge graph according to claim 1, characterized in that: The semantic feature embedding vector and the structure embedding vector are subjected to double-channel semantic structure alignment, and the entity nodes and relationship paths in the knowledge graph are aligned to generate a path candidate set, and the specific steps are as follows, The semantic feature embedding vector and the structure embedding vector are input into a double-channel alignment network to calculate the matching score between each structure embedding vector and the semantic feature embedding vector; The structure embedding vectors are sorted according to the matching scores, and the entity nodes and relationship path combinations with high matching score ranking are selected to generate a preliminary path candidate set; The preliminary path candidate set is mapped to the knowledge graph to extract path sequence information and generate a standardized path candidate set.

3. The AI Agent agent implementation method based on a large language model and a knowledge graph according to claim 2, characterized in that: The structure embedding vectors are sorted according to the matching scores, and the entity nodes and relationship path combinations with high matching score ranking are selected to generate a preliminary path candidate set, and the specific steps are as follows, The matching scores are sorted in descending order, and the structure embedding vector sequence arranged from high to low in score is output; The average value and standard deviation of the matching scores are calculated, and the entity nodes and relationship path combinations with matching scores higher than the statistical threshold are selected as candidates, and selection rules are set; Screening entity nodes and relationship path combinations meeting the selection rules from the sorted structural embedding vector sequence to generate a preliminary path candidate set.

4. The AI Agent agent implementation method based on a large language model and a knowledge graph according to claim 1, characterized in that: The path candidate set is structured and coded to generate prompt information, which is combined with the natural language instruction and input into the large language model to generate a response draft. The specific steps are as follows, The entity nodes and relationship path combinations in the path candidate set are structured and coded to generate prompt information. The prompt information is spliced and integrated with the natural language instruction to form joint input data. Using a pre-trained large language model, the joint input data is subjected to deep semantic understanding and context association analysis, triggering semantic reasoning and response text generation processes to generate a response draft.

5. The AI Agent agent implementation method based on a large language model and a knowledge graph according to claim 1, characterized in that: The response draft is subjected to path consistency verification. If it is inconsistent, a rollback is performed and a new response text draft is generated. If it is consistent, the final response text is output. The specific steps are as follows, The response draft is subjected to semantic matching and logical consistency verification with the path candidate set, and the verification result is output and evaluated to generate a consistency judgment. If the consistency judgment is inconsistent, the rollback mechanism is triggered, and the path candidate set and natural language instruction are re-input into the large language model to generate a new response text draft. If the consistency judgment is consistent, the response draft is taken as the final response text.

6. The AI Agent agent implementation method based on a large language model and a knowledge graph according to claim 1, characterized in that: The final response text is output to the user interface, and the semantic feature embedding vector, structural embedding vector, and path candidate set are recorded to generate an agent behavior log. The specific steps are as follows, The final response text is transmitted to the user interface to output natural language results, and is collectively processed with the semantic feature embedding vector, structural embedding vector, and path candidate set to construct log data content. The log data content is formatted and structured to generate a behavior log containing semantic reasoning processes and path reference information, which is written into a designated storage area to generate an agent behavior log. 7.A computer device, comprising a memory and a processor, wherein the memory stores a computer program, and the computer device is characterized in that: The processor executes the computer program to implement the steps of the AI Agent implementation method based on a large language model and a knowledge graph according to any one of claims 1-6.

8. A computer readable storage medium having stored thereon a computer program, characterized in that: The computer program is executed by the processor to implement the steps of the AI Agent implementation method based on a large language model and a knowledge graph according to any one of claims 1-6.

Citation Information

Patent Citations

  • Method, medium and system for realizing chat memory by using large language model

    CN117891925A

  • Code abstract generation method oriented to semantic structure feature joint enhancement

    CN119537579A