生成ツール

生成ツールは、Google の最新の生成大規模言語モデル(LLM)とユーザーが提供するプロンプトを使用して、実行時にエージェントの動作を生成します。 使用可能なモデルは、Vertex AIから提供されます。

生成ツールを使用すると、独自の外部 Webhook を作成しなくても、Dialogflow CX からネイティブで LLM を呼び出すことができます。通常は LLM に要求するすべての処理を行うように生成ツールを構成できます。

生成ツールは、要約、パラメータ抽出、データ変換などのタスクに適しています。詳細については、以下の例をご覧ください。

制限事項

この機能は Dialogflow のすべての言語でエージェントが利用できますが、使用可能なモデルの言語の制限がより厳しい場合があります。詳細については、Vertex AI をご覧ください。

生成ツールのコンセプトを理解する

Vertex AI のドキュメントには、Dialogflow の生成ツールの作成時に理解すべき重要な情報が記載されています。

生成ツールを定義する

生成ツールを作成するには、次の手順を実施します。

  1. Dialogflow CX コンソールに移動
  2. Google Cloud プロジェクトを選択します。
  3. エージェントを選択します。
  4. [管理] タブをクリックします。
  5. [生成ツール] をクリックします。
  6. [新規作成] をクリックします。
  7. 生成ツール用に、わかりやすい表示名を入力します。
  8. コンセプトにテキスト プロンプト、モデル、コントロールを入力します。
  9. [保存] をクリックします。

テキスト プロンプトは、実行時の入力中に生成モデルに送信されます。モデルが満足のいくレスポンスを生成するためには、質問または要求は明確である必要があります。

単語の前に $ を追加すると、単語をプレースホルダとしてマークすることで、プロンプトをコンテキストにできます。これらの生成ツール プロンプト プレースホルダを入力のセッション パラメータに関連付けると、実行時にセッション パラメータ値に置き換えられます。

生成ツールを定義する
生成ツールを定義する

セッション パラメータに関連付ける必要のない、特別な生成ツール プロンプト プレースホルダがあります。これらの組み込み生成ツール プロンプト プレースホルダは次のとおりです。

用語 定義
$conversation エージェントとユーザーの会話(最後のユーザーの発話とその後のエージェントの発話を除く)。
$last-user-utterance 直近のユーザー発話。

フルフィルメントで生成ツールを使用する

生成ツールは、入力中(ルートイベント ハンドラパラメータなど)で使用できます。

[入力] ペインの [生成ツール] セクションに移動し、展開します。 [生成ツールの追加] をクリックします。事前定義された生成ツールを選択するか、適切な新しい生成ツールを定義できます。

生成ツールを選択したら、プロンプトの生成ツール プロンプト プレースホルダをセッション パラメータに関連付ける必要があります。さらに、実行後に生成ツールの結果を含む出力パラメータを定義する必要があります。

生成ツールを使用する
入力で生成ツールを使用する

1 つの入力に複数の生成ツールを追加できます。これは、並行して実行されます。

出力パラメータは、エージェント・レスポンスなど、後で使用できます。

生成ツール出力を使用する
生成ツールの出力を使用する

生成ツールをテストする

生成ツール 機能は、シミュレータで直接テストできます。

シミュレータで生成ツールをテストする
シミュレータで生成ツールをテストする

このセクションでは、生成ツールのユースケースの例を示します。 生成ツールは大規模言語モデル(LLM)に基づく生成テクノロジーであり、次の例に示すプロンプトを使用した場合のそれぞれの結果は、ここに記載した出力と異なることがあります。Google が返すすべてのプロンプト結果は、ベスト エフォートです。

コンテンツの要約

この例では、コンテンツを要約する方法を示します。

質問:

Your goal is to summarize a given text.

Text:
$text

A concise summary of the text in 1 or 2 sentences is:

会話の要約

この例では、会話の要約を提供する方法を示します。

質問:

You are an expert at summarizing conversations between a User and an Agent.
When providing the summary, always start with "Dear $email_address, the conversation summary is as follows:"
Provide a summary in a few bullet points.
Try to be as brief as possible with each bullet point,
only noting the key points of the conversation.
Output the summary in markdown format.

Conversation:
$conversation

Summary:

解決されたプロンプト:

会話の例として、生成モデルに送信される解決済みプロンプトは次のようになります。

You are an expert at summarizing conversations between a User and an Agent.
When providing the summary, always start with "Dear joe@example.com conversation summary is as follows:"
Provide a summary in a few bullet points.
Try to be as brief as possible with each bullet point,
only noting the key points of the conversation.
Output the summary in markdown format.

Conversation:
Agent: Good day! What can I do for you today?
User: Hi, which models can I use in Dialogflow's generators?
Agent: You can use all models that Vertex AI provides!
User: Thanks, thats amazing!

Summary:

マークダウンの書式設定

次の例は、マークダウンでテキストを書式設定する方法を示しています。

# Instructions

You are presented with a text and your goal is to apply markdown formatting to text.

**NOTE:** Do not change the meaning of the text, only the formatting.

# Example

## Text

Generators allow you to use Googles latest generative models to format text,
or to create a summaries, or even to write code. What an amazing feature.

## Text in Markdown

*Generators* allow you to use Google's latest generative models to

*   format text
*   create a summaries
*   write code

What an amazing feature.

# Your current task

## Text

$text

## Text in Markdown

質問への回答

この一連の例では、生成ツールを使用して質問に回答する方法を示しています。

まず、生成モデルの内部知識に頼って質問に答えることができます。ただし、モデルはトレーニング データに含まれていた情報に基づいて回答を提供するだけです。回答が正しいか、最新のものであるかは保証されません。

自己の知識を使って質問の回答を促す

Your goal is to politely reply to a human with an answer to their question.

The human asked:
$last-user-utterance

You answer:

提供された情報を使って質問の回答を促す

ただし、提供した情報に基づいてモデルで回答を得る場合は、プロンプトに情報を追加できます。これは、提供したい情報がそれほど多くない場合に有効です(例: 小さなレストランのメニューや会社の連絡先情報)。

# Instructions

Your goal is to politely answer questions about the restaurant menu.
If you cannot answer the question because it's not related to the restaurant
menu or because relevant information is missing from the menu, you politely
decline to answer.

# Restaurant menu:

## Starters
Salat 5$

## Main dishes
Pizza 10$

## Deserts
Ice cream 2$

# Examples

Question: How much is the pizza?
Answer: The pizza is 10$.

Question: I want to order the ice cream.
Answer: We do have ice cream! However, I can only answer questions about the menu.

Question: Do you have spaghetti?
Answer: I'm sorry, we do not have spaghetti on the menu.

# Your current task

Question: $last-user-utterance
Answer:

動的な情報を使って質問の回答を促す

多くの場合、モデルで回答の根拠となる情報は、プロンプトに貼り付けるには多すぎます。この場合、生成ツールをデータベースや検索エンジンなどの情報検索システムに接続して、クエリに基づいて情報を動的に取得することができます。単にそのシステムの出力をパラメータに保存し、プロンプト内のプレースホルダに接続するだけで済みます。

# Instructions

Your goal is to politely answer questions based on the provided information.
If you can't answer the question given the provided information, you politely
decline to answer.

# Provided information:
$information

Question: $last-user-utterance
Answer:

コード生成

この例では、生成ツールを使用してコードを記述する方法を示しています。ここでは、コードを生成するように特別にトレーニングされた生成モデルを使用するのが妥当です。

プロンプト

# Instructions:

Your goal is to write code in a given programming language solving a given problem.

Problem to solve:
$problem

Programming language:
$programming-language

# Solution:

人間のエージェントへのエスカレーション

次の例は、人間のエージェントへのエスカレーションを処理する方法を示しています。プロンプトの最後の 2 つの手順は、モデルが冗長になるのを防ぎます。

質問:

# Instructions:

You are a polite customer service agent that handles requests
from users to speak with an operator.

Based on the $last-user-utterance,
respond to the user appropriately about their request to speak with an operator.
Always be polite and assure the user that you
will do your best to help their situation.

Do not ask the user any questions.
Do not ask the user if there is anything you can do to help them.

# Answer:

検索クエリの生成

この例では、ユーザーが入力した Google 検索クエリを最適化する方法を示します。

質問:

# Instructions:

You are an expert at Google Search and using "Google Fu"
to build concise search terms that provide the highest quality results.
A user will provide an example query,
and you will attempt to optimize this to be the best Google Search query possible.

# Example:

User: when was covid-19 first started and where did it originated from?
Agent: covid-19 start origin

# Your task:

User: $text
Agent:

顧客情報の取得

この例では、文字列または JSON 形式で指定された情報の取得と検索を行う方法を示します。これらの形式は、Dialogflow セッション パラメータで一般的に使用されます。

質問:

You are a database engineer and specialize in extracting information
from both structured and unstructured data formats like CSV, SQL, JSON,
and also plain text.

Given a $user_db, extract the information requested
by the user from the $last-user-utterance

EXAMPLE:
user_db: {'customer_name': 'Patrick', 'balance': '100'}
User: What is my current account balance?
Agent: Your current balance is 100.

Begin!

user_db: $user_db
User: $last-user-utterance
Agent:

JSON オブジェクトの更新

この例は、ユーザー(または Webhook)からの入力 JSON オブジェクトを受け入れて、ユーザーのリクエストに基づいてオブジェクトを操作する方法を示しています。

質問:

You are an expert Software Engineer
that specializes in the JSON object data structure.

Given some user $update_request and existing $json_object,
you will modify the $json_object based on the user's $update_request.

EXAMPLE:
json_object = { "a": 1, "b": 123 }
User: Add a new key/value pair to my JSON
Agent: What do you want to add?
User: c: cat
Agent: { "a": 1, "b": 123, "c": "cat"}

json_object = {"accounts": [{"username": "user1", "account_number": 12345}, {"username": "user2", "account_number": 98765}], "timestamp": "2023-05-25", "version":"1.0"}
User: Add a new value for user1
Agent: What do you want to add?
User: birthday, 12/05/1982
Agent: {"accounts": [{"username": "user1", "account_number": 12345, "birthday": "12/05/1982"}, {"username": "user2", "account_number": 98765}], "timestamp": "2023-05-25", "version":"1.0"}

json_object = $json_object
User: Add a new key value to my db
Agent: What do you want to add?
User: $last-user-utterance
Agent:

Codelab

生成ツールの Codelab もご覧ください。

トラブルシューティング

機能をデバッグする場合は、Dialogflow コンソールのシミュレータで、解決された大規模言語モデル(LLM)の入力プロンプトを調べることができます。

  1. [元のレスポンス] ボタンをクリックします。

    元のレスポンス

  2. [生成ツール LLM 入力] フィールドを見つけます。これらのフィールドを書式なしテキストとして読み込み、LLM 入力が理にかなっているかを確認します。フレーズに $ が含まれる場合、シミュレータの入力を調べて、プロンプト内の $ が意図的なものかどうかを明確にします(例: price is $10$ が意図的であると考えられるものの、visit $city は意図的ではなく、誤用またはバグを示していると考えられる場合)。

  3. [生成ツール LLM 入力] オプションがフィールドが見つからない場合、サポートにお問い合わせください。