Files
dify-docs/en/use-dify/tutorials/workflow-101/lesson-05.mdx
Riskey df19776bb0 Add workflow 101 tutorial (#705)
* add the zh and en workflow 101 tutorials

* refine the formats for readability

* refine formatting and minor issues

* Update Workflow 101 lessons and images

* Update image display in Workflow 101 lesson 01

* Rename Dify workflow image

* Update Workflow 101 Lesson 3 with new images and prompt example

* Update Workflow 101 Lesson 03 images

* Update Dify workflow lesson 4 prompt image

* Update Workflow 101 Lesson 5 with new images and content

* Update Workflow 101 Lesson 6 content and images

* Update Workflow 101 Lesson 08 and add new images

* Refine email reply instruction in Workflow 101 lesson 8

* Update Workflow 101 Lesson 9 with new steps and images

* Update Workflow 101 Lesson 09 content and images

* Fix whitespace in Workflow 101 Lesson 9

* Add image alt text to workflow example in zh lesson 01

* Update LLM node images and text formatting in Workflow 101 Lesson 03

* Update zh/use-dify/tutorials/workflow-101/lesson-05.mdx content

* Update zh/workflow-101/lesson-03.mdx for clarity

* Remove unnecessary italics in Workflow 101 lesson 4

* Update Workflow 101 Lesson 5 for clarity and image display

* Update images in Workflow 101 Lesson 06

* Update Lesson 7 workflow tutorial with new images and text fixes

* Update zh/use-dify/tutorials/workflow-101/lesson-06.mdx content

* Update prompt instructions in Workflow 101 Lesson 06

* Clarify condition in Workflow 101 Lesson 07

* Fix formatting in Workflow 101 lesson 8

* Update Workflow 101 Lesson 9 for email formatting optimization

* Fix typo in Workflow 101 Lesson 9

* Remove Jinja2 example from workflow lesson

* Update image syntax in Workflow 101 Lesson 02

* Update image tag in Workflow 101 Lesson 3

* Remove italics from workflow 101 lessons

* Fix typo in zh/use-dify/tutorials/workflow-101/lesson-05.mdx

* Refine parameter types explanation in Workflow 101 lesson 6

* Refine Chinese text in Workflow 101 lesson 06

* Update Lesson 7: Enhance Workflows content

* Fix formatting in Workflow 101 Lesson 7

* Refine Chinese text in Workflow 101 lesson 8

* Refine instructions for Workflow 101 Lesson 08 test run

* Clarify the purpose of template conversion in Workflow 101 lesson 9

* Update Workflow 101 Lesson 10 image syntax

* Polish workflow 101 tutorials (en/zh) and add ja translation

* Update Workflow 101 lesson 1 content

* Fix formatting and update workflow creation instructions in Lesson 02

* Clarify multi-modal model description in Workflow 101 lesson 3

* Remove italics from workflow tutorial lessons

* Update Workflow 101 Lesson 6 prompt example

* Update formatting in Workflow 101 lesson 8

* Update Workflow 101 lesson 1 content

* Update zh/use-dify/tutorials/workflow-101/lesson-02.mdx content

* Refine Chinese text in Workflow 101 Lesson 3

* Refine RAG explanation in Workflow 101 Lesson 04

* Update zh/use-dify/tutorials/workflow-101/lesson-05.mdx content

* Update formatting in Workflow 101 Lesson 08

* final checks

* format and terminology fixes

---------

Co-authored-by: Anne <annezj92@gmail.com>
2026-03-11 15:42:44 +08:00

170 lines
6.5 KiB
Plaintext

---
title: "Lesson 5: The Crossroads of Your Workflow (Sorting and Executing)"
sidebarTitle: "Lesson 5: The Crossroads of Your Workflow"
---
Right now, our Email Assistant treats every message following the same path of the workflow. That's not smart enough. An email asking about Dify's price should be handled differently than an email on bug reporting.
To make our assistant truly intelligent, we need to teach it how to Read the Room. We're going to set up a Crossroads that sends different types of emails down different tracks.
## The If/Else Node
<Frame>
![If/Else Node](/images/difyworkflow101-lesson05-ifelsenode.png)
</Frame>
If/Else node is just like a traffic light. It checks a condition (like Does this email mention pricing? ) and sends the flow left or right based on the result.
### 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.
<Steps>
<Step title="Insert the Node">
Hover over the line between the Start and Knowledge Retrieval nodes. Click the **Plus (+)** icon and select the **If/Else** node.
</Step>
<Step title="Set the Rules">
1. Click the node to open the panel
2. Click **\+ Add Condition** in the IF section. Choose the variable: `{x} email_content`
<Frame>
![Add Condition](/images/difyworkflow101-lesson05-settings1.png)
</Frame>
3. The Logic: Keep it as **Contains**. Type **Dify** in the input box
<Frame>
![Contains](/images/difyworkflow101-lesson05-settings2.png)
</Frame>
Now, the complete logic for the IF branch is: `If the email content contains the word Dify`.
</Step>
</Steps>
<Info>
**Understanding the Traffic Light**
When 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!
</Info>
### 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).
<Frame>
![Connect IF Branch](/images/difyworkflow101-lesson05-connectifbranch.png)
</Frame>
#### 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.
<Steps>
<Step title="Create a new Node">
Click the **(+)** next to ELSE and select a new **LLM Node (LLM 2)**
</Step>
<Step title="Add Prompt to this LLM node">
Copy and paste the prompt below
```plaintext wrap
You are a professional customer service manager. Based on the customer's email, kindly inform the user that no relevant information was found and provide relevant guidance.
Requirements:
1. Address the customer name in a friendly tone.
2. Thank them for their letter.
3. Keep the tone professional and friendly.
4. Sign off as "Anne."
```
</Step>
<Step title="Add User Message">
1. Click **Add Message** button below system.
2. In the User Message box, type **customer name:**.
3. Press `/` on your keyboard.
4. You can see the Variable Selection menu pops out, and click `customer_name`.
5. Press Enter to start a new line, and type **email content:**
6. Press the / key again and click on `email_content`.
<Frame>
![Prompt for LLM 2](/images/difyworkflow101-lesson05-finalpromptforllm2.png)
</Frame>
</Step>
</Steps>
Now we have two tracks generating two different replies. Imagine if we had 10 tracks, our workflow would look like a messy plate of spaghetti.
To keep things clean, we use a Variable Aggregator. Think of it as a Traffic Hub where all the different roads merge back into one main highway.
## Variable Aggregator
<Frame>
![Variable Aggregator](/images/difyworkflow101-lesson05-variableaggregator.png)
</Frame>
Variable Aggregator is like a traffic hub where all the different roads merge back into one main highway.
### Hands-On 3: Add Variable Aggregator
<Steps>
<Step title="Add the Aggregator">
1. Select the connection line between the End Node and the LLM node and delete it.
2. Right-click on the canvas, select **Add Node**, and choose the **Variable Aggregator** node.
<Frame>
![Add Variable Aggregator](/images/difyworkflow101-lesson05-addvariableaggregator.png)
</Frame>
</Step>
<Step title="Merge the Paths">
Connect LLM and LLM 2 node to the Variable Aggregator.
</Step>
<Step title="Assign the Output">
1. Click the Variable Aggregator node.
2. Click the **plus (+)** icon next to **Assign Variables**.
3. Select the **text** from LLM 1 AND the **text** from LLM 2.
<Frame>
![Assign Variable](/images/difyworkflow101-lesson05-assignvariable.png)
</Frame>
Now, no matter which LLM node generates the response, the Variable Aggregator node gathers the content and hands it to the Output Node.
</Step>
<Step title="The Final Step">
1. Connect the Variable Aggregator to the Output node.
2. Update the Output Variable to the Variable Aggregator's result instead of previous LLM results.
<Frame>
![Update Output Variable](/images/difyworkflow101-lesson05-updateoutputvariable.png)
</Frame>
Here's how the workflow looks:
<Frame>
![Final Workflow](/images/difyworkflow101-lesson05-finalworkflow.png)
</Frame>
</Step>
<Step title="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.
</Step>
</Steps>
## Mini Challenge
For business inquiry emails, how should we edit this workflow to generate proper response?
<Tip>
Don't forget to update knowledge base with business-related files.
</Tip>