[アップデート] Amazon Bedrock Flows のトレースでアクション内容を記録する nodeActionTrace が表示されるようになりました

[アップデート] Amazon Bedrock Flows のトレースでアクション内容を記録する nodeActionTrace が表示されるようになりました

Clock Icon2025.03.31

こんにちは!クラウド事業本部コンサルティング部のたかくに(@takakuni_)です。

Amazon Bedrock Flows のトレースでアクション内容を記録する nodeActionTrace が表示されるようになりました。

https://awsapichanges.com/archive/changes/7764f8-bedrock-agent-runtime.html

トレース

Amazon Bedrock Flows におけるトレース情報は、各ノードへの入出力を確認できる機能です。

これらの情報を確認することで、フロー全体の流れをより具体的に把握し、トラブルシューティングや改善に役立てられます。

トレースの表示はコンソール、API どちらも対応しており、API 経由の場合、enableTrace で切り替えられます。

POST /flows/flowIdentifier/aliases/flowAliasIdentifier HTTP/1.1
Content-type: application/json

{
   "enableTrace": boolean,
   "executionId": "string",
   "inputs": [ 
      { 
         "content": { ... },
         "nodeInputName": "string",
         "nodeName": "string",
         "nodeOutputName": "string"
      }
   ],
   "modelPerformanceConfiguration": { 
      "performanceConfig": { 
         "latency": "string"
      }
   }
}

https://docs.aws.amazon.com/ja_jp/bedrock/latest/APIReference/API_agent-runtime_InvokeFlow.html

従来のトレースタイプは、FlowTraceConditionNodeResultEvent, FlowTraceNodeInputEvent, FlowTraceNodeOutputEvent と言った形で各ノード間の入出力にフォーカスしたトレースでした。

今回の nodeActionTrace は、フローから LLM やエージェントなどの外部リソースを呼び出す場合のアクションを記録するトレースタイプで、どのようなアクションが実行されたのかをトラブルシューティングするのに役立ちます。

やってみた

フローの作成

それでは、実際にどんな情報が出てくるのか試してみます。フローの作成は Amazon Bedrock Flows Samples から作成します。

https://github.com/aws-samples/amazon-bedrock-flows-samples?tab=readme-ov-file#how-to-use

(venv) takakuni@ amazon-bedrock-flows-samples % python src/bedrock_flow_manager.py \
  --test-input "What is Amazon Bedrock?"                                      

📋 Configuration:
Region: ap-northeast-1
Profile: takakuni-tf
Templates Directory: ./templates
Test Input:
  • What is Amazon Bedrock?

=== Amazon Bedrock Flow Manager ===
Region: ap-northeast-1
Profile: takakuni-tf
Using existing IAM role: BedrockFlowsRole
Using existing IAM role: BedrockFlowsRole

📂 Available Templates:
--------------------------------------------------
1. rag_kb_flow.json
      Description: This is a template for a knowledgebase node. It is used to run the query against a knowledgebase and get the response.
--------------------------------------------------
2. multi_agent_flow.json
      Description: This is a template for an Agent Node. Flow demonstrates user input handled by an agent.
--------------------------------------------------
3. multi_turn_agent_flow.json
      Description: This is a flow template for a Multi-turn Agent Node. Flow demonstrates a multi-turn conversation flow with an agent.
--------------------------------------------------
4. conditions_flow.json
      Description: This is a template for a condition node. It is used to conditionally execute a prompt or a knowledge base.
--------------------------------------------------
5. prompt_guardrail_flow.json
      Description: This is a template for a Prompt node with Guardrail. It is used to execute a prompt with a guardrail attached.
--------------------------------------------------
6. iterator_collector_flow.json
      Description: This is a template for an Iterator and Collector Node. Template demonstrates a Flow that Iterates over an array of input, sends them to prompt and collects the results for display.
--------------------------------------------------

Select a template number:
Enter number (or 'q' to quit): 6

📝 Step 2: Processing Template
------------------------------
Loading template: iterator_collector_flow.json

Template Variables Found:
------------------------------
• $$PROMPT_MODEL_ID

🔄 Variable Replacement
Enter values for each variable:
Enter value for $$PROMPT_MODEL_ID: apac.anthropic.claude-3-5-sonnet-20241022-v2:0

✅ Template processing complete

Template Metadata:
  • Name: sample-iterator-collector-flow
  • Description: This is a template for an Iterator and Collector Node. Template demonstrates a Flow that Iterates over an array of input, sends them to prompt and collects the results for display.
  • Tags:
    - Environment: dev
    - Project: sample-bedrock-iterator-collector-flow

🚀 Step 3: Creating Flow
------------------------------
Creating flow: sample-iterator-collector-flow
Using flow name from template
Processing flow definition...
✅ Flow created successfully!
Flow ID: X3IRRIQ5W0
Flow Name: sample-iterator-collector-flow

⚙️ Step 4: Preparing Flow
------------------------------
Preparing flow...
Creating flow version...
Created version: 1
Creating flow alias...

✅ Flow preparation complete!
Flow Details:
  • Version: 1
  • Alias ID: STIEP4BVF1

🧪 Step 5: Testing Flow
------------------------------

Invoking flow...

✅ Flow execution successful! (7.13s)

📊 Flow Response:
------------------------------
Iterator Response:

[Response 1]
--------------------
╭─────────────────────────────────────────────────────────────────────────────── Text Response 1 ───────────────────────────────────────────────────────────────────────────────╮
│ Amazon Bedrock is a fully managed service offered by AWS that provides access to high-performing foundation models (FMs) from leading AI companies through a single API. Here │
│ are its key features and characteristics:                                                                                                                                     │
│                                                                                                                                                                               │
│ 1. Foundation Models Access:                                                                                                                                                  │
│ - Offers models from AI companies like Anthropic, AI21 Labs, Stability AI, and Amazon                                                                                         │
│ - Includes models for various tasks like text generation, image generation, and embedding                                                                                     │
│                                                                                                                                                                               │
│ 2. Key Benefits:                                                                                                                                                              │
│ - No need to manage infrastructure                                                                                                                                            │
│ - Pay-as-you-go pricing                                                                                                                                                       │
│ - Private and secure access to models                                                                                                                                         │
│ - Ability to customize models with your own data                                                                                                                              │
│                                                                                                                                                                               │
│ 3. Main Features:                                                                                                                                                             │
│ - Model customization through fine-tuning                                                                                                                                     │
│ - Built-in security and compliance                                                                                                                                            │
│ - Integration with AWS services                                                                                                                                               │
│ - API consistency across different models                                                                                                                                     │
│ - Private endpoints for secure access                                                                                                                                         │
│                                                                                                                                                                               │
│ 4. Use Cases:                                                                                                                                                                 │
│ - Text generation and summarization                                                                                                                                           │
│ - Code generation                                                                                                                                                             │
│ - Image generation                                                                                                                                                            │
│ - Content creation                                                                                                                                                            │
│ - Question answering                                                                                                                                                          │
│ - Language translation                                                                                                                                                        │
│                                                                                                                                                                               │
│ 5. Development Tools:                                                                                                                                                         │
│ - SDKs for various programming languages                                                                                                                                      │
│ - Integration with AWS development tools                                                                                                                                      │
│ - Support for popular ML frameworks                                                                                                                                           │
│                                                                                                                                                                               │
│ Amazon Bedrock makes it easier for developers and organizations to build AI-powered applications without having to manage the underlying infrastructure or deal with multiple │
│ model providers separately.                                                                                                                                                   │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

✨ Operation completed successfully!

https://dev.classmethod.jp/articles/amazon-bedrock-prompt-flow-templates-overview/

フローの実行

現時点ではマネジメントコンソールで nodeActionTrace を確認できなかったため、API 経由で確認します。SDK for Python (boto3) を利用して確認します。

import boto3

client = boto3.client('bedrock-agent-runtime')
response = client.invoke_flow(
    enableTrace=True,
    flowAliasIdentifier='STIEP4BVF1',
    flowIdentifier='X3IRRIQ5W0',
    inputs=[
        {
            'content': {
                'document': [ 'こんにちは!', 'おはようございます!' ],
            },
            'nodeOutputName': 'document',
            'nodeName': 'FlowInputNode'
        },
    ]
)

for event in response['responseStream']:
    print(event)

trace キーに nodeActionTrace と記載された内容が表示されていますね。この例だと LLM に Converse API を実行していることがわかります。参考までに requestIdモデル実行ログの requestId とはマッピングされておらず、独自で採番されていました。

(trace-flow-py3.12) takakuni trace-flow % python main.py             
{'ResponseMetadata': {'RequestId': 'bc56bc21-362c-48fe-aada-fa2131be122b', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Sun, 30 Mar 2025 23:56:37 GMT', 'content-type': 'application/vnd.amazon.eventstream', 'transfer-encoding': 'chunked', 'connection': 'keep-alive', 'x-amzn-requestid': 'bc56bc21-362c-48fe-aada-fa2131be122b', 'x-amz-bedrock-flow-execution-id': '55413fec-f8d8-40db-b59e-cd448c2797ff'}, 'RetryAttempts': 0}, 'executionId': '55413fec-f8d8-40db-b59e-cd448c2797ff', 'responseStream': <botocore.eventstream.EventStream object at 0x1029fcf80>}
{'flowTraceEvent': {'trace': {'nodeOutputTrace': {'fields': [{'content': {'document': ['こんにちは!', 'おはようございます!']}, 'nodeOutputName': 'document'}], 'nodeName': 'FlowInputNode', 'timestamp': datetime.datetime(2025, 3, 30, 23, 56, 37, 586241, tzinfo=tzutc())}}}}
{'flowTraceEvent': {'trace': {'nodeInputTrace': {'fields': [{'content': {'document': ['こんにちは!', 'おはようございます!']}, 'nodeInputName': 'array'}], 'nodeName': 'PromptIterator', 'timestamp': datetime.datetime(2025, 3, 30, 23, 56, 37, 586416, tzinfo=tzutc())}}}}
{'flowTraceEvent': {'trace': {'nodeOutputTrace': {'fields': [{'content': {'document': 'こんにちは!'}, 'nodeOutputName': 'arrayItem'}, {'content': {'document': 2}, 'nodeOutputName': 'arraySize'}], 'nodeName': 'PromptIterator', 'timestamp': datetime.datetime(2025, 3, 30, 23, 56, 37, 586665, tzinfo=tzutc())}}}}
{'flowTraceEvent': {'trace': {'nodeInputTrace': {'fields': [{'content': {'document': 'こんにちは!'}, 'nodeInputName': 'userPrompt'}], 'nodeName': 'PromptProcessor', 'timestamp': datetime.datetime(2025, 3, 30, 23, 56, 37, 586726, tzinfo=tzutc())}}}}
(trace-flow-py3.12) takakuni trace-flow % python main.py
{'ResponseMetadata': {'RequestId': '69388917-6517-448d-a7ef-6d2af88566bd', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Mon, 31 Mar 2025 00:41:47 GMT', 'content-type': 'application/vnd.amazon.eventstream', 'transfer-encoding': 'chunked', 'connection': 'keep-alive', 'x-amzn-requestid': '69388917-6517-448d-a7ef-6d2af88566bd', 'x-amz-bedrock-flow-execution-id': '3ca95081-ea09-4080-b781-d1e21758ef96'}, 'RetryAttempts': 0}, 'executionId': '3ca95081-ea09-4080-b781-d1e21758ef96', 'responseStream': <botocore.eventstream.EventStream object at 0x1027e5850>}
{'flowTraceEvent': {'trace': {'nodeOutputTrace': {'fields': [{'content': {'document': ['こんにちは!', 'おはようございます!']}, 'nodeOutputName': 'document'}], 'nodeName': 'FlowInputNode', 'timestamp': datetime.datetime(2025, 3, 31, 0, 41, 47, 667358, tzinfo=tzutc())}}}}
{'flowTraceEvent': {'trace': {'nodeInputTrace': {'fields': [{'content': {'document': ['こんにちは!', 'おはようございます!']}, 'nodeInputName': 'array'}], 'nodeName': 'PromptIterator', 'timestamp': datetime.datetime(2025, 3, 31, 0, 41, 47, 667592, tzinfo=tzutc())}}}}
{'flowTraceEvent': {'trace': {'nodeOutputTrace': {'fields': [{'content': {'document': 'こんにちは!'}, 'nodeOutputName': 'arrayItem'}, {'content': {'document': 2}, 'nodeOutputName': 'arraySize'}], 'nodeName': 'PromptIterator', 'timestamp': datetime.datetime(2025, 3, 31, 0, 41, 47, 667978, tzinfo=tzutc())}}}}
{'flowTraceEvent': {'trace': {'nodeInputTrace': {'fields': [{'content': {'document': 'こんにちは!'}, 'nodeInputName': 'userPrompt'}], 'nodeName': 'PromptProcessor', 'timestamp': datetime.datetime(2025, 3, 31, 0, 41, 47, 668112, tzinfo=tzutc())}}}}
{'flowTraceEvent': {'trace': {'nodeActionTrace': {'nodeName': 'PromptProcessor', 'operationName': 'Converse', 'requestId': 'ebda6d42-0ac4-4bfa-bf4c-9141622867ef', 'serviceName': 'bedrock', 'timestamp': datetime.datetime(2025, 3, 31, 0, 41, 49, 172717, tzinfo=tzutc())}}}}
{'flowTraceEvent': {'trace': {'nodeOutputTrace': {'fields': [{'content': {'document': 'こんにちは!お手伝いできることがありましたら、お気軽にお申し付けください。'}, 'nodeOutputName': 'modelCompletion'}], 'nodeName': 'PromptProcessor', 'timestamp': datetime.datetime(2025, 3, 31, 0, 41, 49, 172747, tzinfo=tzutc())}}}}
{'flowTraceEvent': {'trace': {'nodeInputTrace': {'fields': [{'content': {'document': 'こんにちは!お手伝いできることがありましたら、お気軽にお申し付けください。'}, 'nodeInputName': 'arrayItem'}, {'content': {'document': 2.0}, 'nodeInputName': 'arraySize'}], 'nodeName': 'ResponseCollector', 'timestamp': datetime.datetime(2025, 3, 31, 0, 41, 49, 172890, tzinfo=tzutc())}}}}
{'flowTraceEvent': {'trace': {'nodeOutputTrace': {'fields': [{'content': {'document': 'おはようございます!'}, 'nodeOutputName': 'arrayItem'}, {'content': {'document': 2}, 'nodeOutputName': 'arraySize'}], 'nodeName': 'PromptIterator', 'timestamp': datetime.datetime(2025, 3, 31, 0, 41, 49, 173810, tzinfo=tzutc())}}}}
{'flowTraceEvent': {'trace': {'nodeInputTrace': {'fields': [{'content': {'document': 'おはようございます!'}, 'nodeInputName': 'userPrompt'}], 'nodeName': 'PromptProcessor', 'timestamp': datetime.datetime(2025, 3, 31, 0, 41, 49, 173878, tzinfo=tzutc())}}}}
{'flowTraceEvent': {'trace': {'nodeActionTrace': {'nodeName': 'PromptProcessor', 'operationName': 'Converse', 'requestId': '15b689f8-1b70-49e4-83cd-da2ecdd5a809', 'serviceName': 'bedrock', 'timestamp': datetime.datetime(2025, 3, 31, 0, 41, 50, 509548, tzinfo=tzutc())}}}}
{'flowTraceEvent': {'trace': {'nodeOutputTrace': {'fields': [{'content': {'document': 'おはようございます!今日もよろしくお願いします。いい一日をお過ごしください。'}, 'nodeOutputName': 'modelCompletion'}], 'nodeName': 'PromptProcessor', 'timestamp': datetime.datetime(2025, 3, 31, 0, 41, 50, 509578, tzinfo=tzutc())}}}}
{'flowTraceEvent': {'trace': {'nodeInputTrace': {'fields': [{'content': {'document': 'おはようございます!今日もよろしくお願いします。いい一日をお過ごしください。'}, 'nodeInputName': 'arrayItem'}, {'content': {'document': 2.0}, 'nodeInputName': 'arraySize'}], 'nodeName': 'ResponseCollector', 'timestamp': datetime.datetime(2025, 3, 31, 0, 41, 50, 509727, tzinfo=tzutc())}}}}
{'flowTraceEvent': {'trace': {'nodeOutputTrace': {'fields': [{'content': {'document': ['こんにちは!お手伝いできることがありましたら、お気軽にお申し付けください。', 'おはようございます!今日もよろしくお願いします。いい一日をお過ごしください。']}, 'nodeOutputName': 'collectedArray'}], 'nodeName': 'ResponseCollector', 'timestamp': datetime.datetime(2025, 3, 31, 0, 41, 50, 510269, tzinfo=tzutc())}}}}
{'flowTraceEvent': {'trace': {'nodeInputTrace': {'fields': [{'content': {'document': ['こんにちは!お手伝いできることがありましたら、お気軽にお申し付けください。', 'おはようございます!今日もよろしくお願いします。いい一日をお過ごしください。']}, 'nodeInputName': 'document'}], 'nodeName': 'FlowOutput', 'timestamp': datetime.datetime(2025, 3, 31, 0, 41, 50, 510382, tzinfo=tzutc())}}}}
{'flowOutputEvent': {'content': {'document': ['こんにちは!お手伝いできることがありましたら、お気軽にお申し付けください。', 'おはようございます!今日もよろしくお願いします。いい一日をお過ごしください。']}, 'nodeName': 'FlowOutput'}}
{'flowCompletionEvent': {'completionReason': 'SUCCESS'}}

なお、エージェントが紐づけられたフローでは以下のように InvokeAgent が nodeActionTrace に記録されていました。

(trace-flow-py3.12) takakuni trace-flow % python main.py
{'ResponseMetadata': {'RequestId': '16701eba-5f58-4308-961e-e483e62d3721', 'HTTPStatusCode': 200, 'HTTPHeaders': {'date': 'Mon, 31 Mar 2025 00:43:09 GMT', 'content-type': 'application/vnd.amazon.eventstream', 'transfer-encoding': 'chunked', 'connection': 'keep-alive', 'x-amzn-requestid': '16701eba-5f58-4308-961e-e483e62d3721', 'x-amz-bedrock-flow-execution-id': '2a8b3855-ab29-4ec1-ba94-2dd64e0aa462'}, 'RetryAttempts': 0}, 'executionId': '2a8b3855-ab29-4ec1-ba94-2dd64e0aa462', 'responseStream': <botocore.eventstream.EventStream object at 0x10b30f1d0>}
{'flowTraceEvent': {'trace': {'nodeOutputTrace': {'fields': [{'content': {'document': 'こんにちは!'}, 'nodeOutputName': 'document'}], 'nodeName': 'FlowInputNode', 'timestamp': datetime.datetime(2025, 3, 31, 0, 43, 9, 156044, tzinfo=tzutc())}}}}
{'flowTraceEvent': {'trace': {'nodeInputTrace': {'fields': [{'content': {'document': 'こんにちは!'}, 'nodeInputName': 'agentInputText'}], 'nodeName': 'AgentsNode_1', 'timestamp': datetime.datetime(2025, 3, 31, 0, 43, 9, 156158, tzinfo=tzutc())}}}}
{'flowTraceEvent': {'trace': {'nodeActionTrace': {'nodeName': 'AgentsNode_1', 'operationName': 'bedrock:InvokeAgent', 'requestId': '06f5da74-da22-454f-9348-3c44b20e1500', 'serviceName': 'bedrock', 'timestamp': datetime.datetime(2025, 3, 31, 0, 43, 12, 120093, tzinfo=tzutc())}}}}
{'flowTraceEvent': {'trace': {'nodeOutputTrace': {'fields': [{'content': {'document': 'こんにちは!お助けロボットです。どのようなことでお手伝いできますか?何か質問や困っていることがあれば、お気軽にお聞かせください。'}, 'nodeOutputName': 'agentResponse'}], 'nodeName': 'AgentsNode_1', 'timestamp': datetime.datetime(2025, 3, 31, 0, 43, 12, 120130, tzinfo=tzutc())}}}}
{'flowTraceEvent': {'trace': {'nodeInputTrace': {'fields': [{'content': {'document': 'こんにちは!お助けロボットです。どのようなことでお手伝いできますか?何か質問や困っていることがあれば、お気軽にお聞かせください。'}, 'nodeInputName': 'document'}], 'nodeName': 'FlowOutputNode', 'timestamp': datetime.datetime(2025, 3, 31, 0, 43, 12, 120304, tzinfo=tzutc())}}}}
{'flowOutputEvent': {'content': {'document': 'こんにちは!お助けロボットです。どのようなことでお手伝いできますか?何か質問や困っていることがあれば、お気軽にお聞かせください。'}, 'nodeName': 'FlowOutputNode'}}
{'flowCompletionEvent': {'completionReason': 'SUCCESS'}}

まとめ

以上、「Amazon Bedrock Flows のトレースでアクション内容を記録する nodeActionTrace が表示されるようになりました。」でした。

各ノード間のデータの入出力から、さらにブレイクダウンしてトレースを終えるようになっていて地味に嬉しいですね。

このブログがどなたかの参考になれば幸いです。クラウド事業本部コンサルティング部のたかくに(@takakuni_)でした!

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.