启动流执行
要运行流执行,请使用 Amazon Bedrock 代理运行时端点发送 StartFlowExecution 请求。在请求中,指定要运行的流的流 ID 和流别名 ID。您也可以指定:
{
"inputs": [{
"nodeName": "FlowInputNode",
"nodeOutputName": "document",
"content": {
"document": "Test"
}
}],
"name": "MyExecution"
}
响应是流执行的 Amazon 资源名称(ARN)。您可以使用 executionArn 轮询流的当前状态,例如流执行完成或条件节点评测其条件的时间。
{
"executionArn": "arn:aws:bedrock:us-west-2:111122223333:flow/FLOWID/alias/TSTALIASID/execution/MyExecution"
}
跟踪流执行的进度
使用 GetFlowExecution 操作获取您通过流的执行 ARN 识别的流当前状态。流状态为 Running、Succeeded、Failed、TimedOut 或 Aborted。
{
"endedAt": null,
"errors": null,
"executionArn": "arn:aws:bedrock:us-west-2:111122223333:flow/FLOWID/alias/TSTALIASID/execution/MyExecution",
"flowAliasIdentifier": "TSTALIASID",
"flowIdentifier": "FLOWID",
"flowVersion": "DRAFT",
"startedAt": "2025-03-20T23:32:28.899221162Z",
"status": "Running"
}
错误(如 Lambda 节点超时)会在 errors 数组中返回,如下例所示:
"errors": [{
"nodeName": "LambdaNode1",
"errorType": "ExecutionTimedOut",
"message": "Call to lambda function timed out"
}],
获取流执行的结果
Amazon Bedrock 会将流的输出写入流的输出节点。您可能会在流完成后或流运行时获得输出(具体取决于您的使用案例)。
如果您希望流先完成,请调用 GetFlowExecution 并确保响应中 status 字段的值为 Succeeded。
要从流执行中获取输出事件的列表,请调用 ListFlowExecutionEvents。在响应中,检查 flowExecutionEvents 中是否有 flowOutputEvent 对象。例如,您可以在 content 字段中获取流的输出:
{
"flowOutputEvent": {
"content": {
"document": "The model response."
},
"nodeName": "FlowOutputNode"
}
}
通过将 eventType 查询参数设置为 Flow,您可以将 ListFlowExecutions 的输出限制为仅输入和输出节点。
查看事件
要帮助调试流执行,您可以使用 ListFlowExecutionEvents 操作来查看节点在流运行时生成的事件。将 eventType 查询参数设置为 Node,以查看响应中所有节点(包括中间节点)的输入和输出,类似于以下示例:
{
"flowExecutionEvents": [{
"nodeOutputEvent": {
"fields": [{
"content": {
"document": "History book"
},
"name": "document"
}],
"nodeName": "FlowInputNode",
"timestamp": "2025-05-05T18:38:56.637867516Z"
}
},
{
"nodeInputEvent": {
"fields": [{
"content": {
"document": "History book"
},
"name": "book"
}],
"nodeName": "Prompt_1",
"timestamp": "2025-05-05T18:38:57.434600163Z"
}
},
{
"nodeOutputEvent": {
"fields": [{
"content": {
"document": "Here's a summary of the history book."
},
"name": "modelCompletion"
}],
"nodeName": "Prompt_1",
"timestamp": "2025-05-05T18:39:06.034157077Z"
}
},
{
"nodeInputEvent": {
"fields": [{
"content": {
"document": "Here's a summary of the history book."
},
"name": "document"
}],
"nodeName": "FlowOutputNode",
"timestamp": "2025-05-05T18:39:06.453128251Z"
}
}
]
}
获取流执行的快照
当流执行开始时,Amazon Bedrock 会自动拍摄流定义和元数据的快照。这很有用,因为可以在流异步运行时对其进行更新。要检索此快照,请调用 GetExecutionFlowSnapshot 操作。响应包含以下流字段:
-
customerEncryptionKeyArn – 加密流的 AWS KMS 密钥的 ARN。
-
definition – 流的定义。
-
executionRoleArn – 流执行使用的 IAM 服务角色的 ARN。
-
flowAliasIdentifier – 流的别名 ID。
-
flowIdentifier – 流的 ID。
-
flowVersion – 流的版本。
{
"customerEncryptionKeyArn": null,
"definition": "{flow-definition}",
"executionRoleArn": "arn:aws:iam::111122223333:role/name",
"flowAliasIdentifier": "TSTALIASID",
"flowIdentifier": "FLOWID",
"flowVersion": "DRAFT"
}
列出流执行
您可以通过调用 ListFlowExecutions 操作来获取流执行列表。响应包含一个 flowExecutionSummaries 数组,其中包含流或流别名的当前 AWS 区域中的每个流执行的相关信息。每个元素都包含执行 ARN、开始时间和流当前状态等信息。
{
"flowExecutionSummaries": [{
"createdAt": "2025-03-11T23:21:02.875598966Z",
"endedAt": null,
"executionArn": "arn:aws:bedrock:us-west-2:111122223333:flow/FLOWID/alias/TSTALIASID/execution/MyExecution",
"flowAliasIdentifier": "TSTALIASID",
"flowIdentifier": "FLOWID",
"flowVersion": "DRAFT",
"status": "Running"
}]
}
停止正在运行的流执行
如果您需要停止正在运行的流执行,请调用 StopFlowExecution 操作并传递要停止的执行的流 ID、流别名 ID 和流执行 ID。