What it is
Two agents that work together.
The research agent turns a technical question into a cited report. It is a LangGraph graph:
- a DSPy planner and a reflector write search queries;
- a researcher runs Tavily web searches in parallel. Optionally, the model then chooses up to three more searches by function calling (off by default; see below);
- a person approves the sources;
- a writer drafts the report;
- a DSPy critic sends the draft back for up to three revisions.
Approved reports are stored in vector memory, so later questions can reuse them. Every job runs on PostgreSQL. Workers hold leases and save checkpoints, so a job survives a crashed worker.
The diagnosis agent steps in when a research job fails. It uses function calling with four tools: inspect_evidence, search_runbooks, check_action_policy and submit_diagnosis. With them it reads the job’s event log, finds the cause and proposes a fix.
The agent doesn’t get the final say:
- a policy validator checks that the proposed action is allowed;
- an evidence verifier checks that the cited events support it.
If either check fails, the agent sees the reason and tries again. If it runs out of steps or time, a rules engine takes over. Once a fix passes the checks, an operator approves it, or a limited auto-recovery runs it. Then the worker re-runs the job, and the incident closes only when the job succeeds.
See it run
The demo site replays real recorded runs in the browser: four research questions and six injected faults.
On the left, a research run: searches, sources, a person’s approval, the report as it’s written, and a check of every citation. On the right, a rate-limited model stops a job, the agent reads the log and checks the policy, and the job is resumed and finishes.
Also included:
- a grounding gate that fails reports citing sources they never retrieved;
- health probes for the model, search, memory and database;
- an operations summary;
- a read-only MCP server, so an assistant can look at incidents but can’t act on them.
Results
The incident labels were committed before the agent was built, and the prompts were frozen before each held-out set was run.
| Evaluation | Result |
|---|---|
| Fresh held-out set (24 incidents) | rules 17, single LLM call 16, agent 23 |
| Recommended the recovery when it was allowed (of 10) | rules 7, previous agent 6, agent 10 |
| Overconfident answers on cases that should abstain | 3 → 0 after adding the verifier |
| Fault injection, 30 real jobs | 30 / 30 diagnosed correctly |
| End-to-end recovery on real jobs | 6 / 6, with an operator and with auto-recovery |
| Cost | about $0.005 per diagnosis on Gemini; $0 on a free OpenRouter model (Nemotron 3.5 Super VL: 24, 22 and 21 of 24 over three runs, with one unsafe trap taken in 72 diagnoses, so diagnosis stays on Gemini) |
I removed one part at a time and re-ran 51 incidents:
| Removed | Correct | Unsafe actions |
|---|---|---|
| nothing | 51 | 0 |
| evidence verifier | 44 | 3 |
| event-name vocabulary | 45 | 0 |
| policy check tool | 47 | 0 |
| runbook search | 49 | 0 |
Unsafe recommendations appeared only without the verifier. The policy validator was still on in those runs, so every action was allowed, but none was justified by the evidence.
Checking the research agent’s citations
The grounding gate checks that each citation points at a source that was retrieved. It doesn’t check whether the source says what the sentence claims.
I built an LLM judge for that and tested it before using it:
- claims paired with sources from an unrelated topic were judged supported 0-2% of the time;
- sentences copied from their source were judged supported 98-100% of the time.
The judge found that only 37% of citations were fully supported. I gave the writer numbered sources and told it to cite only what the source text states, then re-ran the same 10 tasks three times:
| Citations | Fully supported | Unsupported |
|---|---|---|
| Before | 37% | 30% |
| After (3 runs) | 75% (68-80%) | 4% (2-6%) |
The reports did not get shorter, and every paragraph still cites a source. The judge also runs as an optional worker gate: a report fails when at least half of its judged citations are unsupported.
I also tried giving the research agent more agency: after the planned searches, it chooses up to three more by function calling. Over three runs this dropped fully supported citations to 62%. Citations to the sources it found were unsupported 31% of the time, against 9% for the planned ones. It stays off by default. The full write-up is on the blog.
Bugs that only showed up on real jobs
Every part had passing unit tests. The first live recovery runs still failed, and each failure was a real bug:
- Gemini puts its retry delay in the error text, not a header, so no rate-limited job could resume.
- A job paused for approval kept its worker’s lease, so an approved resume was refused.
- “Fresh retrieval” jobs set a no-cache flag that nothing read.
- Incidents never closed, even after a verified recovery.
- The citation parser skipped grouped markers like
[1, 2, 4], which hid a report citing sources that were never retrieved. - Writers numbered their own reference lists, so citations were mis-mapped in 11 of 20 reports.
Each fix came with a regression test that fails without it.
Production hardening
- Switchable model provider: one setting switches every model call between Gemini and OpenRouter. The OpenRouter default is a free model, and paid models can be sent to the cheapest provider.
- A security hole found and closed: the job API accepted worker-internal settings from callers. A caller could plant a finished report with fake sources, or point a job at another job’s saved state. Job settings are now an allowlist.
- Production settings:
- API tokens are required, and production mode refuses to start without them;
- only configured origins can call the API;
- job submission is rate-limited and inputs are length-limited;
- the container runs as a non-root user, verified in a real build;
- an operations runbook covers backups, migrations and key rotation.
Limits
- The incident labels are synthetic and were written by me.
- Most evaluations ran once, on free-tier Gemini.
- It runs locally, as a single tenant, not as a hosted service.
Stack
Python, LangGraph, DSPy, Tavily, Gemini and OpenRouter (OpenAI-compatible APIs), FastAPI, PostgreSQL, Chroma/pgvector, Langfuse, Streamlit, MCP, Docker, GitHub Actions.
