Agents in the Lab¶
A practical lab book for PhD students using AI agents to write scientific code. Start with a small dataset, ask a question, and make something you can check. The examples use Claude Code, but the working habits apply to other agents too.
AI makes it much easier to try an idea, learn an unfamiliar tool or turn a calculation into a useful script. Have fun with it. Give the agent good context, commit often, and do not be afraid to restart when an approach is going nowhere.
Start small¶
The lab-data tutorial takes you through importing, checking,
plotting and analysing the internal gender_intero dataset. For a quick start without
research-data access, use the fictional CSV warm-up. You need basic Python and a terminal; the agent can help with the
mechanics. No cluster, custom skills or workflow framework is required.
Read Start here, get set up, and try the tutorial. Use the other pages as questions arise.
The working cycle¶
Give context → agree a plan → let the agent work → check the result
↑ │
└──────── save useful progress in Git ──────────────┘
You provide the scientific question, definitions and expected behaviour. The agent helps build the code and pipeline. Save small, descriptive commits throughout, including commits made by the agent. A fresh session can pick up from the files and history.
The workflow page gives example prompts. Working with context shows how a model specification can guide implementation.
Choose how far to go¶
| Stage | Read and try | What you should be able to do |
|---|---|---|
| First session | Start here, setup, lab tutorial or quick warm-up | Import a table, check it, make a plot, answer a small question and save commits. |
| Everyday work | Context, layout and Git, project instructions, the loop, practical tips | Give a useful brief, work in small steps and recover from an unhelpful session. |
| Results you will rely on | Verification, reproducibility, figures | Explain your checks and reproduce a result from saved files. |
| Optional extensions | GitHub with an agent, skills, cluster work, genomedk example | Collaborate through PRs, reuse procedures or scale an analysis when your project needs it. |
Before working with participant files, read Human-subject data. The internal tutorial uses the lab's approved access arrangements; the warm-up uses fictional observations.
The references behind the book¶
Our main references are Ten Simple Rules for AI-Assisted Coding in Science and Russ Poldrack's Coding with AI. They provide the scientific computing principles; this book helps you practise them in small steps. You do not need to adopt every tool or advanced practice at once.
Resources suggests where to read further. Contributing explains how to improve the book.
Copyable starters¶
- Fictional trial data for the first exercise.
- Project instructions and project layout.
- Rescorla–Wagner model specification for a later modelling task.
- Verification checklist for results you will rely on.
- Git ignore rules.
- Snakefile, an optional advanced pipeline example.