invoke_agent
async
¶
invoke_agent(
agent_id: AgentId,
agent_alias_id: AgentAliasId,
session_id: SessionId,
*,
config_overrides: Optional[AsyncBedrockAgentRuntimeClientConfig] = None,
session_state: Optional[SessionState] = None,
end_session: Optional[bool] = None,
enable_trace: Optional[bool] = None,
input_text: Optional[InputText] = None,
memory_id: Optional[MemoryId] = None,
bedrock_model_configurations: Optional[BedrockModelConfigurations] = None,
streaming_configurations: Optional[StreamingConfigurations] = None,
prompt_creation_configurations: Optional[PromptCreationConfigurations] = None,
source_arn: Optional[AWSResourceARN] = None,
) -> AsyncGenerator[InvokeAgentResponse]
Amazon Bedrock Agents (now Amazon Bedrock Agents Classic) is no longer open to new customers. For capabilities similar to Bedrock Agents Classic, explore Amazon Bedrock AgentCore. Existing customers can continue to use the service as normal. For more information, see Amazon Bedrock Agents Classic availability change.
Sends a prompt for the agent to process and respond to. Note the following fields for the request:
-
To continue the same conversation with an agent, use the same
sessionIdvalue in the request. -
To activate trace enablement, turn
enableTracetotrue. Trace enablement helps you follow the agent's reasoning process that led it to the information it processed, the actions it took, and the final result it yielded. For more information, see Trace enablement. -
End a conversation by setting
endSessiontotrue. -
In the
sessionStateobject, you can include attributes for the session or prompt or, if you configured an action group to return control, results from invocation of the action group.
The response contains both chunk and trace attributes.
The final response is returned in the bytes field of the chunk object. The InvokeAgent returns one chunk for the entire interaction.
-
The
attributionobject contains citations for parts of the response. -
If you set
enableTracetotruein the request, you can trace the agent's steps and reasoning process that led it to the response. -
If the action predicted was configured to return control, the response returns parameters for the action, elicited from the user, in the
returnControlfield. -
Errors are also surfaced in the response.
Parameters:
-
session_state(Optional[SessionState], default:None) –Contains parameters that specify various attributes of the session. For more information, see Control session context.
If you include
returnControlInvocationResultsin thesessionStatefield, theinputTextfield will be ignored. -
agent_id(AgentId) –The unique identifier of the agent to use.
-
agent_alias_id(AgentAliasId) –The alias of the agent to use.
-
session_id(SessionId) –The unique identifier of the session. Use the same value across requests to continue the same conversation.
-
end_session(Optional[bool], default:None) –Specifies whether to end the session with the agent or not.
-
enable_trace(Optional[bool], default:None) –Specifies whether to turn on the trace or not to track the agent's reasoning process. For more information, see Trace enablement.
-
input_text(Optional[InputText], default:None) –The prompt text to send the agent.
If you include
returnControlInvocationResultsin thesessionStatefield, theinputTextfield will be ignored. -
memory_id(Optional[MemoryId], default:None) –The unique identifier of the agent memory.
-
bedrock_model_configurations(Optional[BedrockModelConfigurations], default:None) –Model performance settings for the request.
-
streaming_configurations(Optional[StreamingConfigurations], default:None) –Specifies the configurations for streaming.
To use agent streaming, you need permissions to perform the
bedrock:InvokeModelWithResponseStreamaction. -
prompt_creation_configurations(Optional[PromptCreationConfigurations], default:None) –Specifies parameters that control how the service populates the agent prompt for an
InvokeAgentrequest. You can control which aspects of previous invocations in the same agent session the service uses to populate the agent prompt. This gives you more granular control over the contextual history that is used to process the current request. -
source_arn(Optional[AWSResourceARN], default:None) –The ARN of the resource making the request.
Raises:
-
AccessDeniedException–The request is denied because of missing access permissions. Check your permissions and retry your request.
-
BadGatewayException–There was an issue with a dependency due to a server issue. Retry your request.
-
ConflictException–There was a conflict performing an operation. Resolve the conflict and retry your request.
-
DependencyFailedException–There was an issue with a dependency. Check the resource configurations and retry the request.
-
InternalServerException–An internal server error occurred. Retry your request.
-
ModelNotReadyException–The model specified in the request is not ready to serve inference requests. The AWS SDK will automatically retry the operation up to 5 times. For information about configuring automatic retries, see Retry behavior in the AWS SDKs and Tools reference guide.
-
ResourceNotFoundException–The specified resource Amazon Resource Name (ARN) was not found. Check the Amazon Resource Name (ARN) and try your request again.
-
ServiceQuotaExceededException–The number of requests exceeds the service quota. Resubmit your request later.
-
ThrottlingException–The number of requests exceeds the limit. Resubmit your request later.
-
ValidationException–Input validation failed. Check your request parameters and retry the request.
-
UnknownServiceError–The service returned an error code this client does not model.
Source code in docs_src/capo_bedrock_agent_runtime/_services/async_bedrock_agent_runtime.py
1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 | |