View a markdown version of this page

Dapatkan rekomendasi - Batuan Dasar Amazon AgentCore

Dapatkan rekomendasi

Ambil status dan hasil rekomendasi. Polling operasi ini sampai rekomendasi mencapai status terminal (COMPLETEDatauFAILED).

Sampel Kode

contoh
AgentCore CLI

agentcore run recommendationmengajukan pekerjaan api-dan-lupa. Lulus --wait ke blok hingga mencapai status terminal, atau periksa nanti dengan ID:

agentcore view recommendation <recommendation-id>

Daftar semua pekerjaan rekomendasi, atau lihat sebagai JSON:

agentcore view recommendation agentcore view recommendation <recommendation-id> --json
AWS SDK (boto3)

Polling sampai selesai dan ekstrak hasilnya:

import time import boto3 client = boto3.client("bedrock-agentcore", region_name="us-west-2") # Poll until terminal state while True: result = client.get_recommendation(recommendationId=recommendation_id) status = result["status"] print(f"Status: {status}") if status in ("COMPLETED", "FAILED"): break time.sleep(15) # Extract system prompt result if status == "COMPLETED": rec_result = result.get("recommendationResult", {}) if "systemPromptRecommendationResult" in rec_result: sys_result = rec_result["systemPromptRecommendationResult"] print(f"Recommended prompt:\n{sys_result['recommendedSystemPrompt']}") if "explanation" in sys_result: print(f"Explanation:\n{sys_result['explanation']}") if "configurationBundle" in sys_result: bundle = sys_result["configurationBundle"] print(f"New bundle version: {bundle['versionId']}") elif "toolDescriptionRecommendationResult" in rec_result: tool_result = rec_result["toolDescriptionRecommendationResult"] for tool in tool_result.get("tools", []): print(f"{tool['toolName']}: {tool['recommendedToolDescription']}") if "explanation" in tool: print(f" Explanation: {tool['explanation']}") elif status == "FAILED": rec_result = result.get("recommendationResult", {}) r = rec_result.get("systemPromptRecommendationResult") or rec_result.get("toolDescriptionRecommendationResult") print(f"Error: [{r['errorCode']}] {r['errorMessage']}")

Ekstrak referensi bundel konfigurasi untuk digunakan dalam A/B pengujian:

result = client.get_recommendation(recommendationId=recommendation_id) if result["status"] == "COMPLETED": rec_result = result["recommendationResult"] sys_result = rec_result.get("systemPromptRecommendationResult", {}) if "configurationBundle" in sys_result: bundle_arn = sys_result["configurationBundle"]["bundleArn"] version_id = sys_result["configurationBundle"]["versionId"] print(f"Use in A/B test: bundle={bundle_arn}, version={version_id}")

Permintaan parameter

Parameter Tipe Diperlukan Deskripsi

recommendationId

Tali

Ya

ID rekomendasi dikembalikan olehStartRecommendation. Lulus sebagai parameter jalur.

Respons

Bidang Tipe Deskripsi

recommendationId

String

Pengidentifikasi unik untuk rekomendasi.

recommendationArn

String

ARN dari rekomendasi.

name

String

Nama rekomendasi.

type

String

SYSTEM_PROMPT_RECOMMENDATION atau TOOL_DESCRIPTION_RECOMMENDATION.

status

String

Status saat ini:PENDING,IN_PROGRESS,COMPLETED,FAILED, atauDELETING.

recommendationConfig

Objek

Konfigurasi yang Anda kirimkan.

recommendationResult

Objek

Hadir saat statusnyaCOMPLETED. Berisi konfigurasi yang dioptimalkan. Bentuknya tergantung pada jenis rekomendasi.

createdAt

Stempel waktu

Ketika rekomendasi dibuat.

updatedAt

Stempel waktu

Ketika rekomendasi terakhir diperbarui.

Bidang hasil prompt sistem

Hadir di recommendationResult.systemPromptRecommendationResult saat tipe adalahSYSTEM_PROMPT_RECOMMENDATION:

Bidang Tipe Deskripsi

recommendedSystemPrompt

String

Teks prompt sistem yang dioptimalkan.

configurationBundle

Objek

Hadir ketika input adalah bundel konfigurasi. Berisi bundleArn dan versionId untuk versi bundel baru.

explanation

String

Penjelasan mengapa rekomendasi dihasilkan dan alasan di balik perubahan yang disarankan.

errorCode

String

Hadir pada kegagalan. Kode kesalahan.

errorMessage

String

Hadir pada kegagalan. Human-readable deskripsi.

Kolom hasil deskripsi alat

Hadir di recommendationResult.toolDescriptionRecommendationResult saat tipe adalahTOOL_DESCRIPTION_RECOMMENDATION:

Bidang Tipe Deskripsi

tools

Daftar

Per-tool hasil. Setiap entri berisitoolName,recommendedToolDescription, danexplanation.

configurationBundle

Objek

Hadir ketika input adalah bundel konfigurasi. Berisi bundleArn dan versionId untuk versi bundel baru.

errorCode

String

Hadir pada kegagalan. Kode kesalahan.

errorMessage

String

Hadir pada kegagalan. Human-readable deskripsi.

Contoh tanggapan

Rekomendasi prompt sistem yang lengkap (input inline):

{ "recommendationId": "MyPromptRec-Ab1Cd2Ef3G", "recommendationArn": "arn:aws:bedrock-agentcore:us-west-2:123456789012:recommendation/MyPromptRec-Ab1Cd2Ef3G", "name": "my-prompt-rec", "type": "SYSTEM_PROMPT_RECOMMENDATION", "status": "COMPLETED", "recommendationConfig": { ... }, "recommendationResult": { "systemPromptRecommendationResult": { "recommendedSystemPrompt": "<optimized system prompt text>", "explanation": "<explanation of why the recommendation was generated>" } }, "createdAt": "2025-03-15T10:00:00Z", "updatedAt": "2025-03-15T10:05:30Z" }

Rekomendasi prompt sistem yang lengkap (input bundel konfigurasi):

{ "recommendationId": "MyBundleRec-Xy9Zw8Vq1R", "recommendationArn": "arn:aws:bedrock-agentcore:us-west-2:123456789012:recommendation/MyBundleRec-Xy9Zw8Vq1R", "name": "my-bundle-prompt-rec", "type": "SYSTEM_PROMPT_RECOMMENDATION", "status": "COMPLETED", "recommendationConfig": { ... }, "recommendationResult": { "systemPromptRecommendationResult": { "recommendedSystemPrompt": "<optimized system prompt text>", "configurationBundle": { "bundleArn": "arn:aws:bedrock-agentcore:us-west-2:123456789012:configuration-bundle/myBundle-Ab1Cd2Ef3G", "versionId": "12345678-1234-1234-1234-123456789012" }, "explanation": "<explanation of why the recommendation was generated>" } }, "createdAt": "2025-03-15T10:00:00Z", "updatedAt": "2025-03-15T10:06:12Z" }

Rekomendasi deskripsi alat lengkap:

{ "recommendationId": "MyToolRec-Qr5St6Uv7W", "recommendationArn": "arn:aws:bedrock-agentcore:us-west-2:123456789012:recommendation/MyToolRec-Qr5St6Uv7W", "name": "my-tool-rec", "type": "TOOL_DESCRIPTION_RECOMMENDATION", "status": "COMPLETED", "recommendationConfig": { ... }, "recommendationResult": { "toolDescriptionRecommendationResult": { "tools": [ { "toolName": "<tool-name-1>", "recommendedToolDescription": "<optimized description for tool 1>", "explanation": "<explanation of why this tool description was changed>" }, { "toolName": "<tool-name-2>", "recommendedToolDescription": "<optimized description for tool 2>", "explanation": "<explanation of why this tool description was changed>" } ] } }, "createdAt": "2025-03-15T11:00:00Z", "updatedAt": "2025-03-15T11:04:45Z" }

Rekomendasi yang gagal:

{ "recommendationId": "MyFailedRec-Mn3Op4Qr5S", "recommendationArn": "arn:aws:bedrock-agentcore:us-west-2:123456789012:recommendation/MyFailedRec-Mn3Op4Qr5S", "name": "my-failed-rec", "type": "SYSTEM_PROMPT_RECOMMENDATION", "status": "FAILED", "recommendationConfig": { ... }, "recommendationResult": { "systemPromptRecommendationResult": { "errorCode": "<error-code>", "errorMessage": "<human-readable error description>" } }, "createdAt": "2025-03-15T12:00:00Z", "updatedAt": "2025-03-15T12:01:10Z" }

Kesalahan

Kesalahan Status HTTP Deskripsi

ResourceNotFoundException

404

Tidak ada rekomendasi yang ditemukan dengan ID yang ditentukan.

ValidationException

400

Format ID rekomendasi tidak valid.

AccessDeniedException

403

Izin tidak mencukupi.

ThrottlingException

429

Tingkat permintaan terlampaui.

InternalServerException

500

Service-side kesalahan.