Pradeerock/self-healing-rag
0
Self-Healing RAG Environment
An OpenEnv benchmark for agents that must detect hallucinations caused by stale internal documents, identify the exact misleading source, repair the knowledge base, and confirm the corrected answer.
Why This Version Is Stronger
- Ground-truth labels are hidden from the observation space.
- Document IDs are randomized on every reset, so agents cannot memorize hardcoded targets.
- Tasks are sampled from a scenario bank spanning HR, pricing, support, refund, travel, and remote-work policies.
- The baseline solver reasons over the retrieved documents instead of relying on fixed answer keys.
Task Suite
Quick Start
python3 -m venv venv
source venv/bin/activate
pip install -r server/requirements.txt
uvicorn server.app:app --host 0.0.0.0 --port 7860In another shell:
from rag_env import RAGEnv, RAGAction
with RAGEnv(base_url="http://localhost:7860").sync() as env:
result = env.reset(task_name="task_full_pipeline")
print(result.observation.question)
print(result.observation.retrieved_documents)Action Space
Observation Space
The agent sees only public document fields:
RAGObservation(
question: str,
retrieved_documents: list[dict], # id, title, content, date, topic
current_answer: str | None,
hallucination_detected: bool,
conflicting_docs: list[dict],
database_fixed: bool,
step_number: int,
message: str,
reward: float,
done: bool,
)Internal labels such as is_outdated and correct_doc_id are never exposed.
Baseline
inference.py is a deterministic baseline that:
- Parses answer-bearing values from the retrieved documents.
- Uses the OpenAI Python client to select the next action.
- Detects the conflict, finds the stale source, fixes it, and verifies the latest answer.
Run it with:
export HF_TOKEN=your_token
export API_BASE_URL=https://api.openai.com/v1
export MODEL_NAME=gpt-4.1-mini
./venv/bin/python inference.pyThe script emits only [START], [STEP], and [END] lines to stdout so it matches the hackathon submission parser.
Validation
./venv/bin/openenv validateProject Layout
.
├── client.py
├── inference.py
├── models.py
├── openenv.yaml
├── pyproject.toml
├── rag_env/
├── server/
│ ├── app.py
│ ├── environment.py
│ └── requirements.txt
└── tasks.py