Repository navigation
feat: AI alerts checked by the analyst agent - #10231
nishantmonu51 wants to merge 9 commits into
Conversation
…YAML Alerts and reports created through the API with a resolver serialized its properties as the protobuf Struct's internals (fields/kind/stringvalue), so the runtime parsed different properties than it was given.
An alert with the ai resolver has its prompt judged as a condition by the analyst agent, which ends with a structured verdict. A met condition returns one row with the verdict's reason and the conversation, so the alert fires; a malformed verdict or an exhausted tool budget is an evaluation error. The check runs with the alert's own claims, and notifications show the reason and link to the conversation.
The data tab switches between criteria and an AI condition written as a sentence. AI alerts load into and save from the dialog however they were created, and the alert page and history show the condition and the reason an AI alert triggered.
Conflicts with main: - Notifications read rows with `notify.rows_limit` (#10140). An AI alert shows the analysis's reason instead of rows. - Alerts run with `alertQueryClaims` (#10148). An AI alert's session is owned by its "for" user, which the parser now requires. - The alert dialog was rewritten on main. The merge takes main's dialog; the AI condition is redone on top of it. Review changes: - The parser limits AI alerts to a cron schedule of at most once an hour, without `ref_update`, a ticker or `intervals`. - The verdict is a separate, tool-less structured call after the normal analyst loop, so it works with providers that reject tools combined with an output schema, and the analysis keeps the number check from #10131. `FailOnIterationLimit` is gone. - The verdict can be "cannot_determine", which fails the check with an error instead of reporting "not met". - The reason shown in notifications is the analysis's summary, so its numbers are the checked ones. - Drop the unreachable `SkipChecks` guard and the redundant chart exclusion. - Share the inherited watermark code between the alert and report reconcilers.
convertV1ExpressionToMapstructure passed a measure filter's subquery through in its proto shape, which Go's metricsview.Subquery can't decode. It now names the dimension and measures as objects and converts the subquery's where and having, the inverse of mapResolverExpressionToV1Expression, which also replaces the duplicate convertMapstructureToV1Expression.
- The data tab switches between criteria and an AI condition (not offered for alerts created from an embed). In AI mode the measure is optional, the split has no rows limit and the time filters offer no comparison. - The criteria tab takes the condition, which names the alert by default. - AI alerts save the `ai` resolver's properties (AIResolverProps plus the prompt) from what the dialog shows: the measure, dimension, filters, time range and zone. Nothing the dialog doesn't edit is kept. - AI alerts are always checked on a schedule (daily or rarer), never when data refreshes, and attach no rows. - Editing an AI alert reads its resolver properties back into the form and the filters, and waits for the explore's metrics view, which the properties don't name. - The alert page links AI alerts to their explore through the "ai" url source and shows the condition; the open route sends AI alerts to the conversation behind the check.
nishantmonu51
left a comment
There was a problem hiding this comment.
A few things inline on editing and delivering these alerts.
| (isEmbedded && $embedOpenUrlQuery.isPending) || | ||
| !exploreState | ||
| !exploreState || | ||
| !metricsViewName |
There was a problem hiding this comment.
This also blocks existing criteria alerts that have no web_open_path and whose metrics view name differs from their Explore name. getAlertDashboardName falls back to the metrics view, useExploreValidSpec finds no Explore by that name, and Edit opens with no form. Could we keep the saved-query path for criteria alerts and require the Explore lookup only for AI alerts that need it?
There was a problem hiding this comment.
Leaving as is: on main the dialog for such an alert opens without its filters, and saving it drops the saved where and time range and writes a web_open_path to a missing explore (I checked this in the dialog spec), so waiting for the explore is the safer outcome. Dialog and chat-created alerts always record their explore, and looking it up by metrics view can be a follow-up; 51d3949 adds a comment saying why.
| // Its condition says what to compare with, so the time filters don't offer a comparison. | ||
| $: isAIAlert = $form["conditionType"] === AIConditionType; | ||
| const aiTimeFiltersConfig: TimeFiltersConfig = { | ||
| showTimeDimensionSelector: true, |
There was a problem hiding this comment.
On an Explore with multiple time dimensions, selecting a secondary date here saves time_range.time_dimension, but ResolveInteractive gives AnalystAgentArgs only the start and end. The analyst has no record of which date field the user chose, so it can check the same window on the primary date instead. Could we pass the selected time dimension through to the analyst's query context, or hide this picker for AI alerts until that works?
There was a problem hiding this comment.
Fixed in 51d3949: AI alerts hide the time dimension picker and no longer save time_range.time_dimension, since the analyst only gets the start and end; passing it through to the analyst can be a follow-up.
| prompt: values.aiCondition.trim(), | ||
| explore: values.exploreName, | ||
| }; | ||
| if (values.measure) props.measures = [values.measure]; |
There was a problem hiding this comment.
An alert created from an Explore's formula measure can still select that measure in AlertDialogDataTab, and getNewAlertInitialFormValues can select it by default. The AI resolver only gets its name, so the analyst can't resolve the formula from the metrics view. Could we exclude formula measures in AI mode and clear an inherited formula selection when switching to it?
There was a problem hiding this comment.
Fixed in 51d3949: in AI mode the measure picker leaves out ephemeral measures, and switching to an AI condition clears an inherited one (new case in AlertDialogDataTab.spec.ts).
| // The runtime adds the session ID to the open link, which keeps opening the conversation if the alert was switched to criteria since. | ||
| // In creator mode the link also carries a magic token, which grants read access to the shared conversation and must be forwarded. | ||
| const sessionId = url.searchParams.get("session_id"); | ||
| if (sessionId || isAIAlertSpec(alertSpec)) { |
There was a problem hiding this comment.
This handles old AI notifications after switching to Criteria, but switching the other way sends old Criteria notifications with an execution_time and no session_id to the AI home. Could we use session_id as the redirect signal and keep a dashboard or alert-details fallback for links without a conversation?
There was a problem hiding this comment.
Fixed in 51d3949: only a session_id redirects to the conversation; links without one go through AlertOpen, which opens the dashboard, or the alert page when the alert has no query.
| return errors.New(`AI alerts can't set "intervals", since every interval is a separate AI analysis`) | ||
| } | ||
| if queryForUserID == "" { | ||
| return errors.New(`AI alerts must set "for.user_id", the user whose access and AI session the analysis runs with`) |
There was a problem hiding this comment.
Could we add an example to docs/docs/reference/project-files/alerts.md? An author adding data.ai to an existing YAML alert also has to set for.user_id, switch to an hourly-or-slower refresh.cron, and remove intervals. The current reference gives them no AI alert example to start from.
There was a problem hiding this comment.
Fixed in 51d3949: added an AI alert example with for.user_id, an hourly-or-slower cron and no intervals, corrected "Only available for reports", and extended the schema examples test to parse the alert examples.
| link, err := addExecutionTime(openURL, executionTime) | ||
| if err != nil || aiSessionID == "" { | ||
| return link, err | ||
| } | ||
| return buildAISessionURL(link, aiSessionID) |
There was a problem hiding this comment.
Could alertOpenLink set execution_time and the optional session_id in one pass through url.Parse and url.ParseQuery? addExecutionTime only has this caller, and buildAISessionURL reparses the same URL. The report caller can keep using buildAISessionURL.
There was a problem hiding this comment.
Fixed in 51d3949: alertOpenLink now sets both parameters in one pass, addExecutionTime is gone, and TestAlertOpenLink covers both cases.
… review - AI alerts no longer offer or save a secondary time dimension, which the analyst never gets. - AI alerts no longer offer ephemeral measures, and switching to an AI condition clears one. - Only a `session_id` sends an alert's open link to the AI conversation; other links open the dashboard or the alert's page. - `alertOpenLink` sets `execution_time` and `session_id` in one pass. - The alert reference gets an AI alert example, and the AI resolver is documented as available for alerts.
|
Thanks for taking this over. The separate tool-less verdict call, the Errors on AI alerts are invisible. Managed alerts do not notify on error by default, so an alert whose condition ends in Reason fallback. When the model omits the Browser check. The description says the dialog has not been checked in a browser yet. Please do that before merging, since the frontend was redone on the rewritten dialog. Schedules. The dialog offering only daily, weekday, weekly and monthly schedules for AI conditions is fine. The parser's hourly limit then only matters for alerts written in project files. Smaller points.
Developed in collaboration with Claude Code |
…y after review - Managed AI alerts set on_error, since a check fails when the analysis can't determine whether the condition holds. - Without a <summary> tag, the reason is the start of the analysis, cut to 500 characters like an AI report's summary. - The dialog spec drops the test of an alert created through the API, and the data tab spec checks that the AI condition can be hidden. - The delivery tab says the parser allows at most one check an hour.
|
@pjain1 Thanks, handled in 93771e7:
|
nishantmonu51
left a comment
There was a problem hiding this comment.
One thing on Slack error delivery.
| } | ||
| // Notification options | ||
| // An AI alert's check fails when the analysis can't determine whether its condition holds, so its owner hears about errors. | ||
| res.OnError = opts.Resolver == "ai" |
There was a problem hiding this comment.
With on_error enabled, a cannot_determine reason goes through SendAlertStatus as ExecutionError. That branch puts the analyst’s text straight into Slack markup, so angle-bracketed text can turn into a link or mention. Could we use slackTextEscaper.Replace(s.ExecutionError) for ErrorMessage, like the alert-triggered branch does for Reason? Slack’s escaping rules
There was a problem hiding this comment.
Fixed in 14c91f5: the error branch now escapes ExecutionError with slackTextEscaper, for every alert, and the Slack notifier test covers it.
With on_error set for AI alerts, a cannot_determine error carries the analysis's text, so it's escaped like an AI alert's reason.
Takes over #10120 from its contributor and addresses its review. It's the first of a stack: #10229 (base) → this → #10232 (admin API) → #10233 (chat alerts) → #10234 (chat reports).
An alert's condition can be written in words (
data: ai: {prompt, explore, ...}). Every check runs the analyst on it, then a tool-less structured call classifies the analysis asmet,not_metorcannot_determine.<summary>. The separate verdict call works with providers that reject tools combined with an output schema.FailOnIterationLimitis gone.metfires the alert with the summary as the reason.cannot_determine, for example a condition on a measure that doesn't exist, fails the check with an error instead of reporting "not met".refresh.cronat most once an hour, rejectsref_update, tickers andintervals, and requiresfor.user_id(the session's owner). The dialog offers only a schedule for AI conditions.notify.rows_limitfrom feat: list matching rows in alert notifications withnotify.rows_limit#10140) and link to the analysis. The open page redirects to the conversation.alertQueryClaims(feat: support alerts for embedded users #10148), plus the owner as session user and the permissions AI reports get.getMappedUrllike AI reports.SkipChecksguard and the chart exclusion.mapResolverExpressionToV1ExpressionandAIResolverProps.aiproperties.TestAnalystAlertEval(expensive) adds a cannot-determine case.Known gaps:
0 NaN * * *(reports have the same problem). So editing an hourly AI alert created from the chat breaks.Checklist: