View a markdown version of this page

從洞見調查結果產生建議 - Amazon Bedrock AgentCore

從洞見調查結果產生建議

檢閱您的洞見結果後,您可以使用相同的代理程式追蹤來產生改善的系統提示。StartRecommendation 指向產生洞見問題清單的已完成批次評估。

注意

建議產生目前僅支援Builtin.Insight.FailureAnalysis洞察,且目前僅提供系統提示建議。

啟動系統提示建議

提供您目前的系統提示,並參考包含追蹤的批次評估:

範例
AgentCore CLI

從已完成的洞見執行產生建議:

agentcore run recommendation --from-insights <id> --type system-prompt --bundle-name my_bundle --json

或直接參考批次評估 ARN:

agentcore run recommendation --batch-evaluation-arn <arn> --type system-prompt --bundle-name my_bundle --json
Interactive
  1. 執行 agentcore以開啟 TUI,然後選取執行並選擇建議

    執行功能表:選取建議

    精靈會引導您選取追蹤來源 (洞見執行或批次評估 ARN)、建議類型和組態套件。

AWS SDK (boto3)
import boto3 import uuid client = boto3.client("bedrock-agentcore", region_name="us-west-2") response = client.start_recommendation( name=f"fix-rate-limiting-{uuid.uuid4().hex[:8]}", type="SYSTEM_PROMPT_RECOMMENDATION", recommendationConfig={ "systemPromptRecommendationConfig": { "systemPrompt": { "text": "You are a helpful customer support assistant. Help users with their orders and returns." }, "agentTraces": { "batchEvaluation": { "batchEvaluationArn": "arn:aws:bedrock-agentcore:us-west-2:123456789012:batch-evaluate/insights-run-ABC1234567" } }, } }, clientToken=str(uuid.uuid4()), ) recommendation_id = response["recommendationId"] print(f"Started recommendation: {recommendation_id}")

擷取建議的提示

輪詢直到完成,然後擷取結果:

import time while True: rec = client.get_recommendation(recommendationId=recommendation_id) if rec["status"] in ("COMPLETED", "FAILED"): break time.sleep(15) if rec["status"] == "COMPLETED": result = rec["recommendationResult"]["systemPromptRecommendationResult"] print(f"Recommended prompt:\n{result['recommendedSystemPrompt']}") print(f"\nExplanation:\n{result['explanation']}")

替代追蹤來源

您也可以透過 CloudWatch Logs 提供追蹤,而不是參考批次評估:

"agentTraces": { "cloudwatchLogs": { "logGroupArns": [ "arn:aws:logs:us-west-2:123456789012:log-group:/aws/bedrock-agentcore/runtimes/MyAgent-abc123-DEFAULT" ], "serviceNames": ["MyAgent.DEFAULT"], "startTime": "2026-05-27T00:00:00Z", "endTime": "2026-06-03T00:00:00Z", } }