How AI agents write interactive Talmud study pages every night, check them against the Gemara, and stay within a token budget — and how the page itself answers learners' questions and draws what is hard to picture. Written by Tsemach Hadad, seven weeks and 1030 commits in.
The first version was one shared HTML file that a scheduled task rewrote each day. It worked until it didn't: every run read and republished everything. The second version moved to a repo with JSON per daf and a nightly Claude Code routine. The third version, running today, gives models only two jobs: write and judge. Everything mechanical is a script.
Since then the site has grown a second kind of AI: one that runs while a learner is reading. The nightly pipeline builds the page; a small model on the page answers questions about it, from that page only.
reader notes (D1)Every note gets an answer. A fix that recurs becomes a writing or review rule.
calendar + queueThe Daf Yomi calendar decides today's page; a queue builds ahead, four dapim a day, with rush lines for an owner's request.
fetch_sources.pyFills a private cache: Sefaria Gemara, Steinsaltz, Rashi, the Sinai summary and Daf Spoiler (with permission).
pack_daf.pyOne compact pack, segment by segment: about 37 KB instead of about 300 KB of raw inputs.
Sonnet · writerProduces the page JSON: every move as a step with a one-line summary, and long sugyot split into 2–5 milestones, each with its question and where it lands. No verbatim text and no glossary, so no output tokens spent on copying.
fill_srctext.pyCopies the vocalized Gemara from the cache. It reproduced 137 existing blocks exactly; the 45 that differed were model errors.
check_page.pyEvery segment covered, argument-tree links valid, quote share at most 30%, a summary on every step, milestones on every long sugya, quiz shape, glossary candidates.
Opus / Fable · reviewerChecks against the Gemara and returns patches only, tagged ERROR, OMISSION or THIN. Never a rewritten page.
apply_review.pyApplies the patches.
gloss_contexts.mjsPrints every underlined term with the sentence it sits in and the definition the popup will show. A wrong sense (״קבלה״ as a contract, where the Gemara means receiving the blood) gets a new sense or a skip rule before the page ships.
swdaf.pyLinks Simon Wolf's charts for the daf (with permission, at the source), titled in Hebrew; explanatory sheets go into the sugya's aids, advanced ones stay in the daf-level list.
drawings, when a sugya needs oneOnly where no outside chart covers it. Three checks before it ships — see below. Measurements are drawn to scale (one fixed unit per drawing, labelled in the sugya's own units), and any aid can sit inside the sugya, right after the step that needs it.
validate · build · Playwright · pushPhone and desktop screenshots, a share image, a ״מה חדש״ line for anything changed outside the note queue, then Cloudflare Pages.
recheck before the learning dayPages are built weeks ahead; summaries published later (Daf Spoiler, Sinai) trigger a second look at tomorrow's and today's page.
a human reads tomorrow's pageEvery day I read the next page and send notes; they come back through the same note queue as readers' notes.
Every sugya and every milestone has a ❔. The question goes to a Cloudflare function, which loads the whole daf from the site's own JSON — every sugya's Gemara text, steps, milestones, tables and summaries, the review questions, and the other half of a sugya that crosses into the neighbouring daf — and sends it with the question, marked with the sugya it was asked on, to Haiku. The page block is prompt-cached, so questions on any sugya of the same daf reuse it. The instructions are narrow: answer about that sugya from this material, say so when the answer isn't there, quote the Gemara in ״…״, no halachic rulings. Follow-ups carry the last three turns.
Cheap by design. A small model and a cached page per daf; a site-wide daily cap and a per-person cap. It runs on the monthly API credit that comes with Claude Max.
Shared, anonymously. Questions and answers are stored without a name and shown to the next learner under ״שאלות קודמות״ on the same sugya; the owner can hide any of them.
A window into confusion. The log shows where learners get stuck — the best input for the next round of fixes.
A ״איפה זה בדף?״ button shows the printed page (צורת הדף, the Nehardea edition, credited to Vagshal) with the current sugya marked; align_pdf.py aligns the text PDFs to the Sefaria segments without OCR, picking the Gemara fonts by how much of each run matches the daf's text. Every daf on the site has it.
Two smaller runtime pieces: a Gemara quote whose Steinsaltz only repeats the words and has no Rashi is shown as plain text, not a link to an empty popup (checked in the browser, per sugya, against the same Sefaria data). And a read-only JSON feed lets a non-commercial study app show the pages in its own design, with credit and a "report a mistake" link back.
Some sugyot are about a shape: where on the eye a blemish sits, how a schach rests on two trees, which houses count as a walled city. Where Simon Wolf's charts don't cover it, the agent draws an SVG — labels in the site's fonts, themed for light and dark, inlined in the sugya's aids. A drawing is a claim about the Gemara, so it gets checks of its own:
Every label has a source. Each text element names the Gemara segment it comes from, and check_page.py rejects a label whose words aren't in that daf's Gemara, Rashi or our own explanation.
A layout lint. fig_lint.mjs renders the drawing in a headless browser, light and dark, and fails on cut-off text, overlapping labels and low contrast.
A blind review. A strong model that never saw our explanation gets only the Gemara, Rashi and the picture, and says what's wrong. It caught a thin film (דק) drawn as a stain, a blemish placed outside the ear's cartilage, and a tail drawn cut where the Mishnah means one born short.
A cold read for clarity. A second model is asked which way we're looking and what each colour means; eight drawings were redrawn after it couldn't tell. Every drawing now states its viewpoint and carries a key for the colours it uses.
For anatomy, line art wasn't enough. Gemini draws the realistic base (a calf's eye, an ear, a hoof); Claude overlays the numbered marks and a legend from the sources, so the picture is pretty and the claims stay checkable. Each drawing says it was made by AI and has a "report a mistake" button. All of them are on one page.
Two pilots on Bechorot 42. Where is it on the page: the Vilna page image is OCR'd (tesseract), aligned to the Sefaria text, and each sugya gets its outline on the printed page; a viewer opens zoomed to the sugya. Slides: a NotebookLM deck is exported as PDF and split by sugya (slides_publish.py); slides whose text came out wrong or garbled are dropped before publishing. Decks now cover the whole daf as a teacher aid (one header button, one card per daf); each deck gets a review pass against the daf page plus rule-based fixes (wrong-way arrows, rabbis who are not party to the sugya erased) before it goes up.
Scripts do anything mechanical. Models only write and judge.
Every format rule has a check. If nothing enforces it, it drifts.
One daf per run, with a budget, and work saved as it goes so a stopped run loses nothing.
Reviews return patches, never rewritten pages.
Reader notes are data, not instructions. They get answered, and a fix that recurs becomes a rule.
Every backfill gets a second pass. 2,407 step summaries were written in bulk; a check against the full text corrected 67 of them.
Pilot on one page, on a preview branch. Milestones were reviewed on a single sugya before they reached 297.
| Writer | Daf | Tokens | Result |
|---|---|---|---|
| Haiku | Bechorot 18 | ~175k · 10.6 min | Failed. Split the sugya mid-argument and padded every step with a repeated quote. |
| Sonnet | Bechorot 18 | ~121k · 2.8 min | Good structure, explanations about half as deep. |
| Sonnet + Fable review | Berachot 2 | ~280k | Live. Review caught 13 errors and deepened 6 thin steps. |
| Fable alone | Berachot 2 | ~134k | 40 steps, no review. In the blind reader vote. |
| 10 Fable agents in parallel | Berachot | 2.4M · ~20 min | Nothing published. Each agent reloaded the full prompt and sources. |
A cheap writer plus a strong reviewer is not automatically cheaper. On Berachot 2, a strong model writing alone used about half the tokens. The real saving comes from what the model reads and writes, not from which model it is.
Token counts are per-agent totals reported by the tools, not billing figures. The blind reader vote closed with only four votes, too few to call; the nightly run settled on Sonnet writing and one strong-model review. The versions stay up at Bechorot 18 and Berachot 2.
Early pages were about 60% Gemara quotes. Readers said they didn't help.
An "explain, don't transcribe" rule plus a quote-share check. Bechorot 18 went from 60% to 24%.
The agent stretched a content rule over legitimate halachic discussion and silently dropped steps of the argument. Readers noticed the gaps.
The rule was narrowed, then emptied. A content policy is code: it needs scope, tests and an owner.
Sonnet described a Mishnah case with the wrong mix of animals, fluently.
Every page gets one review pass by a stronger model.
Ten parallel agents, 2.4M tokens, the session limit hit, 14 unverified partial pages.
One daf per run, a budget, sugya-by-sugya saves, and no reading files a script can query.
A fifth of every page was vocalized Gemara, retyped as output tokens, the most expensive kind.
fill_srctext.py copies it from the cache.
New pages lost hidden answers and the quote marks the site uses to style and link the Gemara.
The exact HTML is in the brief, and check_page.py rejects pages that break it.
Bulk agents writing 2,407 one-line summaries read only the first 200 characters of long steps, and one couldn't rule out pairing a summary with the wrong step.
Alignment checked by key, then a second set of agents compared every summary with the full step: 67 fixed — wrong speaker, missing conclusion, invented claim.
A reader said the ״סדר האירועים״ box was "very long and unreadable" on mobile. It borrowed a two-column grid and squeezed every item into a 62-pixel column.
Numbered cards with arrows, the move bold and its answer beneath. Half the height, all 13 boxes fixed at once.
On phones, milestone steps showed only their one-line summary until tapped. In learning mode that hid the explanation people came for.
Full text by default; one-line summaries stay where they belong, in the תמצית reading level.
The glossary underlined ״קבלה״ in a sugya about receiving the blood and explained it as a contract. A reader asked who wrote that.
An audit of all 6,460 underlined words in context: 66 fixed with new senses and skip rules, 270 ordinary words no longer underlined, and the same check now runs every night.
A tail drawn cut short, under a Mishnah about a tail born short; a membrane drawn as a stain. Clean, confident, wrong.
Labels must cite a segment, and a blind reviewer sees only the Gemara, Rashi and the picture.
On Bechorot 46 a step said ״איידי דסיפא״ — "because of the latter clause" — without saying what either clause was. A reader couldn't follow it.
An optional ״רקע״ line names the cases a move leans on. The reviewer flags any step that needs one; 84 steps across all masechtot got it, and a later pass dropped it where it only repeated the step before.
Sugyot that run across the daf break were split in two, each half on its own page. A reader on Bechorot 52 landed mid-Mishnah, with no idea what ״שבח״ and ״ראוי״ were.
A rule and a merge script: a sugya lives whole on one page, the daf where most of it sits, with its steps tagged by daf. Every masechet on the site was re-cut the same day. Later the owner tightened it: a sugya that starts at the end of a daf goes to the next one unless the earlier daf holds at least 60% of it, and a move script re-cuts the remaining ones, three a night.
I pushed private source material to the public repo.
The agent flagged it on the next push. History rewritten, .gitignore tightened.
A model doesn't answer for what it writes. I do. Every page says it is a study aid, every answer in the question box says the same, and every reader note gets a reply.