SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2507.21892 · ICML · 2025

Graph-R1: Towards Agentic GraphRAG Framework via End-to-end Reinforcement Learning

Anh Luu, Tuan, Haoran Luo, Xiaobao Wu, Yikai Guo, Meina Song, Yifan Zhu, Qika Lin, Guanting Chen, Zemin Kuang, Fangzhi Xu, Hotpotqa Musique, and 2 more

arXiv · PDF · Open in the Atlas

Code that ran

7 of 8 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 2 have no contract verdict; 5 failures of our instrument; 1 no recorded run), measured 2026-11-24; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2507.21892.json · badge: /api/ran/2507.21892.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
LHRLAB/Graph-R1 canonical (classifier label)
classifier basis: census
7 ran · 1 no recorded run
FunctionStatusWhere it lives
azure_openai_complete_if_cache Ran
ran on a synthesized input
LHRLAB/Graph-R1/graphr1/llm.py
code served (permissive licence) · get_code("87f2fd2c739159f1")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned coroutine. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import os
import asyncio
from unittest.mock import AsyncMock, MagicMock, patch

# Set up minimal environment variables for Azure OpenAI
os.environ['AZURE_OPENAI_API_KEY'] = 'test-key-12345'
os.environ['AZURE_OPENAI_ENDPOINT'] = 'https://test.openai.azure.com/'
os.environ['AZURE_OPENAI_API_VERSION'] = '2024-02-15-preview'

# Create mock response object
mock_message = MagicMock()
mock_message.content = "This is a test response from the model."

mock_choice = MagicMock()
mock_choice.message = mock_message

mock_response = MagicMock()
mock_response.choices = [mock_choice]

# Build arguments dictionary
ARGS = {
    'model': 'gpt-4-deployment',
    'prompt': 'What is the capital of France?',
    'system_prompt': 'You are a helpful assistant.',
    'history_messages': [
        {'role': 'user', 'content': 'Hello'},
        {'role': 'assistant', 'content': 'Hi there!'}
    ],
    'base_url': 'https://test.openai.azure.com/',
    'api_key': 'test-key-12345',
    'api_version': '2024-02-15-preview',
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
openai, tenacity — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type coroutine — a coroutine output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a coroutine output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
cl_forward Ran
ran; our contract draft was wrong, not the code
LHRLAB/Graph-R1/evaluation/simcse/models.py
pointer only (licence: MIT); the stored copy get_code serves, from yiren-jian/NonLing-CSE, is pointer only (licence: NONE) · get_code("4e0ff9c4d9a318ff")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from yiren-jian/NonLing-CSE, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

lazy_external_import Ran
ran; our contract draft was wrong, not the code
LHRLAB/Graph-R1/graphr1/graphr1.py
code served (permissive licence) · get_code("c5d52c7f50d771d0")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned function. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import inspect

torch.manual_seed(0)

# The function lazy_external_import takes:
# - module_name: str - the name of a module to import from
# - class_name: str - the name of a class within that module

# The function uses these parameters to:
# 1. Get the caller's frame and module
# 2. Extract the package from the caller's module
# 3. Return a function that lazily imports the specified class from module_name
#    using the caller's package as context

# For testing, we need valid module and class names that exist
# We'll use standard library modules that are guaranteed to exist

ARGS = {
    "module_name": "collections",
    "class_name": "OrderedDict"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type function — a function output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a function output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
make_prefix Ran
ran; our contract draft was wrong, not the code
LHRLAB/Graph-R1/script_process.py
code served (permissive licence) · get_code("018ba1bb83412f58")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch

torch.manual_seed(0)

# Construct a minimal data point dictionary
dp = {
    'question': 'What is the capital of France?'
}

# Define ARGS mapping all parameters to values
ARGS = {
    'dp': dp,
    'template_type': 'base'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
normalize_answer Ran
ran; our contract draft was wrong, not the code
LHRLAB/Graph-R1/evaluation/eval_r.py
code served (permissive licence) · get_code("78b0c6179667e101")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned str. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import re
import string

def normalize_answer(answer: str) -> str:
    """
    Normalize a given string by applying the following transformations:
    1. Convert the string to lowercase.
    2. Remove punctuation characters.
    3. Remove the articles "a", "an", and "the".
    4. Normalize whitespace by collapsing multiple spaces into one.

    Args:
        answer (str): The input string to be normalized.

    Returns:
        str: The normalized string.
    """

    def remove_articles(text):
        return re.sub('\\b(a|an|the)\\b', ' ', text)

    def white_space_fix(text):
        return ' '.join(text.split())

    def remove_punc(text):
        exclude = set(string.punctuation)
        return ''.join((ch for ch in text if ch not in exclude))

    def lower(text):
        return text.lower()
    return white_space_fix(remove_articles(remove_punc(lower(answer))))


ARGS = {
    "answer": "The Quick Brown Fox jumps over a lazy dog! What an amazing feat, isn't it?"
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
openai_complete_if_cache Ran
ran on a synthesized input
LHRLAB/Graph-R1/graphr1/llm.py
code served (permissive licence) · get_code("c919f080ca472441")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API) and returned coroutine. The image it ran in was not recorded. If your copy returns the same type on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import os
import asyncio
from unittest.mock import Mock, AsyncMock, MagicMock
from openai import AsyncOpenAI

# Mock the logger that's used in the function
class MockLogger:
    def debug(self, msg, *args, **kwargs):
        pass

# Create a mock logger
logger = MockLogger()

# Mock the safe_unicode_decode function
def safe_unicode_decode(content):
    return content.decode('utf-8', errors='replace')

# Create mock response objects
class MockDelta:
    def __init__(self):
        self.content = "Test response content"

class MockChoice:
    def __init__(self):
        self.delta = MockDelta()
        self.message = Mock(content="Test response content")

class MockResponse:
    def __init__(self):
        self.choices = [MockChoice()]
    
    def __aiter__(self):
        return self
    
    async def __anext__(self):
        raise StopAsyncIteration

# Mock AsyncOpenAI client
class MockAsyncOpenAI:
    def __init__(self, base_url=None):
        self.base_url = base_url
        self.beta = Mock()
        self.beta.chat = Mock()
        self.beta.chat.completions = Mock()
        self.chat = Mock()
        self.chat.completions = Mock()
    
    async def get_response(self):
        return MockResponse()

# Patch the imports in the function's context
AsyncOpenAI_original = AsyncOpenAI

def mock_async_openai(*args, **kwargs):
    return MockAsyncOpenAI(*args, **kwargs)

# Build arguments for the function
ARGS = {
    'model': 'gpt-3.5-turbo',
    'prompt': 'What is the capital of France?',
    'system_prompt': 'You are a helpful assistant.',
    'history_messages': [
        {'role': 'user', 'content': 'Hello'},
        {'role': 'assistant', 'content': 'Hi there!'}
    ],
    'base_url': None,
    'api_key': 'test-api-key-12345',
    'temperature': 0.7,
    'max_tokens': 100
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
openai, tenacity — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type coroutine — a coroutine output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a coroutine output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
sentemb_forward Ran
ran; our contract draft was wrong, not the code
LHRLAB/Graph-R1/evaluation/simcse/models.py
pointer only (licence: MIT); the stored copy get_code serves, from yiren-jian/NonLing-CSE, is pointer only (licence: NONE) · get_code("cb67cd5ac977480d")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from yiren-jian/NonLing-CSE, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

chunking_by_token_size Not yet run
unverified (harvested, no recorded run)
LHRLAB/Graph-R1/graphr1/operate.py
code served (permissive licence) · get_code("d91c95543a58a3c6")
How it ran

no invocation recorded.

Also present in other papers' code

Of 8 samples lifted from this paper's linked repositories, 8 carry a function identity and 0 do not. Of the 8 distinct functions with an identity, 5 are also present in other papers whose code we hold (5 with at least one paper dated earlier, 0 the same month, 2 later) and 3 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
sentemb_forward 15 other papers
12 dated earlier, 1 later, 2 same year, order not determinable · 4 only as an assembly brick
1908.10084 (2019-08)
Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
2104.08821 (2021-04)
SimCSE: Simple Contrastive Learning of Sentence Embeddings
2203.05877 (2022-03)
A Sentence is Worth 128 Pseudo Tokens: A Semantic-Aware Contrastive Learning Framework for Sentence Embeddings
and 12 more not named here
cl_forward 8 other papers
6 dated earlier, 1 later, 1 same year, order not determinable · 2 only as an assembly brick
1908.10084 (2019-08)
Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks
2104.08821 (2021-04)
SimCSE: Simple Contrastive Learning of Sentence Embeddings
2209.09433 (2022-09)
Non-Linguistic Supervision for Contrastive Learning of Sentence Embeddings
and 5 more not named here
lazy_external_import 4 other papers
3 dated earlier, 1 same year, order not determinable
2025.findings-emnlp.290 (2025 (year only))
ReGraphRAG: Reorganizing Fragmented Knowledge Graphs for Multi-Perspective Retrieval-Augmented Generation
2501.06713 (2025-01)
MiniRAG: Towards Extremely Simple Retrieval-Augmented Generation
2502.14902 (2025-02)
PathRAG: Pruning Graph-based Retrieval Augmented Generation with Relational Paths
and 1 more not named here
chunking_by_token_size 2 other papers
2 dated earlier
2406.04271 (2024-06)
Buffer of Thoughts: Thought-Augmented Reasoning with Large Language Models
2506.18896 (2025-06)
ReasonFlux-PRM: Trajectory-Aware PRMs for Long Chain-of-Thought Reasoning in LLMs
make_prefix 2 other papers
2 dated earlier
2503.09516 (2025-03)
Search-R1: Training LLMs to Reason and Leverage Search Engines with Reinforcement Learning
2505.15117 (2025-05)
An Empirical Study on Reinforcement Learning for Reasoning-Search Interleaved LLM Agents

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-24.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Retrieval-Augmented Generation (RAG) mitigates hallucination in LLMs by incorporating external knowledge, but relies on chunk-based retrieval that lacks structural semantics. GraphRAG methods improve RAG by modeling knowledge as entity-relation graphs, but still face challenges in high construction cost, fixed one-time retrieval, and reliance on long-context reasoning and prompt design. To address these challenges, we propose Graph-R1, the first agentic GraphRAG framework via end-to-end reinforcement learning (RL). It introduces lightweight knowledge hypergraph construction, models retrieval as a multi-turn agent-environment interaction, and optimizes the agent process via an endto-end reward mechanism. Experiments on standard RAG datasets show that Graph-R1 outperforms traditional GraphRAG and RL-enhanced RAG methods in reasoning accuracy, retrieval efficiency, and generation quality. Our software and data are publicly available at https:// github.com/LHRLAB/Graph-R1.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2507.21892")
get_code_for_paper("2507.21892")
have("2507.21892")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2507.21892.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2507.21892.svg)](https://syntology.ai/paper/2507.21892)

Connect an agent — have() is free.