invoke_agent_runtime
async
¶
invoke_agent_runtime(
agent_runtime_arn: str,
payload: Body,
*,
config_overrides: Optional[AsyncBedrockAgentCoreClientConfig] = None,
content_type: Optional[MimeType] = None,
accept: Optional[MimeType] = None,
mcp_session_id: Optional[StringType] = None,
runtime_session_id: Optional[SessionType] = None,
mcp_protocol_version: Optional[StringType] = None,
mcp_method: Optional[StringType] = None,
mcp_name: Optional[StringType] = None,
runtime_user_id: Optional[StringType] = None,
trace_id: Optional[str] = None,
trace_parent: Optional[str] = None,
trace_state: Optional[str] = None,
baggage: Optional[str] = None,
qualifier: Optional[str] = None,
account_id: Optional[str] = None,
) -> AsyncGenerator[InvokeAgentRuntimeResponse]
Sends a request to an agent or tool hosted in an Amazon Bedrock AgentCore Runtime and receives responses in real-time.
To invoke an agent, you can specify either the AgentCore Runtime ARN or the agent ID with an account ID, and provide a payload containing your request. When you use the agent ID instead of the full ARN, you don't need to URL-encode the identifier. You can optionally specify a qualifier to target a specific endpoint of the agent.
This operation supports streaming responses, allowing you to receive partial responses as they become available. We recommend using pagination to ensure that the operation returns quickly and successfully when processing large responses.
For example code, see Invoke an AgentCore Runtime agent.
If you're integrating your agent with OAuth, you can't use the Amazon Web Services SDK to call InvokeAgentRuntime. Instead, make a HTTPS request to InvokeAgentRuntime. For an example, see Authenticate and authorize with Inbound Auth and Outbound Auth.
To use this operation, you must have the bedrock-agentcore:InvokeAgentRuntime permission. If you are making a call to InvokeAgentRuntime on behalf of a user ID with the X-Amzn-Bedrock-AgentCore-Runtime-User-Id header, You require permissions to both actions (bedrock-agentcore:InvokeAgentRuntime and bedrock-agentcore:InvokeAgentRuntimeForUser).
Parameters:
-
content_type(Optional[MimeType], default:None) –The MIME type of the input data in the payload. This tells the agent runtime how to interpret the payload data. Common values include application/json for JSON data.
-
accept(Optional[MimeType], default:None) –The desired MIME type for the response from the agent runtime. This tells the agent runtime what format to use for the response data. Common values include application/json for JSON data.
-
mcp_session_id(Optional[StringType], default:None) –The identifier of the MCP session.
-
runtime_session_id(Optional[SessionType], default:None) –The identifier of the runtime session.
-
mcp_protocol_version(Optional[StringType], default:None) –The version of the MCP protocol being used.
-
mcp_method(Optional[StringType], default:None) –The MCP method being invoked. For example,
tools/call,resources/read, orprompts/get. -
mcp_name(Optional[StringType], default:None) –The name of the MCP resource, tool, or prompt being accessed. The value depends on the method:
-
tools/call– The tool name. -
resources/read– The resource URI. -
prompts/get– The prompt name.
-
-
runtime_user_id(Optional[StringType], default:None) –The identifier of the runtime user.
-
trace_id(Optional[str], default:None) –The trace identifier for request tracking.
-
trace_parent(Optional[str], default:None) –The parent trace information for distributed tracing.
-
trace_state(Optional[str], default:None) –The trace state information for distributed tracing.
-
baggage(Optional[str], default:None) –Additional context information for distributed tracing.
-
agent_runtime_arn(str) –The identifier of the agent runtime to invoke. You can specify either the full Amazon Web Services Resource Name (ARN) or the agent ID. If you use the agent ID, you must also provide the
accountIdquery parameter. -
qualifier(Optional[str], default:None) –The qualifier to use for the agent runtime. This is an endpoint name that points to a specific version. If not specified, Amazon Bedrock AgentCore uses the default endpoint of the agent runtime.
-
account_id(Optional[str], default:None) –The identifier of the Amazon Web Services account for the agent runtime resource. This parameter is required when you specify an agent ID instead of the full ARN for
agentRuntimeArn. -
payload(Body) –The input data to send to the agent runtime. The format of this data depends on the specific agent configuration and must match the specified content type. For most agents, this is a JSON object containing the user's request.
Raises:
-
AccessDeniedException–The exception that occurs when you do not have sufficient permissions to perform an action. Verify that your IAM policy includes the necessary permissions for the operation you are trying to perform.
-
InternalServerException–The exception that occurs when the service encounters an unexpected internal error. This is a temporary condition that will resolve itself with retries. We recommend implementing exponential backoff retry logic in your application.
-
ResourceNotFoundException–The exception that occurs when the specified resource does not exist. This can happen when using an invalid identifier or when trying to access a resource that has been deleted.
-
RetryableConflictException–The exception that occurs when there is a retryable conflict performing an operation. This is a temporary condition that may resolve itself with retries. We recommend implementing exponential backoff retry logic in your application.
-
RuntimeClientError–The exception that occurs when there is an error in the runtime client. This can happen due to network issues, invalid configuration, or other client-side problems. Check the error message for specific details about the error.
-
ServiceQuotaExceededException–The exception that occurs when the request would cause a service quota to be exceeded. Review your service quotas and either reduce your request rate or request a quota increase.
-
ThrottlingException–The exception that occurs when the request was denied due to request throttling. This happens when you exceed the allowed request rate for an operation. Reduce the frequency of requests or implement exponential backoff retry logic in your application.
-
ValidationException–The exception that occurs when the input fails to satisfy the constraints specified by the service. Check the error message for details about which input parameter is invalid and correct your request.
-
UnknownServiceError–The service returned an error code this client does not model.
Source code in docs_src/capo_bedrock_agentcore/_services/async_bedrock_agent_core.py
1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 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 | |