Intelligent agent illusion correction method and device
By parsing and globally planning the user-input questions, an execution plan is generated, inference loops and retrieval enhancements are performed, an enhanced contextual evidence set is generated, and the evidence set is filtered and optimized based on the context. An initial answer is generated based on the optimized context, and a closed-loop verification of factual and logical consistency is performed. If hallucinations are detected, corrections are made, and the process is recorded in a reflective knowledge base. This addresses the shortcomings of intelligent agents in hallucination detection and correction in the policy domain, and improves the reliability and interpretability of the answers.
Patent Information
- Application Number
- CN202511444714.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-10
- Publication Date
- 2025-11-04
AI Technical Summary
Existing technologies lack effective illusion detection and correction mechanisms in the policy field, resulting in insufficient reliability and interpretability of agent responses in long contexts and multi-turn question-and-answer sessions, especially in terms of logical consistency and self-reflection capabilities.
By parsing and globally planning the user's input questions, an execution plan is generated, inference loops and retrieval enhancements are performed, an enhanced contextual evidence set is generated, and the evidence set is filtered and optimized based on the context. An initial answer is generated based on the optimized context, and a closed-loop verification of factual and logical consistency is performed. If hallucinations are detected, corrections are made, and the process is recorded in the reflection knowledge base.
It enables the agent to self-correct and continuously optimize in long contexts and multi-turn question-and-answer sessions, reducing the incidence of hallucinations and improving the reliability and interpretability of the answers.
Smart Images

Figure CN120892546A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of artificial intelligence, and in particular to an agent hallucination correction method and device. BACKGROUND
[0002] In order to alleviate the problem of insufficient professional knowledge of general large models, the industry has proposed a retrieval-augmented generation (RAG) framework to improve the accuracy and reliability of large model question answering to some extent. However, in the application of the policy field, although the RAG framework improves the applicability of the large model to some extent, how to realize the detection and correction of hallucination in the answering process and form a self-correction ability through a logical closed loop and an agent reflection mechanism is still a technical problem to be solved at present.
[0003] The current hallucination detection and correction technology of the large model mainly includes the following: through standardized time and data comparison, the pertinence and accuracy of hallucination detection are enhanced; the entity level is used to improve the accuracy of hallucination detection and positioning by using a named entity recognition model; the output reliability is improved by using an evidence-driven correction mechanism to correct the generated content; and an iterative evaluation algorithm is used to form a closed loop process of "detection-correction-re-evaluation". However, the current method still has limited detection accuracy and adaptability, and the correction efficiency and scalability for long context are insufficient, mainly remaining in single round or limited iteration, lacking unified management of information flow and evidence chain in multi-round tasks, and lacking agent reflection ability.
[0004] Therefore, the existing technology cannot completely solve the problem of hallucination detection, correction and self-reflection optimization of the agent in long context and multi-round question answering, and a new technical solution is needed to realize the logical closed loop hallucination detection and agent reflection correction mechanism to improve the reliability and explainability of the agent answer. SUMMARY
[0005] The present application provides an agent hallucination correction method and device for solving the problem of hallucination detection, correction and self-reflection optimization of the agent in long context and multi-round question answering, realizing the logical closed loop hallucination detection and agent reflection correction mechanism, and improving the reliability and explainability of the agent answer.
[0006] In order to solve the above technical problems, the present application provides the following technical solutions: The present application provides an agent hallucination correction method, which comprises: analyzing and globally planning the problem input by the user to generate an execution plan containing at least one subtask; based on the execution plan, performing reasoning cycle and retrieval enhancement to generate an enhanced context evidence set; screening and context optimization processing is performed on the enhanced context evidence set to generate an optimized context; An initial answer is generated based on the optimized context and the question, and closed-loop verification of factual and logical consistency is performed on the initial answer to detect whether there is an illusion; If an illusion is detected, the initial answer is corrected to generate a corrected answer, and the current illusion event and the correction process are recorded to a reflection knowledge base.
[0007] Correspondingly, the application also provides an agent illusion correction device, which comprises: An analysis and planning module is configured to analyze and globally plan a question input by a user to generate an execution plan comprising at least one subtask; An evidence generation module is configured to generate an enhanced context evidence set based on the execution plan through reasoning cycles and retrieval enhancement; A screening and optimization module is configured to perform screening and context optimization processing on the enhanced context evidence set to generate an optimized context; A closed-loop verification module is configured to generate an initial answer based on the optimized context and the question, and perform closed-loop verification of factual and logical consistency on the initial answer to detect whether there is an illusion; A correction and reflection module is configured to correct the initial answer to generate a corrected answer if an illusion is detected, and record the current illusion event and the correction process to a reflection knowledge base.
[0008] Meanwhile, the application provides an electronic device comprising a processor and a memory, wherein the memory is configured to store a computer program, and the processor is configured to run the computer program in the memory to perform the steps in the above-mentioned agent illusion correction method.
[0009] In addition, the application also provides a computer-readable storage medium, which stores a plurality of instructions, and the instructions are adapted to be loaded by a processor to perform the steps in the above-mentioned agent illusion correction method.
[0010] Beneficial effects: the present application provides an agent hallucination correction method and device. Specifically, the method. The method first analyzes and globally plans the user input question, generates an execution plan containing at least one subtask, performs reasoning cycle and retrieval enhancement based on the execution plan, generates an enhanced context evidence set, then filters and optimizes the context of the enhanced context evidence set, generates an optimized context, then generates an initial answer based on the optimized context and the question, and performs closed-loop verification of the initial answer for factual and logical consistency to detect whether there is hallucination, if hallucination is detected, the initial answer is corrected to generate a corrected answer, and the hallucination event and the correction process are recorded to the reflection knowledge base. The method proposes a context enhancement and reflection framework, which solves the common hallucination phenomenon and logical deviation problem in agent question answering and automatic solution of complex problems through the closed-loop mechanism of question decomposition, global planning, reasoning cycle, retrieval enhancement, filtering and context optimization, hallucination verification and correction reflection, realizes self-correction and continuous optimization, reduces the hallucination rate, and improves the reliability and explainability of the answer. BRIEF DESCRIPTION OF DRAWINGS
[0011] The technical solutions and other beneficial effects of the present application will become apparent from the following detailed description of the specific embodiments of the present application, combined with the accompanying drawings.
[0012] Figure 1 is a scene diagram of the application embodiment of the agent hallucination correction method provided by the present application.
[0013] Figure 2 is a flowchart of the agent hallucination correction method provided by the present application.
[0014] Figure 3 is a context enhancement reasoning and reflection framework provided by the present application.
[0015] Figure 4 is a structure diagram of the agent hallucination correction device provided by the present application.
[0016] Figure 5 is a structure diagram of the electronic device provided by the present application. DETAILED DESCRIPTION
[0017] The technical solutions and other beneficial effects of the present application will become apparent from the following detailed description of the specific embodiments of the present application, combined with the accompanying drawings.
[0018] The terms “include” and “have” and any variations thereof in the specification and claims of this application are intended to cover a non-exclusive inclusion; the division of modules appearing in this application is only a logical division, and in actual application, there can be another division manner, for example, multiple modules can be combined or integrated in another system, or some features can be ignored or not executed.
[0019] In recent years, Large Language Models (LLMs) have made breakthroughs in natural language processing and intelligent question answering. Models such as ChatGPT, GPT-4o, Claude-3.5, and Llama-3 have shown strong capabilities in general dialogue, knowledge question answering, and multi-modal understanding. To alleviate the problem of insufficient professional knowledge of general large models, the industry has proposed the Retrieval-Augmented Generation (RAG) framework. This method retrieves external knowledge bases (such as policy databases and regulatory documents) before the model answers, and then inputs the retrieval results and user questions into the large model together, thereby improving the relevance and accuracy of the answers. Existing research attempts to apply the RAG method in knowledge-intensive scenarios such as law, medicine, and academia to improve the accuracy and reliability of large model question answering to some extent. However, in the application of the policy field, there are still the following problems: (1) The illusion problem is not fundamentally solved: even if RAG is introduced, the large model may still generate answers that are irrelevant to the retrieval content or logically consistent but factually incorrect. This type of “illusion” is particularly dangerous in government affairs question answering and policy-making scenarios, which may lead to misinterpretation of policies or incorrect decision-making. (2) Lack of logical consistency guarantee: existing RAG mechanisms focus on information recall, but do not systematically verify the logical consistency of the generated results. For example, when the model answers questions involving multiple clauses, it may be contradictory or inconsistent with the logic of the policy text; and when the context is too long, key information is easily lost or cut, further amplifying the illusion risk. (3) Lack of self-reflection and correction ability: existing methods mostly stop at “generation as the end”, without introducing a reflective mechanism to evaluate and correct potential incorrect answers, and cannot form a complete detection-correction closed loop. Therefore, although the RAG framework has improved the applicability of large models in the policy field to some extent, how to detect and correct illusions during the answering process and form a self-correcting ability through a logical closed loop and intelligent reflection mechanism is still a technical problem that needs to be solved.
[0020] Currently, there are many detection and correction techniques for large model hallucination. Although these techniques have achieved hallucination detection and correction to some extent, there are still the following shortcomings: (1) limited detection accuracy and adaptability. For example, it is still difficult to accurately identify hallucinations in cross-clause logic, implicit relationships, and complex policy contexts. For example, non-entity information or ambiguous concepts are easily overlooked, resulting in some hallucinations not being detected. (2) Insufficient correction efficiency and scalability. For example, existing correction methods often rely on piece-by-piece disassembly and manually set evidence rules, which are inefficient when dealing with long contexts, multiple rounds of questions and answers, or complex policy clauses. For example, in scenarios with large amounts of information and long contexts, key information is easily lost or cut, reducing the accuracy of the correction. (3) Lack of systematic logic closure. For example, existing methods mainly focus on single rounds or limited iterations, lacking dynamic management and priority retention strategies for important context information. For example, there is a lack of unified management of information flow and evidence chains in multiple rounds of tasks, resulting in continued hallucination risks, especially in policy agent scenarios. (4) Lack of self-reflection ability of agents. For example, existing solutions often rely on rules, explicit evaluation, or external knowledge prompts, lacking a self-reflection mechanism for large models. For example, it is difficult to optimize future generation strategies through error experience, making it difficult to form a continuous self-correction ability in multiple rounds of questions and answers.
[0021] To address the above problems, the present application provides an agent hallucination correction method and device, wherein the agent hallucination correction device can be integrated in an electronic device, which can be a server, a terminal, or other devices.
[0022] Please refer to Figure 1 , Figure 1 is a scene diagram of the application of the agent hallucination correction method provided by the embodiments of the present application, as Figure 1 shown, the scene can include terminals and devices, and the terminals, devices, and terminals and devices are connected and communicate through various gateways, such as the Internet, wherein the application scenario includes at least a server 101, a user terminal 102, and a database 103: The server 101 deploys a physical or virtual server of the agent system. It contains the software modules, algorithm models (such as LLM, reordering models, etc.) and computing resources required for the application. The server 101 can be a standalone server, or a server network or server cluster composed of servers; for example, the server described in the present application includes but is not limited to a computer, a network host, a database server, and an application server, or a cloud server composed of multiple servers, wherein the cloud server is composed of a large number of computers or network servers based on cloud computing (Cloud Computing). As the core brain and processing center of the entire method. It is used to receive requests from the user terminal 102 and execute the method steps of the present application.
[0023] The user terminal 102 includes a web browser or a mobile App. It contains a user interface (UI) for inputting questions, displaying answers, showing reference sources in answers (such as policy clause numbers), and possible historical session records. The user terminal 102 serves as an interface for human-computer interaction. Its main responsibilities are to receive user input questions and send them to the server 101, and to receive answers (including revised answers) returned from the server 101 and present them to the user. It is the window through which the user interacts with the entire intelligent system.
[0024] The database 103 is usually not a single library, but a set of heterogeneous data storage systems, which may include: a policy and regulation document database (storing structured policy original texts, clauses, issuing agencies, issuing times, etc.), which can include a relational database (such as MySQL) or a document database (such as MongoDB); a vector database (storing embedded vectors of policy documents for efficient semantic similarity retrieval (dense retrieval)); a reflection knowledge base (storing case data in historical tasks, including questions, evidence, incorrect answers, revision processes, and final correct answers, for few-shot learning. This can be a time-series database or a special graph database); an external knowledge graph (a graph database storing policy entities (such as agencies, projects, regulations) and their relationships for logical relationship verification). As the knowledge source and memory system of the system, it provides original policy data (through keyword or vector queries) for the evidence generation module of the server 101, and provides historical experience data for the revision reflection module, and is the basis for ensuring the factual nature of the answers and the continuous learning of the system.
[0025] A communication link is provided between the server 101, the user terminal 102, and the database 103 to enable information exchange; the communication link can include wired, wireless communication links, or optical cables, etc., which are not limited in the present application, wherein: The user asks questions to the intelligent agent through the user terminal 102, and the server 101 receives the user's questions, analyzes and globally plans the user input questions, generates an execution plan containing at least one sub-task, based on the execution plan, combines the database 103 for reasoning cycle and retrieval enhancement, generates an enhanced context evidence set, then filters and optimizes the context of the enhanced context evidence set, generates an optimized context, then generates an initial answer based on the optimized context and the question, and performs closed-loop verification of the factual nature and logical consistency of the initial answer to detect whether there is an illusion, if an illusion is detected, the initial answer is revised to generate a revised answer, and the current illusion event and revision process are recorded to the reflection knowledge base.
[0026] In the above agent illusion correction process, the user terminal 102 is the interface responsible for input and display; the server 101 is the brain responsible for all calculations and decision logic of the method of the application; the database 103 is the library and memory responsible for storing raw knowledge and historical experience. The three are connected through the network, work together, and provide high-reliability, traceable, and self-optimizing intelligent question and answer services. Among them, the server 101 solves the common illusion phenomenon and logical deviation problem in the intelligent agent question and answer and automatic solution of complex problems through the closed-loop mechanism of problem decomposition, global planning, reasoning cycle, retrieval enhancement, screening and context optimization, illusion verification and correction reflection, realizes self-correction and continuous optimization, reduces the illusion occurrence rate, and thus improves the reliability and explainability of the answer.
[0027] It should be noted that, Figure 1 The scene diagram shown is only an example, and the terminal, device, and scene described in the embodiments of the application are used to more clearly illustrate the technical solutions of the embodiments of the application, and do not constitute a limitation on the technical solutions provided by the embodiments of the application. Those skilled in the art can know that with the evolution of the system and the appearance of new business scenarios, the technical solutions provided by the embodiments of the application are also applicable to similar technical problems. The following will be described in detail. It should be noted that the description order of the following embodiments does not limit the preferred order of the embodiments.
[0028] In the embodiments of the application, please refer to Figure 2 As shown, Figure 2 is a flowchart of the agent illusion correction method provided by the embodiments of the application. The method at least includes the following steps: S201: Analyzing and globally planning the problem input by the user to generate an execution plan containing at least one subtask.
[0029] In an embodiment, step S201 includes: performing intent recognition and entity extraction on the problem input by the user to obtain a query intent and an entity; based on the query intent and the entity, decomposing the problem into multiple subtasks that can be independently retrieved and verified; and based on the logical relationship between the subtasks, generating an execution plan containing at least one subtask. Wherein, intent recognition refers to using a fine-tuned large language model (LLM) or a classification model to analyze the sentence structure, keywords and semantics, judge the user's intent (such as: query existence, compare differences, verify consistency), and output structured intent labels; entity extraction can use a named entity recognition (NER) model to identify and classify key entities in the problem (such as: location entity [Beijing], policy entity [special, specialized and new policy], measure entity [unsecured loan]); the execution plan includes subtask execution order and resource allocation strategy, etc., which can be a global execution plan (a directed acyclic graph DAG or a sequential list).
[0030] Specifically, after the query intent and entity are obtained by performing intent recognition and entity extraction on the user input question, the user question is decomposed into a series of independent retrievable and verifiable subtasks (such as retrieving a specific file and comparing clauses) based on the query intent and entity according to a preset condition or LLM reasoning. Finally, the logical dependency relationship between the subtasks (for example, task 2 depends on the output of task 1) is analyzed, and the execution order and resource allocation strategy of the subtasks are determined accordingly, so as to obtain an execution plan containing at least one subtask, which constructs an overall semantic context for subsequent reasoning and retrieval. This step ensures that the input question can be structured and systematically decomposed, laying a foundation for subsequent processing.
[0031] S202: Based on the execution plan, perform a reasoning cycle and retrieval enhancement to generate an enhanced context evidence set.
[0032] In an embodiment, step S202 includes performing a ReAct reasoning cycle step based on the execution plan, and dynamically triggering a retrieval enhancement operation according to the instructions generated by the ReAct reasoning cycle step; performing the retrieval enhancement operation to obtain a candidate information set related to the question; and performing fusion processing on the candidate information set to generate an enhanced context evidence set. Wherein, ReAct is a framework that allows LLM to alternately perform reasoning and action when answering questions; the ReAct reasoning cycle consists of three basic units, namely “action”, “observation” and “message”, which continuously correct the reasoning direction through dynamic interaction. Among them, the action (Action) is responsible for performing specific external operations or queries; the observation (Observation) is used to collect and parse feedback information; the message (Message) is responsible for summarizing and re-expressing the interaction results.
[0033] Specifically, under the guidance of the execution plan, the ReAct reasoning and acting loop is entered, first reasoning is performed to analyze the current situation of the problem and output a decision; then in the action step, the decision is converted into an executable specific action instruction, in the process, a "retrieval request" is sent to the retrieval enhancement module to trigger the retrieval enhancement operation; the retrieval enhancement module receives the retrieval request from the action step, performs the retrieval enhancement operation, and obtains an information set related to the problem; then the information set is returned to the observation step in the ReAct reasoning and acting loop, which reads, parses and understands the retrieved information, extracts the summary or key points of the retrieval information, and integrates them into the current reasoning context, which will be the core input of the next reasoning step to guide the next reasoning and action; based on the new context (original problem + historical reasoning + latest observation feedback), the reasoning step is entered again to decide the next action: whether to continue to retrieve deeper information or to synthesize the final answer, if it can be synthesized, the cycle is ended, and a candidate information set is obtained; finally, through fusion processing, an enhanced context evidence set is obtained by processing the candidate information set.
[0034] The traditional retrieval enhancement is "one-time retrieval and then generation", while the ReAct reasoning and acting loop + retrieval enhancement of the present application realizes "iterative retrieval based on reasoning" - the agent can decide what to retrieve next according to the retrieval result of the last step, and so on, until the problem is solved. This dynamic and multi-step retrieval capability improves the agent's ability to handle complex problems such as policy clause cross verification.
[0035] In an embodiment, performing the retrieval enhancement operation to obtain a candidate information set related to the problem specifically includes the following steps: adopting a first retrieval strategy to perform keyword matching retrieval and semantic similarity retrieval from the document library to obtain first retrieval information; adopting a second retrieval strategy to obtain second retrieval information; and merging the first retrieval information and the second retrieval information by a knowledge enhancement method to obtain the candidate information set related to the problem. The first retrieval strategy can include hybrid retrieval, which includes sparse retrieval and dense retrieval; the second retrieval strategy can include a web search strategy; the first retrieval information can include a first candidate document list sorted by relevance score and a second candidate document list sorted by cosine similarity score.
[0036] Specifically, by sparse retrieval (such as BM25 algorithm) in the policy document library, the matching based on word frequency and inverse document frequency is performed, the candidate documents containing the keywords are quickly recalled, the first candidate document list is obtained according to the relevance score, the deep semantic information related to semantics is captured by dense retrieval (such as vector matching based on pre-trained language model), the subtask is converted into a vector, the approximate nearest neighbor (ANN) search is performed in the vector database, the candidate documents related to semantics are recalled, and the second candidate document list is obtained according to the cosine similarity score; then through web search, real-time and external supplementary information is obtained, and the second retrieval information is obtained; finally, the knowledge enhancement means (such as entity association verification by fusing the domain knowledge graph) is introduced, and the first retrieval information and the second retrieval information are merged to obtain the candidate information set related to the question input by the user.
[0037] In an embodiment, the specific steps of performing fusion processing on the candidate information set to generate the enhanced context evidence set can include: calculating the content similarity between different candidate information in the candidate information set, and performing deduplication processing on highly repetitive information; based on the authority, timeliness and relevance to the subtask of the information source, a weight is assigned to each candidate information; based on the weight, the candidate information is prioritized and weighted fused to generate the enhanced context evidence set. Specifically, the unique fusion of the candidate information set obtained by the foregoing retrieval and knowledge enhancement is "deduplication-complement-priority weighting", which ensures to provide "coverage breadth + semantic depth + factual accuracy" evidence support for reasoning. It should be noted that the deduplication processing can also be performed according to the document ID or content hash value of the candidate information set.
[0038] S203: performing screening and context optimization processing on the enhanced context evidence set to generate an optimized context.
[0039] In an embodiment, step S203 comprises: sorting the enhanced context evidence set to obtain a sorted context evidence set by using cross-encoder reordering and information rearrangement; screening high-priority evidence content based on a preset hot channel memory management strategy based on importance scoring and routing decision of the sorted context evidence set; and generating optimized context by performing context optimization processing on the high-priority evidence content. The cross-encoder reordering refers to fine relevance scoring and reordering of the preliminary retrieved document list to screen out the most relevant Top-K documents from the mass of candidate documents, solving the problem of "which document is more relevant"; the information rearrangement is the structural optimization of the context content finally input to the large language model (LLM), adjusting the internal order to adapt to the attention characteristics of the LLM, preventing key information from being ignored, solving the problem of "how to organize the context so that the model can understand and remember"; the hot channel memory management strategy refers to the strategy of preferentially retaining information that is frequently used in the reasoning chain and is essential to the final answer in the context; and the context optimization processing can include redundancy cleaning (pruner), archive compression (abstractor), and organization splicing.
[0040] It should be noted that the retrieval process in step S203 is fast but may not be accurate, and sparse retrieval may only match keywords but not be semantically relevant, and dense retrieval may find semantically relevant but not factually matching documents. Cross-encoder reordering as a "refining" step uses a more powerful but more resource-consuming model to score the TOP candidates again, significantly improving the quality of the final evidence set. In addition, the large language model has a "Lost in the Middle" phenomenon: the model pays the most attention to the information at the beginning and end of the input context, and the memory and understanding effect is the best, while the information in the middle part is easy to be ignored. Even if the most relevant documents are found through cross-encoder reordering, if they are simply spliced together, the key information may be "invisible" to the model if it falls in the middle of the long context, therefore, information rearrangement is needed to actively adjust the structure of the context in the enhanced context evidence set.
[0041] Specifically, the enhanced context evidence set will be reordered across the encoder, and further adjusted by information rearrangement to reduce the "Lost in the Middle" problem by adjusting the key information to the beginning and end of the context, obtaining the ordered context evidence set, so as to ensure the significance and availability of key information in the context. After sorting, although the document highly related to the task has been obtained, in practical application, it may still face the problem of too long or redundant context. Therefore, the system introduces a hot path memory management mechanism, combined with a trimmer-summarizer, to flexibly select different strategies according to the input length and task requirements to enter the memory and compression link. Among them, the preset hot path memory management strategy is adopted to score and route the importance of the ordered context evidence set (based on timeliness, relevance, redundancy, etc.), which specifically includes: calculating the importance score of each piece of evidence content in the ordered context evidence set, and the score is based on but not limited to "relevance to user questions, freshness of information, authority in policy system, and frequency of appearance in multiple retrievals"; then, set the importance score threshold, mark the evidence content higher than the threshold as hot path content, and determine its retention strategy and duration, and ensure that these key information will not be forgotten or mis-trimmed in multiple rounds of reasoning through marking, indexing or caching, so as to screen out high-priority evidence content.The high-priority evidence content is context-optimized to generate an optimized context, which specifically includes: for evidence marked as hot channel content but too long in length, a summarizer is scheduled to compress and archive it, trimming unnecessary or low-value information to ensure that the input does not exceed the maximum token length of the model, retaining core content and traceability information, thereby lightening the processing tool, significantly reducing token occupation in a short time, ensuring that limited window space prioritizes high-weight evidence and pushes key information to the beginning and end of the context; for redundant or repetitive evidence with an importance score below a threshold, a trimmer is scheduled to delete or place it in cold storage, and when the information cannot be directly retained, the information is compressed by generating a summary (for example, using a combination of extractive and generative methods to extract entities, values, and conditions, and embedding an "evidence roadmap" (source, clause number, timestamp) in the summary boundary to maintain traceability and evidence chain integrity across clauses), thereby reducing token occupation while retaining the core; finally, the final evidence segments after the foregoing process are input to a context assembler, which uses a structured format such as ChatML to organize and splice all evidence segments, user questions, and system instructions, explicitly labels regulatory provisions, judicial interpretations, and policy documents as independent evidence segments, and establishes attention convergence points in combination with the organization form of "evidence catalog-clause index-anchor summary". Finally, the generated optimized context is compact and complete, providing traceable and high-confidence input for downstream large models, thereby significantly improving the accuracy and stability of the generated results.
[0042] S204: generating an initial answer based on the optimized context and the question, and performing closed-loop verification of the initial answer for factual and logical consistency to detect whether there is an illusion.
[0043] In an embodiment, step S204 includes: generating an initial answer based on the optimized context and the question; extracting a key entity from the question and obtaining a related attribute description of the key entity based on the initial answer; performing factual verification on the key entity and the related attribute description according to a preset evaluation criterion to obtain a verification result; and comparing the logical consistency of multiple verification results to detect whether there is an illusion.
[0044] Specifically, a key entity e (such as a city name) is extracted from the question using an LLM or information extraction model, and a related attribute description p (such as a certain policy measure of the city) of the entity is obtained from the initial answer; based on the entity e and the attribute p, the large model is asked again to confirm or deny whether the relationship between e and p conforms to the facts, and a verification result is obtained; the above steps are repeated multiple times, and the logical consistency of multiple verification results is compared to determine whether there is an illusion or logical conflict in the answer.
[0045] S205: If the illusion is detected, the initial answer is corrected, the corrected answer is generated, and the current illusion event and correction process are recorded to the reflection knowledge base.
[0046] In an embodiment, step S205 includes: identifying the illusion segment of the initial answer based on the detection result; decomposing the task of correcting the illusion segment into independent sub-correction tasks; constructing a prompt word for correction; generating corrected content for the sub-correction task according to the prompt word; iterating the correction process, synthesizing the corrected answer based on the corrected content; recording the current illusion event and the correction process to the reflection knowledge base. Wherein, the prompt word can be a few-shot prompt word, including system role, error example (showing the illusion segment that needs to be corrected), correct evidence (providing real information extracted from the augmented context that contradicts the illusion segment), correction example (extracting one or two successful correction cases of similar scenarios from the reflection knowledge base as a demonstration), and instructions (explicitly requiring the model to correct according to the given evidence), etc. Through the pre-test and later use of the agent, a number of examples of the existence or non-existence of "illusion" can be accumulated, and based on these examples, a few-shot prompt word for correction can be constructed. The key of the few-shot prompt word is how to let the model grasp the core features of the task through a few examples, and make accurate prediction without a large amount of data support. For example, add factual content such as "Beijing special expertise and new policy no guarantee related support measures" in the prompt word for repairing "illusion", to assist the secondary repair of the answer.
[0047] Specifically, based on the results of the previous hallucination detection step (such as entity-attribute verification failure or logical conflict report), the specific hallucination fragments are accurately located in the initial answer. For example, if the initial answer claims that "a certain city's policy provides non-guaranteed loans", but there is no such provision in the evidence base, then the assertion "provides non-guaranteed loans" is identified as a hallucination fragment. The macro task of "correcting hallucination fragments" is decomposed into independent sub-correction tasks for each identified hallucination fragment. For example, if there are two incorrect assertions A and B in the answer, the system will generate two sub-tasks: correct assertion A and correct assertion B. This decomposition achieves separation of concerns, making the correction process more focused and controllable. Then, for each sub-correction task, a highly structured prompt for correction is dynamically constructed. The constructed prompt is input into a large language model (LLM), which outputs the corrected content for that specific hallucination fragment based on the provided evidence and instructions. For example, for the hallucination fragment "provides non-guaranteed loans", the LLM may output the corrected content as "does not provide non-guaranteed loans, but provides low-guarantee loans with government interest subsidies". The steps of decomposing sub-correction tasks and generating corrected content are iteratively executed until all identified hallucination fragments have been independently corrected. After that, the system integrates and synthesizes the corrected content output by all sub-correction tasks with the correct parts of the initial answer that are not identified as hallucinations, to finally form a complete and consistent corrected answer. Finally, the system records the complete trajectory of this task, including the user's question, the initial answer, the identified hallucination fragments, the correction prompts used, the corrected content, and the final corrected answer, as a structured learning case and stores it in the reflection knowledge base. This case will be retrieved in the future when processing similar problems, serving as a few-shot example to guide the model, thereby realizing the continuous self-optimization of the system.
[0048] It should be noted that the repair of each incorrect description detected in the "hallucination" detection step naturally decomposes the "hallucination" correction task into smaller sub-tasks, effectively improving the efficiency and accuracy of the repair. This detection-repair process is actually a mechanism for the agent to reflect on itself, learn from mistakes, and improve future answers. The present application generates the final answer in combination with the optimized context and the results of the reflective evaluation. This process focuses on maintaining information integrity while improving the clarity and conciseness of the expression, so that users can quickly obtain the required information. The generated answer not only maintains logical consistency, but also has high relevance, reliable facts, and strong pertinence in content, meeting high-standard application requirements such as intelligent question answering, complex problem solving, and policy-assisted decision-making.
[0049] In an embodiment, recording the current hallucination event and the correction process to the reflection knowledge base specifically includes the following steps: recording an event log of hallucination detection; based on the event log, abstracting a correction case and storing it to the reflection knowledge base. The event log at least includes: user question, initial answer, detected hallucination fragment, used evidence set, and final corrected answer.
[0050] Specifically, after each hallucination detection is completed, whether the detection result contains hallucination or not, the system generates a complete and structured event log, which mainly includes: task input (user's original question), processing process (enhanced context evidence set searched and used by the system to answer the question), initial output (initial answer generated by the LLM based on the above context), detection result (detailed report of the hallucination detection link, including: whether hallucination is detected, specific location / content of hallucination, evidence relied on for verification, and verification conclusion (such as "the relationship between entity 'certain city policy' and attribute 'providing unsecured loans' does not exist"), and final result (final answer after correction (if needed)). Instead of simply archiving the original event log, the application intelligently abstracts and refines it, extracting the most core elements from the event log, such as: question pattern: the type of the question processed (such as "policy clause existence verification"); error pattern: the type of hallucination (such as "fictional non-existent policy clause"); key evidence: core evidence characteristics used for falsification or correction; successful correction strategy: effective correction prompt word template or method this time. Finally, these abstracted core elements are constructed into a structured correction case, which is then classified and stored in the reflection knowledge base. This knowledge base is essentially a case database that can be quickly searched, and it is the "cerebral cortex" of the system that accumulates experience and grows wisdom.
[0051] It should be noted that by recording the log, the system retains the original facts; by abstracting into cases, the system extracts transferable solution patterns. This enables the system to directly call relevant successful cases as a reference when encountering similar problems in the future, thereby avoiding repeating the same mistakes and achieving evolution from "post-correction" to "pre-prevention", forming a real closed-loop learning mechanism.
[0052] In an embodiment, step S205 further includes: closed-loop verification of the corrected answer for factual and logical consistency; if the verification result shows that there is still hallucination in the corrected answer, it is determined that the current correction fails; obtaining the execution information of the current task and feeding back the execution information to the global planning link as a feedback signal; based on the feedback signal, adjusting the task analysis strategy and regenerating the execution plan.
[0053] Specifically, the application describes a high-level closed-loop feedback process for dealing with stubborn hallucination problems that cannot be solved by one-time correction. After generating the corrected answer, the system does not immediately output it as the final result, but instead performs a factual and logical consistency verification again. This process will conduct a new round of inspection on the corrected answer with the same strict standards as verifying the initial answer. This ensures that the effectiveness of the correction is objectively evaluated, preventing the situation of "correcting mistakes with mistakes" or incomplete correction. If the verification result shows that there are still factual errors or logical contradictions in the corrected answer, the system formally determines that "this correction fails". Subsequently, the complete "execution information" of this task is collected, including: the user's original question, all evidence retrieved, the initial answer, the correction process record, the failed corrected answer, and a detailed verification failure report (indicating which parts are still wrong), and then this complete execution information is packaged as a strong feedback signal and fed back (feedback) to the "global planning link" at the beginning of the process. After receiving this feedback signal, the global planner of the global planning link will be "activated". Instead of simply performing regular analysis, it will conduct "diagnosis" based on the feedback information to analyze the failure cause. For example, it may be that the initial problem decomposition method is unreasonable, ignoring key sub-questions; or there is a bias in understanding the user's intention. Finally, according to the diagnosis result, a new execution plan different from the first attempt is developed. For example, it may: adopt a more refined problem decomposition method, add a sub-task of "cross-verification of policy A and policy B"; adjust the retrieval strategy to preferentially query more authoritative or specific knowledge sources; change the reasoning path to approach the problem from another angle. This new plan will start a new round of complete process (retrieval-> generation-> verification), thus providing a second, and possibly more successful, opportunity to solve the complex problem.
[0054] It should be noted that this series of steps endows the system with a high-level intelligence of "knowing and correcting" and "understanding and being flexible". Instead of mechanically repeating corrections, it can "rework" when encountering bottlenecks and find new solutions from a higher planning level, greatly enhancing the robustness and final success rate of the system in dealing with difficult cases, forming a truly powerful and strategically deep self-correcting closed loop.
[0055] As can be seen from the above embodiments, the hallucination correction method of the intelligent agent of the application, based on the traditional retrieval-enhanced generation framework, realizes multi-level detection, correction and suppression of hallucination through context-enhanced reasoning, hot channel memory management, multi-source evidence fusion and reflective evaluation and repair technology, thereby significantly improving the accuracy, credibility and traceability of policy-based answers. It solves the problems of severe hallucination, insufficient retrieval and context utilization, and lack of specialized hallucination detection and correction mechanisms that are common in traditional retrieval-enhanced generation-based methods.
[0056] As Figure 3 shown, Figure 3 is a context-enhanced reasoning and reflection framework provided by the embodiments of the present application. The framework builds a closed-loop mechanism from problem analysis, global planning, ReAct reasoning cycle, retrieval enhancement, ranking optimization, memory and context, reflection evaluation, illusion detection, and illusion correction, to realize self-correction and continuous optimization. The framework manages context information and the reasoning process through structuring, so that the policy agent significantly improves the reliability, factuality, and explainability of the answers in multiple rounds of question answering and cross-clause verification. The illusion detection process automatically identifies potential false information or clause conflicts through named entity recognition, information extraction, and logical consistency detection, ensuring the factuality and logical reliability of the generated content. In addition, the illusion correction and reflection strategy decomposes the detected illusions or clause conflicts into sub-tasks, gradually corrects them through prompting the large model, and records the correction experience to form a reflection library for optimizing future generation strategies, achieving self-optimization in multiple rounds of question answering or cross-clause verification. Memory and context introduce hot path memory management, trimmer, and summarizer, which flexibly select strategies according to input length, clause importance, and task requirements, to ensure that key information is prioritized, reduce the risk of illusions caused by context loss, and improve the traceability of generated content.
[0057] Specifically, the present application can be used in the multiple rounds of question answering scenario of policy agents. The user asks the question "Does the latest small and medium-sized enterprise support policy in a certain city contain no-guarantee loan measures?" through the user terminal. The server receives the question, first performs structured decomposition and global planning on the question, generates two sub-tasks: one is to retrieve the latest small and medium-sized enterprise policy document in the city, and the other is to analyze whether the clause contains no-guarantee loan measures; then, through the ReAct reasoning cycle, relevant policy clauses and historical cases are obtained by combining sparse retrieval, dense retrieval, and local policy database, and the retrieval results are de-duplicated, weighted, and context-optimized through ranking optimization, memory and context steps to form evidence segments; during the answer generation process, named entity recognition and information extraction techniques are used to detect potential false information, such as identifying whether the "no-guarantee loan" clause actually exists, if the model-generated answer does not match the original policy text, the large model is prompted for correction through a logical closed loop, and the correction experience is recorded to achieve reflection optimization; the final generated answer is "According to Article 3 of the Small and Medium-sized Enterprise Support Policy (2025) of a certain city, the city does have no-guarantee loan support measures, with a maximum loan amount of 500,000 yuan", which not only ensures the completeness and logical consistency of the information, but also traces back to the specific clause source.
[0058] The present application can also be applied to the scenario of cross-clause logic verification of a policy agent, for example, a user wants to verify whether the funding support clause and the supervision and examination clause in the green and low-carbon industry support policy of a certain province are consistent. The server first receives the user question, structurally decomposes the task, and generates sub-tasks: one is to retrieve the content of the funding support clause and the supervision and examination clause, and the other is to analyze the logical dependency relationship between the clauses; then, relevant clause information is obtained through sparse retrieval, dense retrieval and policy knowledge graph, and is integrated to form a structured context; in the process of generating an answer, the server uses named entity recognition and information extraction technology to detect hallucination of potential false or conflicting information, for example, finding the contradiction of "funding support amount of 500,000 yuan, but the supervision and examination clause requires 30,000 yuan standard examination"; through the logic closed loop mechanism, the large model is prompted for correction, so that the clause logic remains consistent, and the correction operation is recorded for agent reflection optimization; finally, the output answer is "the funding support amount is 500,000 yuan, and the supervision and examination clause has been updated to be consistent with the funding clause", which not only ensures the consistency of the clause logic and the completeness of the information, but also traces back to the specific clause source, thereby significantly improving the reliability, factuality and explainability of the policy agent in the cross-clause verification scenario.
[0059] The context-enhanced reasoning and reflection framework (CERRF) of the present application solves the common hallucination phenomenon and logical deviation problem in intelligent question answering and automatic solution of complex problems. Through the closed loop mechanism of question analysis, global planning, reasoning cycle, retrieval and sorting, memory and context management, and reflection evaluation and detection correction, self-correction and continuous optimization are realized, thereby significantly improving the reliability and explainability of the answer.
[0060] Based on the content of the above embodiment, the embodiment of the present application provides an agent hallucination correction device, specifically, referring to Figure 4 The device comprises: The analysis and planning module 301 is configured to analyze and globally plan the question input by the user, and generate an execution plan comprising at least one sub-task; The evidence generation module 302 is configured to generate an enhanced context evidence set based on the execution plan, through reasoning cycle and retrieval enhancement; The screening and optimization module 303 is configured to screen and context-optimize the enhanced context evidence set, and generate an optimized context; The closed loop verification module 304 is configured to generate an initial answer based on the optimized context and the question, and perform closed loop verification of the initial answer in terms of factuality and logical consistency, to detect whether there is hallucination; The correction reflection module 305 is configured to correct the initial answer if the illusion is detected, generate a corrected answer, and record the current illusion event and the correction process to the reflection knowledge base.
[0061] In an embodiment, the resolution planning module 301 comprises: An identification and extraction module is configured to perform intent identification and entity extraction on the user input question to obtain a query intent and entities. A question disassembly module is configured to disassemble the question into a plurality of sub-tasks that can be independently searched and verified based on the query intent and entities. A planning generation module is configured to generate an execution plan containing at least one sub-task based on the logical relationship between the sub-tasks.
[0062] In an embodiment, the evidence generation module 302 comprises: An inference cycle module is configured to perform ReAct inference cycle steps based on the execution plan and dynamically trigger retrieval enhancement operations according to instructions generated by the ReAct inference cycle steps. A retrieval enhancement module is configured to perform retrieval enhancement operations to obtain a candidate information set related to the question. An information fusion module is configured to perform fusion processing on the candidate information set to generate an enhanced contextual evidence set.
[0063] In an embodiment, the retrieval enhancement module comprises: A first retrieval module is configured to perform keyword matching retrieval and semantic similarity retrieval from the document library using a first retrieval strategy to obtain first retrieval information. A second retrieval module is configured to obtain second retrieval information using a second retrieval strategy. A knowledge enhancement module is configured to merge the first retrieval information and the second retrieval information to obtain a candidate information set related to the question by a knowledge enhancement method.
[0064] In an embodiment, the screening optimization module 303 comprises: A sorting module is configured to sort the enhanced contextual evidence set to obtain a sorted contextual evidence set using cross-encoder reordering and information rearrangement. A screening module is configured to perform importance scoring and routing decision on the sorted contextual evidence set based on a preset hot channel memory management strategy to screen out high-priority evidence content. A context optimization module is configured to perform context optimization processing on the high-priority evidence content to generate an optimized context.
[0065] In an embodiment, the closed-loop verification module 304 comprises: An initial answer generation module is configured to generate an initial answer based on the optimized context and the question. The acquisition module is configured to extract a key entity from a question and obtain a relevant attribute description of the key entity based on an initial answer; The verification module is configured to perform factual verification on the key entity and the relevant attribute description according to a preset evaluation criterion to obtain a verification result; The hallucination detection module is configured to compare logical consistency of multiple verification results to detect whether hallucination exists.
[0066] In an embodiment, the correction reflection module 305 includes: The hallucination identification module is configured to identify a hallucination segment of the initial answer based on the detection result; The task decomposition module is configured to decompose a task of correcting the hallucination segment into independent sub-correction tasks; The prompt word construction module is configured to construct a prompt word for correction; The content correction module is configured to generate corrected content for the sub-correction task according to the prompt word; The correction iteration module is configured to iterate a correction process, and synthesize a corrected answer based on the corrected content; The reflection recording module is configured to record the current hallucination event and the correction process to a reflection knowledge base.
[0067] In an embodiment, the reflection recording module includes: The log recording module is configured to record an event log of hallucination detection; The case storage module is configured to abstract a correction case based on the event log and store the correction case to the reflection knowledge base.
[0068] In an embodiment, the agent hallucination correction apparatus further includes: The correction verification module is configured to perform closed-loop verification on the corrected answer in terms of factual consistency and logical consistency; The correction determination module is configured to determine that the current correction fails if the verification result indicates that hallucination still exists in the corrected answer; The information backflow module is configured to obtain execution information of the current task and use the execution information as a feedback signal to backflow to the global planning link; The planning adjustment module is configured to adjust a task analysis strategy and regenerate an execution plan based on the feedback signal.
[0069] Unlike the current technology, the agent hallucination correction apparatus provided by the present application sets an analysis planning module, an evidence generation module, a screening and optimization module, a closed-loop verification module, and a correction reflection module. Through the synergistic effect of these modules, the hallucination phenomenon and logical deviation problem commonly seen in agent question answering and automatic solution of complex problems are solved, self-correction and continuous optimization are achieved, the hallucination occurrence rate is reduced, and the reliability and explainability of the answer are improved.
[0070] Accordingly, the embodiments of the present application also provide an electronic device, such as Figure 5 As shown in the figure, the electronic device can include a processor 401 with one or more processing cores, a wireless (WiFi) module 402, a memory 403 with one or more computer readable storage media, an audio circuit 404, a display unit 405, an input unit 406, a sensor 407, a power supply 408, and a radio frequency (RF) circuit 409, and the like. Those skilled in the art can understand that Figure 5 The structure of the electronic device shown in the figure does not constitute a limitation on the electronic device, and can include more or fewer components than the figure, or combine certain components, or different component arrangements. Among them: The processor 401 is the control center of the electronic device, which connects all parts of the electronic device through various interfaces and lines, executes various functions of the electronic device and processes data by running or executing software programs and / or modules stored in the memory 403 and calling data stored in the memory 403, thereby overall monitoring the electronic device. In an embodiment, the processor 401 can include one or more processing cores; preferably, the processor 401 can integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface and application programs, etc., and the modem processor mainly processes wireless communication. It can be understood that the above-mentioned modem processor can also not be integrated into the processor 401.
[0071] WiFi belongs to short-range wireless transmission technology, and the electronic device can help users send and receive emails, browse web pages and access streaming media through the wireless module 402, etc., which provides users with wireless broadband Internet access. Although Figure 5 The wireless module 402 is shown, but it can be understood that it does not belong to the necessary components of the terminal, and can be omitted according to needs without changing the essence of the application.
[0072] The memory 403 can be used to store software programs and modules, and the processor 401 executes various functions and data processing by running the computer programs and modules stored in the memory 403. The memory 403 can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, at least one application program required by a function (such as a sound playing function, an image playing function, etc.), and the like; and the data storage area can store data created according to the use of the terminal (such as audio data, a phone book, etc.), and the like. In addition, the memory 403 can include a high-speed random access memory, and can also include a non-volatile memory, such as at least one magnetic disk storage device, a flash memory device, or other volatile solid-state memory device. Accordingly, the memory 403 can also include a memory controller to provide access to the memory 403 for the processor 401 and the input unit 406.
[0073] The audio circuit 404 includes a speaker that can provide an audio interface between the user and the electronic device. The audio circuit 404 can convert received audio data into an electrical signal and transmit the electrical signal to the speaker for conversion into an audible signal.
[0074] The display unit 405 can be used to display information input by the user or information provided to the user and various graphical user interfaces of the terminal, which can be composed of graphics, text, icons, video and any combination thereof. The display unit 405 can include a display panel, which in one embodiment can be configured in the form of a liquid crystal display (LCD), an organic light-emitting diode (OLED), etc. Further, a touch-sensitive surface can cover the display panel, which transmits to the processor 401 when the touch-sensitive surface detects a touch operation on or near the touch-sensitive surface to determine the type of touch event, and then the processor 401 provides corresponding visual output on the display panel according to the type of touch event. Although in the above embodiment, the touch-sensitive surface and the display panel are realized as two independent components to realize the input and output functions, in some embodiments, the touch-sensitive surface and the display panel can be integrated to realize the input and output functions. Figure 5
[0075] The input unit 406 can be configured to receive input of digital or character information, and generate a key signal, a mouse signal, a joystick signal, an optical or trackball signal associated with user manipulation and function control. Specifically, in one embodiment, the input unit 406 can include a touch-sensitive surface and other input devices. The touch-sensitive surface, also known as a touch display or a touchpad, can collect touch operations (e.g., operations by a user using a finger, a stylus, or any suitable object or accessory near or on the touch-sensitive surface) thereon or thereabout, and drive corresponding connected devices according to a pre-set program. In one embodiment, the touch-sensitive surface can include two parts, a touch detection device and a touch controller. The touch detection device detects the touch position of the user and detects a signal caused by the touch operation, and transmits the signal to the touch controller. The touch controller receives the touch information from the touch detection device, converts it into touch coordinates, and sends it to the processor 401, and can also receive commands from the processor 401 and execute them. In addition, the touch-sensitive surface can be implemented in various types such as resistive, capacitive, infrared, and surface acoustic wave. In addition to the touch-sensitive surface, the input unit 406 can also include other input devices. Specifically, the other input devices can include one or more of a physical keyboard, function keys (such as volume control keys, on / off keys, etc.), a trackball, a mouse, a joystick, etc.
[0076] The electronic device can also include at least one sensor 407, such as a light sensor. Specifically, the light sensor can include an ambient light sensor and a distance sensor, wherein the ambient light sensor can adjust the brightness of the display panel according to the brightness of the ambient light. The electronic device can also be equipped with a gyroscope, a barometer, a hygrometer, a thermometer, an infrared sensor, and other sensors, which are not described here.
[0077] The electronic device also includes a power supply 408 (such as a battery) for powering each of the components. Preferably, the power supply can be logically connected to the processor 401 through a power management system, so that the power management system can realize functions such as management of charging, discharging, and power consumption management. The power supply 408 can also include one or more DC or AC power sources, a recharging system, a power failure detection circuit, a power converter or inverter, a power status indicator, and any other components.
[0078] The radio frequency circuit 409 can be used for receiving and sending signals in the process of information or communication, in particular, receiving the downlink information of the base station and handing it over to one or more processors 401 for processing; in addition, sending the data related to the uplink to the base station. Generally, the radio frequency circuit 409 includes but is not limited to an antenna, at least one amplifier, a tuner, one or more oscillators, a Subscriber Identity Module (SIM) card, a transceiver, a coupler, a Low Noise Amplifier (LNA), a duplexer, etc. In addition, the radio frequency circuit 409 can also communicate with the network and other devices through wireless communication. Wireless communication can use any communication standard or protocol, including but not limited to Global System of Mobile communication (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Long Term Evolution (LTE), email, Short Messaging Service (SMS), etc.
[0079] Although not shown, the electronic device can also include a camera, a Bluetooth module, etc., which will not be described here. In particular, in the present embodiment, the processor 401 in the electronic device will load the executable file corresponding to the process of one or more application programs into the memory 403 according to the following instructions, and run the application program stored in the memory 403 by the processor 401, thereby realizing the following functions: analyzing and globally planning the question input by the user, and generating an execution plan containing at least one subtask; based on the execution plan, performing a reasoning cycle and retrieval enhancement to generate an enhanced context evidence set; screening and context optimization processing the enhanced context evidence set to generate an optimized context; generating an initial answer based on the optimized context and the question, and performing closed-loop verification of the initial answer for factual and logical consistency to detect whether there is an illusion; if an illusion is detected, modifying the initial answer to generate a modified answer, and recording the current illusion event and the modification process to a reflection knowledge base.
[0080] Those skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructions, or by related hardware controlled by the instructions, which can be stored in a computer readable storage medium and loaded and executed by a processor.
[0081] To this end, an embodiment of the present application provides a computer readable storage medium, which stores a plurality of instructions capable of being loaded by a processor to implement the functions of the above-mentioned agent hallucination correction method.
[0082] The computer readable storage medium can include a read only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0083] The above describes the agent hallucination correction method, device, electronic device and computer readable storage medium provided by the embodiments of the present application in detail, and the principles and implementation manners of the present application are described by applying specific examples; the above embodiment is only used to help understand the method and its core idea of the present application; meanwhile, for those skilled in the art, according to the idea of the present application, the specific implementation manner and application range will be changed, and the above description should not be understood as limiting the present application.
Claims
1. A method for correcting hallucinations in intelligent agents, characterized in that, The method includes: The system parses and performs global planning on the user-input question, generating an execution plan that includes at least one subtask. Based on the execution plan, inference loops and retrieval enhancements are performed to generate an enhanced set of contextual evidence. The enhanced contextual evidence set is filtered and optimized to generate an optimized context; An initial answer is generated based on the optimization context and the question, and a closed-loop verification of the initial answer in terms of factual and logical consistency is performed to detect whether hallucination exists. If a hallucination is detected, the initial answer is corrected, a corrected answer is generated, and the hallucination event and the correction process are recorded in the reflection knowledge base.
2. The intelligent agent hallucination correction method according to claim 1, characterized in that, The step of parsing and globally planning the user-input question to generate an execution plan containing at least one sub-task includes: The user's input question is subjected to intent recognition and entity extraction to obtain the query intent and entities; Based on the query intent and the entity, the problem is broken down into multiple sub-tasks that can be independently retrieved and verified; Based on the logical relationships between the subtasks, an execution plan containing at least one subtask is generated.
3. The method for correcting hallucinations in intelligent agents according to claim 1, characterized in that, The step of performing inference loops and retrieval enhancements based on the execution plan to generate an enhanced contextual evidence set includes: Based on the execution plan, a ReAct inference loop step is performed, and the retrieval enhancement operation is dynamically triggered according to the instructions generated by the ReAct inference loop step. Perform the search enhancement operation to obtain a set of candidate information related to the question; The candidate information set is fused to generate an enhanced contextual evidence set.
4. The method for correcting hallucinations in intelligent agents according to claim 3, characterized in that, The step of performing the retrieval enhancement operation to obtain a set of candidate information related to the question includes: The first retrieval strategy is used to perform keyword matching and semantic similarity retrieval from the document database to obtain the first retrieval information; The second search strategy was used to obtain the second search information; By using a knowledge enhancement method, the first retrieval information and the second retrieval information are merged to obtain a set of candidate information related to the question.
5. The intelligent agent hallucination correction method according to claim 1, characterized in that, The step of filtering and optimizing the enhanced contextual evidence set to generate optimized context includes: The enhanced contextual evidence set is sorted by cross-encoder reordering and information rearrangement to obtain the sorted contextual evidence set; Based on a preset hot channel memory management strategy, the importance score and routing decision are performed on the sorted context evidence set to filter out high-priority evidence content. The high-priority evidence content is subjected to context optimization processing to generate an optimized context.
6. The method for correcting hallucinations in intelligent agents according to claim 1, characterized in that, The step of generating an initial answer based on the optimization context and the question, and performing a closed-loop verification of the initial answer for factual and logical consistency to detect the existence of hallucinations, includes: An initial answer is generated based on the optimization context and the question. Extract key entities from the question, and obtain relevant attribute descriptions of the key entities based on the initial answer; Based on preset evaluation criteria, factual verification is performed on the key entities and related attribute descriptions to obtain verification results; Compare the logical consistency of multiple verification results to detect the presence of hallucinations.
7. The method for correcting hallucinations in intelligent agents according to claim 1, characterized in that, The steps of revising the initial answer if a hallucination is detected, generating a revised answer, and recording the hallucination event and the revision process in the reflection knowledge base include: Based on the detection results, identify the hallucinatory fragments of the initial answer; The task of correcting the hallucination fragments is broken down into independent sub-correction tasks; Build prompts for correction; Based on the prompt words, generate the corrected content for the sub-correction task; The iterative correction process synthesizes a corrected answer based on the corrected content. Record this hallucination event and the correction process in the reflection knowledge base.
8. The intelligent agent hallucination correction method according to claim 7, characterized in that, The steps for recording this hallucination event and the correction process into the reflection knowledge base include: Record event logs for hallucination detection; Based on the event log, amendment examples are abstracted and stored in the reflection knowledge base.
9. The method for correcting hallucinations in an intelligent agent according to claim 1, characterized in that, After the steps of revising the initial answer if a hallucination is detected, generating a revised answer, and recording the hallucination event and the revision process in the reflection knowledge base, the method further includes: The corrected answer is then subjected to a closed-loop verification to ensure its factual and logical consistency. If the verification results show that hallucinations still exist in the corrected answer, then the correction is deemed to have failed. Obtain the execution information of this task, and use the execution information as a feedback signal to flow back to the global planning stage; Based on the feedback signal, the task parsing strategy is adjusted and the execution plan is regenerated.
10. A device for correcting hallucinations in an intelligent agent, characterized in that, The device includes: The parsing and planning module is used to parse the user-input question and perform global planning, generating an execution plan that includes at least one subtask. The evidence generation module is used to perform inference loops and retrieval enhancements based on the execution plan, and generate an enhanced contextual evidence set; The filtering and optimization module is used to filter and optimize the enhanced contextual evidence set to generate an optimized context. The closed-loop verification module is used to generate an initial answer based on the optimization context and the question, and to perform a closed-loop verification of the factual and logical consistency of the initial answer to detect whether there is a hallucination. The revision and reflection module is used to revise the initial answer if a hallucination is detected, generate a revised answer, and record the hallucination event and the revision process in the reflection knowledge base.
Citation Information
Patent Citations
Large model illusion correction method and device based on iterative evaluation algorithm
CN118709777A
Intelligent question and answer method and device, computer equipment and program product
CN118820436A
Large model illusion relieving method and device, equipment and storage medium
CN118964583A
Question answering system and method based on collaborative mechanism of retrieval enhancement generation agent and plug-in reasoning engine
CN120561240A
Method for reducing large model illusion problem based on RAG technology
CN120633859A
Cited By
Model illusion control method and device, equipment and storage medium
CN121144381A
Large model illusion detection method based on deep learning and semantic structure information
CN121599139A
Dynamic knowledge retrieval enhancement method based on large language model
CN121960791A
RAG illusion suppression method and system based on multi-agent collaborative verification and storage medium
CN122198154A