Skip to content

Report & Email Agent

Role

The Report Agent is the final delivery step in the BWTS IOT pipeline. It receives the fully compiled investigation context from the IOT Manager — root causes, confidence ratings, evidence from all specialists, and remediation procedures — and transforms it into a formatted HTML report delivered via email. It performs no analysis, no synthesis, and no data queries.


How It Works

  1. Validate Inputs

    The Report Agent receives a task containing the report_request_v1 payload from the IOT Manager. It validates that all required fields are present: alert metadata, data findings, PMS findings, casefile findings, confirmed causes with confidence ratings, remediation procedures, and urgency classification.

    If any required field is missing or malformed, the agent fails the task immediately with a descriptive error — it never attempts to generate a partial report.

  2. Write Context JSON

    The validated payload is written to a structured JSON file in the agent’s working directory. This file serves as the input for report_builder.py and is preserved for logging and debugging purposes.

    shared/IOT-manager/report-agent/{alert_ids}_{timestamp}_context.json
  3. Run report_builder.py validate

    The agent invokes report_builder.py in validate mode to perform schema-level checks on the context JSON before attempting to build:

    Terminal window
    python report_builder.py validate --input context.json

    This catches structural issues (missing nested fields, type mismatches) before the build step, producing clear error messages rather than malformed HTML.

  4. Run report_builder.py build

    Once validation passes, the agent invokes report_builder.py in build mode to generate the HTML report:

    Terminal window
    python report_builder.py build --input context.json --output report.html

    The builder applies urgency-based colour coding, formats tables, and embeds all evidence into a self-contained HTML document.

  5. Compose Plain-Text Email Body

    The agent writes a concise plain-text email body summarising the key findings. This ensures the report is readable even in email clients that strip or block HTML attachments. The plain-text body includes:

    • Vessel name and equipment tag
    • Urgency classification
    • Top root cause with confidence level
    • A note that the full HTML report is attached
  6. Send via gmail_send.py

    The agent invokes gmail_send.py to deliver the email with the HTML report attached:

    Terminal window
    python gmail_send.py send \
    --to "ops-team@your-domain.example" \
    --from "alerts@your-domain.example" \
    --subject "[BWTS REPORT] {SEVERITY} — {Parameter} — {Vessel} — {Date}" \
    --body body.txt \
    --attachment report.html
  7. Confirm Delivery

    After gmail_send.py returns success, the agent marks its task as complete and posts a confirmation comment to the parent task. The IOT Manager uses this confirmation to close the investigation loop.


Report Structure

The HTML report is divided into three main sections, each serving a distinct purpose for the engineering team reviewing the alert.

A table of all alerts included in the investigation, providing immediate context.

ColumnDescription
Alert IDUnique alert instance identifier
Equipment TagBWTS equipment identifier (e.g., BWTS-UV-003)
ParameterSensor parameter in violation (e.g., uv_intensity)
Current ValueLatest sensor reading at time of alert
ThresholdConfigured threshold that was breached
Triggered AtISO 8601 timestamp of alert trigger
SeverityCRITICAL, WARNING, or INFO

Urgency Colour Coding

The HTML report applies a colour-coded banner at the top based on the urgency classification determined by the IOT Manager.

UrgencyBanner ColourMeaning
IMMEDIATERed (#dc2626)Action required before next BWTS operation. Compliance breach or safety risk.
SHORT-TERMAmber (#f59e0b)Address at next port call. Degradation trending or maintenance due.
MONITORBlue (#3b82f6)Watch and log. Minor deviation or early warning signal.

Email Format

FieldValue
Fromalerts@your-domain.example
Toops-team@your-domain.example
Subject[BWTS REPORT] {SEVERITY} — {Parameter} — {Vessel} — {Date}
BodyPlain-text summary of key findings
Attachmentreport.html — full formatted report

What It Does NOT Do

No Analysis

Never interprets sensor data, never identifies trends, never correlates parameters. All analysis is completed before the Report Agent is invoked.

No Synthesis

Never cross-references findings, never assigns confidence ratings, never determines root causes. That is the IOT Manager’s exclusive responsibility.

No Data Queries

Never connects to PostgreSQL, never calls the Dashboard API, never queries equipment manuals. Works solely from the compiled payload it receives.


Tools

ToolScriptPurpose
Report Builderreport_builder.py validateValidate the context JSON against the report_request_v1 schema before building
Report Builderreport_builder.py buildGenerate the formatted HTML report from validated context
Email Sendergmail_send.py sendDeliver the report email with HTML attachment via SMTP