> ## Documentation Index
> Fetch the complete documentation index at: https://docs.brainworkup.org/llms.txt
> Use this file to discover all available pages before exploring further.

# The Luria agent pipeline: from intake to PDF

> Understand the five-phase, visit-based agent pipeline that Luria uses to move a case from referral through testing, SIRF synthesis, and final report rendering.

I built Luria to compress the wall-clock time of a neuropsychological evaluation without compressing the clinical care that goes into it. The agent pipeline is the part of that work that runs between visits. It handles intake parsing, transcript summarization, domain interpretation, and report assembly so you can spend your time on the patient, not on copy-paste.

The pipeline is organized into **five phases (A–E)** that map onto the three clinical visits in a standard evaluation plus the deterministic render at the end.

## Pipeline at a glance

| Phase | Stage    | Clinical visit         | What it produces                                 |
| ----- | -------- | ---------------------- | ------------------------------------------------ |
| A     | Intake   | Visit 1 — NSE          | Validated intake folder + NSE summary            |
| B     | Testing  | Visit 2 — NT           | Per-domain interpretations from scored test data |
| C     | SIRF     | Visit 3 — Feedback     | Integrated summary, diagnostic impression, recs  |
| D     | Assembly | Between Visits 2 and 3 | Composed report draft with quality review        |
| E     | Render   | Final                  | Deterministic Typst → PDF (no LLM in the loop)   |

Phases A–C are agent-driven. Phase D is a quality-gate assembly step. Phase E is intentionally deterministic — once the prose and tables are locked, rendering is a pure function of the source.

## Phase A — Intake (Visit 1 / NSE)

Phase A turns the messy reality of an intake folder — consent forms, prior records, audio, rating scales — into a clean, redacted summary you can interpret. The agents fan out in parallel, then converge on a redaction gate before any LLM sees the composed summary.

```text theme={null}
A1 (nse_admin)
 │
 ├──▶ A2 (nse_clinical_past)    ──┐
 ├──▶ A3 (nse_clinical_current) ──┤ parallel
 └──▶ A4 (nse_stt_transcript)   ──┘
                                   │
                                   ▼
                             A5 (nse_cod_summary)   ← PII redaction gate
                                   │
                                   ▼
                             A6 (nse_report)
```

| Step | Agent                  | Job                                                         |
| ---- | ---------------------- | ----------------------------------------------------------- |
| A1   | `nse_admin`            | Verify consent, ROI, referral, and demographics are present |
| A2   | `nse_clinical_past`    | Extract prior medical and psychiatric history               |
| A3   | `nse_clinical_current` | Extract current rating scales and educational records       |
| A4   | `nse_stt_transcript`   | Transcribe the 60–90 minute NSE audio                       |
| A5   | `nse_cod_summary`      | Build the Chief-of-Diagnosis summary (PII-redacted)         |
| A6   | `nse_report`           | Draft the NSE narrative for the report                      |

**When to use it:** Run Phase A as soon as Visit 1 ends and the intake folder is complete. A6 is the artifact you want before moving on to test selection.

## Phase B — Testing (Visit 2 / NT)

Phase B reads scored test data from the `cingulate` pipeline and writes per-domain interpretation paragraphs. Each cognitive and neurobehavioral domain is interpreted independently, so a low-effort flag in one domain does not contaminate the others.

| Agent         | Scope          | Output                                      |
| ------------- | -------------- | ------------------------------------------- |
| `domain_text` | One per domain | Interpretation paragraph + validity caveats |

**When to use it:** Run Phase B once the test scores are scored, classified, and saved to `data/scores/`. The output drops into the domain partials your report includes.

## Phase C — SIRF (Visit 3)

SIRF stands for **S**ummary, **I**nterpretation, **R**ecommendations, **F**eedback — the integrative work that ties the testing data back to the referral question.

| Agent          | Job                                                             |
| -------------- | --------------------------------------------------------------- |
| `sirf_summary` | Integrate Phase B domain interpretations into a unified summary |
| `sirf_recs`    | Generate clinical recommendations grounded in the summary       |

**When to use it:** Run Phase C after Phase B is complete and you have reviewed the per-domain drafts. The output becomes the front matter of the final report — the part the referring provider actually reads first.

## Phase D — Assembly

The `report_assemble` agent stitches the NSE narrative, score tables, domain interpretations, and SIRF output into a single Quarto-ready draft. This is also where the quality checklist runs — completeness, internal consistency, and HIPAA-style redaction checks.

## Phase E — Render

The final step is a plain `quarto render` call against the assembled `.qmd`. There is no LLM in this loop. Same source, same PDF, every time — which is what you want for a clinical document that may end up in a chart, a courtroom, or a school district file.

See [How Luria Voice works](/concepts/overview) for the rendering layer in detail.

## How the visits map to the codebase

The agent code is organized by clinical visit, which mirrors how the work actually unfolds in the clinic:

| Folder         | Phase | Contents                                                                |
| -------------- | ----- | ----------------------------------------------------------------------- |
| `visit1_nse/`  | A     | Intake extraction prompts, NSE transcription, patient documentation     |
| `visit2_nt/`   | B     | Domain interpretation prompts, score table generation, R/Python helpers |
| `visit3_sirf/` | C     | Diagnostic frameworks, reporting standards, recommendation prompts      |

If you are wiring up a new clinic or extending the pipeline, start from the visit folder that matches the stage you are working on.
