Cookbook · example 2
Monitor an instrument overnight
Log a reading every few seconds for a set time, raise an alert if it leaves a band, and read the results back the next morning. The agent starts the run and leaves; the run carries on by itself.
You need: the setup from the cookbook front page. We use the simulated thermocycler's block temperature as the thing to watch, with a two-minute "night" so you can see the whole cycle. About five minutes.
Give the thermocycler something to hold
Set the thermocycler block to 37 degrees.
The agent calls
mhp_writefortarget_temperature= 37. Ask "what is the block temperature?" and it reads it back: 37.0.Start the watch
Watch the thermocycler block temperature every 5 seconds for 2 minutes and alert me if it leaves 36.5 to 37.5. Run it in the background.
The agent finds the
periodic-readingsrecipe and starts it withbackground=true:mhp_run recipe="periodic-readings" background=true params={"device": "thermocycler-01", "signals": ["block_temperature"], "every_s": 5, "hours": 0.033, "alert": {"block_temperature": [36.5, 37.5]}}It replies with the run id, for example
20260910-1402-a1b2, and says it is running in the background. Nothing else happens in the chat while it runs.Cause an alert
About a minute in, change the setpoint so the watch has something to catch:
Set the block to 40 degrees.
The block ramps to 40 within a few seconds. The running watch sees it leave the band.
Ask what happened
After two minutes:
What happened with the watch?
The agent calls
mhp_data op="runs", sees the run is done, and reads its output:ALERT t=65s block_temperature=40.0 outside 36.5..37.5 ALERT t=70s block_temperature=40.0 outside 36.5..37.5 ... 24 rows in readings.csv; 11 alert(s)It summarises: "The block left the band at 65 seconds when it rose to 40 °C and stayed there until the end. 24 readings are in readings.csv."
Look at the data
Show me the readings.
The agent reads
readings.csvfrom the run folder withmhp_data op="read":t_s,block_temperature 0.0,37.0 5.0,37.0 ... 65.0,40.0The file is also on disk at
~/.openmhp/runs/<run-id>/readings.csvif you want to open it yourself.Check the log
What has happened in the lab today?
The agent reads the run log (
mhp_lab op="events"): the two setpoint writes, the run start and finish, and any refusals. If your harness accepts MCP logging messages, the finish and the alerts arrived as they happened.
Doing it on a real instrument
- Any device with readable signals works: an incubator via PyLabRobot or OPC UA, a chamber behind a PLC, a serial thermometer on a freezer.
- Say the real numbers: "every minute for 12 hours, temperature 36.5 to 37.5 and CO₂ 4.8 to 5.2".
- Runs are not limited in length. The CSV is written after every reading, so nothing is lost if the laptop sleeps late in the run.