View a markdown version of this page

Ottieni consigli - Amazon Bedrock AgentCore

Ottieni consigli

Recupera lo stato e i risultati di una raccomandazione. Esegui il polling di questa operazione finché la raccomandazione non raggiunge uno stato terminale (COMPLETEDoFAILED).

Esempi di codice

Esempio
AgentCore CLI

agentcore run recommendationinvia un lavoro «spara e dimentica». Passa --wait al blocco finché non raggiunge uno stato terminale, oppure controllalo più tardi tramite ID:

agentcore view recommendation <recommendation-id>

Elenca tutti i lavori di raccomandazione o visualizza come JSON:

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

Esegui il sondaggio fino al completamento ed estrai il risultato:

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']}")

Estrai il riferimento al pacchetto di configurazione da utilizzare nei A/B test:

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}")

Parametri della richiesta

Parametro Tipo Campo obbligatorio Descrizione

recommendationId

Stringa

L'ID di raccomandazione restituito daStartRecommendation. Passato come parametro di percorso.

Risposta

Campo Tipo Description

recommendationId

Stringa

Identificatore univoco per la raccomandazione.

recommendationArn

Stringa

ARN della raccomandazione.

name

Stringa

Il nome della raccomandazione.

type

Stringa

SYSTEM_PROMPT_RECOMMENDATION o TOOL_DESCRIPTION_RECOMMENDATION.

status

Stringa

Stato attuale: PENDINGIN_PROGRESS,COMPLETED,FAILED, oDELETING.

recommendationConfig

Oggetto

La configurazione che hai inviato.

recommendationResult

Oggetto

Presente quando lo stato èCOMPLETED. Contiene la configurazione ottimizzata. La forma dipende dal tipo di raccomandazione.

createdAt

Time stamp

Quando è stata creata la raccomandazione.

updatedAt

Time stamp

Data dell'ultimo aggiornamento della raccomandazione.

Campi dei risultati del prompt di sistema

Presente recommendationResult.systemPromptRecommendationResult quando il tipo èSYSTEM_PROMPT_RECOMMENDATION:

Campo Tipo Description

recommendedSystemPrompt

Stringa

Il testo ottimizzato del prompt di sistema.

configurationBundle

Oggetto

Presente quando l'input era un pacchetto di configurazione. Contiene bundleArn e versionId per la nuova versione del pacchetto.

explanation

Stringa

Una spiegazione del motivo per cui è stata generata la raccomandazione e del motivo alla base delle modifiche suggerite.

errorCode

Stringa

Presente in caso di fallimento. Codice di errore.

errorMessage

Stringa

Presente in caso di fallimento. Human-readable descrizione.

Descrizione dello strumento, campi dei risultati

Presente recommendationResult.toolDescriptionRecommendationResult quando il tipo èTOOL_DESCRIPTION_RECOMMENDATION:

Campo Tipo Description

tools

List

Per-tool risultati. Ogni voce contiene toolNamerecommendedToolDescription, eexplanation.

configurationBundle

Oggetto

Presente quando l'input era un pacchetto di configurazione. Contiene bundleArn e versionId per la nuova versione del pacchetto.

errorCode

Stringa

Presente in caso di fallimento. Codice di errore.

errorMessage

Stringa

Presente in caso di fallimento. Human-readable descrizione.

Risposte di esempio

Raccomandazione del prompt di sistema completata (input in linea):

{ "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" }

Raccomandazione completata del prompt di sistema (input del pacchetto di configurazione):

{ "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" }

Raccomandazione completa sulla descrizione dell'utensile:

{ "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" }

Raccomandazione non riuscita:

{ "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" }

Errori

Errore Stato HTTP Description

ResourceNotFoundException

404

Nessuna raccomandazione trovata con l'ID specificato.

ValidationException

400

Formato ID di raccomandazione non valido.

AccessDeniedException

403

Autorizzazioni insufficienti.

ThrottlingException

429

Frequenza di richiesta superata.

InternalServerException

500

Service-side errore.