Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3473921
Remote Control: the main window follows every setting made remotely
claude Oct 9, 2026
564a4ae
Core, waveformer: take the max-amplitude keys under the name the wind…
claude Oct 9, 2026
630db38
AI Assistant: lean for cloud models, no timer (plan 2.2, 2.3)
claude Oct 9, 2026
490040a
AI Assistant: no guard, no confirmation (plan 2.1)
claude Oct 9, 2026
8d4c437
AI Assistant: the plan is the model's (plan 2.4)
claude Oct 9, 2026
c4dfdec
AI Assistant docs: lean, no guard, no timer (plan 2.5)
claude Oct 9, 2026
d7d655b
AI Assistant manual: short and general, no rules fitted to cases
claude Oct 9, 2026
9e046ef
Tiling wizard: the field of view, overlap and image counts as functio…
claude Oct 9, 2026
4354c25
Acquisition list: its CSV read and write on the list, not the table m…
claude Oct 9, 2026
901284a
Acquisition table: 'mark current' as a function of the state, not of …
claude Oct 9, 2026
0522bd6
Focus tracking: the interpolation as a function, not a wizard method
claude Oct 9, 2026
3c9138d
Filename wizard: the naming rule on the acquisition list, not in the …
claude Oct 9, 2026
8100b49
WP3: the acquisition manager's features as Remote Control calls
claude Oct 9, 2026
f71d919
Live sweep: the eleven table calls, on a two-row table with the instr…
claude Oct 9, 2026
e9b84b8
Remote Control: the image writers in the config readout, and named in…
claude Oct 9, 2026
4c479b0
AI Assistant: the size help follows the eleven table calls (about 7,5…
claude Oct 9, 2026
058f75d
Real-hardware sweep: the eleven table calls, as in the demo sweep
claude Oct 9, 2026
336780e
AI Assistant: skills, loaded on demand
claude Oct 10, 2026
4d7072b
AI Assistant skills: load the skill before the first change; a look f…
claude Oct 10, 2026
05edcb1
AI Assistant docs: a skill is for a short request with a long procedure
claude Oct 10, 2026
6dba27a
Remote Control: a tiling channel of the wrong type is refused by name
thomdehoog Oct 10, 2026
43cc34f
Remote Control: everything the GUI does, as calls (84)
thomdehoog Oct 11, 2026
01b06dc
Remote Control docs: the open items
thomdehoog Oct 11, 2026
52d43ca
Remote Control docs: how to write a call's description
thomdehoog Oct 11, 2026
c90c3f3
Real-hardware sweep: small changes only, each read back and put back
thomdehoog Oct 11, 2026
e48452c
Remote Control docs: testing at the microscope
thomdehoog Oct 11, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- 💎 **MP OME-Zarr writer keeps up with 12 FPS full-frame with sharded OME-Zarr v0.5 pyramids**: whole shards are now written directly instead of through zarr-python's write path, which ran all writes through one thread and topped out at ~6 FPS. The result is standard Zarr v3 sharding, byte-for-byte the same as zarr-python's own output. Pyramid downsampling is ~1.7x faster (bit-identical) and the hand-off copy into the writer process ~5x faster. Recommended settings (zstd-1, `shards (64,6000,6000)`, `base_chunks (64,1264,1480)`, `target_chunks (64,64,64)`, ~43 files per 1001-plane stack) are in `config/examples/user/config_benchtop-cDAQ-ASI_user-shardedZARR-12FPS.py`. Note that `shards[0]` must equal `base_chunks[0]`: with a shallower chunk, two writer threads fill the same shard concurrently and half of it is lost. Also, `'compression': None` does not disable compression with `ome_version` 0.5: zarr then applies its default zstd.
- BigStitcher XML is now written for OME-Zarr 0.5 as well as 0.4 (`'write_big_stitcher_xml': True`), and records the Zarr version (`zarr.version="ZarrV3"` / `"ZarrV2"`) so BigStitcher opens the container with the matching reader. Verified to open sharded 0.5 data in BigStitcher 3.0.8.
- 💎 **Remote Control tab (TCP and MCP)**: control the running microscope from a script or an MCP client, over a password-protected loopback TCP protocol or an MCP server. One operation runs at a time, every command is checked against the instrument's limits before it reaches Core, and the emergency stop is never blocked. See `docs/source/remote_control/`.
- 💎 **AI Assistant tab (optional)**: a chat window that drives the microscope in plain language through the Remote Control commands, with a cloud model (Gemini, OpenAI, Anthropic or any OpenAI-style server) or a local GGUF model. It can look at camera frames, run scheduled instructions, and asks the operator before large stage moves. The chat is kept in memory only, never saved. Install with `pip install -e ".[ai-assistant]"`. See `docs/source/ai_assistant/`.
- 💎 **AI Assistant tab (optional)**: a chat window that drives the microscope in plain language through every Remote Control command, built for cloud models (Gemini 3.5 Flash-Lite, Claude Haiku 5.5; OpenAI and any OpenAI-style server also work). It can look at camera frames; the instrument's own limits, its one-operation gate and Stop microscope are the safety, as for TCP and MCP. The chat is kept in memory only, never saved; the tab shows each request's size and stops at the model's ceiling. Install with `pip install -e ".[ai-assistant]"`. See `docs/source/ai_assistant/`.
- AI Assistant: the focus measure is chosen in Preferences ("Focus metric": Laplacian, or the Auto-Focus DCT-Shannon), or named in a request; Remote Control's `get_frame` takes `focus_metric`. Not yet tested on hardware.
### Hardware Control & Support 🔧
- Photometrics cameras: new `camera_parameters['series_buffer_frames']` sets the PVCAM circular buffer for image series (default 16 frames, unchanged; ~64 for continuous mode at 12 FPS). Values above 2 GiB are capped, and if PVCAM refuses the size it falls back to 16 frames, logging the reason. Each drain call now takes every frame already buffered and waits at most 5 s for one, instead of exactly one frame and waiting forever.
Expand Down
59 changes: 24 additions & 35 deletions docs/source/ai_assistant/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@ reuses its `Acceptor`, dispatcher, and completion signals.
All in `mesoSPIM/src/ai_assistant/`:

```text
config.py provider presets, local-model settings, timing, and the rules held in code
config.py provider presets (with each model's token warning and ceiling), timing, texts
assistant.py the Endpoint chosen in the tab, the tool builder, the completion wrapper
(dispatch_and_wait), and the AssistantWorker that runs each turn off the GUI/Core threads
local.py the models-folder scan and the llama.cpp server child that serves a local .gguf file
frames.py the frame history, its measures, the map and the calibration
gui.py the AiAssistantGUI tab (setup, status, Connect and Disconnect) and the AssistantWindow
it opens while connected: transcript, input line, Stop microscope, Cancel prompt,
Clear context, Show tool calls
manual.md the rules (units, frames, safety); the system prompt adds the offered commands by kind,
and each tool's description and schema, derived from the command registry
```

Dependencies: `pydantic-ai` (imported lazily, only when a turn runs); `llama-cpp-python` with its
server only for local models (the `ai-assistant-local` extra).
Dependencies: `pydantic-ai` (imported lazily, only when a turn runs).

## Joining mesoSPIM-control

Expand Down Expand Up @@ -76,8 +75,10 @@ Acceptor.

## Tools from the command registry

Each offered command becomes one tool with the command's own JSON schema, the one MCP's
`tools/list` serves, so the tool list is never maintained by hand. The tools skip pydantic's own
Every registered command but `get_manual` becomes one tool with the command's own JSON schema,
the one MCP's `tools/list` serves, so the tool list is never maintained by hand and the model can
do exactly what TCP and MCP clients can. Every tool is sequential: two calls in one reply run one
after the other. The tools skip pydantic's own
validation of a call: the command's `accept()` stays the one place a call is refused, with one
error vocabulary, and the refusal goes back to the model as data. Tool arguments pass straight to
the dispatcher, which validates shape and limits before hardware.
Expand All @@ -91,8 +92,9 @@ moves pass as they do from the GUI, a take-over is refused with a message that n
session, and `stop_activity` ends it (`RUNS_UNTIL_STOPPED`). A run that ends by itself but takes
minutes to hours (the acquisition commands and the time lapse) returns once it is under way, so
the turn ends and the input line is free for "stop"; the run holds the gate against everything
but a stop until it ends (`RUNS_ON_ITS_OWN`). Anything else still running after `WAIT_CAP_S`
returns `still_running`, and the model polls from there.
but a stop until it ends (`RUNS_ON_ITS_OWN`); the model is told not to poll, and a two-second
check in the tab, asked of the worker between turns, writes one line when the run ends, with no
model turn. Anything else still running after `WAIT_CAP_S` returns `still_running`.

The eyes (`VisionSession`) are the vision model's own conversation, kept by the worker for the
session. `look` sends the frame into it as a turn (time, the readout keys a picture depends on,
Expand All @@ -101,45 +103,32 @@ the numbers, the image, the question), `ask_eyes` sends a question alone, and af
keeping the text, so the cost per look stays about one frame with a provider that caches the
prefix. The main model never carries an image.

The scheduler is the tab's, not the model's: `Scheduler` holds named schedules, the two tools
add and cancel them from the worker thread, and a one-second Qt timer on the GUI thread pops the
first due one and submits its instruction as a turn (`SCHEDULED_TURN`), never while a turn runs.
The readout carries the clock and the schedules on every turn, so the model has a clock without
having to keep time.
## No safety layer of its own

## What the model is offered

The **Regular** tool set leaves out what a user setting up a sample has no business with: the
camera settings, the galvos, laser timing, the alignment modes, the generic setting call, and the
ETL's delay and ramps (`set_etl` takes the voltages only). The model is not offered them at all
and is told they exist in the Full set, so it cannot be talked into them and does not stand another
command in for one. **Full** offers every command. See [the two tool sets](tool-sets.md).

## Rules in code, where the prompt was not enough

Small models read a rule and do otherwise, so the rules that matter most are held in code.
`load_sample`, `unload_sample` and `preview_acquisition` cross the stage's range and wait for the
operator's **Run**. `TurnGuard` keeps, for one turn, what a refusal ruled out: no other target on
an axis refused for its limit, no stop to clear a GUI-busy instrument without **Run**, no third
intensity or exposure change without **Run**, no second exposure for a look right after a snap,
and no value the operator did not give: a number or option in their words, or arithmetic they
named on a readout value, passes; "brighter" sent as 20 % waits for **Run**. A reply that called
no tool is handed back once, and the tab says when a turn sent nothing to the microscope.
The safety is the instrument's and the same for every client: Core's stage limits, the
dispatcher's one operation at a time, and Stop microscope. The assistant adds no gate, no
confirmation and no rule held in code; what it adds is advice, attached to a refusal where the
model reads it next. A look right after a snap of the same place and settings reads that frame
instead of exposing the sample twice.

## Context and memory

Every operator message carries the instrument's readout in a `<microscope_state>` block, so the
model acts on current values without reading them first; the block is data, escaped so that no
text in it can close it. Older turns are compacted to a one-line readout and shortened tool
results before each request, and every turn stays whole in a session store the model can search
and recall, so a long session costs little and loses nothing.
text in it can close it. The history is append-only until Clear context: nothing earlier is ever
rewritten, which keeps a provider's signed thinking valid and its prompt cache warm. The
instructions and tools come first and never change; on Anthropic they are cached for an hour
and the conversation for five minutes. The tab shows each request's input tokens and stops at
the model's ceiling.

The conversation lives in memory only. Nothing of the chat (prompts, replies, tool calls, frames)
is written to disk or to the mesoSPIM log; Clear context and Disconnect discard it.

## Failures

A model that is rate-limited or unavailable is an error the operator sees; there is no
whole-turn retry, which would re-run every tool call the first attempt made. The Gemini preset
whole-turn retry, which would re-run every tool call the first attempt made. The SDK's own retry
of a 429 or 529 is a retry of one request on the same history, whose results are already in the
messages, and is fine. The Gemini preset
names no fallback model: a stand-in model can obey a note planted in the readout that the chosen
model does not. When another model answers anyway, the tab says so above the reply.
Loading
Loading