agent-platform-alert-configuration
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.
摘要
- 用途
- 它以可靠性、成本、安全、資安及 Vertex AI 評估品質為核心,規劃代理的告警。
- 使用時機
- 當可靠性、成本、安全或資安告警需涵蓋多種代理執行環境,或需要為使用 Online Monitors 的 Vertex AI 部署設定品質告警時可使用;前者仰賴 OTel 指標。
- 輸出結果
- 它會產生 Terraform(.tf)告警政策設定,涵蓋可靠性、成本、安全、資安與 Vertex AI 品質,並預設以動態方式彙整代理。
上游變更(16 筆,最新收錄 2026-09-23)
efcb6f0 Add semantic versions to the hand-authored agent-platform-* skills. 在技能的前置資訊中新增 `metadata.version: "1.0.0"`。 7072dc4 Eliminate Latin abbreviations (e.g., i.e., etc.) from agent-platform-alert-configuration skill. 將技能各處的拉丁文舉例縮寫 `e.g.` 改為 `such as`、`for example` 等完整說法。 5027f39 Change weak language to a stronger set of verbs for agent-platform-alert-configuration for consistency. 重新措辭探索、指標範圍、重複政策及背景工作的指示,強調驗證並採用更強制的行動要求。 62a8a85 Apply GCP language corrections to agent-platform-alert-configuration skill. 將遙測帳務警告中的匯出措辭改為 Cloud Trace/Cloud Logging,並將 SQL 告警描述中的 Log Analytics 改為 Observability Analytics。 9d9a10f Update documentation links to use docs.cloud.google.com domain. 將 Alerting Policies 與 PromQL 支援連結的網域改為 `docs.cloud.google.com`。 a39f283 - Updated `SKILL.md` front matter description and added good/bad examples for dynamic grouping. - Clarified pinning rules in `reliability_alert_policies.md` to avoid conflicts. 擴充技能描述,加入 Terraform 輸出與適用範圍資訊,並新增對照動態分組與硬編碼篩選的 PromQL、SQL 正反例。 8229c1e Update SKILL.md to clarify gather_agent_info usage and fallbacks so that the agent will not call Gcloud for Metric Scopes if it already has enough information. 明確說明,只有精簡探索未能判定指標範圍時才執行備援檢查;探索成功則直接進入既有政策檢查。 3ea747f Split validate_config.py into single-responsibility scripts: lint_syntax.py and scan_duplicates.py. 將重複項檢查與語法檢查指引改為使用 `scan_duplicates.py` 和 `lint_syntax.py`,取代 `validate_config.py` 的對應模式。 12f4821 Renamed flags in `validate_config.py` to be more semantic (`--scan-duplicates` instead of `--directory`, `--lint-syntax` instead of `--file`) to reduce agent confusion, and updated `SKILL.md` expectations. 將精簡探索列為必做,並將文件中的 `validate_config.py` 參數與命令改名為 `--scan-duplicates` 和 `--lint-syntax`。 984673e - Added gather_agent_info.py script with Fast lookup via Cloud Asset Inventory (CAIS) as the primary track. - Added --regions flag to allow custom region scanning. - Capped printed lists (Linked Datasets, Channels, Scopes, Evaluators) to 5 items to prevent context window overflow. - Updated SKILL.md to guide agents on using the script and handling potential failures. 更新技能,將 `gather_agent_info.py` 列為唯讀工具、新增其探索流程與用法,並擴充工具腳本失敗時的處理指引。 26f2b89 Minor fixes for the agent-platform-alert-configuration skill: - Update the SKILL.md instruction example to use single quotes ('${var.gen_ai_agent_name}') so that bash passes the string literal directly without attempting variable expansion. - In analyze_traffic.py, update argparse so that using `--metric-type` is required. 將重複檢查範例中的 `${var.gen_ai_agent_name}` 參數改為以單引號括住。 f20e4b6 Update skill for agent-platform-alert-configuration 將技能從專屬 Agent Runtime 的告警指引改寫為較廣泛的 OTel 告警指引,新增安全、探索、告警類型、僅限 Terraform、動態分組與驗證規則,並移除詳細的演算法及佈建章節。 439d729 Correct allowed-tools field for agent-platform-alert-configuration 將前置資訊中的 `allowed-tools` 從 YAML 清單改為行內值 `terraform gcloud python`。 c75b500 Restructure the YAML frontmatter in all SKILL.md files to nest the 'category' field under the 'metadata:' block. The 'category' field is used to organize the skills in the README.md 在前置資訊中新增 `metadata` 區塊,並將 `category: AiAndMachineLearning` 移入其中。 40e40d7 Introduce the agent-platform-alert-configuration skill 建立此技能,提供 Vertex AI/Agent Platform 告警、安全層級、政策選擇、動態分組與範圍、遙測與品質監控及 Terraform 驗證指引。 npx skills add "lettucebo/Skills#v2.2.0@agent-platform-alert-configuration" --full-depth ⚠ v2.2.0 發布後即可使用
Agent Platform Alert Configuration
Critical Steps
1. Safety & Confirmation Tiers (CRITICAL)
Before executing any commands or writing configurations on behalf of the user, you MUST adhere to the following safety tiers based on the action requested:
- Tier R: Read-only (
check_telemetry.py/gather_agent_info.py)- Rule: No confirmation needed. You may execute these scripts immediately to inspect telemetry status or gather agent configuration details.
- Tier B: Billing & Resource Creation (
create_online_monitor.py/ provisioning)- Rule: Explicit User Confirmation Required. These actions incur additional billing charges and create cloud resources. The agent MUST ALWAYS warn the user explicitly about the potential extra billing costs of BOTH the Online Monitor (specifically mentioning LLM evaluations) and Telemetry (specifically mentioning Cloud Trace/Cloud Logging export). You MUST STOP and ask for explicit approval before proceeding with provisioning or providing setup commands.
2. Prerequisites & Dependencies
Agent Telemetry
- Disclaimer: For Reliability, Cost, Safety, and Security alerts to function, the underlying agent MUST be instrumented to emit OpenTelemetry (OTel) metrics. If the agent does not emit these metrics, the alerting policies will have no data stream to evaluate.
Python Environment
Before executing any python script in this skill you MUST install the required dependencies in your environment. Run this command first:
pip install -r scripts/requirements.txt
3. Input Assumptions
- Explicit Project Adherence: You must ONLY configure alerts, query telemetry, or interact with the Google Cloud Project(s) explicitly provided by the user in the prompt. Do NOT assume or use other projects from your environment or history unless the user explicitly directs you to do so.
- Sequential File Transformations: If the user explicitly asks to copy a file and then modify it, you MUST perform these actions sequentially (copy first, then modify) rather than writing the final content directly.
4. Execution Steps
Mandatory Prerequisite Execution Protocol (SEQUENTIAL): Before generating or writing ANY configuration, you MUST execute these steps in order:
- Step 1: Streamlined Discovery (Mandatory): Run
gather_agent_info.pyto automatically identify agent runtime, verify telemetry, metric scopes, linked datasets, and more. This script covers most of the manual verifications listed in subsequent steps.- Command:
python3 scripts/gather_agent_info.py --project-id {project_id} --agent-name {agent_name} - Note: If this script fails, returns partial data, or doesn't produce everything you need, you MUST satisfy requirements by running the manual fallback steps listed in Step 2 and then perform Step 3 below. If Step 1 succeeds and provides all info, SKIP to Step 3 (Pre-existing Policies Verification).
- Command:
- Step 2: Metric Scope Verification (Fallback): Run this ONLY if Step
1 failed to determine the metric scope.
- Action A (CLI): Run
gcloud beta monitoring metrics-scopes list projects/{project_id}. If a scoping project is returned, you MUST deploy policies there. - Action B (Code Scan): Search Terraform configurations for
google_monitoring_monitored_projectresources to extract the scoping project. - Action C (Fallback): If ambiguous, ASK the user: "Are you using a multi-project Cloud Monitoring Metric Scope? If so, what is the scoping project ID?"
- Action A (CLI): Run
- Step 3: Pre-existing Policies Verification: Avoid duplicates.
- Action: Scan the target directory to see if aggregated policies
already exist targeting the same metrics (grouped by
reasoning_engine_idorgen_ai_agent_name). Usescan_duplicates.pyto verify.
- Action: Scan the target directory to see if aggregated policies
already exist targeting the same metrics (grouped by
- Step 1: Streamlined Discovery (Mandatory): Run
Alert Policy Type Resource Files: You MUST list and read files under
references/with names ending in_alert_policies.mdto learn how to configure alert policies based on type. By default you MUST configure all of the following alert types UNLESS the user requests to generate explicit alert policies and/or types. Follow their tables of content to help you find the reference sections you need to read:Alert Type Reference File Reliability reliability_alert_policies.md Quality quality_alert_policies.md Cost cost_alert_policies.md Safety safety_alert_policies.md Security security_alert_policies.md
5. Outputs & Formats
Always configure the supported alerting policies for the target agent:
- For Reliability Monitoring: You MUST configure exactly five alerting
policies:
- Latency (anomaly monitoring)
- Error Rate - Fast Burn SLO (1-Hour Window)
- Error Rate - Slow Burn SLO (3-Day Window)
- Model Call Error Rate (SQL-based Observability Analytics Alerting)
- Tool Call Error Rate (SQL-based Observability Analytics Alerting)
- For Quality Monitoring: You MUST configure exactly three alerting
policies (Requires Vertex AI Online Monitors):
- Final Response Quality
- Tool Use Quality
- Hallucination
- For Cost Monitoring: You MUST configure exactly one cost alerting
policy:
- Rapid Token Burn Rate (anomaly monitoring)
- For Safety Monitoring: You MUST configure exactly one safety
alerting policy:
- High Model Armor Safety Policy Trigger Rate (SQL-based Observability Analytics Alerting)
- For Security Monitoring: You MUST configure exactly one security
alerting policy:
- High IAM Permission Denied Trigger Rate (SQL-based Observability Analytics Alerting)
- For Reliability Monitoring: You MUST configure exactly five alerting
policies:
Terraform Only: Write the generated observability configuration ONLY as Terraform (
.tf) files (such asalerts.tf,variables.tf).- You ONLY need to install Terraform if you're asked to deploy the
alerts AND there is no valid Terraform install. SQL-based alerting using
condition_sqlrequires the provider version >= 6.0.0 (or late 5.x versions supporting the feature). - If you are NOT asked to deploy the alerts you do not need to install terraform.
- You ONLY need to install Terraform if you're asked to deploy the
alerts AND there is no valid Terraform install. SQL-based alerting using
Dynamic Multi-Resource Alerting (No Single-Resource Pinning): You MUST NOT hardcode specific agent IDs or resource name filters (for example,
{gen_ai_agent_name="{agent_name}"}ormetric.labels.agent_resource_name="{agent_name}") in alerting conditions unless explicitly requested (for example, "ONLY for this agent"). Merely mentioning a specific agent name or ID in the request does NOT constitute an explicit request to pin/filter; you MUST still default to dynamic grouping to cover all agents. To cover all active agents in the project dynamically:Good Example (PromQL Grouping):
sum(rate(workload_googleapis_com:gen_ai_invoke_agent_duration_count{monitored_resource="generic_node"}[5m])) by (gen_ai_agent_name)Bad Example (PromQL Hardcoded Filter):
sum(rate(workload_googleapis_com:gen_ai_invoke_agent_duration_count{monitored_resource="generic_node", gen_ai_agent_name="support-bot"}[5m]))- For Reliability Metrics using PromQL: ALWAYS use grouping
aggregations. Group by
gen_ai_agent_name(for example,by (gen_ai_agent_name)). Avoid filtering to a single ID/Name unless requested. - For Quality Metrics using Standard Threshold Filters: Omit the
agent_resource_namefilter entirely. Configure the condition filter to only target the monitored resource type (aiplatform.googleapis.com/OnlineEvaluator) and metric type (aiplatform.googleapis.com/online_evaluator/scores) globally for the project.
Good Example (SQL Grouping):
SELECT JSON_VALUE(resource.attributes, '$."cloud.resource_id"') as agent_id, ... FROM ... GROUP BY agent_idBad Example (SQL Hardcoded Filter):
SELECT ... FROM ... WHERE JSON_VALUE(resource.attributes, '$."cloud.resource_id"') = 'support-bot'- For Downstream Calls using SQL: Omit the
ENDS_WITHfilter targeting a specific agent name. Instead, extract the agent identifier (for example,JSON_VALUE(resource.attributes, '$."cloud.resource_id"')) and add it to theGROUP BYclause alongside the model or tool name.
- For Reliability Metrics using PromQL: ALWAYS use grouping
aggregations. Group by
Directory Inference: Prefer the path explicitly provided by the user (if any). Otherwise, deploy configuration files to target Terraform or SRE folders (such as
monitoring/,ops/,sre/). Use tools to locate where alert policies or state pointers exist in the project, rather than blindly writing to the root.Notification Channels: By default, never configure any notification channels without user input. If the user explicitly provides a notification channel in their prompt, configure the alerts to use it. If no notification channel is provided, you MUST explicitly ask the user in your final response if they would like to configure notification channels. This is a mandatory question and you MUST NOT omit it from your response. IMPORTANT Do NOT make assumptions about notification channels. If you search the codebase for a notification channel you must ALWAYS confirm with the user before using it.
Plain English Response: You MUST include a plain English explanation for what the alerts do in your response. This must explain in plain English what the alert measures, how the algorithm works, and what a trigger indicates.
6. Output Verification
- Background Task Cleanup: You MUST verify the status of all background
tasks that you spawn. Before completing your execution and returning your
final response, you MUST terminate or kill any active or hanging background
tasks (using the
manage_tasktool with actionkill). - Validate Configuration: Run the Config Linting tool to make sure all
the output files are written with the correct grammar and structure. See
details about the tool in the
Tooling Scriptssection below.
Tooling Scripts
Use the following scripts to discover agents, gather configuration details, resolve duplicates, and validate configs:
- Agent Information Gathering: Streamlines discovery, environment auditing
(Metric Scopes, BQ Datasets, Notification Channels), table derivations (Log
& Trace), and Online Evaluator verifications.
- Command:
python3 scripts/gather_agent_info.py --project-id {project_id} --agent-name {agent_name}
- Command:
- Duplicate Verification & Merge: Verifies pre-existing alerts in the
target folder to ensure changes are merged in-place rather than appended:
- Command:
python3 scripts/scan_duplicates.py {target_tf_dir} --engine-var '${var.gen_ai_agent_name}'
- Command:
- Config Linting: Validates PromQL grammar, matching engine labels, and
HCL structure:
- Command:
python3 scripts/lint_syntax.py {path_to_tf_file} - Self-Correction Loop: If validation fails (exits non-zero or outputs
errors), you MUST read the command output, locate the line/file
containing the lint error, analyze the PromQL syntax or Terraform HCL
issue, apply adjustments in-place, and re-run the
lint_syntax.pyvalidation. Repeat this loop until the validation script passes successfully.
- Command:
Gotchas & Behavioral Corrections
- Raw Error Boundaries: Explain that raw error counts or absolute failed request count boundaries do not scale under changing traffic throughput. Recommend ratio-based error rate alerts instead.
- Safe Threshold Modulation E2E Validation: When verifying a dynamic metric threshold policy end-to-end, do NOT attempt to force real platform errors. Instead, deploy the alert policy with standard safe bounds (Z-score multiplier > 15), then temporarily update standard deviation Z-score limits to a negative value (for example, > -3) to trigger/verify the "Firing" state before reverting. Always get confirmation before taking this action proactively.
- Expected Script Failures:
scan_duplicates.pyexiting with code 1: Parse the JSON output for duplicate resource targets. Perform in-place upgrade edits, then re-check until it passes with 0.- Avoid Redundant Discovery Calls: If
gather_agent_info.pysuccessfully returns the Trace or Log table names (or writes them to variables file), do NOT redundantly calllist_trace_scope_table_names.pyorlist_log_scope_table_names.py. These scripts are run internally bygather_agent_info.pyand are provided as external Fallbacks only. - Script Execution Failures & Self-Correction: If the execution of
utility scripts (such as
gather_agent_info.py,check_telemetry.py,create_online_monitor.py,analyze_traffic.py,list_log_scope_table_names.py, orlist_trace_scope_table_names.py) fails unexpectedly, you MUST read and inspect the stdout/stderr logs or error output. Analyze the error message and attempt to dynamically correct parameters and retry execution before escalating or falling back to manual plans. Consult the relevant domain-specific reference file for detailed troubleshooting steps for specific scripts.
- Distribution Metric Aligner Constraint: Standard
ALIGN_MEANcannot be applied toDELTAdistribution metrics likeonline_evaluator/scores. You MUST use percentile-based aligners (likeALIGN_PERCENTILE_50) to reduce the score distribution into a comparable numeric stream. - HCL Heredoc Interpolation: When referencing Terraform variables inside PromQL or SQL queries (which are defined as strings), you MUST use the ${var.variable_name} syntax. Bare references like var.variable_name will fail at deployment time.
- Avoid Recursive Directory Operations: You MUST NOT run recursive listing
or search commands (such as
ls -R,find ., or raw recursivegrep) from the repository root if it contains a very large number of files, as this will freeze your session. Always target specific subdirectories.