Search and contents

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:

  • Gate in engine/gate.py is the aggregating Triage Gate itself.
  • SignoffStore in engine/mandatory_human_signoff.py is 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_typePathOutcome
"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_WORTHY drafts a summary and submits it Pending. process() returns the fresh PendingRecord.
  • NOT_CASE_WORTHY returns None. This is a legitimate terminal outcome and a common one, not an error, so it needs no special handling. No ActivityLogEntry is 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 the Title:/Body: parsing in engine/playbook_drafting.py.
  • Failure. A genuine call failure (every retry either a transport error or a blank response) raises CaseSummarizationError through engine.inference.raise_if_failed. An empty or garbled summary is never silently submitted. This is the same fail-closed stance PlaybookDraftingError takes for the Playbook's drafting call.

The record's content

  • trigger_queue_id, trigger_type, manual_flag, summary
  • drafted_by, always present: model for a summary the model wrote, fallback for 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_name and prompt_version, only on a summary the model wrote: the prompt asset that wrote it. The fallback listing carries neither, since no prompt wrote it (see prompt-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.call and 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_by fallback and draft_withheld stated_number_not_in_payload, and no prompt keys.
  • The run's reference_ids carry draft_withheld too, 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.

  • trigger is always "case_triage_scheduled_check" and task_type is always "anomaly narration" (engine.case_triage.TRIGGER and TASK_TYPE). This is the mapping for a scheduled check such as the batch deviation-flagging pass, which is narrated as an anomaly.
  • outcome is always "case_worthy". A NOT_CASE_WORTHY entry never reaches this wiring.
  • reference_ids carries pending_signoff_id (the submitted PendingRecord's id) and trigger_queue_id (the fired Trigger's id). Find which Trigger produced a given Pending record with activity_log.query(reference_id=...). A summary the model wrote adds prompt_name and prompt_version.

Pitfalls

  • CaseTriage never resolves a draft. That is entirely SignoffStore's job (see mandatory-human-sign-off-mechanism.md). record_type is always "case_summary". Approving, rejecting, or editing and resubmitting a draft happens through SignoffStore directly.
  • process() returns None for NOT_CASE_WORTHY, so check for that before assuming a PendingRecord came back. This is the inverse of PlaybookDrafter.ingest's "always returns a fresh record" contract, because Triage's whole point is that not every fired Trigger becomes a case.
  • process() can raise CaseSummarizationError; process_batch() doesn't.
    • process_batch catches CaseSummarizationError per entry and moves on to the next one. It is itself the batching decision. Plain process() 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) before process_batch swallows it. The Activity Log stays a complete record either way. The entry just doesn't appear in process_batch's returned list.
    • A caller invoking process() directly still needs its own per-entry try/except if it iterates a batch itself.
  • This module doesn't own the scheduler. Running on a schedule is a deployment detail. Something calls process_batch periodically with whatever Triggers fired since the last check. CaseTriage has no cron or timer logic of its own.

Release: v0.11.0