atrix-agent
v0.2.0
Published
Local file-format conversion agent for Atrix. Raw data never leaves the computer.
Maintainers
Readme
atrix-agent
Converts a lab's annotation files to NWB, BIDS, EDF+, CSV or JSON on the lab's own computer, using the same format code as the Atrix app. An AI agent plans the hard parts: odd column names, which annotation file goes with which recording, and subject/session/task in messy file names.
Install
Requires Node 20+. No install needed:
npx atrix-agent convert ./study-dataOr install once and use the atrix command:
npm install -g atrix-agent
atrix convert ./study-dataFrom a checkout of this repo: cd agent && npm install (builds dist/), then npx atrix --help.
Usage
export ANTHROPIC_API_KEY=... # your own key (or OPENAI_API_KEY)
atrix convert ./study-data # NWB (default), AI-planned
atrix convert ./study-data --to bids # one BIDS dataset in atrix-out/bids
atrix convert ./study-data --dry-run # plan and print, write nothing
atrix convert ./study-data --no-ai # offline: BIDS names + standard columns onlyOptions: --to nwb|bids|edf|csv|json, --out <dir> (default <folder>/atrix-out), --model <id> (or $ATRIX_MODEL; see below), --tz <IANA zone> (or $ATRIX_TZ; see below).
Bring your own API key
The AI planner runs on your own account with the provider of your choice. Set one key in the environment:
| Key | Talks to | Default model |
|---|---|---|
| ANTHROPIC_API_KEY | Anthropic API directly | claude-opus-5-5 |
| OPENAI_API_KEY | OpenAI API directly | gpt-5-mini |
| AI_GATEWAY_API_KEY | Vercel AI Gateway (any provider/model id) | openai/gpt-5-mini |
With more than one key set, Anthropic is used first, then OpenAI, then the gateway. --model anthropic/claude-sonnet-5-5 or --model openai/gpt-5-mini picks a provider and model explicitly; a bare id such as --model claude-haiku-5-5 goes to whichever provider's key is set. With no key, the tool falls back to offline heuristics and says so.
The tool scans <folder> recursively for recordings (EDF/BDF, BrainVision .vhdr + .vmrk, NWB) and annotation files (*_events.tsv, CSV, EDF+ annotations, including those embedded in an EDF+ recording, and Atrix-style JSON). It pairs each annotation file with a recording by BIDS entities, file name, folder and recording start time. Session start comes from the recording header. Outputs go to atrix-out/, and sources are never modified. A summary table is printed at the end.
Recording timezone
EDF/BDF and BrainVision headers store the recording's local date and time with no zone. The tool needs a zone to turn that into an instant, and takes it from, in order:
- a BIDS
*_scans.tsvin the recording's session or subject folder with anacq_timefor that file (ISO 8601; withZor an offset it is exact, without one it is local time at the recording site, read in the zone below); --tz America/New_YorkorATRIX_TZ=America/New_York(any IANA zone name);- this machine's zone, with a one-line note in the output when a header time was used that way.
NWB files carry a zoned session_start_time, so none of this applies to them. Zone conversion is done with the platform's own Intl data; nothing is downloaded.
Without a key, or with --no-ai, files whose columns aren't standard (onset, duration, trial_type, ..., ignoring case and units such as Onset (s)) are skipped and listed as such.
Privacy
Conversion always runs locally. With AI on, the tool sends requests to the provider whose key you set (Anthropic, OpenAI, or Vercel AI Gateway), under your own account and their data terms. The model only receives aliased file names, header metadata (format, start time, duration, channel names, sample rate; not the patient/recording ID fields), column names, and at most 10 sample rows per table. Signal data and whole files are never sent. This is enforced in src/privacy.ts: every tool result passes a guard that rejects more than 10 rows or an oversized payload, and recordings can't be previewed at all. The tool prints a one-line notice when the agent starts.
File names are aliased before they reach the model (src/alias.ts), because lab file names often carry patient names, initials or MRNs. The rule: folder depth, delimiters and the extension are kept; BIDS entities (sub-, ses-, task-, run-, acq-), dates (2026-03-12, 20260312, 12-MAR-2026) and format words (events, ieeg, ...) stay in the clear because the model needs them to pair files; every other name token becomes n<K>, the same alias for the same token wherever it appears. So patients/DOE_JANE_MRN4471902_2026-03-12_rest.csv is sent as n1/n2_n3_n4_2026-03-12_n5.csv, and the matching .edf as n1/n2_n3_n4_2026-03-12_n5.edf. The map lives only in memory for the run; paths the model sends back are mapped to real files locally (an alias it made up is a tool error), the person at the terminal sees real names in questions and in the results table, and real names typed in an answer are aliased again before they go back. --dry-run prints the alias table so a lab can check what the model would see.
Sample rows are sent as they are, so a free-text column with names in it would still reach the model; keep those out of the first ten rows or convert with --no-ai.
