Quickstart
Installation
Install using pip:
pip install rdgai
Or install directly from the repository:
pip install git+https://github.com/rbturnbull/rdgai.git
Usage
See all the options with the command:
rdgai --help
Preparation
You first need to prepare a TEI XML file with a critical apparatus.
Define categories in the TEI XML header under <interpGrp type="transcriptional">. For example:
<interpGrp type="transcriptional">
<interp xml:id="Addition" corresp="#Omission">An addition of a word or words.</interp>
<interp xml:id="Omission" corresp="#Addition">An omission of a word or words.</interp>
<interp xml:id="Substituion">A substitution of a word or words.</interp>
</interpGrp>
Then annotate pairs of readings in the browser-based GUI (see `Annotation GUI`_ below), where RT is your
xml:id as the annotator:
rdgai annotate apparatus.xml --annotator RT --open
or with Claude through the MCP server (see `MCP server`_ below). Or export classifications to Excel for collaborative editing:
rdgai export apparatus.xml reading-pairs.xlsx
Edit in Excel and re-import with:
rdgai import-classifications apparatus.xml reading-pairs.xlsx output.xml
More information about preparing the TEI XML file can be found in the Preparation documentation.
Evaluation
The accuracy of Rdgai depends on the text, the categories and their definitions, and the model used, so it needs to be evaluated on each document. Draw a sample of units, annotate them, and hold half of them out as test units:
rdgai sample apparatus.xml -n 200 --seed 42
Then evaluate the pipeline against your labels on the test units:
rdgai evaluate apparatus.xml --output-dir evaluation --model anthropic:claude-opus-5-5 --rounds 3
This runs the pipeline on a copy of the file with the test units’ labels removed (so they cannot leak into the
prompts), then compares the draft and the reviewed predictions with your labels. evaluation/report.html shows the
accuracy, per-category precision, recall and F1 (categories with fewer than 10 test pairs are marked as indicative
only), the confusion matrix, every test pair (correct or not) and the revisions made in review. The original file is
not modified.
To compare setups without touching the test units, cross-validate on the example units with --fold (1 to
--folds, 5 by default); the folds are saved and reused. The draft model names a second category when it is unsure,
and --expert-model sends just those pairs to a stronger model (--expert-mode after, the default) or lets the
draft model ask it while it works (--expert-mode tool). --batch drafts through Message Batches at half price:
rdgai evaluate apparatus.xml --output-dir cv/f1 --fold 1 --model anthropic:claude-haiku-5-5 --expert-model anthropic:claude-opus-5-5
Classification
The pipeline uses pydantic-ai, so any model it supports can be used
(anthropic:claude-opus-5-5 by default; openai:…, local models, …). Agents read through the rdgai MCP server
(definitions, units, similar labelled pairs) and give a checked, structured decision for every pair, which is written
with resp="#rdgai", the agent’s confidence as @cert and a <change> recording the run and model.
Human labels are never changed. First estimate the cost (no model is called):
rdgai estimate apparatus.xml --model anthropic:claude-opus-5-5
Then run the draft pass, which classifies every pair still to classify (pairs covered by subreading rules are labelled
by rule instead). It is resumable: run it again to continue, and calibrate the estimate with --limit-units 20 first:
rdgai draft apparatus.xml --model anthropic:claude-opus-5-5
With an Anthropic model, --batch sends the requests through the Message Batches API at half the price, with results
within hours rather than minutes (rdgai estimate shows both prices). The batch’s state is kept in
apparatus.batch-state.json, so if the command is interrupted, running it again collects the submitted batch instead
of paying again. For example, Opus labelled all 42,695 unlabelled pairs of the ECM’s Mark (5,426 units) in about 84
minutes for $131:
rdgai draft apparatus.xml --model anthropic:claude-opus-5-5 --batch
Then review the pipeline’s labels one category at a time, applying the revisions (logged to apparatus.revisions.jsonl):
rdgai review apparatus.xml --rounds 3
rdgai run does all three (rules, draft, review). Check the results in the annotation GUI, where the pipeline’s
labels are shown with their source and can be corrected.
More information about making automated classifications using Rdgai can be found in the Classification documentation.