KG-Agent: An Efficient Autonomous Agent Framework for Complex Reasoning over Knowledge Graph

Jinhao Jiang, Kun Zhou, Xin Zhao, Yang Song, Chen Zhu, Hengshu Zhu, Ji-Rong Wen

Introduction

Large Language Models (LLMs) frequently struggle with factual accuracy due to knowledge cutoffs and hallucinations, particularly regarding niche or complex relationships. Integrating LLMs with structured Knowledge Graphs (KGs) like Freebase or Wikidata offers a solution. However, existing integration methods often suffer from rigidity—relying on pre-defined human-crafted plans—or high costs associated with large closed-source models like GPT-4.

This paper introduces KG-Agent, an autonomous framework designed to empower smaller, open-source models (such as LLaMA2-7B) to perform sophisticated, multi-hop reasoning over massive KGs. By reframing reasoning as an iterative code-generation task, KG-Agent achieves high efficiency and superior performance compared to significantly larger counterparts.

Methodology

The KG-Agent framework operates through a continuous loop involving four primary components:

  1. The Planner: A fine-tuned LLM that determines the next logical step in the reasoning process.
  2. The Toolbox: A collection of Python-like functions for extraction (finding relations), logic (counting/intersecting), and semantics (entity disambiguation).
  3. The Executor: A compiler that runs the selected tools against the KG.
  4. Knowledge Memory: A dynamic "scratchpad" tracking the question, available tools, retrieved data, and reasoning history.
The KG-Agent framework architecture and reasoning process.

A critical innovation is Instruction Synthesis. The authors converted existing KG Question Answering (KGQA) datasets into multi-step "reasoning programs." By fine-tuning LLaMA on these programs, the model learns to generate executable code snippets, reducing ambiguity and providing a clear path for complex graph navigation.

Experimental Setup

KG-Agent was evaluated across diverse benchmarks:

  • In-domain: WebQSP, CWQ, GrailQA, and KQA Pro.
  • Out-of-domain (Zero-shot): WebQuestions, Natural Questions, and TriviaQA.
  • Domain-specific: MetaQA (movie-related).

The primary base model used was LLaMA2-7B, trained on a modest dataset of 10,000 synthesized samples.

Key Results

KG-Agent demonstrates remarkable performance and efficiency:

  • Superior Accuracy: On the WebQSP benchmark, KG-Agent (7B) achieved an F1 score of 81.0, and 69.8 on CWQ, outperforming GPT-4 and specialized models like ReasoningLM and StructGPT.
  • Generalization: In zero-shot scenarios, it showed an 8.5% relative improvement over strong baselines, indicating it has learned general reasoning patterns rather than specific graph structures.
  • Efficiency: The framework achieved nearly 3x faster inference speeds compared to StructGPT, highlighting its suitability for real-world applications.
Comparative performance metrics across multiple KGQA benchmarks.

Discussion and Future Work

The success of KG-Agent highlights that formulating reasoning as programming is highly effective for structured data. While the 7B model is the focus, the framework scales effectively; a 70B variant reached 92.15% accuracy on KQA Pro.

Future research directions include testing the framework on a wider variety of model architectures (e.g., Mistral), expanding the toolbox to incorporate unstructured text or web search, and implementing more robust safety filtering for tool calls. Additionally, extending the agent's capabilities to "data-to-text" tasks remains a promising next step.

Summary updated

BibTeX
@inproceedings{jiang2025kg,
  author = {Jinhao Jiang and Kun Zhou and Xin Zhao and Yang Song and Chen Zhu and Hengshu Zhu and Ji-Rong Wen},
  title = {{KG-Agent: An Efficient Autonomous Agent Framework for Complex Reasoning over Knowledge Graph}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
}
Figure