Files
dify-docs/en/use-dify/tutorials/workflow-101/lesson-03.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

260 lines
9.8 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "Lesson 3: The Brain of the Workflow (LLM Node)"
sidebarTitle: "Lesson 3: The Brain of the Workflow"
---
<Frame>
![LLM Node](/images/difyworkflow101-lesson03-llmnode.png)
</Frame>
In Lesson 2, we set up the Ingredients (Start Node) and the Serving Plate (Output Node).
If the Start Node is the prep cook, the LLM Node is the Master Chef. It is the brain and core of your workflow.
It handles all the thinking, analyzing, and creative writing. Whether you want to summarize an article, write code, or draft an email, this is the node that does the heavy lifting.
## Configure the Model
Before getting started, we need to connect to a model provider.
<Steps>
<Step title="Open Settings">
Click on your avatar in the top right corner and select **Settings**.
<Frame>
![Settings](/images/difyworkflow101-lesson03-llmnode-1.png)
</Frame>
</Step>
<Step title="Install OpenAI Provider">
On the left menu, click **Model Provider**. Find OpenAI, and click **Install**.
<Frame>
![Choose OpenAI](/images/difyworkflow101-lesson03-llmnode-2.png)
</Frame>
<Frame>
![Install OpenAI](/images/difyworkflow101-lesson03-install.png)
</Frame>
</Step>
<Step title="Return to the Canvas">
Once installed, you are ready to go! Click **ESC** (or the **X**) in the upper right corner to return to your canvas.
</Step>
</Steps>
## Understand the Tags
A pastry chef is great at cakes but terrible at sushi. Similarly, different AI models have different strengths.
When selecting a model in Dify, you will see tags next to their names. Here's how to read them so you can pick the right one for you.
<AccordionGroup>
<Accordion title="CHAT (The Conversationalist)">
This is the bread and butter of AI. It's best for:
- Dialogue
- Writing articles
- Summarizing text
- Answering questions
</Accordion>
<Accordion title="128K (The Great Memory)">
This number represents the **Context Window**. You can think of it as short-term memory.
Here, K stands for thousand. **128K** means the model can hold 128,000 tokens (roughly equals to a word or a syllable). The bigger the number is, the better its memory is.
<Info>
If you need to analyze a massive PDF report or a whole book, you need a model with a big number here.
</Info>
</Accordion>
<Accordion title="Multi-modal (The Evolved Senses)">
Modal just means **Type of Information**. Most early AI models could only read text. Multi-modal models are evolved—they have senses like eyes and ears.
**VISION (The Eyes)**
Models with this tag can do more than read; they can see! You can upload a photo of a sunset and ask, What colors are in this? or upload a picture of your fridge ingredients and ask, What can I cook with this?
**AUDIO (The Ears)**
Models with this tag can hear. You can upload an audio recording of a meeting or a lecture, and the model can transcribe it into text or write a summary for you.
**VIDEO (The Movie Analyst)**
These models can watch and understand video content. They can analyze what is happening in a video clip, just like a human watching a movie.
**DOCUMENT (The Reader)**
These models are expert readers. Instead of copying and pasting text, you can just upload a file (like a PDF or Word document). The model will read the file directly and answer questions based on what is written inside.
</Accordion>
</AccordionGroup>
For our Email Assistant, the LLM with the **CHAT** tag is exactly what we need.
## Hands-On 1: Add the LLM Node
Let's put the brain into our workflow.
<Steps>
<Step title="Open your App">
Go back to the **AI Email Assistant** workflow we created in Lesson 2.
</Step>
<Step title="Add the Node">
Right-click in the empty space between Start and Output node. Click on the new **LLM** block. In the right-side panel, look for **Model**. Select **gpt-4o-mini**.
<Frame>
![Add the Node](/images/difyworkflow101-lesson03-addthenode.png)
</Frame>
</Step>
<Step title="Connect the Nodes">
Drag a line from the Start node to the LLM node. Drag a line from the LLM node to the Output node. Your flow should look like this: **Start → LLM → Output**.
<Frame>
![Connect the Nodes](/images/difyworkflow101-lesson03-connectthenodes.png)
</Frame>
</Step>
</Steps>
Now we need to tell LLM exactly what to do by sending instructions which is called a **Prompt**.
<Frame>
![Add Prompt](/images/difyworkflow101-lesson03-prompt.png)
</Frame>
### Key Concept: The Prompt (The Instructions)
**What is a Prompt?** Think of the Prompt as the specific note you attach to the order ticket. It tells the AI exactly **what to do** and **how to do it**.
The most critical part is the ability to use **Variables** from the Start Node directly within your Prompt. This allows the AI to adapt its output based on the different raw materials you provide each time.
In Dify, when you insert a variable like `customer_name` into the prompt, you are telling the AI: Go and look in the box labeled Customer Name and use the text inside.
## Hands-On 2: Write the Prompt
Now, let's apply this. We are going to write a prompt that mixes instructions with our variables.
<Steps>
<Step title="Draft the Instructions">
Click the LLM Node to open the panel and find the **system** box. **System instructions** set the rules for how the model should respond—its role, tone, and behavioral guidelines.
Let's start by writing out the instructions. You can copy and paste the text below.
```plaintext wrap
You are a professional customer service manager. Based on the customer's email, please draft a professional reply.
Requirements:
1. Start by addressing the customer name with a friendly tone.
2. Thank them for their email.
3. Let them know we have received it.
4. Sign off as Anne.
```
</Step>
<Step title="Add User Messages">
User messages are what you send to the model—a question, request, or task for the model to work on.
In this workflow, the customer's name and the email content change every single time. Instead of typing them out manually, we add Variables in user messages.
1. Click **Add Message** button below system box.
2. In the User Message box, type **customer name:**.
3. Press `/` on your keyboard.
4. The Variable Selection menu pops out, and click `customer_name`.
5. Press Enter to start a new line, and type **email content:.** Then, Press the / key again and click on `email_content`.
<Frame>
![Add User Message](/images/difyworkflow101-lesson03-addusermessage.png)
</Frame>
<Tip>
You don't need to type out those curly brackets manually! Just hit `/`, then pick your variable from the menu.
</Tip>
4. Finally, your final Prompt will look like this:
<Frame>
![Final Prompt](/images/difyworkflow101-lesson03-finalprompt.png)
</Frame>
</Step>
</Steps>
<Check>
**Hooray!** You've finished your first AI workflow in Dify!
</Check>
## Run and Test
The ingredients are prepared, the chef is stand-by, and the instructions are ready. But does the dish taste good? Before we serve it to the customer, let's do a recipe testing.
Testing is the secret sauce to a stable workflow. It helps us catch those sneaky little issues before they are put into work.
### Quick Concept: The Checklist
Think of the **Checklist** as your workflow's personal Health Check Doctor.
It monitors your work in real-time, automatically spotting incomplete settings or mistakes (like a node that isn't connected to anything).
Glancing at the Checklist before you hit **Publish** button is the best way to catch unnecessary errors early.
### Hands-On 3: Test & Debug
<Steps>
<Step title="The Pre-flight Check">
Look at the top right corner of your canvas. Do you see the **Checklist** icon with a little number **1** on it? This is Dify telling you: Wait a second! There's one small thing missing here_._
<Frame>
![Checklist](/images/difyworkflow101-lesson03-checklist.png)
</Frame>
</Step>
<Step title="Analyze the Warning">
Click on it, and you will see a warning: **output variable is required**. It means that the output node receives nothing.
Imagine your Head Chef (the LLM) has finished cooking the food, but the Waiter (the Output Node) has empty hands.
</Step>
<Step title="Fix the Issue">
1. Click on the **Output Node**
2. Look for **Output Variable** and click the **Plus (+)** icon next to it
3. Type `email_reply` in the **Variable Name** field
4. Select the value: Click the variable selector and choose `{x} text` from the LLM Node
<Frame>
![Fix the Issue](/images/difyworkflow101-lesson03-fixtheissue.png)
</Frame>
</Step>
<Step title="Make a Test Run">
Now, there's no pop-up number on checklist. Let's do a test run.
Click **Test Run** at the top right corner of the canvas. Enter the customer's name and the email, then click **Start Run**.
<Frame>
![Test Run](/images/difyworkflow101-lesson03-testrun.png)
</Frame>
<CodeGroup>
```text Sample Email for Testing
Customer Name: Amanda
Original Email:
Hi there,
I'm writing to ask for more information about Dify. Could you please tell me more on it?
Best regards,
Amanda
```
</CodeGroup>
</Step>
<Step title="Success!">
This time, you will see green checkmarks ✅ on each of the nodes and the generated reply from AI.
</Step>
</Steps>
<Check>
**Great job!**
You didn't just build a workflow, but also know how to use the checklist and check before it goes live.
</Check>
## Mini Challenge
Use the same structure to build a travel planner.
<Tip>
Explore the **Prompt Generator** to help you craft better prompts!
<Frame>
![Prompt Generator](/images/difyworkflow101-lesson03-promptgenerator.png)
</Frame>
</Tip>