All skills
google avatar

/agent-platform-alert-configuration

@efcb6f0
by googlegoogle/skills21k stars
1,698

Configures best-practice alerting policies for AI agents using OpenTelemetry (OTel) metrics, generating output as Terraform (.tf) configuration files. Use when analyzing, writing, or deploying alerting policies to monitor agent latency, error rates, token usage, and quality metrics. Don't use for standard infrastructure monitoring unrelated to AI agents, or when the agent is not instrumented with OpenTelemetry (for Reliability, Cost, Safety, Security alerts). NOTE: Reliability, Cost, Safety, and Security alerts use generic OTel metrics and work across runtimes (such as Cloud Run, Vertex AI). Quality alerts rely on Vertex AI Online Monitors and are strictly bound to Vertex AI deployments.

Use this Skill: https://skilld.dev/gh/google/skills/agent-platform-alert-configuration

This session only. Nothing lands on disk.

referencescost_alert_policies.md

≈2.3k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Cost Alert Policies

These alert policies will help alert users when their agents are using an unusually high rate of tokens based on their historical metrics.

Table of Contents

Preconditions

Token Usage Workload Pattern

It is required to resolve the workload token usage pattern (Seasonal / Cyclical, Steady / Consistent, or Bursty / Inconsistent), to configure policies monitoring token usage. If you have not done it already, you MUST run the check_telemetry tool with the flag --query-monitoring-metadata enabled to retrieve all namespaces available for the token usage metric and match the closest one to the target agent:

python3 scripts/check_telemetry.py \
  --project_id={gcp_project} \
  --location={location} \
  --agent-resource-name "projects/{project_id}/locations/{location}/reasoningEngines/{agent_id}" \
  --query-monitoring-metadata \
  • If the user provides a namespace to use in their prompt, you DO NOT need to run this tool to retrieve existing namespaces.
  • If the tool does not return a relevant namespace entry, there isn't historical metric data available for this agent.

Follow the instructions corresponding to the availability of historical metrics data:

  • Case 1: No historical metrics data available (for example, brand new agent) or no monitoring namespaces found: You MUST read and follow: no_historical_traffic_data.md
  • Case 2: Historical metrics data available (for example, active agent with traffic): You MUST read and follow: has_historical_traffic_data.md

Critical Rules

  • Brand New Agents (No Token Usage History): When setting up alerts for a brand new agent, you MUST explicitly ask the user what token usage pattern they expect (Steady / Consistent, Seasonal / Cyclical, or Bursty / Inconsistent) in your response. If immediate setup is requested, ask the question but proceed using the default Steady/Consistent (Short-Window Z-Score) pattern. Follow no_historical_traffic_data.md.
  • Alert policy configuration: You MUST configure exactly the following Cost alerting policies. See the Telemetry Metrics to get the required metrics and read the descriptions for each signal:
    1. Rapid Token Burn Rate (15-Minute window)
  • PromQL format: All Cost alert policies must be configured using a PromQL query. Do NOT use any other language like MQL. See the PromQL Queries below to learn which queries to use for each signal.
    • Disclaimer: You will need to group by a different field depending on what the underlying resource is; for example, generic_node uses namespace. The examples below assume generic_node.

Telemetry Metrics

Signal Raw Metric Type Description
**Rapid Token gen_ai.client.token.usage Counter Amount of tokens
: Burn Rate** : : : used by the agent. :

Policy Specifications

Rapid Token Burn Rate

Telemetry Queries
Z-Score (Recommended for Steady Traffic)

Long-Window Z-Score (For Established Agents - >1 week history)

Compares the 5-minute 95th percentile token usage to the 1-week baseline.

  • RAPID_TOKEN_BURN_RATE_ALGORITHM_NAME_SHORT: "long_window_zscore"
  • RAPID_TOKEN_BURN_RATE_ALGORITHM_NAME_LONG: "Long-Window Z-Score"
  • RAPID_TOKEN_BURN_RATE_ALGORITHM_CONDITION_DESCRIPTION: "Rapid Token Burn Rate Long-Window Z-Score > 3"
abs(
  histogram_quantile(0.95,sum by ("namespace","le")(increase({"__name__"="workload_googleapis_com:gen_ai_client_token_usage_bucket","monitored_resource"="generic_node"}[5m])))
  -
  histogram_quantile(0.95,sum by ("namespace","le")(increase({"__name__"="workload_googleapis_com:gen_ai_client_token_usage_bucket","monitored_resource"="generic_node"}[1w])))
)
/
stddev_over_time(
  (histogram_quantile(0.95,sum by ("namespace","le")(increase({"__name__"="workload_googleapis_com:gen_ai_client_token_usage_bucket","monitored_resource"="generic_node"}[5m]))))[1w:5m]
) > 3

Short-Window Z-Score (For Newer Agents with >1 hour history)

Compares the 1-minute 95th percentile token usage to the 1-hour baseline. Useful for quick activation on new agents.

  • RAPID_TOKEN_BURN_RATE_ALGORITHM_NAME_SHORT: "short_window_zscore"
  • RAPID_TOKEN_BURN_RATE_ALGORITHM_NAME_LONG: "Short-Window Z-Score"
  • RAPID_TOKEN_BURN_RATE_ALGORITHM_CONDITION_DESCRIPTION: "Rapid Token Burn Rate Short-Window Z-Score > 3"
abs(
  histogram_quantile(0.95,sum by ("namespace","le")(increase({"__name__"="workload_googleapis_com:gen_ai_client_token_usage_bucket","monitored_resource"="generic_node"}[1m])))
  -
  histogram_quantile(0.95,sum by ("namespace","le")(increase({"__name__"="workload_googleapis_com:gen_ai_client_token_usage_bucket","monitored_resource"="generic_node"}[1h])))
)
/
stddev_over_time(
  (histogram_quantile(0.95,sum by ("namespace","le")(increase({"__name__"="workload_googleapis_com:gen_ai_client_token_usage_bucket","monitored_resource"="generic_node"}[1m]))))[1h:1m]
) > 3
Moving Averages (Recommended for Bursty Traffic)

Compares the 5-minute token usage to the 1-hour average.

  • RAPID_TOKEN_BURN_RATE_ALGORITHM_NAME_SHORT: "moving_average"
  • RAPID_TOKEN_BURN_RATE_ALGORITHM_NAME_LONG: "Moving Average"
  • RAPID_TOKEN_BURN_RATE_ALGORITHM_CONDITION_DESCRIPTION: "Rapid Token Burn Rate 5m window > 1h avg"
histogram_quantile(0.95,sum by ("namespace","le")(increase({"__name__"="workload_googleapis_com:gen_ai_client_token_usage_bucket","monitored_resource"="generic_node"}[5m])))
>
1.5 * histogram_quantile(0.95,sum by ("namespace","le")(increase({"__name__"="workload_googleapis_com:gen_ai_client_token_usage_bucket","monitored_resource"="generic_node"}[1h])))
Seasonal Decomposition (Recommended for traffic with seasonal or time-of-day component)

[!NOTE] ONLY use seasonal decomposition to track Token usage spikes. Alert policies using seasonal decomposition to track both spikes and drops can falsely trigger alerts.

[!CRITICAL] The numerator (current token usage) MUST NOT have any offset. Offsets (offset 1d, offset 1w) MUST only be applied to the denominator to construct the historical baseline for comparison. Never apply an offset to the first numerator.

Compares the 5-minute token usage to the average of 1-week and 1-day lookback baselines.

  • RAPID_TOKEN_BURN_RATE_ALGORITHM_NAME_SHORT: "seasonal_decomposition"
  • RAPID_TOKEN_BURN_RATE_ALGORITHM_NAME_LONG: "Seasonal Decomposition"
  • RAPID_TOKEN_BURN_RATE_ALGORITHM_CONDITION_DESCRIPTION: "Seasonal Decomposition > 2"
histogram_quantile(0.95,sum by ("namespace","le")(increase({"__name__"="workload_googleapis_com:gen_ai_client_token_usage_bucket","monitored_resource"="generic_node"}[5m])))
/
(
  (
    histogram_quantile(0.95,sum by ("namespace","le")(increase({"__name__"="workload_googleapis_com:gen_ai_client_token_usage_bucket","monitored_resource"="generic_node"}[5m] offset 1d)))
    +
    histogram_quantile(0.95,sum by ("namespace","le")(increase({"__name__"="workload_googleapis_com:gen_ai_client_token_usage_bucket","monitored_resource"="generic_node"}[5m] offset 1w)))
  ) / 2
)
> 2
Terraform HCL
resource "google_monitoring_alert_policy" "rapid_token_burn_rate_{rapid_token_burn_rate_algorithm_name_short}" {
  project      = var.project_id
  display_name = "Agent Cost - Rapid Token Burn Rate {rapid_token_burn_rate_algorithm_name_long}"
  combiner     = "OR"

  conditions {
    display_name = "{rapid_token_burn_rate_algorithm_condition_description}"
    condition_prometheus_query_language {
      # Using __name__ for metric with special characters.
      query    = {rapid_token_burn_rate_telemetry_query}
      duration = "300s" # 5m buffer
    }
  }

  user_labels = {
    created-with-google-skill = "agent-platform-alert-configuration"
  }
}

Where:

  • {rapid_token_burn_rate_algorithm_name_short}: The short name version of the algorithm chosen in the Telemetry query section above.
  • {rapid_token_burn_rate_algorithm_name_long}: The long name version of the algorithm chosen in the Telemetry query section above.
  • {rapid_token_burn_rate_algorithm_condition_description}: A description for the alert condition chosen in the Telemetry query section above.
  • {rapid_token_burn_rate_telemetry_query}: The PromQL alert query chosen and configured in the previous Telemetry query section above.

Gotchas

  • Script Failures: If check_telemetry.py fails unexpectedly, verify parameters (project ID, location, agent resource name). Ensure you have permissions to view metrics and reasoning engines.

Source: SKILL.md on GitHub

No alerts8d3 checks · Risk SAFE
  • Gen Agent Trust Hub8d

    This skill is a well-structured tool for configuring Google Cloud alerting policies for AI agents. It utilizes standard Google Cloud SDKs and CLI tools to discover environment metadata and generate Terraform configurations. The skill incorporates explicit safety tiers, requiring user confirmation for any actions that incur billing or create cloud resources.

  • Socket8d

    No alerts

  • Snyk8d

    Risk: LOW · No issues

Signed by skilld at efcb6f0. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last week
metadata
{
  "version": "1.0.0",
  "category": "AiAndMachineLearning"
}
All 1 allowed tools
terraform gcloud python

README badge

README badge for google/skills/agent-platform-alert-configuration