Case triage and summarization: Deviation/Exception gate, manual flag, and auto-draft
This guide covers how CaseTriage in engine/case_triage.py decides which events are case-worthy before full AI summarization runs, and how it drafts the summary for those that are. That decision logic is called Triage.
Mechanically, Triage is a Gate instance that aggregates over Deviation OR Exception. A manual flag is a separate, ungated Trigger, not a third input into the Gate.
CaseTriage is glue over things built elsewhere:
Gateinengine/gate.pyis the aggregating Triage Gate itself.SignoffStoreinengine/mandatory_human_signoff.pyis where every drafted summary lands. This module never resolves a draft itself. It only submits it Pending, because the Mandatory-Human Sign-off Mechanism behaves identically for a Playbook entry and a case summary.
1. Load and version-check the prompt asset
from pathlib import Path
from engine.prompt_assets import assert_version, load_prompt_asset
summarization_asset = load_prompt_asset(Path("engine/prompts/case_summary_drafting.md"))
assert_version(summarization_asset, "0.2.0")
2. Build the triage over already-constructed collaborators
from engine.mandatory_human_signoff import SignoffStore
from engine.case_triage import CaseTriage
signoff_store = SignoffStore()
signoff_store.ensure_schema()
triage = CaseTriage(
inference_client, # engine.inference.InferenceClient
summarization_asset,
signoff_store,
activity_log, # engine.activity_log.ActivityLog
"MES", # this Node's own node_type
node_instance_id, # this Node's own instance id
)
CaseTriage also takes inference_enabled: bool = True. With it False, the summary is the structured-facts-only fallback and no model call is made; see inference-operating-mode.md.
3. Triage one fired Trigger
record = triage.process(entry) # engine.trigger_queue.TriggerQueueEntry
entry.trigger_type decides the outcome:
trigger_type | Path | Outcome |
|---|---|---|
"deviation" or "exception" (engine.case_triage.GATED_TRIGGER_TYPES) |
Routed through the aggregating Triage Gate. | CASE_WORTHY |
"case_manual_flag" (engine.case_triage.MANUAL_FLAG_TRIGGER_TYPE) |
Checked before the Gate and never reaches it. | Always CASE_WORTHY directly. |
| Anything else | The Gate's own fallback. | NOT_CASE_WORTHY |
CASE_WORTHYdrafts a summary and submits it Pending.process()returns the freshPendingRecord.NOT_CASE_WORTHYreturnsNone. This is a legitimate terminal outcome and a common one, not an error, so it needs no special handling. NoActivityLogEntryis written for it either, because nothing ran that was worth logging.
A batch of fired Triggers triages in one call, keeping only the case-worthy summaries. One entry's CaseSummarizationError doesn't stop the rest of the batch (see Pitfalls):
records = triage.process_batch(entries) # Iterable[TriggerQueueEntry] -> list[PendingRecord]
Deviation and Exception are plain trigger_type strings
engine/deviation_flagging.py produces "deviation"-typed entries (see deviation-flagging.md). "Exception" has no dedicated mechanism of its own.
CaseTriage does not import engine/deviation_flagging.py. GATED_TRIGGER_TYPES is read the way every other trigger_type in this codebase is: as a plain string on a TriggerQueueEntry (engine/trigger_queue.py). That needs no schema change and no dependency on whichever Node Type or Gate produced the entry, so CaseTriage stays decoupled from its producers.
The manual flag is checked structurally, not just by outcome
CaseTriage.triage checks entry.trigger_type == MANUAL_FLAG_TRIGGER_TYPE first and returns CASE_WORTHY directly. The Gate's own decide() is never called for a manual flag.
This is more than the Gate happening to resolve manual flags to CASE_WORTHY. The Gate's evaluate function (CaseTriage._gate_evaluate) does not know MANUAL_FLAG_TRIGGER_TYPE exists. A manual flag can therefore never become a third input into the aggregating Gate alongside Deviation and Exception. By design it is a separate, ungated Trigger.
Summarization is a separate step chained after a CASE_WORTHY decision
The model call
One inference call drafts a plain-language summary from entry.trigger_type and entry.payload.
- Validation. Only
InferenceClient.call's default validator applies, which rejects a blank or whitespace-only response. A case summary is a single prose narrative, not a titled entry, so there is no fixed structure to check, unlike theTitle:/Body:parsing inengine/playbook_drafting.py. - Failure. A genuine call failure (every retry either a transport error or a blank response) raises
CaseSummarizationErrorthroughengine.inference.raise_if_failed. An empty or garbled summary is never silently submitted. This is the same fail-closed stancePlaybookDraftingErrortakes for the Playbook's drafting call.
The record's content
trigger_queue_id,trigger_type,manual_flag,summarydrafted_by, always present:modelfor a summary the model wrote,fallbackfor the structured-facts listing a Node with inference disabled submits. A reviewer can tell the two apart at a glance. Records stored before the field existed do not have it and are left as they were. A reader treats the absent key as "drafted before the field existed".draft_withheld, only on the one kind of record that has it (see The explanation of an alert)prompt_nameandprompt_version, only on a summary the model wrote: the prompt asset that wrote it. Thefallbacklisting carries neither, since no prompt wrote it (seeprompt-provenance-and-stated-counts.md).
The explanation of an alert
An instruction conformance alert enqueues a deviation Trigger. The Trigger's id is the alert's id, and its payload names an alert_id (see Instruction bindings). Case Triage handles it like any other deviation.
The summary is the explanation of the alert: a case_summary record submitted Pending for review, whose trigger_queue_id is the alert's id. It is separate from the alert, which is never held for it and never changed by it. A Node with inference disabled submits the structured facts (drafted_by fallback), so the alert reads the same with or without a model.
Stated numbers are checked
For such a Trigger, and only for one, the draft is checked before it is accepted: every number it states must be a number in the payload (engine/stated_numbers.py).
- A draft that states another number is rejected through the validator hook of
InferenceClient.calland drafted again, within the profile's own attempts. There is no second loop. - What counts as a number, and as held, is described on the bindings page.
When every attempt fails the check
If every attempt states a number the payload does not hold, the draft is not submitted. Instead:
- The structured facts stand in (
_build_fallback_summary(entry, withheld=True), which says the explanation was withheld). - The record has
drafted_byfallbackanddraft_withheldstated_number_not_in_payload, and no prompt keys. - The run's
reference_idscarrydraft_withheldtoo, so an operator can count them. - The log line holds the attempt count and none of the text, because a draft can echo anything it was shown.
This is not CaseSummarizationError. That error remains for a model that cannot be reached. An outage after a rejected draft is still an outage: it is retried and dead-lettered as before, never taken for a withheld summary.
Activity Log wiring
Every process() call that reaches CASE_WORTHY writes exactly one ActivityLogEntry, through the Task Execution logging (see wiring-task-execution-to-activity-log.md). CaseTriage does not write it directly. It wraps its summarize-and-submit logic as a trivial one-step Prompt Chaining Task, the same composition engine/playbook_drafting.py and engine/playbook_answer.py use.
triggeris always"case_triage_scheduled_check"andtask_typeis always"anomaly narration"(engine.case_triage.TRIGGERandTASK_TYPE). This is the mapping for a scheduled check such as the batch deviation-flagging pass, which is narrated as an anomaly.outcomeis always"case_worthy". ANOT_CASE_WORTHYentry never reaches this wiring.reference_idscarriespending_signoff_id(the submittedPendingRecord's id) andtrigger_queue_id(the fired Trigger's id). Find which Trigger produced a given Pending record withactivity_log.query(reference_id=...). A summary the model wrote addsprompt_nameandprompt_version.
Pitfalls
CaseTriagenever resolves a draft. That is entirelySignoffStore's job (seemandatory-human-sign-off-mechanism.md).record_typeis always"case_summary". Approving, rejecting, or editing and resubmitting a draft happens throughSignoffStoredirectly.process()returnsNoneforNOT_CASE_WORTHY, so check for that before assuming aPendingRecordcame back. This is the inverse ofPlaybookDrafter.ingest's "always returns a fresh record" contract, because Triage's whole point is that not every fired Trigger becomes a case.process()can raiseCaseSummarizationError;process_batch()doesn't.process_batchcatchesCaseSummarizationErrorper entry and moves on to the next one. It is itself the batching decision. Plainprocess()may be used one-off, and a caller reasonably wants to see the exception directly.- A caught failure is already logged as its own terminal error
ActivityLogEntry(the Task Execution logging) beforeprocess_batchswallows it. The Activity Log stays a complete record either way. The entry just doesn't appear inprocess_batch's returned list. - A caller invoking
process()directly still needs its own per-entrytry/exceptif it iterates a batch itself.
- This module doesn't own the scheduler. Running on a schedule is a deployment detail. Something calls
process_batchperiodically with whatever Triggers fired since the last check.CaseTriagehas no cron or timer logic of its own.
Release: v0.11.0