A Research Agent That Can Wait Three Weeks for a Letter
How Lineage's genealogy research agent went from Inngest inside a Vercel app to a self-hosted Temporal workflow, what the Curiosity Recursion paper measured, and why most of a family's story is not on Google.
- Lineage
- Temporal
- Inngest
- Python
- Next.js
I researched 65 of my own relatives with an AI agent. It worked, but only because I sat there and pushed it. Go deeper. Broaden. Are you sure that's the same man? What about the churches? The ship he sailed on? Books about his regiment? Did that archive ever write back?
The agent wasn't lazy. It was unsupervised, and I was the supervisor. By relative 65 it had done the Civil War, both world wars, the Revolution, immigration, census and burials. But if I came back a month later with relative 66, I had no way to know whether it would get the same care as relative 12. The nudging was the real work, and none of it was written down.
This post is about turning that nudging into code, and about the plumbing it needs underneath. The short version: research like this runs for weeks, so it needs durable execution. I started on Inngest, ended up hand-building half a workflow engine on top of it, and moved the research loop to a self-hosted Temporal server. (The public search on lineage.rexstjohn.com still runs the Vercel version today. The Temporal loop is the research builder, and it's the reference system for the paper.) Then I wrote a paper measuring whether the loop actually finds more, and the honest answer is: not yet.
Code, paper and benchmark are open: github.com/Verafyai/curiosity-recursion.
The problem is dark data
Genealogy is a bad fit for a search engine. The records exist, but the systems that should find them can't see them. A soldier named on page 14 of a scanned regimental history with no index. A marriage register that a town clerk answers by mail in three weeks. A pension file at the National Archives that someone has to request. A box of letters in a cousin's closet.
I wanted a number for how bad this is, so I took three people from my own family history and sorted every documented fact about them by where it could actually be found. Each fact got the most accessible route that carries it: a free page or online book whose text states it (Google can find it), something online but not searchable (scans with no text layer, query-only databases, paywalls), or direct outreach only (archive staff replies, requested copies, family interviews and papers).

Every documented fact about three people, by where it could actually be found.
Erastus Burnham was a whaleman and a Civil War soldier who died in 1921. 61% of his facts are on the open web, mostly because 19th century town histories and regimental books have been scanned and OCR'd. Homer St. John served in the Canadian Expeditionary Force in WWI: 7% on Google, 40% only through outreach. His son John served in the US Army in WWII: 1% on Google, 76% only through outreach.
The closer you get to living memory, the less of the story is online. Three people is an illustration, not a statistic, and the "Google" column is a lower bound because the check is keyword matching. But the shape matches what I lived through. The recent records are the ones you write letters for.
So a research agent for this work has to do two things a chatbot doesn't. It has to keep asking the next question long after the obvious searches run dry. And it has to wait, sometimes for weeks, for a human or an archive to answer.
First build: Inngest inside the app
Lineage started as a Next.js app on Vercel with Postgres on Neon. The build spec I wrote for it put the agent on Inngest from day one:
Inngest for the agent, scheduling, retries and long-running work. Everything agentic runs in Inngest, never in a Next.js request handler. Research takes minutes to hours.
That choice fit the stack. Inngest calls back into a route handler in your app, so there is no separate worker process to run. The whole product stayed one deploy. The search flow (a name and a birth decade go in, a seven-stage research pass runs, a family tree fills in live over server-sent events) shipped with three Inngest functions:
export const runSearchPass = inngest.createFunction(
{ id: 'search-pass-run', retries: 2, concurrency: { limit: 4 } },
{ event: PASS_REQUESTED },
async ({ event, step }) => {
const passId = String(event.data.passId);
await step.run('run-pass', async () => {
const { runPass } = await import('@/lib/search/run-pass');
await runPass(passId);
return { passId };
});
return { passId };
},
);
Look at what that function actually does. It wraps the entire seven-stage pass in one step.run. The durable unit was the whole pass, so the durability had to live in my code, not in the engine. And I made Inngest optional on purpose so the demo path needed no vendor keys. Without them, the same runPass ran in-process from the request, using Next's after().
Either way, the work ran inside a Vercel function, and a Vercel function has a clock. This comment is from the code:
/**
* The in-process runner shares the search page's request budget
* (`export const maxDuration = 300` in app/search/page.tsx). Next requires
* that export to be a literal, so the two numbers are kept in step by hand.
* Stage 1 is the long read: 165–181s observed, agent budget 230s.
*/
export const PASS_MAX_DURATION_MS = 300_000;
const STAGE_NEED_MS = [0, 190_000, 20_000, 20_000, 20_000, 45_000, 20_000, 40_000];
Stage 1, the agent's main read, took 165 to 181 seconds of a 300-second budget. Everything else had to fit in what was left. When it didn't, passes got cut off at the limit and then sat on the results page as "running" forever. I wrote about that when I shipped the fix. One pass claimed it had been running for 1,462 minutes.

A pass that hit the function limit and never said so, closed out after the fix.
The fix was a pile of machinery. Every stage writes a heartbeat. A budget check refuses to start a stage it can't finish. A cron job runs every five minutes and fails any pass that has been silent for 15 minutes, with a conditional claim so two sweeps can't refund the same pass twice. The family tree builder researches one relative per Inngest step "so each research turn gets its own invocation and its own time budget," with a lock column and a stale-lock timeout, and the same cron job picks up trees "the in-process runner left queued."
Heartbeats, leases, a reaper, resume-from-last-stage, idempotency keys. That is a home-made durable execution engine, written one bug at a time on top of Postgres.
To be fair to Inngest: it has sleeps, event waits and per-step retries, and I used almost none of that. My problem was the shape I'd built, not the product. But the next thing I wanted made the shape matter a lot more.
What the research actually needs
The nudging loop I wanted to automate looks like this. Run a baseline checklist for the person's heritage group: a Civil War veteran gets muster rolls, pension files, regimental histories, burial records. Then, after every finding, ask new questions sparked by that finding. "He served in the 12th Connecticut, so which books cover that regiment, does any of them name him, on which page?" Dedupe against everything already asked. Research the best leads. Repeat until a depth, breadth, node or time limit says stop.
Then the parts that don't fit in five minutes:
- An archive answers by mail in three weeks. The run has to wait for it without holding a process open.
- Archives are flaky. A lookup has to retry with backoff and not get repeated once it succeeds.
- A letter to an archive is drafted, never sent, until I approve it. The final report waits for a person to approve, reject, or say "dig here first."
- Coming back later, I need to see exactly what it did, in what order, and why. That was the black box problem with my first 65 relatives.
Every one of those is a durable execution feature. Timers that survive restarts. Activity retries. Signals from outside. An event history you can replay. I could keep building them myself in Postgres, or use an engine that is nothing but those features. I picked Temporal.
The loop on Temporal
The research loop is one Temporal workflow in Python. Workflow code only decides. Every side effect (a full-text search across Internet Archive, a search inside one book, a Chronicling America query, a write to the question store) is an activity that Temporal records, retries, and never runs again once it has finished.
Every lookup gets the same retry policy:
LIVE_RETRY = RetryPolicy(initial_interval=timedelta(seconds=2), backoff_coefficient=2.0,
maximum_interval=timedelta(seconds=30), maximum_attempts=8)
Each question in the graph is worked by one activity call. When it comes back, the loop asks the generator for follow-ups, grounded in that finding, and drops anything it has already asked:
out = await workflow.execute_activity(
investigate, InvestigateInput(request=req, question=q),
start_to_close_timeout=timedelta(seconds=90), retry_policy=LIVE_RETRY, activity_id=f"node-{q.id}",
)
A follow-up question can't be vague. The rule-based generator reads the finding and writes a specific question with its evidence attached. This is the one that turns a unit number into a book search:
add(_key("unit-books", unit), f"Which books cover the {unit}, and do they name him?",
f"because {ref_label(ref, claim)} says \"{short}\"", "unit->books",
Plan(handler="ia_title", query=...), 6, parent=ref, parent_q=qid, about=about)
The generator also adds the two questions I used to type by hand. "Are you sure these are the same Erastus?" comes up when a hit matched only on the surname or came from a newspaper. "Where else might this be?" sends the next search to a different kind of source. Questions are keyed, stored, and compared on the next run, so a later search for the same person rechecks what earlier runs asked instead of starting cold.

A live run. The orange node reading "retrying 3/8" is Temporal's retry state, read straight from the pending activity.
When the report is written, the workflow parks on a signal:
await workflow.wait_condition(lambda: self.decision is not None or bool(self.redirects),
timeout=timedelta(hours=req.approval_timeout_hours))
While it waits, nothing is running. No process holds it open. If I send a "dig here first" redirect instead of approving, it researches my question down to the configured depth, rewrites the report, and parks again. An archive's reply comes in the same way, as a signal, kept verbatim and added as a lead.
The living-person gate runs in workflow code too, using workflow.now(), so the decision is deterministic and recorded in history. Nobody gets researched unless a death is on record or they were born at least 110 years ago. Unknown means living.
Kill it and watch
The best part to demo is the part that used to hurt. Kill the worker in the middle of a run:

Worker killed with SIGKILL. The run is just history now, and it waits.
Start the worker again and it carries on from the same question. In the pilot I killed the worker with SIGKILL five times during runs. Temporal held them with 74, 128, 87, 194 and 158 history events and lookups pending. In the two full histories I checked (303 and 209 events), no activity was scheduled again after it had completed. In-flight lookups were retried after their 90-second timeout.
I also ran the same loop without Temporal, as a plain process, under injected failures and kills: 12 runs each, four subjects. Both versions finished all 12 runs. The difference is what they redid. The durable loop's duplicate-work ratio was 0.00. The plain loop's was 6.17. Only the plain loop lost finished work and did it again.

The event history is the audit trail. Event 420 is the three-day approval timer.
That history page is the answer to my black box problem. Every question, every retry, every timer and every human decision is there, in order, and replayable.
Why self-hosted
Temporal Cloud exists, and for a production Lineage it's still on the table. The research builder runs on the open-source Temporal dev server instead, on my own box, with its history in a local SQLite file. Three reasons, and they're all practical.
First, Temporal workers are long-lived pollers. They can't run inside a Vercel function, which is the exact constraint I'd been fighting. Whatever hosts the server, the workers need a real machine.
Second, I want people to run it. Everyone has a family, so anyone should be able to try it on their grandmother tonight. The quickstart is the Temporal CLI, a Python venv, a worker and a small web app. No API key, no account, nothing to sign up for:
temporal server start-dev --ui-port 8233
.venv/bin/python worker.py &
.venv/bin/uvicorn web.app:app --port 8090 &
.venv/bin/python start_run.py examples/erastus.json
Third, I'd rather own the stack. The things I build sit on infrastructure I can run myself, and a research tool for family records is a good place to hold that line. The production plan is self-hosted Temporal on Postgres or Temporal Cloud, workers on a small VM, and the web app staying on Vercel, which is fine for pages and API routes.
What the paper measured
I wrote the method up as a paper, Curiosity Recursion: Durable, Grounded Question Graphs for Genealogical Dark Data. The idea has a name now. Curiosity Recursion (CR) turns the human nudging loop into an explicit question graph. Every new question must quote the finding that sparked it, is deduplicated against a memory of every question asked before, and expands under explicit limits. The numbers below come from the generated results files in the repo, not from me retyping them.
The main benchmark is corpus replication. I took six people from one family, all deceased, whose lives I had already researched by hand into full dossiers. Each strategy gets only a name and a birth year, and 100 lookups in free public sources: Internet Archive, Chronicling America, Wikidata. My own sites, repos and deployments are blocked at the tool layer, and any page that copies eight or more words from a dossier is dropped, so nothing can score by reading the answer.
Share of each dossier recovered:
| Strategy | Overall | Reachable facts only | Precision |
|---|---|---|---|
| CR, preregistered rules (B5) | 9.8% | 19.4% | 66.9% |
| ReAct agent (B1) | 11.6% | 22.0% | 49.3% |
| Single-pass search (B0) | 6.9% | 14.3% | 30.5% |
| CR, repaired rules, post hoc (B5-fix) | 12.4% | 24.4% | 67.2% |
CR lost to the ReAct agent. It was better for none of the six people and worse for four (exact sign-flip p = 0.125). It beat single-pass search and it was the most precise: two thirds of what it cited was about the right person, against about half for ReAct. After the preregistered run I repaired its question rules, and that version came out on top at 12.4%. That repair is post hoc, and with six people none of these differences is statistically significant. Six is too small. I'm saying that plainly because it's the most important number in the table.
The preregistered record-level test, on 12 test subjects from a separate benchmark of hidden records called DarkKin-Bench, went worse. CR found 0.128 of the hidden records, the ReAct agent 0.288, and single-pass search 0.221. The main hypothesis was not supported.
A second version, also preregistered, ran parallel research lanes as Temporal child workflows behind a shared search ledger that refuses repeat calls. The ledger did its job. Exact repeats fell to 0.28%, the swarm used 94.4% of its budget at zero model spend, and its precision was 76.3%, above both comparators. It recovered 11.5% against 12.4% for both ReAct and the repaired rules. Not supported either. And with some irony, 4 of its 108 runs died on a Temporal client timeout during an infrastructure hiccup on the benchmark machine. They're kept and scored as zeros.
Model spend for every experiment in the paper came to $6.29. Archive lookups are free.
The bigger finding is the ceiling
The strategy mattered less than the sources. Most dossier facts come from paywalled newspapers, military files, books and family interviews that no free tool can reach. Homer has zero facts reachable with these tools. John has two. In the first benchmark, every strategy scored zero on both of them. That is the same pattern as the Google chart above, measured a second way.
One error worth showing
The most useful thing the loop did wasn't a score. In one run it found a line in a scanned encyclopedia: "Erastus W. Burnham, son of Phineas and Abigail (Huntley) Burnham." A plain agent would write that down as his parents. The evidence check read the rest of the passage, which says that man was "born April 15, 1810, and died October 20, 1854." The documented record has 1834 to 1921.

Every node explains itself: the question, what sparked it, where it looked, and the lead it produced, marked Possible and in conflict.
So the report keeps the parents lead as Possible, names both conflicts, and notes the passage may describe a different man with the same name. Another book mentions an Erastus who is the "son of Erastus W.", which fits an older Erastus, but that reading is only a lead too. The report doesn't pick a side.

The draft is written only from documented records, every sentence footnoted. Conflicts stay visible and unresolved.
One honest note on that report: most of its documented facts come from curated test fixtures, labelled as stubs in the app. The live sources add leads, not facts. One live lead worth showing is a roster on page image 14 of the 12th Connecticut's regimental history that reads, verbatim, "Burke, John Burnham, Erastus W. Carlan, John." That's a full-name match in a book no name index covers. It's a lead, not an identification.
What's next
- Real sources behind the stubs. Swap fixtures for live clients one at a time, behind the same activity signatures. Keyed sources read their secrets in the worker only.
- Longer runs. No continue-as-new yet. A brainstorm of hundreds of nodes or weeks of timers needs each subtree in its own child workflow.
- Better questions. The generator is rules today. A model-written version did worse in the benchmark (9.3%, post hoc), so this is open.
- More people. Six dossiers can't separate strategies. The benchmark needs many more families, and the reachability ceiling says some of them should be families whose records live in archives, not on the web.
- Outreach that stays ask-first. Drafted letters become requests I approve and send myself. Nothing goes out automatically.
The point was never a leaderboard. It was to stop being the supervisor, and to have every run leave a record that the next one can pick up. Temporal turned out to be the right tool for that part. The searching part still has a lot of work left.
- Code, paper and benchmark: github.com/Verafyai/curiosity-recursion
- The paper (PDF): verafyai.github.io/curiosity-recursion/paper/main.pdf
- Benchmark page: verafyai.github.io/curiosity-recursion/benchmark
- Lineage search: lineage.rexstjohn.com/search