Skip to main content
Our email assistant can now flip through our knowledge base. But what if a customer asks a beyond-knowledge-base question, like: What is in the latest Dify release? If the knowledge base hasn’t been updated yet, the workflow will be at a loss. To fix this, we need to equip it with a Live Search skill!

Tools

Tools
Tools are the superpower for your AI workflow. The Dify Marketplace is like a Plugin Supermarket. It’s filled with ready-made superpowers—searching Google, checking the weather, drawing images, or calculating complex math. You just install and plug them into your workflow with several clicks. Now, let’s continue to upgrade on current workflow.

Hands-On 1: Upgrade the Sub-process Area in Iteration

We are going to add a new logic to our assistant: Check the Knowledge Base first; if the answer isn’t there, go search Google. To focus on the new logic, let’s keep only these nodes: User input, Parameter Extractor, and Iteration.

Step 1: Knowledge Query and the Judge

1

Enter the Iteration

  1. Click to enter the sub-process area of the Iteration node.
  2. Keep Knowledge Retrieval node, and make sure the query variable is {x} item.
  3. Delete the previous LLM node.
2

Add the Judge (LLM Node)

Add an LLM node right after Knowledge Retrieval node. Its job is to decide if the Knowledge Base info can actually respond to the questions.
  • For Context session: Select the Knowledge Retrieval / {x} result Array [Object] from Knowledge Retrieval
  • System Prompt:
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:
questions: Iteration/{x} item
LLM Settings
Here’s what it looks like on the canvas.
Workflow Preview

Step 2: Setting the Crossroads

1

Add If/Else Node

After LLM node, let’s add If/Else node. Set the rule: If LLM Output Contains Information not found in knowledge base.This means, when we can’t respond with the information in knowledge base.
Add If/Else Node
2

Add Tool for Searching

Let’s connect a search tool after the IF branch. This indicates that when the knowledge base cannot find relevant answer information, we use web search to find the answers.
  1. After the IF node, click plus(+) icon and select Tool.
  2. In the search box, type Google. Hover over Google, click Install on the right, and then click Install again in the pop-up window.
Install Plugin
3

Install Google Search

Click Google Search in Google.
Install Google Search
4

Get Your API Key

Using Google Search for the first time requires authorization—it’s like needing a Wi-Fi password.
Google Search Setup
  1. Click API Key Authorization Configuration, then click Get your SerpApi API key from SerpApi. Sign in to get your private API key.
    Your API Key is your passport to the outside world. Keep it safe and avoid sharing it with others.
    API Key Authorization Configuration
  2. Copy and paste the API key in SerpApi API key. Click Save.
  3. Once the API key is successfully authorized, the settings panel shows up immediately. Head to Query string field, and select Iteration/{x} item.
Add Query String
5

Configure the Two Paths

Now, we need different ways to answer depending on which path we’re looking at.The Search Answer PathAdd a new LLM node to answer the question based on the search results. Connect it to the Google Search node.System:
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:
results: GOOGLESEARCH/{x} text
questions: Iteration/{x} item
Prompt for LLM 2
The Knowledge Searching PathAfter the Else node, add a new LLM node to handle answers based on the knowledge base.System:
You are a professional Dify Customer Service Manager. Strictly follow the `Context` to reply to questions.
User Message:
questions: Iteration/{x} item
Prompt for LLM 3
6

Combine the Information

  1. In the sub-process (inside the Iteration box), add a Variable Aggregator node that connects both LLM 2 and LLM 3 at the very end.
  2. In the Variable Aggregator panel, select the variables LLM 2/{x}text String and LLM 3/{x}text String as the Assign Variables.
In this way, we’re merging the two possible answers into a single path.
Variable Aggregator Setup
This is how the current workflow looks.
Workflow Preview 2

Step 3: The Final Email Assembly

Now that our logic branches have finished processing, let’s combine all the answers into a single, polished email.
1

Configure Iteration Output

Click on the Iteration node, and set {x}Variable Aggregator/{x}output String as the output variables.
Iteration Output
2

Connect the Summary LLM

After the Iteration node, connect a new LLM node to summarize all outputs. Feel free to use the prompt below.System:
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:
questions: Iteration/ {x} output
customer: User Input / {x} customer_name
Prompt for LLM 4
3

Finalize with the Output Node

After the LLM node, add an End node. Set the output variable as LLM 4/{x}text String.
Output Setup
We have now completed the entire setup and configuration of the workflow. Our email assistant can now answer questions based on the Knowledge Base and use Google Search for supplementary answers when needed.
Final Workflow Preview
Try sending an email with question that definitely isn’t in the knowledge base. Let’s see if the AI successfully uses Google to find the related answers.

Mini Challenge

  1. What are other conditions you can choose in If/Else node?
  2. Browse marketplace to see if you can add another tool for this workflow?