pycsamt.agents.iot_agent#
pycsamt.agents.iot_agent#
IoTFieldAgent — AI-assisted monitoring for IoT-enabled AMT / MT /
CSAMT / CSEM field acquisition.
Where DataQCAgent reasons about processed EDI
data, this agent reasons about the live field campaign: the telemetry
stream coming off edge nodes while the survey is still running. It is a thin,
defensive orchestration layer over pycsamt.iot that turns whatever
acquisition evidence the caller has — a FieldSession,
a bag of telemetry packets, or an existing EDI survey to re-occupy — into:
a single
MonitoringStatus(OK / WARN / CRITICAL) with the concrete issues that tripped it,per-topic telemetry, per-station, and pipeline hand-off tables,
optional clock-sync and power-budget summaries,
an optional reproducible
AcquisitionManifest(written and, on request, signed),dashboard / edge-QC / power / sync figures rendered with the shared pycsamt plotting configuration, and
a plain-English field-ops interpretation from the configured LLM.
Every sub-step is wrapped so that a failure in one diagnostic degrades to a
warning rather than sinking the whole assessment — the agent always returns a
usable AgentResult.
Wraps pycsamt.iot:
telemetry_summary(),packet_table(),monitoring_status_table()plot_field_dashboard(),plot_edge_qc_summary(),plot_power_budget(),plot_sync_quality()
Classes
|
Assess and monitor an IoT-enabled EM field acquisition. |
- class pycsamt.agents.iot_agent.IoTFieldAgent(*, api_key=None, model=None, llm_provider='claude', method=None, write_manifest=False)[source]#
Bases:
BaseAgentAssess and monitor an IoT-enabled EM field acquisition.
- Parameters:
api_key (str, optional) – LLM configuration. When
api_keyisNonethe agent runs fully offline andllm_interpretationisNone.model (str, optional) – LLM configuration. When
api_keyisNonethe agent runs fully offline andllm_interpretationisNone.llm_provider (str, optional) – LLM configuration. When
api_keyisNonethe agent runs fully offline andllm_interpretationisNone.method (str, optional) – EM method hint (
"amt","mt","csamt","csem","tdem","tem"). Used to seed sessions built from packets and to tag the manifest. When omitted it is inferred from the telemetry.write_manifest (bool, default False) – When
TrueanAcquisitionManifestis built for every run (and written whenmanifest_path/output_diris available).keys (Output data)
----------
order) (One acquisition source is required (tried in this)
session (FieldSession or mapping) – A live session, or a mapping from
to_dict().packets (iterable of TelemetryPacket or mapping) – Raw telemetry to fold into a fresh session.
sites (path / edis /) – An existing survey to seed a re-occupation session via
field_session_from_edis()(no live packets).deployment (DeploymentConfig, optional) – Declared device capabilities; tabulated via
deployment_report().keys
survey_id (str) – Identifier for sessions built from packets/EDIs (default
"iot_survey").now (float) – Reference epoch seconds for live latency / gap calculations.
output_dir (str) – Directory for saved figures and (when requested) the manifest.
manifest (bool) – Force building the acquisition manifest for this run.
manifest_path (str) – Explicit path to write the manifest JSON.
sign_key (str or bytes) – When given with a manifest, the written manifest is HMAC-signed.
sync_references (mapping) – Per-device reference clocks for
batch_assess_sync().energy_configs (iterable of EnergyConfig) – Device energy budgets for
estimate_deployment_energy().figures (bool, default True) – Whether to render dashboard/edge/power/sync figures.
api (bool) – Passed through to pycsamt table builders (API-object vs raw frame).
keys
----------------
:param
sessionthe resolvedFieldSession: :paramstatusMonitoringStatus: :paramstatus_tableone-row monitoring-status table: :paramtelemetry_summarypacket counts by device and topic: :parampacket_tablefull telemetry packet table: :paramstation_tableregistered stations: :parampipeline_inputacquisition hand-off dict for the processing flow: :paramdeployment_tabledevice-capability table (whendeploymentgiven): :paramsync_tableclock-sync table (whensync_referencesgiven): :parampower_tableenergy-budget table (whenenergy_configsgiven): :parammanifestAcquisitionManifest(optional): :parammanifest_pathwritten manifest path (optional): :paramsignaturemanifest HMAC signature dict (whensign_keygiven): :paramlevelmonitoring level string (ok/warn/critical): :paramissueslist of issue strings: :paramn_packets/n_stations/n_devices: :typen_packets/n_stations/n_devices: int :paramfiguresdict of matplotlib Figure objects: :paramfigure_pathsdict of saved figure paths (whenoutput_dirset):Examples
>>> agent = IoTFieldAgent() >>> res = agent.execute({"packets": packets, "output_dir": "/out/iot"}) >>> res["level"] 'warn' >>> res["status"].issues ['battery_min_v below 11.5 V on 2 device(s)'] >>> res["figures"]["dashboard"] <Figure ...>
- SYSTEM_PROMPT: str = 'You are an expert IoT field-operations analyst for pycsamt v2, supervising a\nlive AMT/MT/CSAMT/CSEM acquisition through its edge telemetry stream.\nGiven a survey monitoring summary, write 3-5 sentences that:\n1. State the overall health of the acquisition (healthy / degraded / critical).\n2. Call out the specific stations, channels, or devices that need field\n attention, and the dominant failure mode (packet loss, high latency,\n low battery, clock drift, edge rejections, sensor dropout).\n3. Explain the most likely field cause (power budget, GPS/clock, comms link,\n contact resistance, powerline or near-field interference).\n4. Recommend the single most important field action to take right now.\nReply in plain English. No bullet points, no markdown headings.\n'#
Override in subclasses to give the LLM its domain expertise.
- execute(input_data)[source]#
Run this agent on input_data and return an
AgentResult.Subclasses must implement this method. The contract:
Reset
self._last_cost = 0.0at the top.Record wall-clock time with
t0 = time.time().Return
AgentResult(elapsed_seconds=time.time()-t0, cost_estimate_usd=self._last_cost, ...).
- Parameters:
- Return type: