Skip to content

Remote Control: everything the GUI does as calls, the acquisition manager, skills, and a lean AI Assistant - #122

Open
thomdehoog wants to merge 26 commits into
mesoSPIM:release/candidate-py312from
thomdehoog:remote-control-ai-assistant
Open

thomdehoog wants to merge 26 commits into
mesoSPIM:release/candidate-py312from
thomdehoog:remote-control-ai-assistant

Conversation

@thomdehoog

@thomdehoog thomdehoog commented Oct 13, 2026 •

Copy link
Copy Markdown

Everything the GUI can do is now a Remote Control call: 84 calls, the same over TCP, MCP and the AI Assistant. An operator's whole workflow, from the live view and the acquisition manager to the optimizer and the analyses, can be driven from outside the window. That makes it possible to build skills in any agent harness that speaks MCP (or in the built-in AI Assistant): short Markdown procedures that chain calls into a lab's own routines, such as "centre the sample", "find focus and start a tiling run".

Every call goes through the same registry, validation and execute path. Core's limits, busy gate and Stop are the safety, the same for every client.

What is in it

1. The main window follows every remote setting (2 commits)

  • A setting made over TCP, MCP or by the AI Assistant now shows in the window's widgets. Before, only filter, shutter and ETL-file changes did.
  • The window no longer echoes a refreshed value back to Core as a new request.
  • The max-amplitude keys reach Core under the name the window sends.

2. A lean AI Assistant for cloud models (5 commits)

  • Removed: history trimming and compaction, tool profiles, memory tools, Local AI mode, the scheduler, the turn guard and the Run / Cancel gate.
  • The manual goes from about 100 lines to 34. One rule for unclear requests: suggest what you would do and ask first.

3. The acquisition manager as calls (10 commits)

  • Update, add, delete, move and mark rows; save and load a list; name rows; track focus; build a tiling list; set the snap folder.
  • The wizards' arithmetic moved into utils/ as plain functions, one move per commit, so the window and the calls share one implementation. Moved, not rewritten.

4. Skills, loaded on demand (3 commits)

  • One Markdown file per skill in a skills folder next to the microscope's config; none ship.
  • The assistant lists skills by description and load_skill hands over the steps.
  • Docs page: how to write and test a skill.

5. Everything the GUI does, as calls (3 commits)

  • The live view and other windows: levels, lookup tables, regions of interest (pixels and µm), the image view's ROI and profile, the contrast window, the tile overview, opening and arranging windows, a picture of any window, Open TIFF.
  • What only a window offered: the filename wizard's writer parameters, max amplitude, the processor chain, AmpL=0 / AmpR=0 / Freeze galvos, the optimizer (AUTO Focus) with Accept or Discard, Save config file, Auto L/R illumination, and the Utils menu's PSF and field-curvature analyses.
  • Left out on purpose: the jog step boxes, the script editor, closing mesoSPIM.
  • One new module, remote_control/gui_handles.py, works the windows with their own controls; every call is checked in commands.py.
  • build_tiling_list refuses a channel value of the wrong type by name.

Footprint on existing modules

 mesoSPIM/src/mesoSPIM_Core.py                      |   4 +-
 mesoSPIM/src/mesoSPIM_MainWindow.py                |  18 ++-
 mesoSPIM/src/mesoSPIM_WaveFormGenerator.py         |   4 +-
 mesoSPIM/src/utils/acquisitions.py                 | 138 +++++++++++++++++++++
 mesoSPIM/src/utils/filename_wizard.py              |  76 +-----------
 mesoSPIM/src/utils/focus_tracking_wizard.py        |   8 +-
 mesoSPIM/src/utils/models.py                       |  38 +-----
 .../src/utils/multicolor_acquisition_builder.py    |  18 +++
 .../src/utils/multicolor_acquisition_wizard.py     |  17 +--
 mesoSPIM/src/utils/utility_functions.py            |  15 +--

Everything else is in remote_control/, ai_assistant/, their tests and the docs.

Tested

  • Windows demo mode: all 84 calls over TCP and over MCP, each checked by its effect and put back; the real-Qt test profile passes with the camera window driven offscreen.
  • Tool choice with all 84 calls on a small cloud model: the window calls did not crowd out the others, and 16 of 16 confusable cases pick the right call. The rule for writing a call's description is in docs/source/remote_control/architecture.md.
  • Skills in the assistant tab: a skills folder found, a skill loaded before its first change, a time lapse run to the end.
  • Offline: the full test suite passes.

Still to check

  • On the microscope, with an operator present: mesoSPIM/test/remote_control/live/test_all_commands_real_hardware.py. It makes small changes only, each read back and put back (X moves of at most 25 µm, the optimizer discarded, exposures at 1-2 % laser, a copy of the ETL file). Large moves run only with MESOSPIM_REAL_LARGE_MOVES=1.
  • Open items are listed in docs/source/remote_control/open.md.

Open questions

  • The window calls add about 2,900 tokens to each AI Assistant request; they could be TCP/MCP only.
  • Should waveform generation apply the max amplitude? It can be set, as in the window, but nothing uses it.
  • Are per-call limits on intensity or move size wanted at the instrument level?
  • Found, not fixed: Core's disk check calls os.statvfs('') off Windows, so a time lapse cannot start on Linux or macOS.

claude and others added 26 commits October 9, 2026 17:27
A zoom, laser, intensity or camera setting made over TCP, MCP or by the AI
Assistant changed Core's state but not the window's widgets: Core refreshes
the window itself only after a filter, a shutter or an ETL file change.

Remote Control: refresh_window_after(core, expected) polls Core's state on
its own event loop until every key a setter set reads its value or
READ_BACK_S has passed, then emits sig_update_gui_from_state; every setter
calls it. The wait matters for the camera keys, which the camera worker
writes on its own thread after the setter returned. Core's handler and
set_intensity stay as they are. galvo_amp_scale_w_zoom, forwarded by Core
and applied by nobody, is written by the shared layer. READ_BACK_S moves to
remote_control/config.py; the AI Assistant's read-back takes it from there.

Main window: spinbox_to_state_parameter and set_laser_intensity return while
update_gui_from_state shows Core's state (showing_state, as the combo boxes
do), so a refresh never sends a value back to Core, rounded or stale. The
state-to-widget table gains the binning and subsampling boxes, the
scale-with-zoom check box and the two indicators, with a str() for the
subsampling ints and a QCheckBox and a QLabel branch; run_timepoint reads
Core's time point count, so the progress bar works for a remote time lapse.

Tests: test_combobox_state_requests.py gets one test per remote setter path
and one for the rounded echo.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RH8VsZbnUgYcVt3KuXjNFk
…ow sends

The main window sends laser_l_max_amplitude_% and laser_r_max_amplitude_% (the
state keys, mesoSPIM_State.py); Core's state_request_handler and the
waveformer's listed them without the _%, so both max-amplitude boxes never
reached Core. The four strings now match the window and the state. Nothing in
waveform generation reads the value afterwards; applying it is a separate
decision.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RH8VsZbnUgYcVt3KuXjNFk
The assistant is built for gemini-3.5-flash-lite and claude-haiku-5-5; what
existed to fit a small or local model goes, and so do the scheduler and wait.

Gone: history trimming and compaction (and the thinking stripping they
needed), the "called nothing" challenge, the Regular/Full tool profiles, the
memory tools and their store queries, the Local AI mode (local.py, the
ai-assistant-local extra, --local in the runner), the Scheduler, schedule,
cancel_schedule, wait, requests.py and the continuation turns, the tab's
schedule rows and request line, the Tools and Memory boxes.

The history is append-only until Clear context. The tab shows each
session's size (the last request's input tokens), warns past the model's
warning and refuses a turn past its ceiling (per preset; Haiku warns at
100k, where its price per token rises). On Anthropic, prompt caching
through pydantic-ai's settings: tool definitions and instructions for an
hour, the growing history for five minutes (three of four breakpoints,
the hour first). Every tool is sequential, so two calls in one reply run
in order instead of the second being refused as busy. A run that returns
while under way ends the turn ("do not poll"); a 2 s check in the tab
writes one grey line when it ends, with no model turn. One clock: the
worker's clock attribute, which the harness sets to the simulator's.

The Anthropic preset now names claude-haiku-5-5. The scheduler's real-Qt
smoke goes with the scheduler. (The fork's dev suite and evaluation cases
change with this on agent/lean; they are not part of this branch.)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RH8VsZbnUgYcVt3KuXjNFk
Core's stage limits, its busy gate and Stop microscope are the safety, the
same for every client (decision 2). The assistant's own layer goes with no
code replacement: the Run / Cancel gate and its bar in the tab, TurnGuard
and its number matching, the light budget, measured values (measured.py and
its config). Load, unload, preview, calibrate and any move within Core's
limits run when asked.

One behaviour is kept, re-homed: a look right after a snap reads that frame
instead of exposing the sample a second time. It is now a check on the frame
history (the newest frame is a snap of this place and these settings, from
the last 30 s), not a flag in the guard; frames.place_and_settings is the
one definition of "same place and settings".

The manual: "When a request leaves a value or a choice open, ask; otherwise
act and say what you chose" replaces the values-only-from-the-operator rule;
the Run / Cancel lines go; "never retry a limit rejection" stays; one
sentence on not stopping the operator's run.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RH8VsZbnUgYcVt3KuXjNFk
No request line, no plan display (they went with the timer); one rule in the
manual says when to plan: a short numbered plan, at most five lines, when a
request needs more than one call or the next step depends on a look; a
target and three rounds for work that repeats; never a plan for one call.
A numbered line in the reply is what both cloud models keep (Haiku's
thinking is hidden).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RH8VsZbnUgYcVt3KuXjNFk
index.md and architecture.md follow the code: one model box per role (cloud,
or a server through the OpenAI-style preset), Preferences without Tool set or
Memory, the session's size and the caching, the done notice, the plan rule,
the instrument's limits as the only safety; the schedules, requests, measured
values, Local AI and the two tool sets are gone, and tool-sets.md with them.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RH8VsZbnUgYcVt3KuXjNFk
The manual goes from about 100 lines to 34. Removed, because they were
written against particular cases or old failures: the snap-then-look
rule, the list of questions that need a look, the ALL-CAPS "be decisive"
block, the confirm-before-run list, the plan rule's line and round counts,
the values-only rule with its example words, and the snap tool-description
override. Removed as duplicates: the failure and option-retry paragraphs
(the refusal's own advice says it), the second movement-limit rule, the
exact-options rule, and the focus metric, frame and map notes (the look
tool's schema has them). The exposure rule and the nominal centring move
go into look's description.

Kept: who the assistant serves, the readout and tool results as data, the
units and axes, no polling, nothing reported that no tool shows, not
stopping the operator's run, and one rule for unclear requests: suggest
what you would do and ask before doing it; if you don't know, ask. The
request is smaller, about 6,000 tokens; the size help says so.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RH8VsZbnUgYcVt3KuXjNFk
…ns of the builder

Moved, not changed: the wizard's three calculations become field_of_view_um,
tile_offsets and image_counts in multicolor_acquisition_builder.py (Qt-free),
which the wizard calls, so a remote build_tiling_list uses the same maths
instead of a copy. math.ceil replaces numpy's for the one ceiling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RH8VsZbnUgYcVt3KuXjNFk
…odel

Moved, not changed: saveModel's writer and loadModel's typed reader become
AcquisitionList.to_csv and AcquisitionList.from_csv (Qt-free); the model's
methods call them. A remote save_acquisition_list and load_acquisition_list
then use the same format and the same type rules as the window's buttons.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RH8VsZbnUgYcVt3KuXjNFk
…the table model

Moved, not changed: setDataFromState's choice and rounding of a row's value
from the state becomes value_from_state in acquisitions.py (Qt-free), which
the model calls; it also gives the focus range the current focus, as the
window's 'mark current focus' does. A remote mark_acquisition_rows computes
the same values and installs them through set_acquisition_list's checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RH8VsZbnUgYcVt3KuXjNFk
Moved, not changed: calculate_f_pos's line through two (z, f) points becomes
focus_at in acquisitions.py (Qt-free); the wizard's method calls it. A remote
track_focus sets each row's focus range by the same rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RH8VsZbnUgYcVt3KuXjNFk
…wizard

Moved, not changed: generate_filename_list's rule (description, zoom, tile,
channels, filter, shutter, rotation, suffix, extension; one name for a
single-file writer) becomes AcquisitionList.filenames(file_names, extension,
description), which the wizard calls; replace_with_underscores moves beside
it into acquisitions.py (Qt-free), and utility_functions imports it from there
for Core and the image writer. Checked: the old code and the function give
the same names for all 256 combinations of a writer's naming options. A
remote name_acquisition_rows names rows by the same rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RH8VsZbnUgYcVt3KuXjNFk
Eleven calls, all through the one registry, the one accept and the one
execute path, reachable by TCP, MCP and the AI Assistant alike:
update_acquisition_row, add_acquisition_rows, delete_acquisition_rows,
move_acquisition_row, mark_acquisition_rows, save_acquisition_list,
load_acquisition_list, name_acquisition_rows, track_focus,
build_tiling_list and set_snap_folder.

Every table edit builds the whole new list and goes through
set_acquisition_list's own accept and install (decision 9): the same row
checks, the same busy gate, the same bridge to the window. The wizards'
arithmetic is the code lifted into utils/, so the window and the calls
share one implementation. The assistant's own row tool is gone; the
registered call replaces it.

In the fork's dev suite, test_window_coverage maps every control of both
.ui files to its call, "display", or "not exposed" with the reason, and
fails on an unmapped control. Six controls are left for the owner (plan 3.4b). 67 calls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RH8VsZbnUgYcVt3KuXjNFk
…ument's own options

Each table call gets a fresh two-row table first and is checked by reading the
table back; set_snap_folder is restored in the cleanup. On the demo (Linux,
offscreen, Windows-only imports stubbed in a scratch launcher): 67 calls
verified and the state restored, over TCP and over MCP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RH8VsZbnUgYcVt3KuXjNFk
… a writer refusal

The AI Assistant's evaluation cases for the tiling and table calls (in the
fork's dev suite) found a defect: a call that takes a writer, given none or a
wrong one, refused with "unknown image writer None" and no choices, so a
model asked for TIFF could not find Tiff_Writer. get_config now lists the
image writers with their extensions (the reader for the choice), the
refusal names them, and the assistant treats a writer refusal like the
other option refusals.

On gemini-3.5-flash-lite, the four cases pass 12 of 12 runs (6 of 12 before).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RH8VsZbnUgYcVt3KuXjNFk
…00 tokens)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RH8VsZbnUgYcVt3KuXjNFk
Each table call gets a fresh two-row table built from the microscope's own
state and is checked by reading the table back; the tiling list is one tile
at the current position with the current laser and filter; set_snap_folder
is restored in the cleanup. Without this the sweep sent the demo's example
values (488 nm, Tiff_Writer) to a real instrument.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RH8VsZbnUgYcVt3KuXjNFk
A skill is one Markdown file: a head (name, description, tools) and the steps.
The microscope's skills live in a `skills` folder next to its config file; none
ship with mesoSPIM. At connect the tab loads them and writes in the transcript
which it found and what it left out (a broken head, too long, a tool that is
not offered). The prompt then lists each skill by name and description only,
with one rule: when a request matches, call load_skill first and follow what it
returns. load_skill hands over the steps. Without a skills folder the prompt
and the tools are exactly as before. The docs gain a page on how skills are
used, where they live, and how to write and test one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RH8VsZbnUgYcVt3KuXjNFk
…irst is fine

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RH8VsZbnUgYcVt3KuXjNFk
build_tiling_list checked that each channel has a laser, an intensity and a filter, but not what
they are. A laser given as get_config lists it ({"name": "488 nm", "wavelength_nm": 488}) or as a
number, or a filter given as a number, passed and failed while the rows were named, as
"[execution] slice(None, -3, None)" or "'int' object is not subscriptable"; the list stayed as it
was. Each channel value now goes through check_setting, as every other setting does, and the
refusal names the channel: "channels[1]: 'laser' must be a string".

Found on the Windows demo over TCP. The tests are on the development branch (test_table_calls.py).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ZqNvKiWUmd8wAY5yR8ZKy
TCP, MCP and the AI Assistant can now do what the operator can do in mesoSPIM's windows: 17 calls,
84 in all. Only three things are left out on purpose: the jog buttons' step boxes (move_relative
takes the step), the script editor (it runs code) and closing mesoSPIM.

- The live view and the other windows: levels and Adjust levels; a lookup table by name or of
  one's own colours; the view; the overlay; box and line regions of interest, placed, moved and read
  back in frame pixels and um with their offset from the centre; the image view's own ROI with its
  profile; normalisation; the contrast window and its map; the tile overview; the main window's tab
  and readouts (status bar, progress bars, time-lapse estimate, alignment toggles); opening and
  arranging windows; a picture of any window; Open TIFF and its frames; the acquisition table's
  selection and grouping (get_display, set_display, set_windows, get_picture, open_image_file,
  set_table_view).
- What only a window offered: the filename wizard's writer parameters, the laser pulse's max
  amplitude, the processor chain, AmpL=0 / AmpR=0 / Freeze galvos, the optimizer (AUTO Focus) with
  Accept or Discard, Save config file, Auto L/R illumination.
- The Utils menu's analyses of files: PSF (beads), field curvature / chromatic shift.

How: the windows are worked from outside, with their own controls and methods, by one new module,
remote_control/gui_handles.py; no file of mesoSPIM outside remote_control/ and ai_assistant/
changes. Every call's arguments are checked in commands.py with the shared validators. A change to
what a window shows is a new kind of call, DISPLAY: never refused as busy (the operator can change
the live view during a run too), returning a request number at once; get_display {request} reports
when the window shows it, and the AI Assistant's tool waits for that. The window features that
change the instrument are operations under the busy gate, ended by the GUI thread. Save to config
and auto illumination repeat their handlers' logic (the handlers open dialogs) and are tested equal
to them; the analyses are tested equal to their tools' windows.

Tests on this branch: the live sweep verifies every window call by its effect and undoes it; the
real camera window, offscreen (test_gui_handles_real_qt.py, in run.py's pyqt profile). On the demo
on Windows, from this branch: ALL 84 COMMANDS VERIFIED over TCP and over MCP, state restored; the
pyqt profile passes. The offline suite (1355) and the AI Assistant's evaluation, the windows cases
recorded with Claude Haiku 5.5 (33 of 33, held-out 27 of 27), are on agent/gui-handles.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ZqNvKiWUmd8wAY5yR8ZKy
A page of what is not finished, not verified or left for a decision: the webcam's picture and the
real microscope not verified; no Cancel for an analysis; the size of each AI Assistant request
(about 2,900 tokens of the window calls' definitions); the max amplitude, settable but not applied
by waveform generation; HTTPS inspection, which keeps the AI Assistant from a cloud model unless
SSL_CERT_FILE names a bundle with the Windows roots; a table row drag that may delete rows; a test
that fails without this change; and where the offline tests are. Linked from the Remote Control
page; the call count there is 84.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ZqNvKiWUmd8wAY5yR8ZKy
The rule the 84 descriptions follow, from a live A/B on Claude Haiku 5.5: in/out first, then the
facts that set the call apart from its neighbour, in the window's own names; facts, not
procedures; argument details in the schema. Shortened descriptions that dropped such a fact lost
the choice; the style did not show in the replies.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ZqNvKiWUmd8wAY5yR8ZKy
The sweep's aim is to show that every call has an effect without harm to a sample in place. X
moves at most 25 um; the optimizer sweeps the focus +-20 um in 5 snaps and discards; every
exposure runs at 1-2 % laser (MESOSPIM_REAL_LASER_PERCENT); mesoSPIM reads and saves a copy of
the ETL file, so the real one is never written; load, unload and centre sample run only with
MESOSPIM_REAL_LARGE_MOVES=1 and are reported as not run otherwise. The 17 window calls are
checked by their effect and put back (Freeze galvos, processor chain, writer compression,
display), as in the demo sweep, whose test-stack writer moves to live_session for both.

On the demo, with the DemoStage refusal taken out of a copy: 81 of 84 over TCP (the three
travels not run), 84 of 84 over MCP with them, the ETL file unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ZqNvKiWUmd8wAY5yR8ZKy
One page for the session at the instrument: the real-hardware sweep over TCP and MCP, the stage
travels on an empty stage, display changes checked by eye, one tiling list built by call and run,
and a short AI Assistant session; what to watch and what to report.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017ZqNvKiWUmd8wAY5yR8ZKy

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants