Marek SrokaArticles

From machine alarm to work order: an AI agent that never decides safety on its own

Marek Sroka · Updated 3 December 2026

Every maintenance team knows the pattern: an alarm pops up on the HMI, someone looks it up in a manual, guesses the cause, and writes a work order. It is slow, it depends on who is on shift, and the manual is often in a folder nobody can find.

I built an agent for exactly this step: a machine alarm goes in, a checked maintenance work order comes out. The interesting part is not the language model. It is what sits around it.

What the agent does

  1. Reads the alarm: machine, code, text and the context around it.
  2. Looks up the relevant pages of that machine's manual.
  3. Diagnoses the likely fault and drafts a work order: what to check, in which order, which parts may be needed.
  4. Hands the draft to a deterministic checker before anything reaches the plant.

The agent is built as a LangGraph graph, so each step is an explicit node, and every run is traced in Langfuse with its inputs, outputs, tokens and time.

Why a deterministic checker, not a smarter prompt

A language model can write a convincing work order for a fault it misread. In maintenance that is not a style problem, it is a safety problem. So the final decision is not made by the model at all.

The checker is plain code with plain rules. It looks at the alarm class and the drafted actions and decides one of two things: the draft can go to the maintenance queue, or it must wait for a person. Anything safety-critical goes to a person, every time. In my measurements that rule held for 100% of the safety alarms.

This split is the main design idea: the model is good at reading manuals and writing clear instructions, and code is good at enforcing a rule without exceptions.

How I measured it

I do not trust an agent I have not measured. The test set was 38 real alarms, each with a known correct outcome. I ran two versions of the prompt against the same set and compared them in Langfuse:

The third question is a hard requirement, not a score to trade off. A prompt version that improves diagnosis but lets one safety alarm through automatically is a worse version.

What I would tell a plant that wants this

The same pattern works outside maintenance: an AI drafts, a deterministic rule decides what needs a human, and every run is traced. It is how I run all of my agents, which I describe in approval gates for AI agents.

Marek SrokaAI engineer with ten years of industrial automation: robots, PLCs and vision in live plants, now AI agents, evals and machine-data ML. CV and projects