Q uery A gent: A Reliable and Efficient Reasoning Framework with Environmental Feedback based Self-Correction (2024)

Abstract: Employing Large Language Models (LLMs) for semantic parsing has achieved remarkable success. However, we find existing methods fall short in terms of reliability and efficiency when hallucinations are encountered. In this paper, we address these challenges with a framework called QueryAgent, which solves a question step-by-step and performs stepwise self-correction. We introduce an environmental feedback-based self-correction method called ERASER. Unlike traditional approaches, ERASER leverages rich environmental feedback in the intermediate steps to perform selective and differentiated self-correction only when necessary. Experimental results demonstrate that QueryAgent notably outperforms all previous few-shot methods using only one example on GrailQA and GraphQ by 5.7 and 15.0 points. Furthermore, our approach exhibits superiority in terms of efficiency, including run-time, query overhead, and API invocation costs. By leveraging ERASER, we further improve another baseline (i.e., AgentBench) by approximately 10 points, validating the strong transferability of our approach.

## introduction recent advances in employing large language models (llms) on various tasks have exhibited impressive performance @xcite . among these tasks, knowledge base question answering (kbqa), which aims to answer questions over knowledge base (kb), has emerged as a critical and complex challenge, serving as an ideal testbed for assessing the reasoning capabilities of llms over structured data @xcite . however, despite their remarkable achievements, we find that existing llm-backend kbqa methods fall short in both reliability (the credibility of results) and efficiency (i.e., running time, query icl-based agent-based queryagent reliable and efficient step n question logic form step 1 ... step n question logic form step 1 ... question logic form eraser end-to-end for a complex task，prone to hallucinate suffer from error propagation times, and api invocation cost). following the popular in-context learning (icl) paradigm, @xcite and @xcite generate the target query with few-shot demonstrations. they consider llms as a black box and complete a complex task in one go. as a result, it lacks interpretability and is prone to hallucination @xcite , leading to lower accuracy of the top-1 candidate. to alleviate these issues, they employ beam search and self-consistency @xcite . however, these also result in numerous unreliable candidates, thus increasing the running time and query times. typically, it requires querying thousands of sparql queries and several minutes to obtain the final answer. for a complex task, solving it step-by-step has emerged as a promising solution @xcite . agentbench @xcite implements an agent-based @xcite kbqa system by progressively invoking tools to build the target query. however, its iterative nature dictates that each step strictly relies on the previous steps. when hallucination occurs, subsequent reasoning processes would be built upon erroneous foundations, resulting in unreliable candidates and meaningless resource wastage. additionally, the necessity to invoke an llm at each step renders beam search unaffordable, placing a high demand on the accuracy of the top-1 results. in our preliminary experiments, we observed that 35% of the questions in agentbench suffer from various hallucinations. as a result, agentbench achieves unsatisfactory performance, only 57% f1 of the state-of-the-art icl-based methods on grailqa. in view of these challenges, we introduce a framework called queryagent to explore more reliable and efficient reasoning in complex environments. specifically, queryagent models kbqa as a multi-turn generation task to stepby-step construct the target query with tools and perform stepwise self-correction. to mitigate the error accumulation issue of multistep reasoning, we propose an environmental feedback-based self-correction method called eraser (environmental feedback-based self-correction). for each llm generated text, eraser detects whether it is erroneous and analyzes the possible causes based on the feedback from environments (e.g., kb execution results, python interpreter execution status, previous reasoning memory) in the intermediate steps. upon analyzing this feedback, eraser provides potential causes of errors and general guidelines for correction. based on the guidelines, llm can reconsider and correct the erroneous result. unlike previous self-correction methods @xcite @xcite which purposelessly correct every generated result with the same few-shot demonstrations, the idea of eraser is to actively identify and differentiate various errors based on the rich environmental feedback in the intermediate reasoning steps and then provide tailored guidelines for the distinct error type. with the help of various environmental feedback, eraser has a more solid basis for precise detection, analysis, and correction, rather than relying solely on the final answer. moreover, eraser distinguishes between different types of errors, allowing it to provide guidelines specifically tailored for each error type. this targeted approach makes eraser more purposeful and scalable. in situations where there are numerous potential error scenarios, the guidelines for different errors can be independently developed without the need to encode all possible error cases to a single prompt. we conduct extensive experiments to evaluate the effectiveness of queryagent and eraser. with only 1 example, queryagent notablely surpasses all few-shot methods, which require up to 100 shots, on grailqa (+5.7), graphq (+15.0), webqsp (+3.4), and metaqa (+2.0). moreover, our approach exhibits significant efficiency improvements. compared with icl-based methods, queryagent reduces runtime and query overhead to several orders. compared with agentbased methods, queryagent allows for approximately a 50% reduction in api invocation costs and runtime. these results highlight the reliability and efficiency of our methods. we also evaluate queryagent on a text2sql dataset (wikisql), and adapt eraser to another system (agent-bench), to demonstrate their versatility. results reveal that queryagent outperforms the previous 32shot method by 6.9 points. besides, eraser relatively yields an additional improvement for agent-bench by 26% and 42% in f1 on the grailqa and graphq, respectively foot_0 . ## detailed analysis to gain more insights into queryagent's strong performance, we conduct some in-depth analysis. ## conclusion in this paper, we present a reliable and efficient framework called queryagent, which constructs the target query step-by-step with tools and performs stepwise self-correction. we also introduce a novel self-correction method called eraser. it leverages rich environmental feedback to enable selective and differentiated self-correction, departing from the conventional approach which only uses the final result to conduct correction on every output with the same prompt. experimental results demonstrate that queryagent notably outperforms all existing few-shot methods on four kbqa datasets with only a single example, especially on grailqa (+5.7) and graphq (+15.0). moreover, queryagent also exhibits superiority in efficiency with faster solving speed and lower resource utilization. compared to icl-based methods, our approach reduces runtime and query costs by a factor of tens, while compared to agent-based methods, it reduces time and api invocation costs by more than half. we also show the versatility of queryagent and eraser by evaluating them on a text2sql dataset and applying eraser on another system (agentbench). queryagent outper-forms previous few-shot methods and eraser further boosts the performance of agentbench.