> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dify.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Lesson 6: Handle Multiple Tasks (Parameter Extraction & Iteration)

Imagine you get an email saying:

> Hi! What exactly is Dify? Also, which models does it support? And do you have a free plan?

If we send this to our current AI assistant, it might only answer the first question or give a vague response to both.

We need a way to identify every question first, and then loop through our Knowledge Base to answer them one by one.

## Parameter Extractor

<Frame>
  <img src="https://mintcdn.com/dify-6c0370d8/W-660XSNevX1HYUo/images/use-dify/tutorial/workflow-101-lesson-06/parameter-extractor.png?fit=max&auto=format&n=W-660XSNevX1HYUo&q=85&s=0cc50fc71964e9ba999a2c485b162a3c" alt="Parameter Extractor" width="608" height="212" data-path="images/use-dify/tutorial/workflow-101-lesson-06/parameter-extractor.png" />
</Frame>

You can take Parameter Extractor as a highly organized scout. It reads a paragraph of texts (like an email) and picks out the specific piece of information you asked for, putting them into a neat and organized list.

### Hands-On 1: Add Parameter Extractor

Before we upgrade the email assistant, let's remove these nodes: Knowledge Retrieval, If/Else, LLM, LLM 2, and Variable Aggregator.

<Steps>
  <Step title="Add the Node">
    Right after the Start node, add the **Parameter Extractor** node.

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8/W-660XSNevX1HYUo/images/use-dify/tutorial/workflow-101-lesson-06/add-parameter-extractor.png?fit=max&auto=format&n=W-660XSNevX1HYUo&q=85&s=a0d0ffd22b85af35ac0969f443bd3f1f" alt="Add Parameter Extractor" width="1326" height="316" data-path="images/use-dify/tutorial/workflow-101-lesson-06/add-parameter-extractor.png" />
    </Frame>
  </Step>

  <Step title="Set the Input">
    Click Parameter Extractor, and in the **Input Variable** section on the right panel, choose `email_content`.

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8/W-660XSNevX1HYUo/images/use-dify/tutorial/workflow-101-lesson-06/set-the-input.png?fit=max&auto=format&n=W-660XSNevX1HYUo&q=85&s=eaea05aecf31f23df0c733cce1e46464" alt="Set the Input" width="778" height="422" data-path="images/use-dify/tutorial/workflow-101-lesson-06/set-the-input.png" />
    </Frame>

    Since AI doesn't automatically know which specific information we need from the email, we must tell it to collect all the questions.
  </Step>

  <Step title="Add Extract Parameter">
    Click the **plus (+)** icon next to **Extract Parameters** to start defining what the AI should look for. Let's call it `question_list`.

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8/W-660XSNevX1HYUo/images/use-dify/tutorial/workflow-101-lesson-06/add-extract-parameter.png?fit=max&auto=format&n=W-660XSNevX1HYUo&q=85&s=ab8da89dab8852d6a799ffe75d57af7d" alt="Add Extract Parameter" width="838" height="1000" data-path="images/use-dify/tutorial/workflow-101-lesson-06/add-extract-parameter.png" />
    </Frame>

    <Info>
      **Parameter Types**

      If Parameter Extractor is a scout, then Type is the bucket they use to carry the info. You need the right bucket for the right information.

      **Single Items (The Small Buckets)**

      * **String (Text)**: For a single piece of text, e.g. customer's name
      * **Number**: For a single digit, e.g. order quantity
      * **Boolean**: A simple Yes or No (True/False), good for a judgement result or a decision

      **List Items (The Arrays)**

      * **Array\[String]**: Array means List, and String means Text. So, `Array[String]` means we are using a basket that can hold multiple pieces of text—like all the separate questions in an email
      * **Array\[Number]**: A container that holds different numbers, e.g. a list of prices or commodities
      * **Array\[Boolean]**: Used to store multiple Yes/No judgment results. For example, checking a list containing multiple to-do items and returning whether each item is completed, such as `[Yes, No, Yes]`
      * **Array\[Object]**: An advanced folder that holds sets of data (like a contact list where each entry has a Name and a Phone Number)
    </Info>
  </Step>

  <Step title="Finish Adding Extract Parameter">
    1. Based on our needs, choose `Array[String]` for the email content.
    2. Add description for providing additional context. You can write: All the questions raised by the user in the email. After that, click **Add**.

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8/W-660XSNevX1HYUo/images/use-dify/tutorial/workflow-101-lesson-06/finish-add-extract-parameter.png?fit=max&auto=format&n=W-660XSNevX1HYUo&q=85&s=6f625186b687f2c0e6fc9f62565c7da1" alt="Finish Adding Extract Parameter" width="838" height="998" data-path="images/use-dify/tutorial/workflow-101-lesson-06/finish-add-extract-parameter.png" />
    </Frame>
  </Step>

  <Step title="Add Instructions">
    In the **Instructions** box below the extracted parameters, type a clear command to tell the AI how to act.

    For example: Extract all questions from the email, and make each question as a single item on the list.
  </Step>
</Steps>

By doing this, the node will be able to find all the questions in the email. Now that our scout has successfully gathered the Golden Nuggets, we need to move to the next step: teaching the AI to process each question.

## Iteration

<Frame>
  <img src="https://mintcdn.com/dify-6c0370d8/W-660XSNevX1HYUo/images/use-dify/tutorial/workflow-101-lesson-06/iteration.png?fit=max&auto=format&n=W-660XSNevX1HYUo&q=85&s=bd15b71e2daab281c871cee3cbc2d606" alt="Iteration" width="576" height="332" data-path="images/use-dify/tutorial/workflow-101-lesson-06/iteration.png" />
</Frame>

With iteration, your assistant has a team of identical twins. When you hand over a list (like questions in the mail list), a twin appears for every single item on that list.

Each twin takes their assigned item and performs the exact same task you've set up, ensuring nothing gets missed.

### Hands-On 2: Set up Iteration Node

<Steps>
  <Step title="Add the Node">
    1. Add an Iteration node after the Parameter Extractor.
    2. Click on the Iteration node and navigate to the Input panel on the right.
    3. Select `{x} question_list` from the Parameter Extractor. Leave the output variable blank for now.

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8/W-660XSNevX1HYUo/images/use-dify/tutorial/workflow-101-lesson-06/add-iteration.png?fit=max&auto=format&n=W-660XSNevX1HYUo&q=85&s=ceff768cc655e3ba5af3e689e784bc6e" alt="Add Iteration Node" width="782" height="644" data-path="images/use-dify/tutorial/workflow-101-lesson-06/add-iteration.png" />
    </Frame>

    **Advanced Options in Iteration**

    In the Iteration panel, you'll see more settings. Let's have a quick walk-through.

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8/W-660XSNevX1HYUo/images/use-dify/tutorial/workflow-101-lesson-06/advanced-iteration-options.png?fit=max&auto=format&n=W-660XSNevX1HYUo&q=85&s=43410b854452093e2239cca328d364e8" alt="Advanced Options in Iteration" width="1214" height="476" data-path="images/use-dify/tutorial/workflow-101-lesson-06/advanced-iteration-options.png" />
    </Frame>

    **Parallel Mode**: OFF (Default)

    * When disabled, the workflow processes each item in the list one after another (finish Question 1, then move to Question 2).
    * When enabled, the workflow attempts to process all items in the list simultaneously (similar to 5 chefs cooking 5 different dishes at the same time).

    **Error Response Method**: Terminate on error by default.

    * **Terminate**: This means if any single item in the list (e.g., the 2nd question) fails during the sub-process, the entire workflow will stop immediately
    * **Ignore Error and Continue**: This means even if the 2nd question fails, the workflow will skip it and move on to process the remaining questions
    * **Remove Abnormal Output**: Similar to ignore, but it also removes that specific failed item from the final output list results

    Back to the workflow, you'll see a sub-process area under the Iteration node. Every node inside this box will run once for every question.
  </Step>

  <Step title="Add Knowledge Retrieval Node">
    1. Inside the Iteration box, add a Knowledge Retrieval node.
    2. Set the query text to `{x} item`. In Iteration, item always refers to the question that is currently being processed.

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8/W-660XSNevX1HYUo/images/use-dify/tutorial/workflow-101-lesson-06/knowledge-retrieval-query-text.png?fit=max&auto=format&n=W-660XSNevX1HYUo&q=85&s=ace5330dd78dac95bb38335bbb668793" alt="Add Knowledge Retrieval Node and Set Query Text" width="401" height="340" data-path="images/use-dify/tutorial/workflow-101-lesson-06/knowledge-retrieval-query-text.png" />
    </Frame>
  </Step>

  <Step title="Add LLM Node">
    1. Add an LLM node after Knowledge Retrieval.
    2. Configure it to answer the question based on the retrieved context.

    <Tip>
      Remember Lesson 4? Use those Prompt skills and don't forget context!
    </Tip>

    Feel free to use the prompt below:

    **System**:

    ```plaintext wrap theme={null}
    You are a professional Dify Customer Service Manager. Please provide a response to questions strictly based on the `Context`.
    ```

    **User**:

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

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8/W-660XSNevX1HYUo/images/use-dify/tutorial/workflow-101-lesson-06/add-llm-and-prompt.png?fit=max&auto=format&n=W-660XSNevX1HYUo&q=85&s=06873a578f29c2cd2dd8b8ad967a8b83" alt="Add LLM Prompt" width="2172" height="1010" data-path="images/use-dify/tutorial/workflow-101-lesson-06/add-llm-and-prompt.png" />
    </Frame>

    Since the iteration node generates an answer for each individual question, we need to gather all these answers to create one complete reply email.
  </Step>

  <Step title="Set Iteration Output">
    1. Click the Iteration node.
    2. In the **Output Variable**, select the variable representing the LLM's answer inside the loop. Now, the Iteration node will collect every answer and gather them into a new list.

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8/W-660XSNevX1HYUo/images/use-dify/tutorial/workflow-101-lesson-06/set-iteration-output.png?fit=max&auto=format&n=W-660XSNevX1HYUo&q=85&s=143cedf39ca1a8eb95b30fee23d7988e" alt="Set Iteration Output" width="405" height="458" data-path="images/use-dify/tutorial/workflow-101-lesson-06/set-iteration-output.png" />
    </Frame>
  </Step>

  <Step title="Add Final LLM Node">
    Finally, connect one last LLM node. This final editor will take all the collected answers and polish them into one professional email.

    Don't forget to add prompt in system and user message. Feel free to refer the prompt below.

    ```plaintext wrap theme={null}
    You are a professional customer service assistant. Please organize the answers prepared for customer into a clear and complete email reply.
    Sign the email as Anne.
    ```

    **User**:

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

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8/W-660XSNevX1HYUo/images/use-dify/tutorial/workflow-101-lesson-06/add-final-llm-node.png?fit=max&auto=format&n=W-660XSNevX1HYUo&q=85&s=210a15c11654a2e798a060562e5f6207" alt="Add Final LLM Node" width="1366" height="1060" data-path="images/use-dify/tutorial/workflow-101-lesson-06/add-final-llm-node.png" />
    </Frame>
  </Step>

  <Step title="Final Check">
    1. Click on the checklist to see if there's any missing spot. According to the notes, we need to connect Output node while fix the invalid variable issue.
    2. Connect Output node with LLM 2 node before it, remove its previous variable, then select text in LLM 2 as the output variable.

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8/W-660XSNevX1HYUo/images/use-dify/tutorial/workflow-101-lesson-06/output-variable.png?fit=max&auto=format&n=W-660XSNevX1HYUo&q=85&s=acc5da9334775a4785978fb60602b1a8" alt="Select Output Variable" width="612" height="376" data-path="images/use-dify/tutorial/workflow-101-lesson-06/output-variable.png" />
    </Frame>
  </Step>
</Steps>

Now, you can write a test email with 3 different questions and check on the generated reply.

## Mini Challenge

What else could Parameter Extractor find?

<Tip>
  Try exploring the parameter type in it.
</Tip>
