スマート作成

スマート作成機能は、エンドユーザーとのテキスト チャット中に人間のエージェントを支援します。人間のエージェントが書き始めた文を完成させるフレーズを提案します。この機能を使用すると、エージェントのチャット インターフェースにカスタムの提案機能を実装できます。

人間のエージェントがチャット インターフェースで入力しているときに、テキストの候補が表示される。 このガイドでは、API を直接呼び出してスマート作成機能を実装する方法について説明します。必要に応じて、Agent Assist コンソールを使用してモデルをトレーニングし、シミュレータを使用してモデルのパフォーマンスをテストすることもできます。手順については、スマート作成シミュレータのチュートリアルをご覧ください。

スマート作成を独自のシステムに統合し、候補の品質を向上させるためのガイドラインについては、スマート作成のベスト プラクティスに関するドキュメントをご覧ください。

始める前に

このガイドを読む前に、次のことを完了してください。

  1. プロジェクトで Dialog Flow API を有効にします。

個人を特定できる情報と子供のデータ

この API にデータを送信すると、API はすべての個人情報(PII)を削除しようとします。モデルに個人情報が含まれていないことを保証する必要がある場合は、API に送信する前にデータをサニタイズする必要があります。単に削除するのではなく、編集された単語を `REDACTED_NUMBER` や `REDACTED_NAME` などのプレースホルダに置き換えます。

また、データに子から収集した情報が含まれている場合は、API に送信する前に子のデータを削除する必要があります。

モデルのトレーニングとデプロイ

Agent Assist スマート リプライ モデルは、会話データセットを使用してトレーニングされます。会話データセットには、アップロードした独自の音声文字変換データが含まれています。このセクションでは、会話データセットの作成、会話データのアップロード、モデルのトレーニングとデプロイの手順について説明します。API を直接呼び出したくない場合は、Agent Assist コンソールを使用してこれらの操作を行うこともできます。

会話データセットを作成する

会話の文字起こしのアップロードを開始する前に、まずこういった文字起こしを配置する会話データセットを作成する必要があります。ConversationDataset リソースの create メソッドを呼び出して、会話データセットを作成します。

レスポンスには会話データセット ID が含まれます。

会話の文字起こしを会話データセットにインポートする

チャットの会話データを会話データセットにアップロードして、Agent Assist で処理できるようにします。各会話の文字起こしが JSON 形式Cloud Storage バケットに保存されていることを確認します。会話データセットには 30,000 件以上の会話が含まれている必要があります。そうでない場合、モデルのトレーニングは失敗します。一般に、会話が多いほど、モデルの品質は向上します。できるだけ多くのユースケースを十分にカバーするため、少なくとも 3 か月分の会話をアップロードすることをおすすめします。会話データセット内のメッセージの最大数は 1,000,000 です。

ConversationDataset リソースの importConversationData メソッドを呼び出して、会話をインポートします。

必須フィールド:

  • 以前に作成した会話データセット ID。
  • inputConfig パスは、Cloud Storage バケット内の会話文字起こしデータにつながります。

レスポンスは長時間実行オペレーションです。ポーリングして完了を確認できます。

会話モデルを作成する

ConversationModel リソースの create メソッドを呼び出して、会話モデルを作成します。このアクションでは、モデルの許可リストも作成されます。

必須フィールド:

  • datasets で、前に作成した会話データセット ID を使用して、単一のデータセットを指定します。
  • smartReplyModelMetadata を空のオブジェクトに設定するか、フィールドに入力してデフォルトをオーバーライドします。

レスポンスは長時間実行オペレーションです。ポーリングして完了を確認できます。完了すると、モデル ID と許可リスト ID がオペレーションのメタデータに含まれます。

  • モデル ID: name
  • 許可リスト ID: smart_reply_model_metadata.associated_allowlist_info.document

会話モデルをデプロイする

ConversationModel リソースで deploy メソッドを呼び出して、会話モデルをデプロイします。

必須フィールド:

  • conversationModels を使用: 以前に作成した会話モデル ID を入力します。

許可リストを管理する

各モデルには、会話モデルの作成時に自動的に作成される許可リストが関連付けられています。許可リストには、会話データセットから生成され、実行時に人間のエージェントに表示できるすべてのレスポンスが含まれています。このセクションでは、許可リストの作成と管理について説明します。API を直接呼び出したくない場合は、Agent Assist コンソールを使用してこれらの操作を行うこともできます。

許可リストの内容を CSV ファイルにエクスポートする

モデルを作成すると、新しいモデルに関連付けられた許可リストが自動的に作成されます。許可リストは、一意の ID を持つドキュメント リソースです。ID は、モデルの作成時に smart_reply_model_metadata.associated_allowlist_info.document で返されます。許可リストのメッセージを確認して変更するには、Cloud Storage バケットにエクスポートする必要があります。

Document リソースで export メソッドを呼び出して、ドキュメントを Cloud Storage バケット内の CSV ファイルにエクスポートします。smart_messaging_partial_update フィールドは省略可能ですが、今後この許可リストを更新する方法に影響します。true に設定すると、エクスポートされた CSV ファイルに、各メッセージの一意の ID を含む列が含まれます。メッセージ ID を使用すると、ドキュメント全体ではなく、指定したメッセージのみを更新できます。smart_messaging_partial_updatefalse に設定されているか、設定されていない場合、ファイルに余分な列は表示されず、許可リストの更新にはドキュメント全体の更新が必要になります。

必須フィールド:

  • gcsDestination パスは Cloud Storage バケットに移動します。

レスポンスは長時間実行オペレーションです。ポーリングして完了を確認できます。その後、リクエストで指定した CSV ファイルにレスポンス候補が入力されます。

許可リストを確認する

生成された許可リストには、会話データに基づいてスマート リプライによって自動的に生成された返信が含まれています。これらの回答を確認し、必要に応じて更新できるようになりました。Cloud Storage バケットから CSV ファイルをダウンロードし、ニーズに合わせて編集して、Cloud Storage バケットにアップロードします。許可リストに登録されている回答のみが人間のエージェントに表示されます。

回答を編集する場合は、スペルと文法に限定し、メッセージの意味は変更しないことをおすすめします。編集されたテキストがモデルの意味から離れているほど、メッセージが表示される可能性が少なくなります。

必要に応じて、新しいメッセージを作成することもできます。編集されたメッセージと同様に、作成されたメッセージは実行中に表示される可能性が低くなります。

許可リストを更新する

CSV ファイルの更新が完了したら、それを使用して Document リソースを更新できます。許可リスト全体を更新するか、指定したメッセージのみを更新するかを選択できます。指定したメッセージのみを更新するには、許可リストをエクスポートしたときに smart_messaging_partial_updatetrue に設定しておく必要があります。すでにこの操作を行っている場合は、エクスポートされた CSV ファイルで自動生成された列を使用して、更新するメッセージを指定します。

Document リソースで reload メソッドを呼び出して、許可リストを更新します。指定されたメッセージのみを更新するには、ReloadDocumentRequestsmart_messaging_partial_updatetrue に設定します。許可リスト全体を更新するには、smart_messaging_partial_update を未設定のままにするか、false に設定します。

必須フィールド:

  • gcsSource は、CSV ファイルの Cloud Storage パスです。
  • name には、会話モデルを作成したときに生成された許可リストのリソース名を使用します。

リクエストの例:

{
  "name":"projects/project-id/knowledgeBases/knowledge-base-id/documents/allowlist-id",
  "gcsSource" {
      "uri": "gs://revised_smart_reply_allowlist_path"
   }
}

トレーニング済みモデルのパフォーマンスを評価する

モデルをデプロイして、そのモデルの許可リストを作成したら、モデルのパフォーマンスをテストできます。また、テスト データセットも指定する必要があります。トレーニング済みのスマート リプライ モデルとその関連する許可リストによって生成されたレスポンスが、テスト データセット内の実際のエージェント メッセージと比較されます。テスト データセットは実際の会話データで構成する必要がありますが、モデルのトレーニングに使用した会話データセットのデータを含んではなりません。たとえば、1 か月分の会話トラフィックがある場合、3 週間分の会話データを使用して会話データセットを作成し、残りの 1 週間分のデータを使用してテスト データセットを作成できます。テスト データセットには 1, 000 件以上の会話を含める必要がありますが、一般的に、テスト データセットの会話が多いほど、評価指標の信頼性が高くなります。テスト データセットの形式は、会話データセットの形式と同じです。

新しいモデル評価を作成するには、ConversationModel リソースの CreateConversationModelEvaluation メソッドを呼び出します。このメソッドは、長時間実行オペレーションを返します。オペレーションをポーリングして状態を確認できます。状態は INITIALIZINGRUNNINGSUCCEEDEDCANCELLEDFAILED のいずれかで返されます。

必須フィールド:

  • InputDataset: モデルのパフォーマンスをテストするために使用されるテスト データセット。
  • allowlist_document: テストするスマート リプライ モデルに関連付けられた許可リスト。

長時間実行オペレーションが完了すると、ConversationModelEvaluation リソースが返されます。次の 2 つの指標が含まれています。

  • allowlist_coverage: 許可リストでカバーされているテスト データセット内のエージェント メッセージの割合。
  • recall: テスト データセット内のエージェント メッセージのうち、許可リストに含まれており、スマート リプライ モデルによって表示された上位 3 つの候補に表示されるものの割合。

会話プロファイルを構成する

会話プロファイルでは、会話中にエージェントに提示される候補を制御する一連のパラメータを構成します。次の手順では、HumanAgentAssistantConfig オブジェクトを使用して ConversationProfile を作成します。API を直接呼び出したくない場合は、Agent Assist コンソールを使用してこれらの操作を行うこともできます。

会話プロファイルを作成する

会話プロファイルを作成するには、ConversationProfile リソースの create メソッドを呼び出します。ナレッジベース ID、ドキュメント ID、プロジェクト ID、モデル ID を指定します。

JSON の例を次に示します。
{
  "displayName": "smart_compose_assist",
  "humanAgentAssistantConfig": {
    "humanAgentSuggestionConfig": {
      "featureConfigs": [
        {
          "suggestionFeature": {
            "type": "SMART_COMPOSE"
          },
          "queryConfig": {
            "documentQuerySource": {
              "documents": "projects/PROJECT_ID/knowledgeBases/KNOWLEDGE_BASE_ID/documents/DOCUMENT_ID"
            },
           "maxResults": "1"
          },
         "conversationModelConfig": {
           "model": "projects/PROJECT_ID/conversationModels/MODEL_ID"
         }
        }
      ]
    }
  }
}

レスポンスには、新しい会話プロフィール ID が含まれます。

ランタイムに会話を処理する

エンドユーザーと人間のエージェントとの会話が開始されると、会話が作成されます。候補を表示するには、エンドユーザーの参加者と人間のエージェントの参加者を両方とも作成して、会話に加える必要があります。以下のセクションでは、このプロセスについて詳しく説明します。

会話を作成する

会話を作成するには、Conversation リソースの create メソッドを呼び出します。

REST

リクエストのデータを使用する前に、次のように置き換えます。

  • PROJECT_ID: 実際の Cloud プロジェクトの ID
  • LOCATION_ID: 地域 ID
  • CONVERSATION_PROFILE_ID: 会話プロファイルの作成時に受け取った ID

HTTP メソッドと URL:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/locations/LOCATION_ID/conversations

リクエストの本文(JSON):

{
  "conversationProfile": "projects/PROJECT_ID/locations/LOCATION_ID/conversationProfiles/CONVERSATION_PROFILE_ID",
}

リクエストを送信するには、次のいずれかのオプションを展開します。

次のような JSON レスポンスが返されます。

{
  "name": "projects/PROJECT_ID/locations/LOCATION_ID/conversations/CONVERSATION_ID",
  "lifecycleState": "IN_PROGRESS",
  "conversationProfile": "projects/PROJECT_ID/locations/LOCATION_ID/conversationProfiles/CONVERSATION_PROFILE_ID",
  "startTime": "2018-11-05T21:05:45.622Z"
}

conversations の後のパスセグメントには、新しい会話 ID が含まれます。

Python

Agent Assist に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

def create_conversation(project_id, conversation_profile_id):
    """Creates a conversation with given values

    Args:
        project_id:  The GCP project linked with the conversation.
        conversation_profile_id: The conversation profile id used to create
        conversation."""

    client = dialogflow.ConversationsClient()
    conversation_profile_client = dialogflow.ConversationProfilesClient()
    project_path = client.common_project_path(project_id)
    conversation_profile_path = conversation_profile_client.conversation_profile_path(
        project_id, conversation_profile_id
    )
    conversation = {"conversation_profile": conversation_profile_path}
    response = client.create_conversation(
        parent=project_path, conversation=conversation
    )

    print("Life Cycle State: {}".format(response.lifecycle_state))
    print("Conversation Profile Name: {}".format(response.conversation_profile))
    print("Name: {}".format(response.name))
    return response

エンドユーザーの参加者を作成する

候補を表示するには、エンドユーザーと人間のエージェントの両方の参加者を会話に追加する必要があります。エンドユーザーの参加者を作成するには、Participant リソースの create メソッドを呼び出します。role フィールドに会話 ID と END_USER を指定します。

REST

リクエストのデータを使用する前に、次のように置き換えます。

  • PROJECT_ID: 実際の Cloud プロジェクトの ID
  • LOCATION_ID: 地域 ID
  • CONVERSATION_ID: 会話 ID

HTTP メソッドと URL:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/locations/LOCATION_ID/conversations/CONVERSATION_ID/participants

リクエストの本文(JSON):

{
  "role": "END_USER",
}

リクエストを送信するには、次のいずれかのオプションを展開します。

次のような JSON レスポンスが返されます。

{
  "name": "projects/PROJECT_ID/locations/LOCATION_ID/conversations/CONVERSATION_ID/participants/PARTICIPANT_ID",
  "role": "END_USER"
}

participants の後のパスセグメントには、新しいエンドユーザー参加者 ID が含まれます。

Python

Agent Assist に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

def create_participant(project_id: str, conversation_id: str, role: str):
    from google.cloud import dialogflow_v2beta1 as dialogflow

    """Creates a participant in a given conversation.

    Args:
        project_id: The GCP project linked with the conversation profile.
        conversation_id: Id of the conversation.
        participant: participant to be created."""

    client = dialogflow.ParticipantsClient()
    conversation_path = dialogflow.ConversationsClient.conversation_path(
        project_id, conversation_id
    )
    if role in ROLES:
        response = client.create_participant(
            parent=conversation_path, participant={"role": role}, timeout=600
        )
        print("Participant Created.")
        print(f"Role: {response.role}")
        print(f"Name: {response.name}")

        return response

人間のエージェントの参加者を作成する

人間のエージェントの参加者を作成するには、Participant リソースの create メソッドを呼び出します。role フィールドに会話 ID と HUMAN_AGENT を指定します。

REST

リクエストのデータを使用する前に、次のように置き換えます。

  • PROJECT_ID: 実際の Cloud プロジェクトの ID
  • LOCATION_ID: 地域 ID
  • CONVERSATION_ID: 会話 ID

HTTP メソッドと URL:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/locations/LOCATION_ID/conversations/CONVERSATION_ID/participants

リクエストの本文(JSON):

{
  "role": "HUMAN_AGENT",
}

リクエストを送信するには、次のいずれかのオプションを展開します。

次のような JSON レスポンスが返されます。

{
  "name": "projects/PROJECT_ID/locations/LOCATION_ID/conversations/CONVERSATION_ID/participants/PARTICIPANT_ID",
  "role": "HUMAN_AGENT"
}

participants の後のパスセグメントには、新しい人間のエージェントの参加者 ID が含まれます。

Python

Agent Assist に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

def create_participant(project_id: str, conversation_id: str, role: str):
    from google.cloud import dialogflow_v2beta1 as dialogflow

    """Creates a participant in a given conversation.

    Args:
        project_id: The GCP project linked with the conversation profile.
        conversation_id: Id of the conversation.
        participant: participant to be created."""

    client = dialogflow.ParticipantsClient()
    conversation_path = dialogflow.ConversationsClient.conversation_path(
        project_id, conversation_id
    )
    if role in ROLES:
        response = client.create_participant(
            parent=conversation_path, participant={"role": role}, timeout=600
        )
        print("Participant Created.")
        print(f"Role: {response.role}")
        print(f"Name: {response.name}")

        return response

人間のエージェントからのメッセージを追加して分析する

いずれかの参加者が会話でメッセージを入力するたびに、API にメッセージを送信して処理する必要があります。Agent Assist は、人間のエージェントとエンドユーザー メッセージの分析に基づいて提案を行います。会話の人間のエージェント メッセージを追加して分析するには、Participant リソースの analyzeContent メソッドを呼び出します。会話 ID と人間のエージェントの参加者 ID を指定します。

REST

リクエストのデータを使用する前に、次のように置き換えます。

  • PROJECT_ID: GCP プロジェクト ID
  • CONVERSATION_ID: 会話 ID
  • PARTICIPANT_ID: 人間のエージェントの参加者 ID

HTTP メソッドと URL:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/conversations/CONVERSATION_ID/participants/PARTICIPANT_ID:analyzeContent

リクエストの本文(JSON):

{
  "textInput": {
    "text": "How may I help you?",
    "languageCode": "en-US"
  }
}

リクエストを送信するには、次のいずれかのオプションを展開します。

次のような JSON レスポンスが返されます。

{
  "message": {
    "name": "projects/PROJECT_ID/conversations/CONVERSATION_ID/messages/MESSAGE_ID",
    "content": "How may I help you?",
    "languageCode": "en-US",
    "participant": "PARTICIPANT_ID",
    "participantRole": "HUMAN_AGENT",
    "createTime": "2020-02-13T00:01:30.683Z"
  },
  "humanAgentSuggestionResults": [
    {
      "suggestSmartRepliesResponse": {
      "smartReplyAnswers": [
          {
            "reply": "I am here to help you.",
            "confidence": 0.5,
            "answerRecord": "projects/PROJECT_ID/answerRecords/ANSWER_RECORD_ID_1"
          },
          {
            "reply": "Sorry for the wait, we have a high volume of chats right now.",
            "confidence": 0.3,
            "answerRecord": "projects/PROJECT_ID/answerRecords/ANSWER_RECORD_ID_2"
          },
          {
            "reply": "Thank you for contacting us!",
            "confidence": 0.1,
            "answerRecord": "projects/PROJECT_ID/answerRecords/ANSWER_RECORD_ID_3"
          }
        ]
      }
    }
  ]
}

Python

Agent Assist に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

def analyze_content_text(
    project_id: str, conversation_id: str, participant_id: str, text: str
):
    from google.cloud import dialogflow_v2beta1 as dialogflow

    """Analyze text message content from a participant.

    Args:
        project_id: The GCP project linked with the conversation profile.
        conversation_id: Id of the conversation.
        participant_id: Id of the participant.
        text: the text message that participant typed."""

    client = dialogflow.ParticipantsClient()
    participant_path = client.participant_path(
        project_id, conversation_id, participant_id
    )
    text_input = {"text": text, "language_code": "en-US"}
    response = client.analyze_content(
        participant=participant_path, text_input=text_input
    )
    print("AnalyzeContent Response:")
    print(f"Reply Text: {response.reply_text}")

    for suggestion_result in response.human_agent_suggestion_results:
        if suggestion_result.error is not None:
            print(f"Error: {suggestion_result.error.message}")
        if suggestion_result.suggest_articles_response:
            for answer in suggestion_result.suggest_articles_response.article_answers:
                print(f"Article Suggestion Answer: {answer.title}")
                print(f"Answer Record: {answer.answer_record}")
        if suggestion_result.suggest_faq_answers_response:
            for answer in suggestion_result.suggest_faq_answers_response.faq_answers:
                print(f"Faq Answer: {answer.answer}")
                print(f"Answer Record: {answer.answer_record}")
        if suggestion_result.suggest_smart_replies_response:
            for (
                answer
            ) in suggestion_result.suggest_smart_replies_response.smart_reply_answers:
                print(f"Smart Reply: {answer.reply}")
                print(f"Answer Record: {answer.answer_record}")

    for suggestion_result in response.end_user_suggestion_results:
        if suggestion_result.error:
            print(f"Error: {suggestion_result.error.message}")
        if suggestion_result.suggest_articles_response:
            for answer in suggestion_result.suggest_articles_response.article_answers:
                print(f"Article Suggestion Answer: {answer.title}")
                print(f"Answer Record: {answer.answer_record}")
        if suggestion_result.suggest_faq_answers_response:
            for answer in suggestion_result.suggest_faq_answers_response.faq_answers:
                print(f"Faq Answer: {answer.answer}")
                print(f"Answer Record: {answer.answer_record}")
        if suggestion_result.suggest_smart_replies_response:
            for (
                answer
            ) in suggestion_result.suggest_smart_replies_response.smart_reply_answers:
                print(f"Smart Reply: {answer.reply}")
                print(f"Answer Record: {answer.answer_record}")

    return response

エンドユーザーからのメッセージの追加と分析

エンドユーザー メッセージを会話に追加して分析するには、Participant リソースの analyzeContent メソッドを呼び出します。会話 ID とエンドユーザー参加者 ID を指定します。

レスポンスにはメッセージ ID が含まれます。提案は次のステップで取得されます。

REST

リクエストのデータを使用する前に、次のように置き換えます。

  • PROJECT_ID: GCP プロジェクト ID
  • CONVERSATION_ID: 会話 ID
  • PARTICIPANT_ID: エンドユーザーの参加者 ID

HTTP メソッドと URL:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/conversations/CONVERSATION_ID/participants/PARTICIPANT_ID:analyzeContent

リクエストの本文(JSON):

{
  "textInput": {
    "text": "I want to reserve a room.",
    "languageCode": "en-US"
  }
}

リクエストを送信するには、次のいずれかのオプションを展開します。

次のような JSON レスポンスが返されます。

{
  "message": {
    "name": "projects/PROJECT_ID/conversations/CONVERSATION_ID/messages/MESSAGE_ID",
    "content": "I want to reserve a room.",
    "languageCode": "en-US",
    "participant": "PARTICIPANT_ID",
    "participantRole": "END_USER",
    "createTime": "2020-02-13T00:07:35.925Z"
  },
  "humanAgentSuggestionResults": [
    {
      "suggestSmartRepliesResponse": {
      "smartReplyAnswers": [
          {
            "reply": "Where would you like to reserve a room?",
            "confidence": 0.5,
            "answerRecord": "projects/PROJECT_ID/answerRecords/ANSWER_RECORD_ID_1"
          },
          {
            "reply": "What type of rooms would you like to reserve?",
            "confidence": 0.3,
            "answerRecord": "projects/PROJECT_ID/answerRecords/ANSWER_RECORD_ID_2"
          },
          {
            "reply": "How long do you want to stay?",
            "confidence": 0.1,
            "answerRecord": "projects/PROJECT_ID/answerRecords/ANSWER_RECORD_ID_3"
          }
        ]
      }
    }
  ]
}

Python

Agent Assist に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

def analyze_content_text(
    project_id: str, conversation_id: str, participant_id: str, text: str
):
    from google.cloud import dialogflow_v2beta1 as dialogflow

    """Analyze text message content from a participant.

    Args:
        project_id: The GCP project linked with the conversation profile.
        conversation_id: Id of the conversation.
        participant_id: Id of the participant.
        text: the text message that participant typed."""

    client = dialogflow.ParticipantsClient()
    participant_path = client.participant_path(
        project_id, conversation_id, participant_id
    )
    text_input = {"text": text, "language_code": "en-US"}
    response = client.analyze_content(
        participant=participant_path, text_input=text_input
    )
    print("AnalyzeContent Response:")
    print(f"Reply Text: {response.reply_text}")

    for suggestion_result in response.human_agent_suggestion_results:
        if suggestion_result.error is not None:
            print(f"Error: {suggestion_result.error.message}")
        if suggestion_result.suggest_articles_response:
            for answer in suggestion_result.suggest_articles_response.article_answers:
                print(f"Article Suggestion Answer: {answer.title}")
                print(f"Answer Record: {answer.answer_record}")
        if suggestion_result.suggest_faq_answers_response:
            for answer in suggestion_result.suggest_faq_answers_response.faq_answers:
                print(f"Faq Answer: {answer.answer}")
                print(f"Answer Record: {answer.answer_record}")
        if suggestion_result.suggest_smart_replies_response:
            for (
                answer
            ) in suggestion_result.suggest_smart_replies_response.smart_reply_answers:
                print(f"Smart Reply: {answer.reply}")
                print(f"Answer Record: {answer.answer_record}")

    for suggestion_result in response.end_user_suggestion_results:
        if suggestion_result.error:
            print(f"Error: {suggestion_result.error.message}")
        if suggestion_result.suggest_articles_response:
            for answer in suggestion_result.suggest_articles_response.article_answers:
                print(f"Article Suggestion Answer: {answer.title}")
                print(f"Answer Record: {answer.answer_record}")
        if suggestion_result.suggest_faq_answers_response:
            for answer in suggestion_result.suggest_faq_answers_response.faq_answers:
                print(f"Faq Answer: {answer.answer}")
                print(f"Answer Record: {answer.answer_record}")
        if suggestion_result.suggest_smart_replies_response:
            for (
                answer
            ) in suggestion_result.suggest_smart_replies_response.smart_reply_answers:
                print(f"Smart Reply: {answer.reply}")
                print(f"Answer Record: {answer.answer_record}")

    return response

候補を取得する(省略可)

候補はいつでもオフにできます。必要に応じて、メッセージ ID を指定して、そのメッセージに基づく候補を受け取ることができます。このフィールドが設定されていない場合、デフォルトではいずれかの参加者の最新のメッセージに基づいて候補が表示されます。候補を取得するには、Suggestion リソースの suggestSmartReplies メソッドを呼び出します。会話 ID、人間のエージェントの参加者 ID、参加者のメッセージ ID(省略可)を指定します。

レスポンスには、人間のエージェント向けのスマート リプライの返信文の候補が含まれます。

REST

リクエストのデータを使用する前に、次のように置き換えます。

  • PROJECT_ID: GCP プロジェクト ID
  • CONVERSATION_ID: 会話 ID
  • PARTICIPANT_ID: エンドユーザーの参加者 ID

HTTP メソッドと URL:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/conversations/CONVERSATION_ID/participants/PARTICIPANT_ID:analyzeContent

リクエストの本文(JSON):

{
  "textInput": {
    "text": "I want to reserve a room.",
    "languageCode": "en-US"
  }
}

リクエストを送信するには、次のいずれかのオプションを展開します。

次のような JSON レスポンスが返されます。

{
  "message": {
    "name": "projects/PROJECT_ID/conversations/CONVERSATION_ID/messages/MESSAGE_ID",
    "content": "I want to reserve a room.",
    "languageCode": "en-US",
    "participant": "PARTICIPANT_ID",
    "participantRole": "END_USER",
    "createTime": "2020-02-13T00:07:35.925Z"
  },
  "humanAgentSuggestionResults": [
    {
      "suggestSmartRepliesResponse": {
      "smartReplyAnswers": [
          {
            "reply": "Where would you like to reserve a room?",
            "confidence": 0.5,
            "answerRecord": "projects/PROJECT_ID/answerRecords/ANSWER_RECORD_ID_1"
          },
          {
            "reply": "What type of rooms would you like to reserve?",
            "confidence": 0.3,
            "answerRecord": "projects/PROJECT_ID/answerRecords/ANSWER_RECORD_ID_2"
          },
          {
            "reply": "How long do you want to stay?",
            "confidence": 0.1,
            "answerRecord": "projects/PROJECT_ID/answerRecords/ANSWER_RECORD_ID_3"
          }
        ]
      }
    }
  ]
}

Python

Agent Assist に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

def analyze_content_text(
    project_id: str, conversation_id: str, participant_id: str, text: str
):
    from google.cloud import dialogflow_v2beta1 as dialogflow

    """Analyze text message content from a participant.

    Args:
        project_id: The GCP project linked with the conversation profile.
        conversation_id: Id of the conversation.
        participant_id: Id of the participant.
        text: the text message that participant typed."""

    client = dialogflow.ParticipantsClient()
    participant_path = client.participant_path(
        project_id, conversation_id, participant_id
    )
    text_input = {"text": text, "language_code": "en-US"}
    response = client.analyze_content(
        participant=participant_path, text_input=text_input
    )
    print("AnalyzeContent Response:")
    print(f"Reply Text: {response.reply_text}")

    for suggestion_result in response.human_agent_suggestion_results:
        if suggestion_result.error is not None:
            print(f"Error: {suggestion_result.error.message}")
        if suggestion_result.suggest_articles_response:
            for answer in suggestion_result.suggest_articles_response.article_answers:
                print(f"Article Suggestion Answer: {answer.title}")
                print(f"Answer Record: {answer.answer_record}")
        if suggestion_result.suggest_faq_answers_response:
            for answer in suggestion_result.suggest_faq_answers_response.faq_answers:
                print(f"Faq Answer: {answer.answer}")
                print(f"Answer Record: {answer.answer_record}")
        if suggestion_result.suggest_smart_replies_response:
            for (
                answer
            ) in suggestion_result.suggest_smart_replies_response.smart_reply_answers:
                print(f"Smart Reply: {answer.reply}")
                print(f"Answer Record: {answer.answer_record}")

    for suggestion_result in response.end_user_suggestion_results:
        if suggestion_result.error:
            print(f"Error: {suggestion_result.error.message}")
        if suggestion_result.suggest_articles_response:
            for answer in suggestion_result.suggest_articles_response.article_answers:
                print(f"Article Suggestion Answer: {answer.title}")
                print(f"Answer Record: {answer.answer_record}")
        if suggestion_result.suggest_faq_answers_response:
            for answer in suggestion_result.suggest_faq_answers_response.faq_answers:
                print(f"Faq Answer: {answer.answer}")
                print(f"Answer Record: {answer.answer_record}")
        if suggestion_result.suggest_smart_replies_response:
            for (
                answer
            ) in suggestion_result.suggest_smart_replies_response.smart_reply_answers:
                print(f"Smart Reply: {answer.reply}")
                print(f"Answer Record: {answer.answer_record}")

    return response

会話を完了する

会話を完了するには、conversations リソースの complete メソッドを呼び出します。会話 ID を指定します。

REST

リクエストのデータを使用する前に、次のように置き換えます。

  • PROJECT_ID: GCP プロジェクト ID
  • CONVERSATION_ID: 会話の作成時に受け取った ID

HTTP メソッドと URL:

POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/conversations/CONVERSATION_ID:complete

リクエストを送信するには、次のいずれかのオプションを展開します。

次のような JSON レスポンスが返されます。

{
  "name": "projects/PROJECT_ID/conversations/CONVERSATION_ID",
  "lifecycleState": "COMPLETED",
  "conversationProfile": "projects/PROJECT_ID/conversationProfiles/CONVERSATION_PROFILE_ID",
  "startTime": "2018-11-05T21:05:45.622Z",
  "endTime": "2018-11-06T03:50:26.930Z"
}

Python

Agent Assist に対する認証を行うには、アプリケーションのデフォルト認証情報を設定します。詳細については、ローカル開発環境の認証の設定をご覧ください。

def complete_conversation(project_id, conversation_id):
    """Completes the specified conversation. Finished conversations are purged from the database after 30 days.

    Args:
        project_id: The GCP project linked with the conversation.
        conversation_id: Id of the conversation."""

    client = dialogflow.ConversationsClient()
    conversation_path = client.conversation_path(project_id, conversation_id)
    conversation = client.complete_conversation(name=conversation_path)
    print("Completed Conversation.")
    print("Life Cycle State: {}".format(conversation.lifecycle_state))
    print("Conversation Profile Name: {}".format(conversation.conversation_profile))
    print("Name: {}".format(conversation.name))
    return conversation