AISOCin‑a‑box

LLM Triage Internals

How the agent orchestrator turns an ingested alert into a verdict, a gated action, and a verifiable trail — and where every boundary is. Source of implementation: apps/agent-orchestrator/src/orchestrator/. Source of contract: spec §3.2–§3.5.

The invariant that shapes everything below: LLM output is data, never control flow. The LLM proposes hypotheses and verdicts; routing is a pure function of validated state, and every action the verdict proposes passes through a deterministic OPA gate before it can exist as a side effect (§3.2/§3.3). A prompt injection in telemetry can at worst produce a proposal the gate refuses.

The graph

triage_graph.build_graph() compiles a LangGraph state machine with MemorySaver checkpointing in the reference stack (the spec's production checkpoint is PostgresSaver on the RLS-scoped control-plane DB — §3.2.4; the in-memory saver is why a restarted orchestrator forgets open HITL requests: the durable record is the case projection + audit chain, not the run):

START → ingest_alert → hypothesis → esql_context_hunter
      → vector_rag_enrichment → verdict_attack_mapping
      → autonomy_gate ─┬→ approval_wait → gate_finalize ─┬→ auto_remediate → finalize_case → END
                      │   (interrupt)                    ├→ escalate_to_analyst → finalize_case → END
                      └→ gate_finalize                   └→ finalize_case → END
verdict(insufficient_context, replans < 2) loops back to hypothesis

Routing is explicit and testable — three small functions in triage_graph.py, each a deterministic function of validated state:

Router Condition Next
route_after_verdict routing_hint == "insufficient_context" and replan_count < 2 hypothesis (replan)
replan bound exhausted escalate_to_analyst — never a silent no-action close
otherwise autonomy_gate
route_after_autonomy_gate any action requires human_approval approval_wait (durable interrupt)
all autonomous or none gate_finalize
route_after_gate all actions autonomous auto_remediate
any non-autonomous (all-or-nothing) escalate_to_analyst

Budgets that make a run bounded (constants at the top of triage_graph.py and esql_validator.py):

Constant Value Effect
MAX_REPLANS 2 verdict → hypothesis replans before forced escalation
MAX_ESQL_PER_RUN 5 EsqlDispatches per run, accumulated across replan passes
MAX_LIMIT 200 per-query row cap — the same number as the dispatch frame's max_rows
MAX_SPAN_S 7 days ?ts_start/?ts_end window bound
LLM timeout 120 s per completion, both real backends
temperature 0.0 determinism where the provider allows it

The LLM lanes

One seam — LaneLLM in llm_router/router.py — with three backends selected by SOC_LLM_BACKEND:

Backend SOC_LLM_BACKEND What it is
StubRouterLLM stub (reference default) deterministic, no network; keys lanes on marker strings so the demo exercises both autonomy tiers (see below)
VllmLLM vllm local vLLM chat/completions (customer-hosted, §3.3.5 tier "local")
FrontierLLM frontier frontier provider endpoint (zero-data-retention contract per spec)

Both real backends call /chat/completions with temperature: 0.0 and a 120 s timeout; the model id is env-configured.

The stub is a test fixture, not a detector. Its "intelligence" is: if "HIGHBLAST" appears in the prompt text it returns the high-blast lane (confidence 0.93, host_isolate + ioc_enrichment_push, MITRE T1489 / T1021.001 → routes to HITL); otherwise the default autonomous lane (confidence 0.88, token_revoke, T1078 → remediated). The reference seeders drive the high-blast lane honestly: the marker arrives via meta.rule_id = "seed-…" + meta.hitl = "1", which the verdict node appends to the prompt (triage_graph.node_verdict_attack_mapping) — the audit chain records which lane fired and why.

No per-tenant token/cost tracking exists in the code. If you size a real deployment, meter at the LLM gateway; the orchestrator's audit events give you per-run completion count + latency, not token spend.

Prompt structure (what the model actually sees)

Two prompt templates, both logged to the audit chain — as prompt_sha256

  • redacted_prompt, never the full prompt (repo logging rule: full LLM prompts are audit-chain material only in redacted form):

hypothesis/v2:

Alert: {json(alert.ecs)}
Asset: {json(alert.asset)}
Return <=3 hypotheses as JSON {"hypotheses": [{id, statement, likelihood, esql_draft}]};
each esql_draft must be one ES|QL pipeline over the alert window.

verdict/v2:

Alert: {json(alert.ecs)}
Hypotheses: {json(state.hypotheses)}
ES|QL results: {json(state.esql_results)}
Enrichment: {json(state.enrichment)}
Return a Verdict JSON (outcome, confidence, mitre_techniques, narrative, proposed_actions[]);
every proposed action must carry evidence_refs (audit seqs or doc ids).

The alert's ecs block is the redacted edge payload — the prompt cannot see what redaction dropped, because the cloud never received it.

The verdict schema

Validated by Pydantic on the spot — malformed output is data failure, not crash:

class Verdict(BaseModel):
    outcome: Literal["true_positive", "false_positive", "benign", "insufficient_context"]
    confidence: float  # 0..1
    mitre_techniques: list[str]
    narrative: str
    proposed_actions: list[RemediationAction]

class RemediationAction(BaseModel):
    action_type: Literal[
        "token_revoke", "ioc_enrichment_push",   # low blast radius
        "host_isolate", "ad_account_disable",    # high blast radius
        "firewall_ban", "mailbox_purge",
    ]
    target: str
    target_type: str
    reversibility: Literal["reversible", "partially_reversible", "irreversible"]
    scope: Literal["single_entity", "single_host", "tenant_wide"]
    confidence: float
    evidence_refs: list[str]
    params: dict[str, Any]

MITRE technique IDs are fence-checked against the ATT&CK ID shape (T\d{4}(\.\d{3})?); unknown IDs are dropped and recorded as rejected_techniques in the verdict_recorded event — the LLM cannot invent technique IDs into the case.

The autonomy gate (OPA)

node_autonomy_gate evaluates every proposed action against the Rego bundle (apps/agent-orchestrator/policies/hitl_guardrails.rego) via the OPA sidecar. Decision contract (§3.3.2):

{"mode": "autonomous | human_approval | forbidden",
 "reasons": ["…"], "policy_id": "soc.hitl.v1/…", "expires_in_seconds": 900}
  • Unknown lane ⇒ forbidden (fail-closed; new action types must land in the Rego policy and its decision-table tests in the same PR — 18 tests, opa test).
  • OPA error ⇒ forbidden with policy_id: "fail-closed/opa-error" — the gate never fails open.
  • human_approval opens a HITL request: hitl_requested is sealed in the audit chain before the graph suspends at approval_wait (audit-before-execute).
  • The approval is only consumable if it is bound to the open request (request_id match), inside the policy ttl, and — for approve — mfa_verified: true (D-V1: unverified ⇒ forbidden soc.hitl.v1/hitl/mfa-unverified). gate_finalize re-evaluates OPA with the approver attached; the policy, not the graph or the portal, confirms the action may run (§3.3.3 r6).

ES|QL — the investigation query

The hunter node turns hypothesis drafts into EsqlDispatch frames, each pre-flight-validated by the single-source validator (esql_validator.py, spec §3.5). Five rules, all enforced before anything crosses toward the edge:

  1. FROM first; every index in the list allow-listed (reference prefixes logs-/logs./audit-/audit.; the graph form fnmatch-checks against the tenant's patterns from the registry — never from the alert itself, which would make the guard self-certifying).
  2. Single pipeline statement — no ;, no second FROM.
  3. Every verb in the read-only allow-list (WHERE, STATS, SORT, ENRICK→ENRICH, LOOKUP, DEDUPE, KEEP, ROWS, …) — no write/mutation verbs.
  4. LIMIT present, ≤ 200, and the only LIMIT (mid-pipeline second LIMIT rejected).
  5. ?ts_start/?ts_end, if referenced, must both be bound with span ≤ 7 days — a referenced-but-unbound parameter is rejected, never skipped.

String-literal masking: |, ;, ?, and LIMIT inside double-quoted literals are blanked before structural scans, so a regex like "(?i)(rubeus|secretdump|klist)" validates without faking pipeline verbs.

Known drift, honestly: the validator's verb allow-list still includes SELECT, which the ES 9.1.4 engine in the reference stack rejects at execution — the validator is the pre-flight fence (shape, tenancy, caps); engine-level rejection is the last line. Queries that pass validation may still fail at the engine; the failure is returned in the dispatch result (status: "error") and recorded in the run, not hidden.

Execution in the reference stack is SimulatedTunnel.dispatch_esql: the validated query runs against the tenant's ES over the compose network (simulated_tunnel: true in every receipt); receipts are posted to the control plane's /internal/action-result. The spec's real leg is the edge executing the dispatch under its own OPA bundle + allow-list expansion (§1.2.4.b, §3.5) — Phase 1.

What a run writes to the audit chain

Every step above is an event in the tenant's hash chain (types seen in a live run):

alert_ingested → llm_prompt (hypothesis) → llm_completion
→ esql_generated (validation_status + reasons) ×≤5
→ intel_lookup → rag_retrieval
→ llm_prompt (verdict) → verdict_recorded (verdict, confidence,
   techniques, rejected_techniques) → llm_completion
→ policy_decision ×n (opa_input_digest, decision, policy_bundle_sha256, opa_version)
→ hitl_requested → [approval: hitl_resolved] → policy_decision (re-evaluated)
→ action_executed ×n (mode, receipt, directive_id)
→ escalated_to_analyst | finalize_case/case_closed

A run's audit_refs (chain seqs) are carried in the case row and the verdict's evidence — the case page's "Audit refs" block is that linkage.

Failure modes (and what happens)

Failure Behavior Audit trail
LLM completion malformed / empty lane returns insufficient_context; replan ≤ 2, then forced escalation — never a silent no-action close llm_completion with rejected reason; escalated_to_analyst
LLM timeout (120 s) same path — the exception is the rejection llm_completion rejected
ES QL draft invalid (5 rules) draft rejected with reasons; hunter stays within budget; verdict sees the rejection
ES QL engine error at execution dispatch result status: "error"; run continues with what it has
OPA unreachable / error fail closed: forbidden, policy_id: fail-closed/opa-error policy_error + policy_decision
Approval without MFA forbidden soc.hitl.v1/hitl/mfa-unverified — forwarded and refused, never silently dropped (D-V1) hitl_resolved with the decision as presented
Approval late (past policy ttl) or unbound request_id rejected at the gate; a stale approval is superseded, never executed superseded_approval on the new request
Orchestrator unreachable at ingest alert row still lands and commits (dedupe marker); triage reported deferred — no case, no chain trail yet alert in PG, triage: "deferred: …" in the ingest response
Orchestrator restart mid-HITL in-memory checkpointer forgets the run; the durable record (case state awaiting_approval, approval row, chain) remains — the reference does not auto-resume; re-seed or re-drive the case the case page says "no live orchestrator run"

Observability

  • GET /v1/graph (orchestrator, :8130) — the static topology + invariants, for the portal timeline skin.
  • GET /v1/status/{case_id} — live run view: node, state, verdict, interrupt, action results, audit refs.
  • GET /v1/audit/{tenant}/chain — the chain itself with recomputed verification.
  • Control plane: GET /api/cases/{id}/timeline — the durable, RLS-scoped per-case projection of the chain (survives orchestrator restarts).

Cross-references