View a markdown version of this page

週期性洞見報告 - Amazon Bedrock AgentCore

週期性洞見報告

建立具有洞察和叢集排程的線上評估組態。此服務會自動在設定的節奏上執行洞見分析,無需手動介入。

建立組態

範例
AgentCore CLI
agentcore add online-insights --name my_agent_insights --runtime MyAgent --insights Builtin.Insight.FailureAnalysis --sampling-rate 100 --clustering-frequency DAILY --enable-on-create --json

然後,透過 CloudFormation 部署:

agentcore deploy -y --json
Interactive
  1. 執行 agentcore以開啟 TUI,然後選取新增,然後選擇線上洞見

    Insights 精靈:選取要監控的代理程式
  2. 選取要啟用的洞見:

    Insights 精靈:選取洞見
  3. 設定取樣率:

    Insights 精靈:設定取樣率
  4. 選擇叢集頻率:

    Insights 精靈:選取叢集頻率
  5. 輸入組態名稱:

    Insights 精靈:輸入組態名稱
  6. 檢閱組態,然後按 Enter 鍵確認:

    Insights 精靈:檢閱組態
AWS SDK (boto3)
import boto3 client_cp = boto3.client("bedrock-agentcore-control", region_name="us-west-2") response = client_cp.create_online_evaluation_config( onlineEvaluationConfigName="my_agent_insights", rule={ "samplingConfig": {"samplingPercentage": 100.0}, "sessionConfig": {"sessionTimeoutMinutes": 30}, }, dataSourceConfig={ "cloudWatchLogs": { "serviceNames": ["MyAgent.DEFAULT"], "logGroupNames": [ "/aws/bedrock-agentcore/runtimes/MyAgent-abc123-DEFAULT" ], } }, insights=[ {"insightId": "Builtin.Insight.FailureAnalysis"}, {"insightId": "Builtin.Insight.UserIntent"}, ], clusteringConfig={"frequencies": ["DAILY"]}, evaluationExecutionRoleArn="arn:aws:iam::123456789012:role/AgentCoreEvaluationRole", enableOnCreate=True, ) config_id = response["onlineEvaluationConfigId"] print(f"Created config: {config_id}")

這會通知服務:

  • 以設定的速率取樣工作階段 (在此範例中為 100% — 調整 --sampling-ratesamplingPercentage以分析一部分的流量)。

  • 在每個取樣工作階段上執行失敗分析和使用者意圖擷取。

  • 每天觸發叢集報告。

組態參數

參數 Type 必要 說明

insights

清單

必要 (與 互斥evaluators)

要執行的洞見類型清單。每個項目都有 insightId。上限為 10。

rule.samplingConfig.samplingPercentage

Number

否 (預設值:100)

要分析的工作階段百分比 (1—100)。為高流量代理程式使用較低的取樣率來控制成本,同時仍然浮現失敗模式。

clusteringConfig

物件

設定叢集的定期批次評估任務。包含frequencies清單。只能在提供 insights 時使用。

clusteringConfig.frequencies

字串清單

是 (在 內clusteringConfig)

一或多個:DAILYWEEKLYMONTHLY。最多 3 個值。

注意

洞見和評估者是互斥的 - 您必須提供其中一個,而不是兩者。如果您想要相同代理程式的品質評分和失敗分類,請建立指向相同資料來源的兩個不同組態。

更新組態

修改洞見或叢集頻率:

client_cp.update_online_evaluation_config( onlineEvaluationConfigId=config_id, insights=[ {"insightId": "Builtin.Insight.FailureAnalysis"}, {"insightId": "Builtin.Insight.UserIntent"}, ], clusteringConfig={"frequencies": ["DAILY", "WEEKLY"]}, )

檢視週期性報告結果

週期性報告會自動產生批次評估任務。使用 ListBatchEvaluations 尋找已完成的報告,然後使用 GetBatchEvaluation 擷取結果:

client = boto3.client("bedrock-agentcore", region_name="us-west-2") # List recent batch evaluations evaluations = client.list_batch_evaluations() for eval_summary in evaluations.get("batchEvaluations", []): if eval_summary["status"] == "COMPLETED" and eval_summary.get("insights"): result = client.get_batch_evaluation( batchEvaluationId=eval_summary["batchEvaluationId"] ) print(f"Report: {eval_summary['batchEvaluationName']}") if "failureAnalysisResult" in result: failures = result["failureAnalysisResult"]["failures"] print(f" Found {len(failures)} failure categories")

管理組態

範例
AgentCore CLI

暫停:

agentcore pause online-insights my_agent_insights --json

繼續:

agentcore resume online-insights my_agent_insights --json

移除:

agentcore remove online-insights --name my_agent_insights --yes --json
AWS SDK (boto3)

暫停或繼續:

# Pause client_cp.update_online_evaluation_config( onlineEvaluationConfigId=config_id, executionStatus="DISABLED", ) # Resume client_cp.update_online_evaluation_config( onlineEvaluationConfigId=config_id, executionStatus="ENABLED", )

刪除:

client_cp.delete_online_evaluation_config( onlineEvaluationConfigId=config_id, )
警告

刪除組態不會刪除過去的批次評估結果。歷史洞見結果仍可透過 存取GetBatchEvaluation