🌍 Introduction
In this lab, you will explore automation of science experiments using the Opentrons API for pipetting robots. You will first practice running protocols in simulation mode to understand how the API works.
Then, you will move to Code Agents: integrating the lab context into a Hypha MCP endpoint, configuring Gemini CLI with your MCP tool, and letting an AI agent design and execute experiments.
This lab combines programming, robotics simulation, and AI orchestration.
Part I — Getting Started with Opentrons in Google Colab
Step 1: Open the Module 6 Notebook in Colab
Notes:
- Runtime: CPU is sufficient.
- You can run a cell with Shift+Enter.
Install Gemini CLI in Colab
Go to the terminal in Google Colab and run the following commands to install Gemini CLI:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
source /root/.bashrc
nvm install 21
nvm use 21
npm install -g @google/gemini-cli
Step 2: Install and Import the Opentrons API
The notebook will guide you through installing the Opentrons package and setting up a ProtocolContext.
Step 3: Practice with the Opentrons API
You will:
- Load labware (
96-well plate
,reservoir
,tiprack
). - Load an instrument (
p1000_single
pipette). - Write and run a serial dilution protocol in simulation.
- Inspect the output log from the simulator to confirm your steps.
By the end of Part I, you will:
- Understand how the Opentrons API structures labware, wells, and pipettes.
- Be able to write short protocols for common lab tasks (aspirate, dispense, mix, transfer).
Part II — From Simulation to AI Agents
🤖 What is a Code Agent?
A Code Agent is an AI agent that doesn’t just call tools — it can also generate, execute, and adapt code to solve problems. Instead of relying only on predefined MCP tools (e.g., “train BINN model,” “plot SHAP values”), a code agent works in a more open-ended way:
Writes Python snippets in response to your request.
Executes them in a controlled environment (e.g., Google Colab).
Observes the results (success, error, printed logs).
Improves or retries the code if needed.
This loop is similar to how a human scientist programs: write → run → debug → refine.
đź’ˇ Why do we need Code Agents?
Flexibility: In real experiments, not everything can be wrapped into fixed MCP tools. Sometimes you just need quick logic (loops, conditions, data munging).
Exploration: Scientists often don’t know in advance what exact steps are needed. Code agents allow the AI to try things and refine them.
Automation: Instead of giving you a “template,” the agent can adaptively build a protocol (e.g., change pipetting volumes, add new mix steps, generate a serial dilution loop).
In short: MCP tools are like predefined functions. Code Agents are like giving the agent a Jupyter cell to think in.
Related Materials
This approach is inspired by research on Code Agents and practical tutorials from Hugging Face’s Agents Course.
Task 2: Code Agents for Automated Protocol Design
Step 2.1 — Set up a Hypha MCP Endpoint
In Colab, you will:
- Create a Python interpreter MCP tool exposing the Opentrons
protocol
,plate
,reservoir
, andpipette
objects. - Register it on Hypha so it is accessible as an MCP service.
At the end of this step, you will see a URL for your MCP endpoint, e.g.:
https://hypha.aicell.io/<workspace>/mcp/<service-id>/mcp
Keep this URL — you’ll need it for Gemini.
Step 2.2 — Configure Gemini MCP Settings & GEMINI.md
Create a
GEMINI.md
file describing:- The role of the agent (designing Opentrons experiments).
- Instructions for using the
pipette
,plate
, andreservoir
. - Guardrails (no large prints, no external commands).
- Example snippets (e.g. serial dilution, column dosing).
Create a
settings.json
file and add anmcpServers
entry like this:
{ “mcpServers”: { “opentrons-mcp”: { “httpUrl”: “your url link” } } }
Then move this file to the Gemini config directory:
```bash
mkdir -p /root/.gemini
mv /content/drive/MyDrive/DDLS-Course/Module6/settings.json /root/.gemini/settings.json
Tips: Gemini CLI discovers MCP servers from this file; use /mcp list
in the chat to list available tools.
Important Note: Based on previous experience, AI agents may attempt to read and display entire data matrices, which can cause system crashes. To prevent this issue, include the following critical tips in your GEMINI.md file:
**Critical Tips**
-------------
- ⚠️ When running Opentrons protocol scripts, add print() statements to show progress and confirm actions like loading labware and instruments.
Step 2.3 — Start Gemini in VS Code and Run Experiments
Set up VS Code Tunnel (Optional but Recommended)
For better code editing and debugging experience, you can set up a VS Code tunnel to work with your Colab environment:
Install VS Code CLI in the Colab terminal:
curl -Lk 'https://code.visualstudio.com/sha/download?build=stable&os=cli-alpine-x64' --output vscode_cli.tar.gz tar -xf vscode_cli.tar.gz
Start the tunnel:
./code tunnel
Follow the authentication steps using your GitHub account, then name your machine (e.g., “colab”).
Open VS Code in your browser using the provided link and navigate to your Module6 folder:
cd /content/drive/MyDrive/DDLS-Course/Module6/ code .
Start Gemini CLI and Verify Setup
Launch Gemini CLI in your terminal (either in Colab or VS Code):
gemini
Verify MCP server discovery: You should see this message at the top of the Gemini input box:
Using: 1 GEMINI.md file | 1 MCP server (ctrl+t to view)
Check available tools: Enter
/mcp list
in the chat interface to see all your configured MCP tools.Begin experimenting: Ask Gemini to design and execute Opentrons protocols using your MCP tools!
Deliverables
At the end of this lab, submit in your Google Drive folder:
- Completed Notebook from Part I.
- MCP Tool + GEMINI.md (Part II).
- Gemini Chat History showing your designed experiment.
- Short Markdown Report (
REPORT.md
) summarizing:- What protocol you designed.
- Example output from the agent.
- Your own reflection: how did the agent help?
Submission Tips
Save Gemini chat history regularly:
/chat save computer-lab-6
Copy checkpoint files from Colab runtime:
cp /root/.gemini/tmp/*/checkpoint-computer-lab-6.json .
Important: Copy your completed notebook to your Google Drive folder at
DDLS-Course/Module6/
after finishing the lab.Share your Google Drive folder with “Anyone with the link can view and comment.”
Submit via the course form: https://forms.gle/EHnrmGksJZD3aVx2A
âś… Grading Pass/Fail based on:
- Completion: Notebook + MCP tool + GEMINI.md + Report.
- Engagement: Evidence of running both simulation and agent workflows.
- Clarity: Organized folder, clear report.
- Reproducibility: All steps can be re-run from your materials.