initial commit: retrieval + agent artifacts

This commit is contained in:
Danil Poliakov
2026-10-28 20:44:23 +07:00
commit 17e4fab0d2
13 changed files with 630 additions and 0 deletions
+60
View File
@@ -0,0 +1,60 @@
# agent-graph
A small agent loop built on LangGraph, with a checkpointer, retrieval tools and acceptance
that is checked by rules instead of a second model.
## Loop
```
plan -> retrieve (search_docs) -> answer -> verify
^ |
+-- retry <--+ (max 2 attempts)
```
- **plan** — the model returns a validated `Plan` (1-4 steps, each with a tool and a query).
- **retrieve** — one tool, `search_docs`, calling the rag-lab HTTP API.
- **answer** — must answer strictly from retrieved chunks and cite them as `[chunk-id]`.
- **verify** — pure rules: answer is not empty, every citation exists in the retrieved set,
a citation to a document that was not retrieved is rejected, and the required fact must be
present verbatim. Retry carries the rejection reasons back into the state.
## Why rules for acceptance
An LLM judge approving its own answer is the same problem as an agent writing its own report:
both reward confidence. Deterministic checks are boring and reproducible, and they fail for the
right reason.
## Checkpointer
SQLite-backed (`langgraph-checkpoint-sqlite`), one thread id per task: after a run the whole
state can be replayed with `graph.get_state(config)`.
## Run
```bash
pip install -e ".[dev]"
python scripts/build_tasks.py # 12 tasks from BEIR test qrels
python scripts/run_tasks.py # needs rag-lab API on 127.0.0.1:8088
pytest -q
```
Environment: `AGENT_GATE_URL` (OpenAI-compatible endpoint), `AGENT_MODEL`, `AGENT_GATE_KEY_FILE`.
## Results
12 tasks built from BEIR test qrels (real query, gold document, a verbatim span from that document):
| metric | value |
|--------|-------|
| accepted | 12 / 12 |
| gold document in top-8 | 12 / 12 |
| p50 end-to-end | 6.8 s |
| p95 end-to-end | 29.6 s |
Earlier run with top-5 chunks passed 10 / 12: the document was retrieved but the chunk holding
the required span was not, and the verifier rejected the answer for a missing fact. Retrieving
8 chunks fixed both tasks. That failure is the point of a rules-based verifier: it fails for a
specific, inspectable reason.
Model: deepseek-v4.1-flash through a local OpenAI-compatible gateway, temperature 0. Run log and
per-task verdicts: `results/runs.json`, checkpoints: `runs.db` (one thread per task).