[Amazon Lex] PostContent及び、PostTextにおける、現在の会話の状態について確認してみました。

2019.04.02

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

1 はじめに

こんにんちは、AIソリューション部の平内(SIN)です。

Amazon Lex(以下、Lex)のAPIでは、PostContent及び、PostTextを使用して、ボットとの会話が可能ですが、このAPIのレスポンスに、dialogStateというエレメントがあります。

dialogStateは、ユーザーとの会話の現在の状態を表現するもので、クライアントは、この値に基づいて、適切なUIを提供することができます。

今回は、このエレメントについて確認してみました。

2 Valid Values

dialogStateは、取りうる値は、以下の6つです。

  • ElicitIntent - インテント不明(まだ、該当するインテントが見つからない場合は、このステータスが返される)
  • ConfirmIntent - インテント完了の確認(インテントの完了時、その内容に問題がないかどうかを確認するため、「YES」若しくは、「NO」のレスポンスを期待している)
  • ElicitSlot - スロット入力(スロット値の入力を期待している)
  • Failed - 会話失敗(指定回数を超えて要求に答えられなかった)
  • Fulfilled - インテントが完了した事を伝える
  • ReadyForFulfillment - 後の処理は、クライアントが処理する必要があることを伝える

3 実際の例

サンプルボットとして提供されているであるOrderFlowersを使用して、各種のdialogStateが返される状況を確認してみました。

Lexのクライアントは、下記のものを使用しました。

[Amazon Lex] HTML+JavaScriptでLexクライアントを作ってみました

(1) ElicitIntent

ユーザーが、「good night」と発話していますが、Sample utterancesにヒットするインテントが見つからないため、当該インテントが見つからないということで、ElicitIntentが返されています。

{
"intentName": null,
"sessionAttributes": {},
"message": "I didn't understand you, what would you like to do?",
"messageFormat": "PlainText",
"dialogState": "ElicitIntent",
"slotToElicit": null
}

(2) ElicitSlot

ユーザーの「I would like to pick up flowers」と言う発話が、OrderFlowersインテントにヒットしたため、そこで指定されているスロットの値を回収しようとしています。

slotToElicitFlowerTypeが入っていることから、注文したい花の種類を聞く状態になっています。

{
"intentName": "OrderFlowers",
"slots": {
"FlowerType": null,
"PickupDate": null,
"PickupTime": null
},
"sessionAttributes": {},
"message": "What type of flowers would you like to order?",
"messageFormat": "PlainText",
"dialogState": "ElicitSlot",
"slotToElicit": "FlowerType"
}

(3) ConfirmIntent

必要なスロットが全部揃ったので、内容に問題ないかをユーザーに問い合わせています。「YES」若しくは、「NO」の返答を期待しています。

{
"intentName": "OrderFlowers",
"slots": {
"FlowerType": "roses",
"PickupDate": "2019-04-02",
"PickupTime": "16:00"
},
"sessionAttributes": {},
"message": "Okay, your roses will be ready for pickup by 16:00 on 2019-04-02. Does this sound okay?",
"messageFormat": "PlainText",
"dialogState": "ConfirmIntent",
"slotToElicit": null
}

(4) Fulfilled

ConfirmIntentに対して、「YES」を返し、インテントが完了したということでFulfilledとなっています。

{
"intentName": "OrderFlowers",
"slots": {
"FlowerType": "roses",
"PickupDate": "2019-04-02",
"PickupTime": "21:00"
},
"sessionAttributes": {},
"message": "Thanks, your order for roses has been placed and will be ready for pickup by 21:00 on 2019-04-02",
"messageFormat": "PlainText",
"dialogState": "Fulfilled",
"slotToElicit": null
}

(5) Failed

注文を取りに来る時間を聞いているのに、無効な回答を続けたため、「失敗」を返しています。

{
"intentName": "OrderFlowers",
"slots": {
"FlowerType": "roses",
"PickupDate": "2019-04-02",
"PickupTime": null
},
"sessionAttributes": {},
"message": "Sorry, I am not able to assist at this time",
"messageFormat": "PlainText",
"dialogState": "Failed",
"slotToElicit": null
}

ConfirmIntentに対する返答が「NO」であった場合も、インテントの失敗ということで、Failedが返されています。

{
"intentName": "OrderFlowers",
"slots": {
"FlowerType": "yes",
"PickupDate": "2019-04-01",
"PickupTime": "18:00"
},
"sessionAttributes": {},
"message": "Okay, I will not place your order.",
"messageFormat": "PlainText",
"dialogState": "Failed",
"slotToElicit": null
}

(6) ReadyForFulfillment

下記のように、FulfillmentにLambdaファンクションを設定せず、また、返すメッセージなども指定していない場合、インテント完了時の処理は、クライアントに委ねられることになります。

以下が、その例です。

ConfirmIntentに対して、「YES」を返した後に、ReadyForFulfillmentが返っています。この時、messageもnullなので、何らかの処理をクライアントでまるっと実装する必要があるでしょう。

{
"intentName": "OrderFlowers",
"slots": {
"FlowerType": "roses",
"PickupDate": "2019-04-02",
"PickupTime": "15:00"
},
"sessionAttributes": {},
"message": null,
"messageFormat": null,
"dialogState": "ReadyForFulfillment",
"slotToElicit": null
}

4 最後に

今回は、PostContent及び、PostTextのレスポンスに含まれるdialogStateについて確認してみました。

Lexの場合は、Alexaと違って、クライアント側の実装についても検討する必要が出てきます。そんな中、会話の現在の状態を表現する、dialogStateを適切に処理することは、非常に重要となるでしょう。

5 参考リンク

Amazon Lex Runtime Service » PostContent

Amazon Lex Runtime Service » PostText


弊社ではAmazon Connectのキャンペーンを行なっております。

3月に引き続き、4月も「無料Amazon Connectハンズオンセミナー」を開催致します。導入を検討されておられる方は、是非、お申し込み下さい。

また音声を中心とした各種ソリューションの開発支援も行なっております。