:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(alerts): investigation agent frontend — opt-in + column (#55186)
Andrew Maguiree54dcd894e40
diff --git a/frontend/src/lib/components/Alerts/alertFormLogic.ts b/frontend/src/lib/components/Alerts/alertFormLogic.tsindex 630d6b9a4235..afa116cf0006 100644--- a/frontend/src/lib/components/Alerts/alertFormLogic.ts+++ b/frontend/src/lib/components/Alerts/alertFormLogic.ts@@ -37,6 +37,9 @@ export type AlertFormType = Pick<| 'skip_weekend'| 'schedule_restriction'| 'detector_config'+ | 'investigation_agent_enabled'+ | 'investigation_gates_notifications'+ | 'investigation_inconclusive_action'> & {id?: AlertType['id']created_by?: AlertType['created_by'] | null@@ -44,11 +47,12 @@ export type AlertFormType = Pick<}export function canCheckOngoingInterval(alert?: AlertType | AlertFormType): boolean {+ const upper = alert?.threshold?.configuration?.bounds?.upperreturn (- (alert?.condition.type === AlertConditionType.ABSOLUTE_VALUE ||- alert?.condition.type === AlertConditionType.RELATIVE_INCREASE) &&- alert?.threshold.configuration.bounds?.upper != null &&- !isNaN(alert?.threshold.configuration.bounds.upper)+ (alert?.condition?.type === AlertConditionType.ABSOLUTE_VALUE ||+ alert?.condition?.type === AlertConditionType.RELATIVE_INCREASE) &&+ upper != null &&+ !isNaN(upper))}@@ -223,6 +227,9 @@ export const alertFormLogic = kea<alertFormLogicType>([skip_weekend: false,schedule_restriction: null,detector_config: null,+ investigation_agent_enabled: false,+ investigation_gates_notifications: false,+ investigation_inconclusive_action: 'notify',insight: props.insightId,} as AlertFormType),errors: (alert: AlertType | AlertFormType) =>@@ -246,6 +253,16 @@ export const alertFormLogic = kea<alertFormLogicType>([check_ongoing_interval: canCheckOngoingInterval(alert) && alert.config.check_ongoing_interval,},detector_config: alert.detector_config ?? null,+ // Investigation agent only applies to anomaly (detector-based) alerts — force off otherwise.+ investigation_agent_enabled: alert.detector_config+ ? (alert.investigation_agent_enabled ?? false)+ : false,+ // Notification gating requires the investigation agent to be on.+ investigation_gates_notifications:+ alert.detector_config && alert.investigation_agent_enabled+ ? (alert.investigation_gates_notifications ?? false)+ : false,+ investigation_inconclusive_action: alert.investigation_inconclusive_action ?? 'notify',schedule_restriction:(alert.schedule_restriction?.blocked_windows?.length ?? 0) > 0? alert.schedule_restrictiondiff --git a/frontend/src/lib/components/Alerts/views/AlertHistorySection.tsx b/frontend/src/lib/components/Alerts/views/AlertHistorySection.tsxindex 1d6895eac64b..996c0610b233 100644--- a/frontend/src/lib/components/Alerts/views/AlertHistorySection.tsx+++ b/frontend/src/lib/components/Alerts/views/AlertHistorySection.tsx@@ -1,7 +1,17 @@import { useActions, useValues } from 'kea'import { useMemo } from 'react'-import { LemonSegmentedButton, LemonSkeleton, LemonTable, SpinnerOverlay } from '@posthog/lemon-ui'+import { IconNotebook } from '@posthog/icons'+import {+ LemonSegmentedButton,+ LemonSkeleton,+ LemonTable,+ LemonTag,+ Link,+ Spinner,+ SpinnerOverlay,+ Tooltip,+} from '@posthog/lemon-ui'import type { LemonTableColumn } from '@posthog/lemon-ui'import { AlertHistoryChart } from 'lib/components/Alerts/views/AlertHistoryChart'@@ -10,10 +20,90 @@ import { EmptyMessage } from 'lib/components/EmptyMessage/EmptyMessage'import { TZLabel } from 'lib/components/TZLabel'import { dayjs } from 'lib/dayjs'import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'+import { IconOpenInNew } from 'lib/lemon-ui/icons'import { formatDate } from 'lib/utils'import { alertLogic, CHART_CHECKS_LIMIT, TABLE_CHECKS_PAGE_SIZE } from '../alertLogic'-import type { AlertCheck, AlertType } from '../types'+import type { AlertCheck, AlertType, InvestigationVerdict } from '../types'++const VERDICT_CONFIG: Record<InvestigationVerdict, { label: string; className: string; tooltip: string }> = {+ true_positive: {+ label: 'True positive',+ className: 'text-danger',+ tooltip: 'Agent thinks this is a real anomaly worth looking at.',+ },+ false_positive: {+ label: 'False positive',+ className: 'text-muted',+ tooltip: 'Agent thinks this was a data/release artifact, not a real anomaly.',+ },+ inconclusive: {+ label: 'Inconclusive',+ className: 'text-warning',+ tooltip: 'Agent could not reach a confident conclusion from the available data.',+ },+}++function InvestigationCell({ check }: { check: AlertCheck }): JSX.Element {+ const status = check.investigation_status+ const shortId = check.investigation_notebook_short_id+ const summary = check.investigation_summary?.trim() || null+ const verdict = check.investigation_verdict ?? null+ const suppressed = !!check.notification_suppressed_by_agent++ if (status === 'done') {+ const verdictCfg = verdict ? VERDICT_CONFIG[verdict] : null+ return (+ <div className="flex flex-col gap-1 items-start max-w-md">+ {suppressed && (+ <Tooltip title="The investigation agent concluded this fire wasn't worth notifying about, so the notification was suppressed.">+ <LemonTag type="muted" size="small">+ Notification suppressed+ </LemonTag>+ </Tooltip>+ )}+ <Tooltip title={summary || undefined}>+ <div className="text-sm leading-normal line-clamp-2 text-muted">+ {verdictCfg && (+ <Tooltip title={verdictCfg.tooltip}>+ <span className={`font-semibold ${verdictCfg.className}`}>{verdictCfg.label}</span>+ </Tooltip>+ )}+ {verdictCfg && summary && <span> — </span>}+ {summary && <span>{summary}</span>}+ </div>+ </Tooltip>+ {shortId && (+ <Link to={`/notebooks/${shortId}`} className="inline-flex items-center gap-1 text-sm">+ <IconNotebook /> View notebook <IconOpenInNew className="text-xs" />+ </Link>+ )}+ </div>+ )+ }+ if (status === 'running' || status === 'pending') {+ return (+ <span className="inline-flex items-center gap-1 text-secondary">+ <Spinner textColored /> Running+ </span>+ )+ }+ if (status === 'failed') {+ return (+ <Tooltip title="The investigation agent couldn't complete in time. The alert was still delivered. If this keeps happening, you can turn off the investigation agent in this alert's settings.">+ <span className="text-danger">Failed</span>+ </Tooltip>+ )+ }+ if (status === 'skipped') {+ return (+ <Tooltip title="Skipped because another investigation ran for this alert within the last hour.">+ <span className="text-secondary">Skipped</span>+ </Tooltip>+ )+ }+ return <span className="text-secondary">—</span>+}/** Placeholder while alert detail (including check history) is loading; avoids an empty gap before `AlertHistorySection` mounts. */export function AlertHistorySectionSkeleton({ showChartArea = true }: { showChartArea?: boolean }): JSX.Element {@@ -54,6 +144,8 @@ export function AlertHistorySection({ alertId }: { alertId: AlertType['id'] }):} = useValues(logic)const { selectAlertHistoryView, alertHistoryTablePageForward, alertHistoryTablePageBackward } = useActions(logic)+ const investigationAgentEnabled = alertHistoryIsAnomalyDetection && !!alert?.investigation_agent_enabled+const checkHistoryColumns = useMemo((): LemonTableColumn<AlertCheck, keyof AlertCheck | undefined>[] => {const columns: LemonTableColumn<AlertCheck, keyof AlertCheck | undefined>[] = [{@@ -85,6 +177,12 @@ export function AlertHistorySection({ alertId }: { alertId: AlertType['id'] }):},})}+ if (investigationAgentEnabled) {+ columns.push({+ title: 'Investigation',+ render: (_value, check) => <InvestigationCell check={check} />,+ })+ }columns.push({title: 'Targets notified',key: 'targets_notified',@@ -92,7 +190,7 @@ export function AlertHistorySection({ alertId }: { alertId: AlertType['id'] }):render: (_value, check) => (check.targets_notified ? 'Yes' : 'No'),})return columns- }, [alertHistoryIsAnomalyDetection])+ }, [alertHistoryIsAnomalyDetection, investigationAgentEnabled])if (!alert) {return nulldiff --git a/frontend/src/lib/components/Alerts/views/EditAlertModal.tsx b/frontend/src/lib/components/Alerts/views/EditAlertModal.tsxindex 0a0c2e4df925..c3d887eb7f37 100644--- a/frontend/src/lib/components/Alerts/views/EditAlertModal.tsx+++ b/frontend/src/lib/components/Alerts/views/EditAlertModal.tsx@@ -162,6 +162,7 @@ export function EditAlertModal({const anomalyDetectionEnabled = useFeatureFlag('ALERTS_ANOMALY_DETECTION')const inlineNotificationsEnabled = useFeatureFlag('ALERTS_INLINE_NOTIFICATIONS')const quietHoursEnabled = useFeatureFlag('ALERTS_QUIET_HOURS')+ const investigationAgentEnabled = useFeatureFlag('ALERTS_INVESTIGATION_AGENT')const { pendingNotifications } = useValues(alertNotificationLogic({ alertId: alertId }))const hasPendingNotifications = inlineNotificationsEnabled && pendingNotifications.length > 0@@ -228,7 +229,7 @@ export function EditAlertModal({])return (- <LemonModal onClose={handleClose} isOpen={isOpen} width={750} simple title="">+ <LemonModal onClose={handleClose} isOpen={isOpen} width={900} simple title="">{alertLoading && !alert ? (<SpinnerOverlay />) : (@@ -478,6 +479,103 @@ export function EditAlertModal({/>)}+ {alertMode === 'detector' &&+ alertForm.detector_config &&+ investigationAgentEnabled && (+ <div className="deprecated-space-y-2">+ <div className="flex items-center gap-1">+ <h4 className="m-0">Investigation agent</h4>+ <Tooltip+ title="An optional AI agent that investigates anomaly fires against this insight's own data. It runs read-only HogQL queries, looks at the metric chart, and writes its findings — verdict, hypotheses, recommendations — to a notebook linked from the alert history. You can also have it gate notifications so false positives don't page you."+ placement="right"+ delayMs={0}+ >+ <IconInfo />+ </Tooltip>+ </div>+ <div className="flex flex-wrap items-center gap-x-6 gap-y-2">+ <LemonCheckbox+ data-attr="alertForm-investigation-agent-enabled"+ checked={!!alertForm.investigation_agent_enabled}+ onChange={(checked) =>+ setAlertFormValue('investigation_agent_enabled', checked)+ }+ label={+ <span className="flex items-center gap-1">+ Run investigation agent when this alert fires+ <Tooltip+ title="On the transition to firing, an agent validates the anomaly with read-only queries, writes a notebook with its findings, and links it from the alert check history. Runs once per transition."+ placement="right"+ delayMs={0}+ >+ <IconInfo />+ </Tooltip>+ </span>+ }+ />+ <LemonCheckbox+ data-attr="alertForm-investigation-gates-notifications"+ checked={!!alertForm.investigation_gates_notifications}+ onChange={(checked) =>+ setAlertFormValue(+ 'investigation_gates_notifications',+ checked+ )+ }+ disabledReason={+ !alertForm.investigation_agent_enabled+ ? 'Enable the investigation agent first'+ : undefined+ }+ label={+ <span className="flex items-center gap-1">+ Wait for the verdict before notifying+ <Tooltip+ title="Notifications are delayed ~30–90s while the agent investigates. False-positive verdicts are suppressed. A safety-net task force-fires after a few minutes if the investigation stalls, so real fires can't be silently missed."+ placement="right"+ delayMs={0}+ >+ <IconInfo />+ </Tooltip>+ </span>+ }+ />+ </div>+ {alertForm.investigation_agent_enabled &&+ alertForm.investigation_gates_notifications && (+ <div className="flex flex-wrap items-center gap-2 text-sm text-secondary">+ <span>On inconclusive verdict</span>+ <LemonSegmentedButton+ size="xsmall"+ value={+ alertForm.investigation_inconclusive_action ??+ 'notify'+ }+ onChange={(value) =>+ setAlertFormValue(+ 'investigation_inconclusive_action',+ value+ )+ }+ options={[+ {+ value: 'notify',+ label: 'Notify',+ tooltip:+ 'Safe default — an unsure agent is itself signal.',+ },+ {+ value: 'suppress',+ label: 'Suppress',+ tooltip: 'Only notify on true positives.',+ },+ ]}+ />+ </div>+ )}+ </div>+ )}+{alertMode === 'detector' && alertForm.detector_config && (<div className="deprecated-space-y-2"><div className="flex gap-2 items-center">