View a markdown version of this page

Ottieni consigli - Fondamento Amazon AgentCore

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Ottieni consigli

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

Esempi di codice

Esempio
AgentCore CLI

agentcore run recommendationinvia un lavoro «fire-and-forget». Passa --wait al blocco finché non raggiunge lo stato del terminale, oppure controllalo più tardi tramite ID:

agentcore view recommendation <recommendation-id>

Elenca tutti i lavori consigliati o visualizzali in formato 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 del 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

Sì

L'ID della 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 del consiglio.

Campi dei risultati del prompt di sistema

Presente recommendationResult.systemPromptRecommendationResult quando il tipo èSYSTEM_PROMPT_RECOMMENDATION:

Campo Tipo Description

recommendedSystemPrompt

Stringa

Il testo del prompt di sistema ottimizzato.

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 il ragionamento 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 contienetoolName,recommendedToolDescription, 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 errore. 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 del prompt di sistema completata (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" }

Descrizione completa dello strumento consigliata:

{ "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 del consiglio non valido.

AccessDeniedException

403

Autorizzazioni insufficienti.

ThrottlingException

429

Percentuale di richieste superata.

InternalServerException

500

Service-side errore.