Pour configurer une orchestration personnalisée à l’aide des opérations d’API, envoyez une demande UpdateAgent (voir le lien pour les formats de demande et de réponse et les détails des champs) avec un point de terminaison de développement des agents Amazon Bedrock. Spécifiez l’objet orchestrationType en tant que CUSTOM_ORCHESTRATION.
Exemple de données utiles d’orchestration dans React
Voici un exemple React qui montre la chaîne d’une orchestration pensée. Dans cet exemple, après chaque étape, l’agent Amazon Bedrock demande au modèle de prévoir la prochaine action. Notez que le premier état de toute conversation est toujours START. Les événements sont les réponses que la fonction envoie en réponse aux agents Amazon Bedrock.
function react_chain_of_thought_orchestration(event) {
const incomingState = event.state;
let payloadData = '';
let responseEvent = '';
let responseTrace = '';
let responseAttribution = '';
if (incomingState == 'START') {
// 1. Invoke model in start
responseEvent = 'INVOKE_MODEL';
payloadData = JSON.stringify(intermediatePayload(event));
}
else if (incomingState == 'MODEL_INVOKED') {
const stopReason = modelInvocationStopReason(event);
if (stopReason == "tool_use") {
// 2.a. If invoke model predicts tool call, then we send INVOKE_TOOL event
responseEvent = 'INVOKE_TOOL';
payloadData = toolUsePayload(event);
}
else if (stopReason == "end_turn") {
// 2.b. If invoke model predicts an end turn, then we send FINISH event
responseEvent = 'FINISH';
payloadData = getEndTurnPayload(event);
}
}
else if (incomingState == 'TOOL_INVOKED') {
// 3. After a tool invocation, we again ask LLM to predict what should be the next step
responseEvent = 'INVOKE_MODEL';
payloadData = intermediatePayload(event);
}
else {
// Invalid incoming state
throw new Error('Invalid state provided!');
}
// 4. Create the final payload to send back to BedrockAgent
const payload = createPayload(payloadData, responseEvent, responseTrace, ...);
return JSON.stringify(payload);
}
Exemple de données utiles d’orchestration dans Lambda
L’exemple suivant illustre la chaîne de l’orchestration pensée. Dans cet exemple, après chaque étape, l’agent Amazon Bedrock demande au modèle de prévoir la prochaine action. Notez que le premier état de toute conversation est toujours START. Les événements sont les réponses que la fonction envoie en réponse aux agents Amazon Bedrock.
La structure de données utiles pour l’orchestration Lambda
{
"version": "1.0",
"state": "START | MODEL_INVOKED | TOOL_INVOKED | APPLY_GUARDRAIL_INVOKED | user-defined",
"input": {
"text": "user-provided text or tool results in converse format"
},
"context": {
"requestId": "invoke agent request id",
"sessionId": "invoke agent session id",
"agentConfiguration": {
"instruction": "agent instruction>,
"defaultModelId": "agent default model id",
"tools": [{
"toolSpec": {...}
}
...
],
"guardrails": {
"version": "guardrail version",
"identifier": "guardrail identifier"
}
},
"session": [{
"agentInput": "input utterance provided in invokeAgent",
"agentOutput": "output response from invokeAgent",
"intermediarySteps": [{
"orchestrationInput": {
"state": "START | MODEL_INVOKED | TOOL_INVOKED | APPLY_GUARDRAIL_INVOKED | user defined",
"text": "..."
},
"orchestrationOutput": {
"event": "INVOKE_MODEL | INVOKE_TOOL | APPLY_GUARDRAIL | FINISH | user defined",
"text": "Converse API request or text"
}
}]
}],
"sessionAttributes": {
key value pairs
},
"promptSessionAttributes": {
key value pairs
}
}
}
La structure de données utiles d’une orchestration Lambda
{
"version": "1.0",
"actionEvent": "INVOKE_MODEL | INVOKE_TOOL | APPLY_GUARDRAIL | FINISH | user defined",
"output": {
"text": "Converse API request for INVOKE_MODEL, INVOKE_TOOL, APPLY_GUARDRAIL or text for FINISH",
"trace": {
"event": {
"text": "Trace message to emit as event in InvokeAgent response"
}
}
},
"context": {
"sessionAttributes": {
key value pairs
},
"promptSessionAttributes": {
key value pairs
}
}
}
Exemple d’un START_STATE envoyé par Amazon Bedrock Agents à l’orchestrateur Lambda
{
"version": "1.0",
"state": "START",
"input": {
"text": "{\"text\":\"invoke agent input text\"}"
},
"context": {
...
}
}
En réponse, si l’orchestration Lambda décide d’envoyer une réponse INVOKE_MODEL EVENT, cela peut ressembler à ce qui suit :
{
"version": "1.0",
"actionEvent": "INVOKE_MODEL",
"output": {
"text": "converse API request",
"trace": {
"event": {
"text": "debug trace text"
}
}
},
"context": {}
}
Exemple d’un INVOKE_TOOL_EVENT utilisant une API Converse
{
"version": "1.0",
"actionEvent": "INVOKE_TOOL",
"output": {
"text": "{\"toolUse\":{\"toolUseId\":\"unique id\",\"name\":\"tool name\",\"input\":{}}}"
}
}