Open-source AI Security Operations Center: alert fusion, LLM-agent triage, MITRE ATT&CK investigation, and a replayable decision ledger for every agent step. Self-hostable, runs with no API keys, MIT licensed. Ships an MCP server for Claude, Cursor and Continue.
Python agentic-aiai-securityalert-triageblue-teamcybersecuritydetection-engineeringincident-responselanggraphllm-agentsmcpmitre-attackmodel-context-protocolpurple-teamsecurity-operationsself-hostedsiemsoarsocthreat-detectionthreat-intelligence
fix(agents,api): send real alert payload to investigation; stop fabricated evidence
Alexandru Mateescu128ebb0af658
diff --git a/services/agents/app/investigator/forensic_agent.py b/services/agents/app/investigator/forensic_agent.pyindex 9809a83fb..f232595ea 100644--- a/services/agents/app/investigator/forensic_agent.py+++ b/services/agents/app/investigator/forensic_agent.py@@ -54,11 +54,27 @@ async def _llm_forensic(state: InvestigatorState) -> dict[str, Any]:max_depth=2,)+ # The original alert payload is the ONLY primary evidence this agent+ # has; it used to be absent from the prompt entirely, which is how a+ # run on an empty payload produced a confident fictional timeline.+ raw_alert_blob = summarize_structure_for_llm(+ dict(state.raw_alert or {}),+ label="raw_alert",+ max_lines=80,+ max_depth=3,+ )+ evidence_available = bool((state.raw_alert or {}).get("alerts")+ or (state.enrichment_cache or {}))+prompt = (f"Alert summary:\n{safe_summary}\n\n"+ f"Original alert data:\n{raw_alert_blob}\n\n"f"Recon findings:\n{safe_recon}\n"f"MITRE techniques: {safe_mitre}\n\n"f"Enrichment data (sample):\n{enrichment_blob}"+ + ("" if evidence_available else+ "\n\nWARNING: no alert payload, no enrichment, no lake results "+ "were retrieved. Produce only an inconclusive analysis."))bundle_append = format_bundle_prompt_append(state.context_bundle)if bundle_append:@@ -150,7 +166,7 @@ async def run_forensic(state_dict: dict[str, Any]) -> dict[str, Any]:llm_result = await _llm_forensic(state)- state.forensic = ForensicFindings(+ findings = ForensicFindings(timeline=llm_result.get("timeline", []),artefacts=llm_result.get("artefacts", []),root_cause_hypothesis=llm_result.get("root_cause_hypothesis", ""),@@ -159,11 +175,44 @@ async def run_forensic(state_dict: dict[str, Any]) -> dict[str, Any]:summary=llm_result.get("summary", ""),)- # Cite each forensic artefact as evidence for downstream replay+ # Honesty gate: an analysis built on zero retrieved evidence is a+ # hypothesis factory, not a forensic result. Strip invented artefacts,+ # cap confidence, and mark the run inconclusive so the report and the+ # UI cannot present fiction as fact (2026-10 live incident: a run over+ # an empty raw_alert "found" C:\\Windows\\Temp\\malware.exe).+ has_primary = bool((state.raw_alert or {}).get("alerts")+ or (state.raw_alert or {}).get("title")+ or (state.raw_alert or {}).get("full_log"))+ has_enriched = bool(state.enrichment_cache)+ if not has_primary and not has_enriched:+ findings = findings.model_copy(update={+ "artefacts": [],+ "confidence": min(findings.confidence, 0.1),+ "root_cause_hypothesis": (+ "INCONCLUSIVE - no alert payload or retrieved evidence was "+ "available to this investigation; any finding would be "+ "speculation."+ ),+ "summary": (+ "Automated forensic analysis inconclusive: zero evidence "+ "retrieved. Manual review with the Wazuh locator on the "+ "case is required."+ ),+ })+ state.log(+ StepKind.WARNING if hasattr(StepKind, "WARNING") else StepKind.DECISION_REASON,+ "ForensicAgent",+ "inconclusive: zero evidence retrieved; artefacts suppressed",+ )+ state.forensic = findings++ # Cite forensic artefacts for downstream replay. Provenance is the+ # model's inference, not a retrieved observation - say so, otherwise+ # the audit log launders fabricated artefacts into "evidence_cited".for artefact in state.forensic.artefacts[:50]:state.log_evidence(agent="ForensicAgent",- evidence_kind="artefact",+ evidence_kind="artefact_hypothesis",ref=str(artefact),weight=state.forensic.confidence,)diff --git a/services/agents/app/llm/prompt_registry.py b/services/agents/app/llm/prompt_registry.pyindex 532c0a849..1e09e111e 100644--- a/services/agents/app/llm/prompt_registry.py+++ b/services/agents/app/llm/prompt_registry.py@@ -359,6 +359,15 @@ Respond ONLY with a JSON object matching this schema:"""_FORENSIC_SYSTEM = r"""You are the ForensicAgent of an AI Security Operations Centre.+HARD RULES:+- Work ONLY from the alert payload, enrichment and lake data provided.+- NEVER invent file paths, registry keys, timestamps, users or hosts that+ do not appear in the input data. Example values in this prompt are+ FORMAT ILLUSTRATIONS, never findings.+- Timeline entries must use timestamps taken from the provided data only.+- If the provided data contains no concrete artefacts or event details,+ return empty timeline/artefacts, confidence <= 0.1, and state the+ analysis is inconclusive due to missing evidence.Given a security alert and its enrichment data, produce:1. A chronological timeline of events (at most 15 entries).2. A list of forensic artefacts (file paths, registry keys, network indicators).diff --git a/services/api/app/api/v1/endpoints/cases.py b/services/api/app/api/v1/endpoints/cases.pyindex 65cd67b33..df84b31ce 100644--- a/services/api/app/api/v1/endpoints/cases.py+++ b/services/api/app/api/v1/endpoints/cases.py@@ -1500,13 +1500,14 @@ async def case_investigate(user: Annotated[AuthUser, Depends(require_permission("cases:write"))],) -> dict[str, Any]:cid = await _resolve_case_id(case_id, db, user.tenant_id)- exists = (+ case_row = (await db.execute(- text("SELECT 1 FROM aisoc_cases WHERE id = :id AND tenant_id = :tenant_id").bindparams(id=cid, tenant_id=user.tenant_id)+ text("SELECT alert_ids FROM aisoc_cases WHERE id = :id AND tenant_id = :tenant_id").bindparams(id=cid, tenant_id=user.tenant_id))).fetchone()- if not exists:+ if not case_row:raise HTTPException(status_code=404, detail="Case not found.")+ case_alert_ids = [str(a) for a in (case_row.alert_ids or [])]# The evidence, assembled server-side from the case's own alerts rather# than taken from the caller. The console was sending the literal string@@ -1531,10 +1532,56 @@ async def case_investigate(# is scoped by tenant_id, so without this the whole run is never persisted.# Service-token path requires the acting tenant on the header, not just# in the body: tenant_scope refuses a service token with no tenant.+ # The agents service stores raw_alert on the run and every downstream+ # agent reads it; forwarding {} meant the forensic/report models got an+ # empty payload and filled the gap with fabricated artefacts+ # (C:\\Windows\\Temp\\malware.exe and friends). Load the case's linked+ # alerts and pass their real content, truncated so the prompt stays+ # bounded and free of multi-MB raw blobs.+ raw_alert_payload: dict[str, Any] = {}+ try:+ if case_alert_ids:+ rows = (+ await db.execute(+ text(+ "SELECT id, title, description, severity, connector_type, "+ "affected_ips, affected_hosts, affected_users, event_time, raw_event "+ "FROM alerts WHERE id::text = ANY(:ids) AND tenant_id = :tenant_id "+ "ORDER BY event_time DESC LIMIT 3"+ ).bindparams(ids=case_alert_ids, tenant_id=user.tenant_id)+ )+ ).mappings().all()+ alerts_out = []+ for r in rows:+ raw = r["raw_event"] if isinstance(r["raw_event"], dict) else {}+ full_log = raw.get("full_log") or ""+ alerts_out.append(+ {+ "id": str(r["id"]),+ "title": r["title"],+ "description": (r["description"] or "")[:1000],+ "severity": r["severity"],+ "source": r["connector_type"],+ "affected_ips": list(r["affected_ips"] or [])[:20],+ "affected_hosts": list(r["affected_hosts"] or [])[:20],+ "affected_users": list(r["affected_users"] or [])[:20],+ "event_time": r["event_time"].isoformat() if r["event_time"] else None,+ "full_log": str(full_log)[:4000],+ }+ )+ if alerts_out:+ raw_alert_payload = {"alerts": alerts_out}+ except Exception: # noqa: BLE001 - never block launch on enrichment+ logger.warning("investigate.launch.raw_alert_enrichment_failed", case_id=str(cid), exc_info=True)+resp = await _agents_proxy("POST",f"/api/v1/cases/{cid}/investigate",- json={"alert_summary": body.alert_summary or "", "tenant_id": str(user.tenant_id)},+ json={+ "alert_summary": body.alert_summary or (raw_alert_payload.get("alerts", [{}])[0].get("title") if raw_alert_payload.get("alerts") else ""),+ "raw_alert": raw_alert_payload,+ "tenant_id": str(user.tenant_id),+ },headers={"X-AiSOC-Tenant-ID": str(user.tenant_id)},)if resp.status_code >= 400: