The If/Else Node

Hands-On 1: Set up the Crossroads
Let’s upgrade our assistant so it can tell the difference between Dify-related emails and Everything else.1
Insert the Node
Hover over the line between the Start and Knowledge Retrieval nodes. Click the Plus (+) icon and select the If/Else node.
2
Set the Rules
- Click the node to open the panel
- Click + Add Condition in the IF section. Choose the variable:
{x} email_content

- The Logic: Keep it as Contains. Type Dify in the input box

If the email content contains the word Dify.Understanding the Traffic LightWhen setting conditions, Dify offers several ways to judge information, much like the different signals at a crossroads:
- Is / Is Not Like a perfect key for a lock. The content must match your value exactly.
- Contains / Not Contains Like a magnifying glass. It checks if a specific keyword exists anywhere in the text. This is what we are using today.
- Starts with / Ends with Check if the text begins or ends with specific characters.
- Is Empty / Is Not Empty Check if the variable has any content. For example: Checking if a user actually uploaded an attachment. Understanding these helps you set accurate and flexible rules, building a much smarter workflow!
Hands-On 2: Plan Different Paths
Now that we have the crossroad here, we need to decide what happens on each road.A. The Dify-Related Email Track (IF Branch)
Click the plus (+) icon on the right side of the IF branch, drag out a line, and connect it to Knowledge Retrieval node. What this means: When the email contains the word Dify, the flow will execute the professional reply process we built in the last lesson (which looks up information in the Knowledge Base).
B. The Unrelated Email Track (ELSE Branch)
For emails that are not related or mention Dify, we want to create a simple, polite, and general reply process.1
Create a new Node
Click the (+) next to ELSE and select a new LLM Node (LLM 2)
2
Add Prompt to this LLM node
Copy and paste the prompt below
3
Add User Message
- Click Add Message button below system.
- In the User Message box, type customer name:.
- Press
/on your keyboard. - You can see the Variable Selection menu pops out, and click
customer_name. - Press Enter to start a new line, and type email content:
- Press the / key again and click on
email_content.

Variable Aggregator

Hands-On 3: Add Variable Aggregator
1
Add the Aggregator
- Select the connection line between the End Node and the LLM node and delete it.
- Right-click on the canvas, select Add Node, and choose the Variable Aggregator node.

2
Merge the Paths
Connect LLM and LLM 2 node to the Variable Aggregator.
3
Assign the Output
- Click the Variable Aggregator node.
- Click the plus (+) icon next to Assign Variables.
- Select the text from LLM 1 AND the text from LLM 2.

4
The Final Step
- Connect the Variable Aggregator to the Output node.
- Update the Output Variable to the Variable Aggregator’s result instead of previous LLM results.


5
Test and Run
Click Test Run, enter a customer name, and try testing with inputs that both include and exclude the keyword Dify to see the different results.