> ## Documentation Index
> Fetch the complete documentation index at: https://dify-6c0370d8-docs-new-agent-experience.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# レッスン 7：ワークフローを強化する（ツール）

> このドキュメントは AI によって自動翻訳されています。不正確な部分がある場合は、[英語版](/en/learn/tutorials/workflow-101/lesson-07) を参照してください。

メールアシスタントはナレッジベースを活用できるようになりました。しかし、ナレッジベースの範囲を超えた質問が来たらどうでしょうか？例えば、「Dify の最新リリースには何が含まれていますか？」のような質問です。

ナレッジベースがまだ更新されていない場合、ワークフローは対応できません。これを解決するために、ライブ検索スキルを装備しましょう！

## ツール

<Frame>
  <img src="https://mintcdn.com/dify-6c0370d8-docs-new-agent-experience/m7n3yF17cj5TGqhL/images/use-dify/tutorial/workflow-101-lesson-07/tools.png?fit=max&auto=format&n=m7n3yF17cj5TGqhL&q=85&s=6e99335c3c12952dd0ac220fcb334e9c" alt="ツール" width="2908" height="1504" data-path="images/use-dify/tutorial/workflow-101-lesson-07/tools.png" />
</Frame>

ツールは AI ワークフローに超能力を与えるものです。

[Dify マーケットプレイス](https://marketplace.dify.ai/)はツールのスーパーマーケットのようなものです。Google 検索、天気の確認、画像生成、複雑な計算など、すぐに使える機能が揃っています。数回クリックするだけでインストールしてワークフローに組み込めます。

それでは、現在のワークフローをアップグレードしていきましょう。

### ハンズオン 1：イテレーション内のサブプロセスをアップグレードする

アシスタントに新しいロジックを追加します：まずナレッジベースを確認し、回答が見つからない場合は Google で検索します。

新しいロジックに集中するため、次のノードのみを残しておきましょう：**ユーザー入力、パラメータ抽出器、イテレーション**。

#### ステップ 1：ナレッジベースの照会と判定

<Steps>
  <Step title="イテレーションに入る">
    1. クリックしてイテレーションノードのサブプロセスエリアに入ります。
    2. ナレッジ検索ノードを残し、クエリ変数が `{x} item` であることを確認します。
    3. 以前の LLM ノードを削除します。
  </Step>

  <Step title="判定用 LLM ノードを追加する">
    ナレッジ検索ノードの直後に LLM ノードを追加します。このノードの役割は、ナレッジベースの情報が質問に回答できるかどうかを判定することです。

    * **コンテキストセッション**：ナレッジ検索から `Knowledge Retrieval / {x} result Array [Object]` を選択します。
    * **System プロンプト**：

    ```plaintext wrap theme={null}
    Based on the `Context`, determine if the answer contains enough information to answer the questions. If the information is insufficient, you MUST reply with: "Information not found in knowledge base".
    ```

    * **User Message**：

    ```plaintext wrap theme={null}
    questions: Iteration/{x} item
    ```

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8-docs-new-agent-experience/m7n3yF17cj5TGqhL/images/use-dify/tutorial/workflow-101-lesson-07/llm-settings.png?fit=max&auto=format&n=m7n3yF17cj5TGqhL&q=85&s=7c6cf7e6c49852cc136046e7ddacaf74" alt="LLM 設定" width="1232" height="1062" data-path="images/use-dify/tutorial/workflow-101-lesson-07/llm-settings.png" />
    </Frame>
  </Step>
</Steps>

「キャンバス」上ではこのように表示されます。

<Frame>
  <img src="https://mintcdn.com/dify-6c0370d8-docs-new-agent-experience/m7n3yF17cj5TGqhL/images/use-dify/tutorial/workflow-101-lesson-07/workflow-preview-01.png?fit=max&auto=format&n=m7n3yF17cj5TGqhL&q=85&s=fe713b47d315f8c6ce256850e28d2e38" alt="ワークフロープレビュー" width="2238" height="320" data-path="images/use-dify/tutorial/workflow-101-lesson-07/workflow-preview-01.png" />
</Frame>

#### ステップ 2：分岐点の設定

<Steps>
  <Step title="If/Else ノードを追加する">
    LLM ノードの後に If/Else ノードを追加します。ルールを設定します：LLM の出力が **Information not found in knowledge base** を **含む**場合。

    これは、ナレッジベースの情報では回答できない場合を意味します。

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8-docs-new-agent-experience/m7n3yF17cj5TGqhL/images/use-dify/tutorial/workflow-101-lesson-07/add-if-else-node.png?fit=max&auto=format&n=m7n3yF17cj5TGqhL&q=85&s=acb31766f7a9f609184fd059a884a051" alt="If/Else ノードの追加" width="1220" height="496" data-path="images/use-dify/tutorial/workflow-101-lesson-07/add-if-else-node.png" />
    </Frame>
  </Step>

  <Step title="検索ツールを追加する">
    IF 分岐の後に検索ツールを接続しましょう。これは、ナレッジベースで関連する回答情報が見つからない場合に、ウェブ検索を使って回答を探すことを意味します。

    1. IF ノードの後、プラス（+）アイコンをクリックしてツールを選択します。
    2. 検索ボックスに Google と入力します。Google にカーソルを合わせ、右側の「インストール」をクリックし、ポップアップウィンドウで再度「インストール」をクリックします。

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8-docs-new-agent-experience/m7n3yF17cj5TGqhL/images/use-dify/tutorial/workflow-101-lesson-07/add-tools.png?fit=max&auto=format&n=m7n3yF17cj5TGqhL&q=85&s=01ed3a2c614e77ff1c42604376ddb738" alt="ツールのインストール" width="1167" height="689" data-path="images/use-dify/tutorial/workflow-101-lesson-07/add-tools.png" />
    </Frame>
  </Step>

  <Step title="Google Search をインストールする">
    Google 内の Google Search をクリックします。

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8-docs-new-agent-experience/m7n3yF17cj5TGqhL/images/use-dify/tutorial/workflow-101-lesson-07/install-google-search.png?fit=max&auto=format&n=m7n3yF17cj5TGqhL&q=85&s=89322dd7733d456686f302000d433b67" alt="Google Search のインストール" width="1166" height="744" data-path="images/use-dify/tutorial/workflow-101-lesson-07/install-google-search.png" />
    </Frame>
  </Step>

  <Step title="API キーを取得する">
    Google Search を初めて使用するには認証が必要です。Wi-Fi のパスワードを入力するようなものです。

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8-docs-new-agent-experience/m7n3yF17cj5TGqhL/images/use-dify/tutorial/workflow-101-lesson-07/google-search-setup.png?fit=max&auto=format&n=m7n3yF17cj5TGqhL&q=85&s=5d8a1a672e39ed6424f1aef14cff631d" alt="Google Search の設定" width="1224" height="282" data-path="images/use-dify/tutorial/workflow-101-lesson-07/google-search-setup.png" />
    </Frame>

    1. 「API Key 認証設定」をクリックし、「SerpApi から SerpApi API key を取得」をクリックします。SerpApi にサインインして、専用の API キーを取得してください。

           <Note>
             API キーは外部世界へのパスポートです。安全に保管し、他人と共有しないようにしましょう。
           </Note>

           <Frame>
             <img src="https://mintcdn.com/dify-6c0370d8-docs-new-agent-experience/m7n3yF17cj5TGqhL/images/use-dify/tutorial/workflow-101-lesson-07/api-key-authorization-configuration.png?fit=max&auto=format&n=m7n3yF17cj5TGqhL&q=85&s=9b37c0d0c5f1ef67c4e06698de235d61" alt="API Key 認証設定" width="1330" height="968" data-path="images/use-dify/tutorial/workflow-101-lesson-07/api-key-authorization-configuration.png" />
           </Frame>
    2. API キーをコピーして SerpApi API key に貼り付けます。**Save** をクリックします。
    3. API キーの認証が成功すると、設定パネルがすぐに表示されます。Query string フィールドに移動し、`Iteration/{x} item` を選択します。

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8-docs-new-agent-experience/m7n3yF17cj5TGqhL/images/use-dify/tutorial/workflow-101-lesson-07/add-query-string.png?fit=max&auto=format&n=m7n3yF17cj5TGqhL&q=85&s=bfbdd13b1dfbd062e15f4e8bcbfbd1e1" alt="クエリ文字列の追加" width="1194" height="524" data-path="images/use-dify/tutorial/workflow-101-lesson-07/add-query-string.png" />
    </Frame>
  </Step>

  <Step title="2 つのパスを設定する">
    次に、どちらのパスかに応じて異なる回答方法を設定する必要があります。

    **検索回答パス**

    検索結果に基づいて質問に回答するため、新しい LLM ノードを追加します。Google Search ノードに接続してください。

    **System**：

    ```plaintext wrap theme={null}
    You are a Web Research Specialist. Based on Google Search, concisely answer the user's questions. Please do not mention the knowledge base in your response.
    ```

    **User Message**：

    ```plaintext wrap theme={null}
    results: GOOGLESEARCH/{x} text
    questions: Iteration/{x} item
    ```

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8-docs-new-agent-experience/m7n3yF17cj5TGqhL/images/use-dify/tutorial/workflow-101-lesson-07/llm-02-prompt.png?fit=max&auto=format&n=m7n3yF17cj5TGqhL&q=85&s=04f99175d4ebed52910c90ad4588f9e7" alt="LLM 2 のプロンプト" width="2248" height="1034" data-path="images/use-dify/tutorial/workflow-101-lesson-07/llm-02-prompt.png" />
    </Frame>

    **ナレッジベース回答パス**

    Else ノードの後に、ナレッジベースに基づく回答を処理するための新しい LLM ノードを追加します。

    **System**：

    ```plaintext wrap theme={null}
    You are a professional Dify Customer Service Manager. Strictly follow the `Context` to reply to questions.
    ```

    **User Message**：

    ```plaintext wrap theme={null}
    questions: Iteration/{x} item
    ```

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8-docs-new-agent-experience/m7n3yF17cj5TGqhL/images/use-dify/tutorial/workflow-101-lesson-07/prompt-llm-03.png?fit=max&auto=format&n=m7n3yF17cj5TGqhL&q=85&s=1d22cf04d4fc29528626a0e6cdf16ee7" alt="LLM 3 のプロンプト" width="1918" height="1034" data-path="images/use-dify/tutorial/workflow-101-lesson-07/prompt-llm-03.png" />
    </Frame>
  </Step>

  <Step title="情報を統合する">
    1. サブプロセス内（イテレーションボックスの内部）の最後に、変数アグリゲーターノードを追加し、LLM 2 と LLM 3 の両方に接続します。
    2. 変数アグリゲーターパネルで、変数の割り当てとして `LLM 2/{x}text String` と `LLM 3/{x}text String` を選択します。

    このようにして、2 つの可能な回答を 1 つのパスに統合します。

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8-docs-new-agent-experience/m7n3yF17cj5TGqhL/images/use-dify/tutorial/workflow-101-lesson-07/variable-aggregator-setup.png?fit=max&auto=format&n=m7n3yF17cj5TGqhL&q=85&s=974b5a9cfa836e92ce47156c406d9fcf" alt="変数アグリゲーターの設定" width="1170" height="544" data-path="images/use-dify/tutorial/workflow-101-lesson-07/variable-aggregator-setup.png" />
    </Frame>
  </Step>
</Steps>

現在のワークフローはこのようになっています。

<Frame>
  <img src="https://mintcdn.com/dify-6c0370d8-docs-new-agent-experience/m7n3yF17cj5TGqhL/images/use-dify/tutorial/workflow-101-lesson-07/workflow-preview-02.png?fit=max&auto=format&n=m7n3yF17cj5TGqhL&q=85&s=ace4c30eaac24f8e77061d74b296cb55" alt="ワークフロープレビュー 2" width="2612" height="544" data-path="images/use-dify/tutorial/workflow-101-lesson-07/workflow-preview-02.png" />
</Frame>

#### ステップ 3：最終的なメール作成

ロジック分岐の処理が完了したので、すべての回答を 1 つの洗練されたメールにまとめましょう。

<Steps>
  <Step title="イテレーションの出力を設定する">
    イテレーションノードをクリックし、出力変数として `{x}Variable Aggregator/{x}output String` を設定します。

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8-docs-new-agent-experience/m7n3yF17cj5TGqhL/images/use-dify/tutorial/workflow-101-lesson-07/iteration-output.png?fit=max&auto=format&n=m7n3yF17cj5TGqhL&q=85&s=eec8ca897954e24539a7704b1bf5c12e" alt="イテレーション出力" width="1152" height="580" data-path="images/use-dify/tutorial/workflow-101-lesson-07/iteration-output.png" />
    </Frame>
  </Step>

  <Step title="要約 LLM を接続する">
    イテレーションノードの後に、すべての出力を要約するための新しい LLM ノードを接続します。以下のプロンプトを参考にしてください。

    **System**：

    ```plaintext wrap theme={null}
    You are a professional Customer Service Manager. Summarize all the answers of the questions, and organize a clear and complete email reply for the customer.
    Do not include content where the knowledge base could not find relevant information.
    Signature: Anne.
    ```

    **User Message**：

    ```plaintext wrap theme={null}
    questions: Iteration/ {x} output
    customer: User Input / {x} customer_name
    ```

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8-docs-new-agent-experience/m7n3yF17cj5TGqhL/images/use-dify/tutorial/workflow-101-lesson-07/prompt-for-llm-04.png?fit=max&auto=format&n=m7n3yF17cj5TGqhL&q=85&s=e0271ef342c9f232b3d4dd5b34a246a1" alt="LLM 4 のプロンプト" width="2036" height="1048" data-path="images/use-dify/tutorial/workflow-101-lesson-07/prompt-for-llm-04.png" />
    </Frame>
  </Step>

  <Step title="出力ノードで仕上げる">
    LLM ノードの後に End ノードを追加します。出力変数を `LLM 4/{x}text String` に設定します。

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8-docs-new-agent-experience/m7n3yF17cj5TGqhL/images/use-dify/tutorial/workflow-101-lesson-07/output-setup.png?fit=max&auto=format&n=m7n3yF17cj5TGqhL&q=85&s=48e7ccb07c168fe270592c60f2106219" alt="出力設定" width="1152" height="452" data-path="images/use-dify/tutorial/workflow-101-lesson-07/output-setup.png" />
    </Frame>
  </Step>
</Steps>

これでワークフローのセットアップと設定がすべて完了しました。メールアシスタントは、ナレッジベースに基づいて質問に回答し、必要に応じて Google Search で補足的な回答を検索できるようになりました。

<Frame>
  <img src="https://mintcdn.com/dify-6c0370d8-docs-new-agent-experience/m7n3yF17cj5TGqhL/images/use-dify/tutorial/workflow-101-lesson-07/final-workflow-preview.png?fit=max&auto=format&n=m7n3yF17cj5TGqhL&q=85&s=94f94bca3eff160daee85882159059d2" alt="最終ワークフロープレビュー" width="2656" height="452" data-path="images/use-dify/tutorial/workflow-101-lesson-07/final-workflow-preview.png" />
</Frame>

ナレッジベースに確実に載っていない質問を含むメールを送信してみましょう。AI が Google を使って関連する回答を見つけられるか確認してください。

## ミニチャレンジ

1. If/Else ノードで選択できる他の条件にはどのようなものがありますか？
2. マーケットプレイスを閲覧して、このワークフローに追加できる別のツールを見つけてみましょう。
