lightfall 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lightfall/__init__.py +8 -0
- lightfall/__main__.py +10 -0
- lightfall/_version.py +24 -0
- lightfall/acquire/__init__.py +74 -0
- lightfall/acquire/buffer.py +363 -0
- lightfall/acquire/device_wrapper.py +416 -0
- lightfall/acquire/engine/__init__.py +155 -0
- lightfall/acquire/engine/base.py +587 -0
- lightfall/acquire/engine/bluesky.py +358 -0
- lightfall/acquire/engine/mock.py +165 -0
- lightfall/acquire/engine/plugins/__init__.py +9 -0
- lightfall/acquire/engine/plugins/bluesky_plugin.py +56 -0
- lightfall/acquire/engine/plugins/mock_plugin.py +55 -0
- lightfall/acquire/engine/protocol.py +145 -0
- lightfall/acquire/engine/registry.py +152 -0
- lightfall/acquire/engine/state.py +32 -0
- lightfall/acquire/engine/waiting_hook.py +225 -0
- lightfall/acquire/nats_bridge.py +62 -0
- lightfall/acquire/plan_ui.py +78 -0
- lightfall/acquire/plans/__init__.py +38 -0
- lightfall/acquire/plans/adaptive.py +288 -0
- lightfall/acquire/plans/example_plans.py +995 -0
- lightfall/acquire/plans/lightfall_plans.py +587 -0
- lightfall/acquire/plans/registry.py +543 -0
- lightfall/acquire/plans/standard_plans.py +186 -0
- lightfall/acquire/plans/user_plans.py +470 -0
- lightfall/acquire/runengine.py +36 -0
- lightfall/acquire/signals.py +452 -0
- lightfall/acquire/triggers/__init__.py +16 -0
- lightfall/acquire/triggers/base.py +25 -0
- lightfall/acquire/triggers/filter.py +37 -0
- lightfall/acquire/triggers/manager.py +73 -0
- lightfall/acquire/triggers/manual.py +36 -0
- lightfall/acquire/triggers/run_end.py +74 -0
- lightfall/acquire/triggers/run_start.py +52 -0
- lightfall/auth/__init__.py +38 -0
- lightfall/auth/policy.py +518 -0
- lightfall/auth/providers/__init__.py +30 -0
- lightfall/auth/providers/base.py +124 -0
- lightfall/auth/providers/keycloak.py +1017 -0
- lightfall/auth/providers/local.py +319 -0
- lightfall/auth/providers/pam.py +250 -0
- lightfall/auth/service_key.py +173 -0
- lightfall/auth/service_key_auth.py +79 -0
- lightfall/auth/session.py +656 -0
- lightfall/claude/__init__.py +52 -0
- lightfall/claude/_internal/__init__.py +1 -0
- lightfall/claude/_internal/serialization.py +195 -0
- lightfall/claude/_internal/threading.py +61 -0
- lightfall/claude/_internal/worker.py +757 -0
- lightfall/claude/_session_assembly.py +124 -0
- lightfall/claude/agent.py +596 -0
- lightfall/claude/lightfall_core_tools.py +410 -0
- lightfall/claude/markdown.py +103 -0
- lightfall/claude/permission_manager.py +588 -0
- lightfall/claude/tools/__init__.py +45 -0
- lightfall/claude/tools/controller.py +143 -0
- lightfall/claude/tools/interaction.py +177 -0
- lightfall/claude/tools/introspection.py +127 -0
- lightfall/claude/tools/logs.py +155 -0
- lightfall/claude/tools/screenshot.py +87 -0
- lightfall/claude/widget.py +851 -0
- lightfall/claude/widgets/__init__.py +5 -0
- lightfall/claude/widgets/permission_request.py +282 -0
- lightfall/claude/widgets/question_request.py +227 -0
- lightfall/claude/widgets/task_card.py +223 -0
- lightfall/config/__init__.py +23 -0
- lightfall/config/layers.py +317 -0
- lightfall/config/manager.py +244 -0
- lightfall/config/schema.py +154 -0
- lightfall/core/__init__.py +23 -0
- lightfall/core/application.py +727 -0
- lightfall/core/services.py +235 -0
- lightfall/devices/__init__.py +53 -0
- lightfall/devices/backends/__init__.py +17 -0
- lightfall/devices/backends/bcs.py +448 -0
- lightfall/devices/backends/happi.py +986 -0
- lightfall/devices/backends/mock.py +646 -0
- lightfall/devices/base.py +338 -0
- lightfall/devices/catalog.py +1039 -0
- lightfall/devices/connection_manager.py +676 -0
- lightfall/devices/model.py +290 -0
- lightfall/devices/monitoring.py +442 -0
- lightfall/devices/sim/__init__.py +26 -0
- lightfall/devices/sim/areadetector.py +436 -0
- lightfall/devices/sim/generators.py +223 -0
- lightfall/devices/sim/plugins.py +116 -0
- lightfall/epics/__init__.py +28 -0
- lightfall/epics/ca/__init__.py +10 -0
- lightfall/epics/ca/context.py +100 -0
- lightfall/epics/ca/pv.py +303 -0
- lightfall/epics/widgets/__init__.py +49 -0
- lightfall/epics/widgets/areadetector/__init__.py +16 -0
- lightfall/epics/widgets/areadetector/areadetector.py +281 -0
- lightfall/epics/widgets/areadetector/controls.py +478 -0
- lightfall/epics/widgets/areadetector/image_view.py +447 -0
- lightfall/epics/widgets/auto.py +319 -0
- lightfall/epics/widgets/base.py +404 -0
- lightfall/epics/widgets/checkbox.py +239 -0
- lightfall/epics/widgets/combobox.py +202 -0
- lightfall/epics/widgets/label.py +176 -0
- lightfall/epics/widgets/lineedit.py +253 -0
- lightfall/epics/widgets/motor.py +694 -0
- lightfall/epics/widgets/ophyd_base.py +469 -0
- lightfall/epics/widgets/ophyd_combobox.py +86 -0
- lightfall/epics/widgets/ophyd_label.py +54 -0
- lightfall/epics/widgets/ophyd_lineedit.py +170 -0
- lightfall/epics/widgets/ophyd_spinbox.py +79 -0
- lightfall/epics/widgets/slider.py +272 -0
- lightfall/epics/widgets/status_indicator.py +98 -0
- lightfall/epics/widgets/style.py +188 -0
- lightfall/exporter/__init__.py +1 -0
- lightfall/exporter/cli.py +67 -0
- lightfall/exporter/converters/__init__.py +26 -0
- lightfall/exporter/converters/base.py +39 -0
- lightfall/exporter/converters/noop.py +39 -0
- lightfall/exporter/converters/nxsas.py +73 -0
- lightfall/exporter/service.py +200 -0
- lightfall/exporter/tiled_utils.py +92 -0
- lightfall/ipc/__init__.py +6 -0
- lightfall/ipc/service.py +701 -0
- lightfall/ipc/trust.py +144 -0
- lightfall/logbook/__init__.py +46 -0
- lightfall/logbook/action_dialog.py +207 -0
- lightfall/logbook/action_logger.py +432 -0
- lightfall/logbook/block_mapper.py +562 -0
- lightfall/logbook/client.py +799 -0
- lightfall/logbook/converter.py +273 -0
- lightfall/logbook/editors/__init__.py +19 -0
- lightfall/logbook/editors/highlighter.py +305 -0
- lightfall/logbook/editors/markdown_editor.py +319 -0
- lightfall/logbook/editors/richtext_editor.py +1397 -0
- lightfall/logbook/entry_widget.py +1065 -0
- lightfall/logbook/event_listener.py +221 -0
- lightfall/logbook/fragment_widgets.py +925 -0
- lightfall/logbook/position_mapper.py +320 -0
- lightfall/logbook/protection.py +402 -0
- lightfall/logbook/style.py +394 -0
- lightfall/logbook/url.py +29 -0
- lightfall/logbook/visual_protection.py +330 -0
- lightfall/logbook/widget.py +680 -0
- lightfall/main.py +1091 -0
- lightfall/pipelines/__init__.py +4 -0
- lightfall/pipelines/client.py +148 -0
- lightfall/plugins/__init__.py +119 -0
- lightfall/plugins/agent_plugin.py +106 -0
- lightfall/plugins/agents/__init__.py +10 -0
- lightfall/plugins/agents/_mcp_helpers.py +52 -0
- lightfall/plugins/agents/alignment.py +94 -0
- lightfall/plugins/agents/autonomous_experiment/__init__.py +12 -0
- lightfall/plugins/agents/autonomous_experiment/nats_tools.py +210 -0
- lightfall/plugins/agents/autonomous_experiment/plugin.py +60 -0
- lightfall/plugins/agents/autonomous_experiment/prompts.py +164 -0
- lightfall/plugins/agents/current_esaf.py +435 -0
- lightfall/plugins/agents/device_tools.py +1043 -0
- lightfall/plugins/agents/engine_tools.py +720 -0
- lightfall/plugins/agents/ipython_tools.py +444 -0
- lightfall/plugins/agents/panel_builder.py +637 -0
- lightfall/plugins/agents/panel_design/references/cross_panel_patterns.md +95 -0
- lightfall/plugins/agents/panel_design/references/panel_design.md +680 -0
- lightfall/plugins/agents/panel_design.py +94 -0
- lightfall/plugins/agents/plan_design/references/plan_design.md +398 -0
- lightfall/plugins/agents/plan_design.py +90 -0
- lightfall/plugins/agents/plan_tools.py +878 -0
- lightfall/plugins/agents/scan_planning.py +101 -0
- lightfall/plugins/builtin_manifest.py +348 -0
- lightfall/plugins/controller_plugin.py +162 -0
- lightfall/plugins/engine_plugin.py +124 -0
- lightfall/plugins/errors.py +104 -0
- lightfall/plugins/info.py +112 -0
- lightfall/plugins/loader.py +878 -0
- lightfall/plugins/manifest.py +150 -0
- lightfall/plugins/panel_plugin.py +119 -0
- lightfall/plugins/plan_plugin.py +163 -0
- lightfall/plugins/registry.py +309 -0
- lightfall/plugins/settings_plugin.py +226 -0
- lightfall/plugins/statusbar_plugin.py +289 -0
- lightfall/plugins/theme_plugin.py +165 -0
- lightfall/plugins/types.py +136 -0
- lightfall/plugins/user_plugins.py +764 -0
- lightfall/project/__init__.py +37 -0
- lightfall/project/model.py +375 -0
- lightfall/project/service.py +427 -0
- lightfall/project/welcome.py +106 -0
- lightfall/resources/__init__.py +126 -0
- lightfall/resources/images/__init__.py +1 -0
- lightfall/resources/images/icon.ico +0 -0
- lightfall/resources/images/icon.png +0 -0
- lightfall/resources/images/logo.png +0 -0
- lightfall/services/__init__.py +33 -0
- lightfall/services/_alshub_client.py +73 -0
- lightfall/services/access_stamper.py +240 -0
- lightfall/services/als_beam_status.py +347 -0
- lightfall/services/ca_tunnel.py +325 -0
- lightfall/services/threaded_tiled_writer.py +174 -0
- lightfall/services/tiled_auth.py +21 -0
- lightfall/services/tiled_service.py +971 -0
- lightfall/services/tiled_writer_patch.py +301 -0
- lightfall/settings/__init__.py +1 -0
- lightfall/settings/image_helpers.py +30 -0
- lightfall/settings/user_settings_client.py +232 -0
- lightfall/ui/__init__.py +28 -0
- lightfall/ui/annotations.py +208 -0
- lightfall/ui/common/__init__.py +7 -0
- lightfall/ui/dialogs/__init__.py +26 -0
- lightfall/ui/dialogs/about_dialog.py +131 -0
- lightfall/ui/dialogs/add_trigger_dialog.py +152 -0
- lightfall/ui/dialogs/base.py +44 -0
- lightfall/ui/dialogs/bug_report_dialog.py +353 -0
- lightfall/ui/dialogs/create_plan_dialog.py +189 -0
- lightfall/ui/dialogs/device_edit_dialog.py +183 -0
- lightfall/ui/dialogs/export_dialog.py +565 -0
- lightfall/ui/dialogs/go_to_position_dialog.py +192 -0
- lightfall/ui/dialogs/login_dialog.py +756 -0
- lightfall/ui/dialogs/oauth_browser_dialog.py +305 -0
- lightfall/ui/dialogs/run_pipeline_dialog.py +131 -0
- lightfall/ui/dialogs/sample_metadata_dialog.py +316 -0
- lightfall/ui/docking/__init__.py +22 -0
- lightfall/ui/docking/icon_sidebar.py +806 -0
- lightfall/ui/docking/manager.py +682 -0
- lightfall/ui/docking/state.py +113 -0
- lightfall/ui/docking/theme.py +399 -0
- lightfall/ui/docking/widget.py +214 -0
- lightfall/ui/events.py +75 -0
- lightfall/ui/mainwindow.py +1006 -0
- lightfall/ui/models/__init__.py +49 -0
- lightfall/ui/models/device_selection.py +389 -0
- lightfall/ui/models/device_tree.py +1095 -0
- lightfall/ui/models/thread_model.py +667 -0
- lightfall/ui/models/tiled_model.py +384 -0
- lightfall/ui/panels/__init__.py +28 -0
- lightfall/ui/panels/base.py +525 -0
- lightfall/ui/panels/bluesky_panel.py +619 -0
- lightfall/ui/panels/claude/__init__.py +9 -0
- lightfall/ui/panels/claude/agent_registry.py +168 -0
- lightfall/ui/panels/claude_panel.py +887 -0
- lightfall/ui/panels/device_panel.py +370 -0
- lightfall/ui/panels/documents_panel.py +166 -0
- lightfall/ui/panels/ipython_panel.py +580 -0
- lightfall/ui/panels/logbook_entries_panel.py +84 -0
- lightfall/ui/panels/logbook_panel.py +627 -0
- lightfall/ui/panels/logging_panel.py +587 -0
- lightfall/ui/panels/pipeline_jobs_panel.py +160 -0
- lightfall/ui/panels/pipeline_triggers_panel.py +170 -0
- lightfall/ui/panels/plugins/__init__.py +34 -0
- lightfall/ui/panels/plugins/bluesky_plugin.py +27 -0
- lightfall/ui/panels/plugins/claude_plugin.py +29 -0
- lightfall/ui/panels/plugins/device_plugin.py +27 -0
- lightfall/ui/panels/plugins/documents_plugin.py +26 -0
- lightfall/ui/panels/plugins/ipython_plugin.py +27 -0
- lightfall/ui/panels/plugins/logbook_entries_plugin.py +23 -0
- lightfall/ui/panels/plugins/logbook_plugin.py +27 -0
- lightfall/ui/panels/plugins/logging_plugin.py +27 -0
- lightfall/ui/panels/plugins/pipeline_jobs_plugin.py +23 -0
- lightfall/ui/panels/plugins/pipeline_triggers_plugin.py +25 -0
- lightfall/ui/panels/plugins/queue_plugin.py +29 -0
- lightfall/ui/panels/plugins/synoptic_plugin.py +38 -0
- lightfall/ui/panels/plugins/threads_plugin.py +27 -0
- lightfall/ui/panels/plugins/tiled_browser_plugin.py +27 -0
- lightfall/ui/panels/plugins/visualization_plugin.py +27 -0
- lightfall/ui/panels/queue.py +754 -0
- lightfall/ui/panels/registry.py +483 -0
- lightfall/ui/panels/synoptic/__init__.py +27 -0
- lightfall/ui/panels/synoptic/editors.py +481 -0
- lightfall/ui/panels/synoptic/items.py +556 -0
- lightfall/ui/panels/synoptic/models.py +336 -0
- lightfall/ui/panels/synoptic/panel.py +889 -0
- lightfall/ui/panels/synoptic/serialization.py +300 -0
- lightfall/ui/panels/synoptic/view.py +504 -0
- lightfall/ui/panels/threads_panel.py +621 -0
- lightfall/ui/panels/tiled_browser_panel.py +854 -0
- lightfall/ui/panels/visualization_panel.py +508 -0
- lightfall/ui/preferences/__init__.py +24 -0
- lightfall/ui/preferences/backend.py +148 -0
- lightfall/ui/preferences/builtin.py +220 -0
- lightfall/ui/preferences/claude_settings.py +762 -0
- lightfall/ui/preferences/device_settings.py +461 -0
- lightfall/ui/preferences/dialog.py +234 -0
- lightfall/ui/preferences/editor_settings.py +227 -0
- lightfall/ui/preferences/ipc_settings.py +226 -0
- lightfall/ui/preferences/logbook_settings.py +232 -0
- lightfall/ui/preferences/login_settings.py +183 -0
- lightfall/ui/preferences/manager.py +562 -0
- lightfall/ui/preferences/plugin_settings.py +392 -0
- lightfall/ui/preferences/proxy_settings.py +561 -0
- lightfall/ui/preferences/skill_settings.py +28 -0
- lightfall/ui/preferences/tiled_settings.py +469 -0
- lightfall/ui/preferences/tool_settings.py +393 -0
- lightfall/ui/preferences/user_portable_backend.py +131 -0
- lightfall/ui/preferences/user_profile_settings.py +316 -0
- lightfall/ui/preferences/visualization_settings.py +159 -0
- lightfall/ui/resources/__init__.py +1 -0
- lightfall/ui/resources/logo.png +0 -0
- lightfall/ui/statusbar/__init__.py +11 -0
- lightfall/ui/statusbar/manager.py +379 -0
- lightfall/ui/statusbar/plugins/__init__.py +28 -0
- lightfall/ui/statusbar/plugins/als_beam_status.py +218 -0
- lightfall/ui/statusbar/plugins/auth_status.py +116 -0
- lightfall/ui/statusbar/plugins/connection_status.py +100 -0
- lightfall/ui/statusbar/plugins/thread_status.py +556 -0
- lightfall/ui/statusbar/plugins/tiled_status.py +179 -0
- lightfall/ui/statusbar/plugins/user_status.py +84 -0
- lightfall/ui/theater/__init__.py +28 -0
- lightfall/ui/theater/manager.py +124 -0
- lightfall/ui/theater/overlay.py +279 -0
- lightfall/ui/theater/proxy.py +111 -0
- lightfall/ui/theme/__init__.py +18 -0
- lightfall/ui/theme/builtin.py +1015 -0
- lightfall/ui/theme/manager.py +875 -0
- lightfall/ui/theme/registry.py +195 -0
- lightfall/ui/toast.py +221 -0
- lightfall/ui/tutorial.py +1100 -0
- lightfall/ui/widgets/__init__.py +110 -0
- lightfall/ui/widgets/base_control.py +259 -0
- lightfall/ui/widgets/camera/__init__.py +36 -0
- lightfall/ui/widgets/camera/base.py +815 -0
- lightfall/ui/widgets/camera/dark_frames.py +213 -0
- lightfall/ui/widgets/camera/image_view.py +649 -0
- lightfall/ui/widgets/camera/panels/__init__.py +14 -0
- lightfall/ui/widgets/camera/panels/cooler.py +320 -0
- lightfall/ui/widgets/camera/panels/temperature.py +192 -0
- lightfall/ui/widgets/camera/plan_based.py +202 -0
- lightfall/ui/widgets/compact_motor.py +522 -0
- lightfall/ui/widgets/controller_matcher.py +278 -0
- lightfall/ui/widgets/controller_registry.py +144 -0
- lightfall/ui/widgets/device_control.py +411 -0
- lightfall/ui/widgets/device_selector.py +438 -0
- lightfall/ui/widgets/device_tree_tab.py +461 -0
- lightfall/ui/widgets/document_stream.py +1028 -0
- lightfall/ui/widgets/favorites_tab.py +191 -0
- lightfall/ui/widgets/motor_control.py +1120 -0
- lightfall/ui/widgets/observers/__init__.py +8 -0
- lightfall/ui/widgets/observers/camera.py +48 -0
- lightfall/ui/widgets/observers/image_view.py +130 -0
- lightfall/ui/widgets/plan_config.py +954 -0
- lightfall/ui/widgets/plan_edit_dialog.py +294 -0
- lightfall/ui/widgets/plan_selector.py +452 -0
- lightfall/ui/widgets/profile_avatar.py +128 -0
- lightfall/ui/widgets/queue_view.py +647 -0
- lightfall/ui/widgets/runengine_control.py +549 -0
- lightfall/ui/widgets/signal_control.py +793 -0
- lightfall/ui/widgets/skill_trigger_button.py +183 -0
- lightfall/ui/widgets/tiled_filter_widget.py +314 -0
- lightfall/ui/widgets/tiled_status.py +149 -0
- lightfall/ui/widgets/warning_banner.py +185 -0
- lightfall/utils/__init__.py +53 -0
- lightfall/utils/crash_diagnostics.py +454 -0
- lightfall/utils/data_migration.py +22 -0
- lightfall/utils/editor_launcher.py +594 -0
- lightfall/utils/error_collector.py +245 -0
- lightfall/utils/git_tracker.py +197 -0
- lightfall/utils/log_buffer.py +233 -0
- lightfall/utils/logging.py +229 -0
- lightfall/utils/module_resolver.py +70 -0
- lightfall/utils/sentry.py +722 -0
- lightfall/utils/threads.py +991 -0
- lightfall/utils/tiled_helpers.py +96 -0
- lightfall/visualization/__init__.py +50 -0
- lightfall/visualization/base.py +5 -0
- lightfall/visualization/base_visualization.py +74 -0
- lightfall/visualization/fitting/__init__.py +24 -0
- lightfall/visualization/fitting/base.py +267 -0
- lightfall/visualization/fitting/fitters.py +325 -0
- lightfall/visualization/fitting/panel.py +265 -0
- lightfall/visualization/memory.py +392 -0
- lightfall/visualization/motor_mixin.py +524 -0
- lightfall/visualization/pg.py +156 -0
- lightfall/visualization/registry.py +144 -0
- lightfall/visualization/spec.py +79 -0
- lightfall/visualization/theme.py +266 -0
- lightfall/visualization/widgets/__init__.py +28 -0
- lightfall/visualization/widgets/adaptive/__init__.py +1 -0
- lightfall/visualization/widgets/adaptive/heatmap.py +655 -0
- lightfall/visualization/widgets/adaptive/plot.py +233 -0
- lightfall/visualization/widgets/heatmap.py +264 -0
- lightfall/visualization/widgets/image_stack.py +316 -0
- lightfall/visualization/widgets/image_view_toolbar.py +227 -0
- lightfall/visualization/widgets/lazy_image_view.py +590 -0
- lightfall/visualization/widgets/plot_1d.py +262 -0
- lightfall/visualization/widgets/scatter.py +247 -0
- lightfall/visualization/widgets/table.py +221 -0
- lightfall/visualization/widgets/time_axis.py +93 -0
- lightfall-0.1.1.dist-info/METADATA +223 -0
- lightfall-0.1.1.dist-info/RECORD +388 -0
- lightfall-0.1.1.dist-info/WHEEL +4 -0
- lightfall-0.1.1.dist-info/entry_points.txt +6 -0
- lightfall-0.1.1.dist-info/licenses/LEGAL.md +13 -0
- lightfall-0.1.1.dist-info/licenses/LICENSE.md +33 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
"""MCP tools that bridge the Lightfall embedded agent to Tsuchinoko's NATS surface.
|
|
2
|
+
|
|
3
|
+
All tools share a single request helper. Each tool is stateless and
|
|
4
|
+
returns a dict shaped for the agent SDK (``success``, plus tool-specific
|
|
5
|
+
fields, or ``success: false`` with an ``error`` string).
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
from lightfall.plugins.agents._mcp_helpers import mcp_result
|
|
12
|
+
from lightfall.utils.logging import logger
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _ipc_request(subject: str, payload: dict, *, timeout: float = 5.0) -> dict | None:
|
|
16
|
+
"""Send a NATS request via the Lightfall IPC service.
|
|
17
|
+
|
|
18
|
+
Returns the decoded reply dict on success, or ``None`` if the
|
|
19
|
+
broker did not reply within *timeout* seconds (or the IPC service
|
|
20
|
+
is unavailable). Callers must distinguish ``None`` from
|
|
21
|
+
``{"status": "error", ...}``.
|
|
22
|
+
"""
|
|
23
|
+
from lightfall.ipc.service import get_ipc_service
|
|
24
|
+
ipc = get_ipc_service()
|
|
25
|
+
if ipc is None:
|
|
26
|
+
return None
|
|
27
|
+
return ipc.request(subject, payload, timeout_ms=int(timeout * 1000))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _ipc_error_response() -> dict:
|
|
31
|
+
return {
|
|
32
|
+
"success": False,
|
|
33
|
+
"error": "Lightfall IPC is not running; enable it in Settings → IPC and retry.",
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _wire_error_response(subject: str, reply: dict | None) -> dict | None:
|
|
38
|
+
"""Return a structured error dict, or None if the call succeeded."""
|
|
39
|
+
if reply is None:
|
|
40
|
+
return {
|
|
41
|
+
"success": False,
|
|
42
|
+
"error": f"No reply on '{subject}' (timeout or broker unreachable).",
|
|
43
|
+
}
|
|
44
|
+
if isinstance(reply, dict) and reply.get("status") == "error":
|
|
45
|
+
return {
|
|
46
|
+
"success": False,
|
|
47
|
+
"error": reply.get("message", "<tsuchinoko returned an error with no message>"),
|
|
48
|
+
}
|
|
49
|
+
return None
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def build_tools() -> list[Any]:
|
|
53
|
+
try:
|
|
54
|
+
from claude_agent_sdk import tool
|
|
55
|
+
except ImportError:
|
|
56
|
+
logger.warning(
|
|
57
|
+
"claude_agent_sdk not available; autonomous_experiment tools disabled"
|
|
58
|
+
)
|
|
59
|
+
return []
|
|
60
|
+
|
|
61
|
+
@tool(
|
|
62
|
+
name="tsuchinoko_discover",
|
|
63
|
+
description=(
|
|
64
|
+
"Discover Tsuchinoko instances on the NATS bus. Returns at most "
|
|
65
|
+
"one instance (multi-instance routing is out of scope). Empty "
|
|
66
|
+
"list means no Tsuchinoko is running — tell the user to start one."
|
|
67
|
+
),
|
|
68
|
+
input_schema={"type": "object", "properties": {}},
|
|
69
|
+
)
|
|
70
|
+
async def discover(args: dict) -> dict[str, Any]:
|
|
71
|
+
from lightfall.ipc.service import get_ipc_service
|
|
72
|
+
if get_ipc_service() is None:
|
|
73
|
+
return mcp_result(_ipc_error_response(), is_error=True)
|
|
74
|
+
reply = _ipc_request("_tsuchinoko.discover", {}, timeout=2.0)
|
|
75
|
+
if reply is None:
|
|
76
|
+
return mcp_result({"success": True, "instances": []})
|
|
77
|
+
return mcp_result({"success": True, "instances": [reply]})
|
|
78
|
+
|
|
79
|
+
@tool(
|
|
80
|
+
name="tsuchinoko_upload_design_code",
|
|
81
|
+
description=(
|
|
82
|
+
"Upload an agent-authored callable (acquisition function, kernel, "
|
|
83
|
+
"prior mean, or noise function) to the running Tsuchinoko instance. "
|
|
84
|
+
"Returns the 'user:<name>' ref to use in tsuchinoko_configure. "
|
|
85
|
+
"Tsuchinoko validates name (^[a-z][a-z0-9_]{0,62}$), kind "
|
|
86
|
+
"(acquisition|kernel|prior_mean|noise), syntax, and the expected "
|
|
87
|
+
"callable name before writing the file."
|
|
88
|
+
),
|
|
89
|
+
input_schema={
|
|
90
|
+
"type": "object",
|
|
91
|
+
"properties": {
|
|
92
|
+
"name": {"type": "string"},
|
|
93
|
+
"kind": {
|
|
94
|
+
"type": "string",
|
|
95
|
+
"enum": ["acquisition", "kernel", "prior_mean", "noise"],
|
|
96
|
+
},
|
|
97
|
+
"code": {"type": "string"},
|
|
98
|
+
},
|
|
99
|
+
"required": ["name", "kind", "code"],
|
|
100
|
+
},
|
|
101
|
+
)
|
|
102
|
+
async def upload_design_code(args: dict) -> dict[str, Any]:
|
|
103
|
+
from lightfall.ipc.service import get_ipc_service
|
|
104
|
+
if get_ipc_service() is None:
|
|
105
|
+
return mcp_result(_ipc_error_response(), is_error=True)
|
|
106
|
+
subject = "tsuchinoko.experiment.upload_design_code"
|
|
107
|
+
reply = _ipc_request(subject, {
|
|
108
|
+
"name": args["name"], "kind": args["kind"], "code": args["code"],
|
|
109
|
+
}, timeout=5.0)
|
|
110
|
+
err = _wire_error_response(subject, reply)
|
|
111
|
+
if err is not None:
|
|
112
|
+
return mcp_result(err, is_error=True)
|
|
113
|
+
return mcp_result({
|
|
114
|
+
"success": True,
|
|
115
|
+
"ref": reply["ref"],
|
|
116
|
+
"path": reply.get("path", ""),
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
@tool(
|
|
120
|
+
name="tsuchinoko_configure",
|
|
121
|
+
description=(
|
|
122
|
+
"Send an experiment design to Tsuchinoko. IMPORTANT: configure only "
|
|
123
|
+
"updates GP parameters — it does NOT reset the iteration counter, "
|
|
124
|
+
"accumulated data, or run state. Always call tsuchinoko_stop() first "
|
|
125
|
+
"and wait for Inactive state before configuring a new experiment. "
|
|
126
|
+
"The payload schema is documented in the autonomous_experiment skill "
|
|
127
|
+
"prompt (parameter_bounds, kernel, acquisition_function, prior_mean, "
|
|
128
|
+
"noise_function, noise_variances, initial_points, training_method, "
|
|
129
|
+
"hyperparameters, x_out, dimensionality). Unknown keys are an error "
|
|
130
|
+
"— fix them before retrying. Use 'user:<name>' refs for callables "
|
|
131
|
+
"previously uploaded via tsuchinoko_upload_design_code."
|
|
132
|
+
),
|
|
133
|
+
input_schema={
|
|
134
|
+
"type": "object",
|
|
135
|
+
"properties": {"payload": {"type": "object"}},
|
|
136
|
+
"required": ["payload"],
|
|
137
|
+
},
|
|
138
|
+
)
|
|
139
|
+
async def configure(args: dict) -> dict[str, Any]:
|
|
140
|
+
from lightfall.ipc.service import get_ipc_service
|
|
141
|
+
if get_ipc_service() is None:
|
|
142
|
+
return mcp_result(_ipc_error_response(), is_error=True)
|
|
143
|
+
subject = "tsuchinoko.experiment.configure"
|
|
144
|
+
reply = _ipc_request(subject, args["payload"], timeout=5.0)
|
|
145
|
+
err = _wire_error_response(subject, reply)
|
|
146
|
+
if err is not None:
|
|
147
|
+
return mcp_result(err, is_error=True)
|
|
148
|
+
return mcp_result({"success": True})
|
|
149
|
+
|
|
150
|
+
@tool(
|
|
151
|
+
name="tsuchinoko_status",
|
|
152
|
+
description=(
|
|
153
|
+
"Query Tsuchinoko's current state. Returns "
|
|
154
|
+
"{state, iteration, data_count}. Use this for textual progress "
|
|
155
|
+
"checks during a running adaptive experiment."
|
|
156
|
+
),
|
|
157
|
+
input_schema={"type": "object", "properties": {}},
|
|
158
|
+
)
|
|
159
|
+
async def status(args: dict) -> dict[str, Any]:
|
|
160
|
+
from lightfall.ipc.service import get_ipc_service
|
|
161
|
+
if get_ipc_service() is None:
|
|
162
|
+
return mcp_result(_ipc_error_response(), is_error=True)
|
|
163
|
+
subject = "tsuchinoko.status"
|
|
164
|
+
reply = _ipc_request(subject, {}, timeout=5.0)
|
|
165
|
+
err = _wire_error_response(subject, reply)
|
|
166
|
+
if err is not None:
|
|
167
|
+
return mcp_result(err, is_error=True)
|
|
168
|
+
return mcp_result({
|
|
169
|
+
"success": True,
|
|
170
|
+
"state": reply.get("state"),
|
|
171
|
+
"iteration": reply.get("iteration"),
|
|
172
|
+
"data_count": reply.get("data_count"),
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
def _make_control(action: str, subject: str, description: str):
|
|
176
|
+
@tool(
|
|
177
|
+
name=f"tsuchinoko_{action}",
|
|
178
|
+
description=description,
|
|
179
|
+
input_schema={"type": "object", "properties": {}},
|
|
180
|
+
)
|
|
181
|
+
async def control(args: dict) -> dict[str, Any]:
|
|
182
|
+
from lightfall.ipc.service import get_ipc_service
|
|
183
|
+
if get_ipc_service() is None:
|
|
184
|
+
return mcp_result(_ipc_error_response(), is_error=True)
|
|
185
|
+
reply = _ipc_request(subject, {}, timeout=5.0)
|
|
186
|
+
err = _wire_error_response(subject, reply)
|
|
187
|
+
if err is not None:
|
|
188
|
+
return mcp_result(err, is_error=True)
|
|
189
|
+
return mcp_result({
|
|
190
|
+
"success": True,
|
|
191
|
+
"state": reply.get("state"),
|
|
192
|
+
})
|
|
193
|
+
return control
|
|
194
|
+
|
|
195
|
+
pause = _make_control(
|
|
196
|
+
"pause", "tsuchinoko.experiment.pause",
|
|
197
|
+
"Pause Tsuchinoko's adaptive loop. The Lightfall adaptive_experiment "
|
|
198
|
+
"plan keeps the run open; new targets stop until tsuchinoko_resume.",
|
|
199
|
+
)
|
|
200
|
+
resume = _make_control(
|
|
201
|
+
"resume", "tsuchinoko.experiment.resume",
|
|
202
|
+
"Resume a paused Tsuchinoko adaptive loop.",
|
|
203
|
+
)
|
|
204
|
+
stop = _make_control(
|
|
205
|
+
"stop", "tsuchinoko.experiment.stop",
|
|
206
|
+
"Stop Tsuchinoko's adaptive loop and finalise. The Lightfall plan exits "
|
|
207
|
+
"cleanly once targets stop arriving (configurable timeout).",
|
|
208
|
+
)
|
|
209
|
+
|
|
210
|
+
return [discover, upload_design_code, configure, status, pause, resume, stop]
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""AutonomousExperimentAgent AgentPlugin."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from lightfall.plugins.agent_plugin import AgentPlugin
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class AutonomousExperimentAgent(AgentPlugin):
|
|
11
|
+
"""Embeds gpCAM's experiment-design skills and exposes a NATS bridge
|
|
12
|
+
to a running Tsuchinoko instance.
|
|
13
|
+
|
|
14
|
+
Together with the existing ``adaptive_experiment`` plan and the
|
|
15
|
+
adaptive viz widgets, this plugin lets the embedded agent drive an
|
|
16
|
+
end-to-end autonomous experiment from chat.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
def name(self) -> str:
|
|
21
|
+
return "autonomous_experiment"
|
|
22
|
+
|
|
23
|
+
@property
|
|
24
|
+
def display_name(self) -> str:
|
|
25
|
+
return "Autonomous Experiment"
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def description(self) -> str:
|
|
29
|
+
return "Design and run GP-driven adaptive experiments via Tsuchinoko"
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def category(self) -> str:
|
|
33
|
+
return "acquisition"
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def priority(self) -> int:
|
|
37
|
+
return 30
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def enabled_by_default(self) -> bool:
|
|
41
|
+
return True
|
|
42
|
+
|
|
43
|
+
def get_system_prompt(self) -> str:
|
|
44
|
+
from .prompts import STUB
|
|
45
|
+
return STUB
|
|
46
|
+
|
|
47
|
+
def create_tools(self) -> list[Any]:
|
|
48
|
+
from .nats_tools import build_tools
|
|
49
|
+
return build_tools()
|
|
50
|
+
|
|
51
|
+
def get_references_dir(self) -> Path | None:
|
|
52
|
+
try:
|
|
53
|
+
import importlib.resources as ir
|
|
54
|
+
ref = ir.files("gpcam.skills")
|
|
55
|
+
except (ImportError, ModuleNotFoundError, FileNotFoundError):
|
|
56
|
+
return None
|
|
57
|
+
try:
|
|
58
|
+
return Path(str(ref))
|
|
59
|
+
except Exception:
|
|
60
|
+
return None
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"""System-prompt text for the AutonomousExperimentAgent."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
STUB = """
|
|
5
|
+
## Autonomous Experiments
|
|
6
|
+
|
|
7
|
+
When the user asks for a smart/adaptive scan, peak finding, parameter
|
|
8
|
+
optimisation, or any other GP-driven experiment, follow this workflow.
|
|
9
|
+
Do not improvise around it — each step relies on the previous one.
|
|
10
|
+
|
|
11
|
+
### 1. Design
|
|
12
|
+
|
|
13
|
+
Load gpCAM's `experiment-designer` skill from this plugin's references
|
|
14
|
+
and follow its conversation flow. If you cannot see that skill, gpCAM
|
|
15
|
+
is not installed in Lightfall's environment — tell the user:
|
|
16
|
+
|
|
17
|
+
> "I can't see the gpCAM design skills. Install gpCAM with
|
|
18
|
+
> `pip install gpcam` in the Lightfall environment and restart Lightfall,
|
|
19
|
+
> then ask me again."
|
|
20
|
+
|
|
21
|
+
…and stop. Do not proceed with `tsuchinoko_*` tools before the user
|
|
22
|
+
confirms.
|
|
23
|
+
|
|
24
|
+
Sibling skills are available for lazy load via the Skill tool when the
|
|
25
|
+
design needs them: `acquisition-functions`, `kernel-designer`,
|
|
26
|
+
`prior-mean-functions`, `noise-functions`, `cost-functions`,
|
|
27
|
+
`gp2scale-advanced`, `multi-task-advanced`.
|
|
28
|
+
|
|
29
|
+
Tsuchinoko also ships skills for live engine state. Load
|
|
30
|
+
`parameter-tree` (from Tsuchinoko) when the design needs to set
|
|
31
|
+
hyperparameter bounds/initial values, change the training-schedule
|
|
32
|
+
milestones, or read/write any other field not exposed by
|
|
33
|
+
`tsuchinoko.experiment.configure`.
|
|
34
|
+
|
|
35
|
+
### 2. Discover Tsuchinoko
|
|
36
|
+
|
|
37
|
+
Call `tsuchinoko_discover()`. If the list is empty, tell the user:
|
|
38
|
+
|
|
39
|
+
> "No Tsuchinoko instance is responding on the bus. Start one
|
|
40
|
+
> (`tsuchinoko run`) and tell me when it's ready."
|
|
41
|
+
|
|
42
|
+
…and stop.
|
|
43
|
+
|
|
44
|
+
### 3. Reset stale state
|
|
45
|
+
|
|
46
|
+
If Tsuchinoko's state is anything other than `Inactive` (check with
|
|
47
|
+
`tsuchinoko_status()`), a previous experiment left residual state.
|
|
48
|
+
**You must stop it before configuring:**
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
tsuchinoko_stop()
|
|
52
|
+
# poll tsuchinoko_status() until state == "Inactive"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`configure` only updates GP parameters — it does **not** reset the
|
|
56
|
+
iteration counter, accumulated data, or run state. The full reset
|
|
57
|
+
happens during the `stop → Inactive` transition (clears data) and
|
|
58
|
+
the subsequent `Starting` transition (resets the GP model). Skipping
|
|
59
|
+
this step causes the new plan to connect to a stale engine that
|
|
60
|
+
serves few or no targets, leading to a near-empty run.
|
|
61
|
+
|
|
62
|
+
### 4. Upload custom callables (if needed)
|
|
63
|
+
|
|
64
|
+
If the design includes a user-authored acquisition function, kernel,
|
|
65
|
+
prior mean, or noise function, upload each one before configure:
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
tsuchinoko_upload_design_code(
|
|
69
|
+
name="my_ucb", kind="acquisition", code="<python source>"
|
|
70
|
+
)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
`kind` is one of `acquisition`, `kernel`, `prior_mean`, `noise`. The
|
|
74
|
+
tool returns a ref string of the form `"user:<name>"`; use it in
|
|
75
|
+
configure.
|
|
76
|
+
|
|
77
|
+
### 5. Configure
|
|
78
|
+
|
|
79
|
+
`tsuchinoko_configure(payload)` — payload is a dict with these fields
|
|
80
|
+
(omit any that should keep the engine default):
|
|
81
|
+
|
|
82
|
+
- `parameter_bounds`: list of `[lo, hi]` per axis (required)
|
|
83
|
+
- `dimensionality`: optional int
|
|
84
|
+
- `kernel`: `"matern_3_2" | "matern_1_2" | "matern_5_2" | "se" | "periodic" | "user:<name>"`
|
|
85
|
+
- `acquisition_function`: `"variance" | "ucb" | "ei" | "user:<name>"`
|
|
86
|
+
- `prior_mean`: `null` or `"user:<name>"`
|
|
87
|
+
- `noise_function`: `null` or `"user:<name>"`
|
|
88
|
+
- `noise_variances`: `null`, float, or list of floats
|
|
89
|
+
- `initial_points`: int (default 10)
|
|
90
|
+
- `training_method`: `"global" | "local" | "mcmc" | "adam" | "hgdl"`
|
|
91
|
+
- `hyperparameters`: optional list of floats (initial values)
|
|
92
|
+
- `x_out`: optional, for fvGP multi-task
|
|
93
|
+
|
|
94
|
+
Unknown keys are an error. The configure tool will surface that
|
|
95
|
+
verbatim — fix it before retrying.
|
|
96
|
+
|
|
97
|
+
### 6. Pre-flight: verify motor positions are within bounds
|
|
98
|
+
|
|
99
|
+
Before launching the plan, read each motor's current position with
|
|
100
|
+
`lightfall_read_device(name=<motor>)` and verify it lies inside the
|
|
101
|
+
corresponding `[lo, hi]` from `parameter_bounds`. If any motor is
|
|
102
|
+
outside its bound, **do not start the plan**. Tell the user which
|
|
103
|
+
motor is where, then either:
|
|
104
|
+
|
|
105
|
+
1. Ask permission to move the motor into range, or
|
|
106
|
+
2. Ask the user to widen `parameter_bounds` and re-run configure
|
|
107
|
+
(remember: configure requires `tsuchinoko_stop()` → `Inactive`
|
|
108
|
+
first — see step 3).
|
|
109
|
+
|
|
110
|
+
Tsuchinoko/gpCAM initialise the GP from the supplied bounds. A motor
|
|
111
|
+
sitting outside its axis bound rejects the first measurement as
|
|
112
|
+
out-of-domain and the run dies before producing any data.
|
|
113
|
+
|
|
114
|
+
### 7. Run
|
|
115
|
+
|
|
116
|
+
Use the existing plan tool:
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
lightfall_run_plan(
|
|
120
|
+
plan_name="adaptive_experiment",
|
|
121
|
+
params={
|
|
122
|
+
"detectors": [<detector names>],
|
|
123
|
+
"motors": [<motor names, in the same order as parameter_bounds>],
|
|
124
|
+
"timeout": 300.0,
|
|
125
|
+
},
|
|
126
|
+
)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The plan opens a single Bluesky run, hands off Tiled credentials to
|
|
130
|
+
Tsuchinoko via `bind_run`, and drives the move-and-measure loop.
|
|
131
|
+
|
|
132
|
+
### 8. Monitor
|
|
133
|
+
|
|
134
|
+
Tell the user to open the Visualization Panel — the
|
|
135
|
+
`AdaptiveHeatmapVisualization` (posterior mean / variance /
|
|
136
|
+
acquisition) and `AdaptiveHyperparameterPlot` widgets will populate
|
|
137
|
+
live as iterations land in the Tiled `adaptive` stream.
|
|
138
|
+
|
|
139
|
+
For textual progress, call `tsuchinoko_status()`.
|
|
140
|
+
|
|
141
|
+
### 9. Control
|
|
142
|
+
|
|
143
|
+
`tsuchinoko_pause()`, `tsuchinoko_resume()`, `tsuchinoko_stop()` —
|
|
144
|
+
each takes no arguments. Use `tsuchinoko_stop()` to finalise the
|
|
145
|
+
experiment from the Tsuchinoko side; the Lightfall plan exits cleanly
|
|
146
|
+
when targets stop arriving (configurable timeout).
|
|
147
|
+
|
|
148
|
+
### Constraints
|
|
149
|
+
|
|
150
|
+
- **Always stop before reconfiguring.** `tsuchinoko_configure` only
|
|
151
|
+
updates GP parameters — it does not reset state, data, or the
|
|
152
|
+
iteration counter. You must call `tsuchinoko_stop()` and wait for
|
|
153
|
+
`Inactive` before configuring a new experiment, whether the
|
|
154
|
+
previous one is running, paused, or finished.
|
|
155
|
+
- Do not start a new `adaptive_experiment` before stopping the
|
|
156
|
+
current one — the bind_run handshake is single-occupant.
|
|
157
|
+
- `motors` order in `lightfall_run_plan` must match the axes order in
|
|
158
|
+
`parameter_bounds`. Disagreement silently produces nonsense.
|
|
159
|
+
- **Verify motor positions before running.** A motor sitting outside
|
|
160
|
+
its `parameter_bounds` axis crashes gpCAM at the first iteration —
|
|
161
|
+
the plan opens a Bluesky run, then dies with no data. Always read
|
|
162
|
+
each motor with `lightfall_read_device` after configure and before
|
|
163
|
+
`lightfall_run_plan`; the plan itself does not validate this.
|
|
164
|
+
"""
|