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,然后选择添加并选择 O nline Insights

    见解向导:选择要监控的代理
  2. 选择要启用的见解:

    见解向导:选择见解
  3. 设置采样率:

    见解向导:设置采样率
  4. 选择聚类频率:

    见解向导:选择聚类频率
  5. 输入配置名称:

    见解向导:输入配置名称
  6. 查看配置并按 Enter 进行确认:

    见解向导:查看配置
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

数字

否(默认值:100)

要分析的会话百分比 (1—100)。对高流量代理使用较低的采样率来控制成本,同时仍能显示故障模式。

clusteringConfig

对象

为群集配置定期批量评估作业。包含一个frequencies列表。只有在提供insights时才能使用。

clusteringConfig.frequencies

字符串列表

是(在内clusteringConfig

其中一个或多个:DAILY,WEEKLY, MONTHLY。最多 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", )

Delete:

client_cp.delete_online_evaluation_config( onlineEvaluationConfigId=config_id, )
警告

删除配置不会删除过去的批量评估结果。仍可通过以下方式访问历史洞察结果GetBatchEvaluation