> ## Documentation Index
> Fetch the complete documentation index at: https://dify-6c0370d8-preview-yajing-marketplace-doc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Lesson 8: The Agent Node

Let's look back at the upgrades we've made for our email assistant.

* Learned to Read: It can search a Knowledge Base
* Learned to Choose: It uses Conditions to make decisions
* Learned to Multitask: It handles multiple questions via Iteration
* Learned to Use Tools: It can access the Internet via Google Search

These nodes work, but we have had to describe every step in advance. What if we could give the job to an AI teammate that already knows how to reason, use its resources, and improve over time?

Meet your AI teammate: the **Agent**.

## From Workflow to Agentic Workflow

A traditional workflow follows a path designed by its builder. An Agentic workflow combines that dependable structure with an Agent that can decide how to complete a task inside the boundaries you set.

Think of the workflow as the shared operating procedure and the Agent as the teammate performing part of it:

* The **workflow** supplies inputs, order, checks, fallbacks, and outputs.
* The **Agent** works toward a goal, uses its available knowledge and tools, and returns a result.
* The **Agent node** is where that Agent appears in this particular workflow.

The same Agent can be invited into several workflows, or even appear more than once in one workflow. Its core identity and capabilities belong to the Agent. The instructions you add in an Agent node describe only its job at that point in the workflow.

You do not need to install or select a reasoning strategy. The Agent manages its own reasoning loop. Your job is to give it the right assignment, inputs, and expected outputs.

## Agent & Agent Node

There are two ways to add an Agent to a workflow:

* **Invite an Agent**: Reuse an existing Agent that you or your team has already built.
* **Start from Scratch**: Create a one-time Agent directly on the canvas. This is useful for a role that exists only in this workflow. You can save it to **Agents** later if it becomes reusable.

In the earlier lessons, we did not create an agent, so we will start from scratch and this tutorial works from a clean workspace. At the end, you can save it to the **Agents** page and reuse it elsewhere.

After this lesson, the whole workflow is: `Start → Knowledge Retrieval → Product Support Agent → Output`

## Hands-on 1: Create an Agent

Our goal is to replace the entire manually orchestrated middle section with one Agent. The Agent will receive the complete customer email, identify and answer every question, and return one coherent email body.

<Steps>
  <Step title="Remove Extra Nodes">
    Starting from Lesson 7's workflow, delete the Parameter Extractor and the Iteration node (everything inside it goes with it), leaving only Start and Output.
  </Step>

  <Step title="Add Knowledge Retrieval">
    After Start, click **+** and add a Knowledge Retrieval node. Select the Dify product Knowledge Base used in the previous lessons.

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8-preview-yajing-marketplace-doc/sPaesDqCRjA9finA/images/use-dify/tutorial/workflow-101-lesson-08/add-knowledge-retrieval.png?fit=max&auto=format&n=sPaesDqCRjA9finA&q=85&s=13aa08b5f569e3263dc9a2af06c514bf" alt="Add a Knowledge Retrieval Node" width="1166" height="424" data-path="images/use-dify/tutorial/workflow-101-lesson-08/add-knowledge-retrieval.png" />
    </Frame>
  </Step>

  <Step title="Add an Agent Node">
    After Knowledge Retrieval, click **+**, choose **Agent**, and select **Start from Scratch**.

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8-preview-yajing-marketplace-doc/sPaesDqCRjA9finA/images/use-dify/tutorial/workflow-101-lesson-08/create-agent-node.png?fit=max&auto=format&n=sPaesDqCRjA9finA&q=85&s=3e03e0a4a6a84b11b71824846ac900bd" alt="Add an Agent Node and Start from Scratch" width="2086" height="816" data-path="images/use-dify/tutorial/workflow-101-lesson-08/create-agent-node.png" />
    </Frame>

    This opens the agent's setup over the workflow canvas:

    * The **Configure** panel on the left contains the model, prompt, skills, files, tools, etc. You can set them up manually.
    * **Build** on the right lets you build your agent by chatting, and the configuration is filled automatically.
    * **Preview** lets you try the Agent before returning to the workflow.

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8-preview-yajing-marketplace-doc/sPaesDqCRjA9finA/images/use-dify/tutorial/workflow-101-lesson-08/build-mode.png?fit=max&auto=format&n=sPaesDqCRjA9finA&q=85&s=30ddff001485f533d825c3c1fceadaa9" alt="The Agent Setup with Build Mode" width="2328" height="1246" data-path="images/use-dify/tutorial/workflow-101-lesson-08/build-mode.png" />
    </Frame>
  </Step>

  <Step title="Connect to the Required Resources">
    Before entering Build mode, do a quick setup:

    * **Model**: select a compatible model if the current model is missing or marked incompatible.
    * **Tools**: add Google Search.
  </Step>

  <Step title="Build the Agent by Chatting">
    In Build mode, enter the following request.

    ```text wrap theme={null}
    Create a Dify Product Support Agent.
    Configure the Agent to use context provided by the workflow first and search only when that context is insufficient or current information is required.
    Do not create duplicate search capabilities.
    ```

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8-preview-yajing-marketplace-doc/sPaesDqCRjA9finA/images/use-dify/tutorial/workflow-101-lesson-08/build-by-chatting.png?fit=max&auto=format&n=sPaesDqCRjA9finA&q=85&s=719b28ef6112583de00c07a91581cda5" alt="Describe the Agent in Build Mode" width="2974" height="1648" data-path="images/use-dify/tutorial/workflow-101-lesson-08/build-by-chatting.png" />
    </Frame>

    After the build finishes, the agent has set up its own assets:

    * `product-support`: an embedded skill carrying the Agent's support behavior and source-use rules.
    * `build_note.md`: a note recording what was set up during the build chat.
  </Step>

  <Step title="Add the Main Prompt">
    After you click **Apply**, Build mode closes and the **Configure** panel becomes editable again. Add the following instruction to **Prompt**:

    ```text wrap theme={null}
    Answer accurately using the context provided with each assignment. Treat that context as the primary source. Use Google Search only when the context is insufficient, irrelevant, or outdated.
    ```

    The generated skill defines the Agent's reusable product-support expertise. The prompt adds a clear rule for when the Agent should use Google Search.

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8-preview-yajing-marketplace-doc/sPaesDqCRjA9finA/images/use-dify/tutorial/workflow-101-lesson-08/generated-skills.png?fit=max&auto=format&n=sPaesDqCRjA9finA&q=85&s=9a9cef8214e2fb7d808a0f6819e686ab" alt="The Generated Skill and Prompt in Configure" width="2588" height="1680" data-path="images/use-dify/tutorial/workflow-101-lesson-08/generated-skills.png" />
    </Frame>
  </Step>

  <Step title="Preview the Agent">
    Switch to **Preview** and ask a Dify product question to confirm the agent answers concisely and searches only when necessary.

    When the setup looks correct, close it and return to the workflow canvas.
  </Step>
</Steps>

<Check>
  🎉 The Agent is ready now.
</Check>

## Hands-on 2: Assign the Workflow Task

Now the Agent has a reusable role, support expertise, and a search tool. Next, let's give it an assignment of what to do in this workflow.

<Steps>
  <Step title="Provide the Email and Retrieved Knowledge">
    Select the Agent node. In **Agent task**, describe this step's assignment:

    ```text wrap theme={null}
    Answer every question or request in {{email_content}}.
    Use the retrieved product knowledge in {{result}} first.
    Combine all answers into one email body.
    ```

    Type `/` to insert `email_content` from User Input and `result` from Knowledge Retrieval, so they arrive as variables rather than plain text.

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8-preview-yajing-marketplace-doc/sPaesDqCRjA9finA/images/use-dify/tutorial/workflow-101-lesson-08/agent-task.png?fit=max&auto=format&n=sPaesDqCRjA9finA&q=85&s=d41faf90718d245e28eb9fcaed7d65d3" alt="Describe the Assignment in Agent Task" width="1748" height="1198" data-path="images/use-dify/tutorial/workflow-101-lesson-08/agent-task.png" />
    </Frame>
  </Step>

  <Step title="Connect the Output Node">
    Click the Output node and set its variable to the Agent's `text` output. This way, the workflow returns the generated email reply.

    <Frame>
      <img src="https://mintcdn.com/dify-6c0370d8-preview-yajing-marketplace-doc/sPaesDqCRjA9finA/images/use-dify/tutorial/workflow-101-lesson-08/output-node.png?fit=max&auto=format&n=sPaesDqCRjA9finA&q=85&s=802d1cde3242d8c7ad26e21aeec972e3" alt="Set the Output to the Agent's Text" width="2796" height="798" data-path="images/use-dify/tutorial/workflow-101-lesson-08/output-node.png" />
    </Frame>
  </Step>
</Steps>

Here comes the final workflow.

<Frame>
  <img src="https://mintcdn.com/dify-6c0370d8-preview-yajing-marketplace-doc/sPaesDqCRjA9finA/images/use-dify/tutorial/workflow-101-lesson-08/final-workflow.png?fit=max&auto=format&n=sPaesDqCRjA9finA&q=85&s=a324abff5160dafbb6fac2dbf6973cc8" alt="The Final Four-Node Workflow" width="2576" height="478" data-path="images/use-dify/tutorial/workflow-101-lesson-08/final-workflow.png" />
</Frame>

Click **Test Run** and input a customer email with a few questions. The Agent answers from the retrieved knowledge and searches only when it needs to.

## Optionally Save the Agent

The Product Support Agent is already stored as part of this workflow. You do not need to save it separately to continue to the next lesson.

To reuse it in other workflows: click the Agent node to open its setup, then in **Configure**, click **⋯** and select **Save to Agents**.

<Frame>
  <img src="https://mintcdn.com/dify-6c0370d8-preview-yajing-marketplace-doc/sPaesDqCRjA9finA/images/use-dify/tutorial/workflow-101-lesson-08/save-to-agents.png?fit=max&auto=format&n=sPaesDqCRjA9finA&q=85&s=d16a3ce122feebe7227baffb5f5cc215" alt="Save the Agent to Agents" width="918" height="250" data-path="images/use-dify/tutorial/workflow-101-lesson-08/save-to-agents.png" />
</Frame>

Give the agent a name, an icon, and a description.

<Frame>
  <img src="https://mintcdn.com/dify-6c0370d8-preview-yajing-marketplace-doc/sPaesDqCRjA9finA/images/use-dify/tutorial/workflow-101-lesson-08/add-agent-info.png?fit=max&auto=format&n=sPaesDqCRjA9finA&q=85&s=6dc35f3e9418b71b65a6a0ff650d8342" alt="Name the Saved Agent" width="2218" height="974" data-path="images/use-dify/tutorial/workflow-101-lesson-08/add-agent-info.png" />
</Frame>

## Mini Challenge

1. Add a requirement that the Agent clearly labels information obtained from an Internet search.
2. Ask one question that cannot be answered from either the retrieved knowledge or Google Search. Confirm that the Agent acknowledges the limitation instead of omitting the question.
