In this categoryDify · 9
DifyIntermediate

How to Build an AI Agent in Dify

Create a Dify agent that can call tools, search the web, and run multi-step tasks without writing orchestration code.

15 minIntermediate

A Dify agent is a loop: the model reads your instruction, decides which tool to call, reads the result, and repeats until the task is done. You define the tools and the stopping condition; Dify handles the rest. This guide builds a research agent that searches the web and returns a structured summary.

What you need

  • Dify running locally or on Dify Cloud
  • A model provider connected (Claude or GPT-4o recommended for agents)
  • About 15 minutes

Step 1: Create an Agent app

From the Dify dashboard, click New App and select Agent. Unlike a basic Chatbot, Agent mode enables the tool-call loop so the model can take actions between turns.

Step 2: Write a system prompt with scope

The system prompt is the only place where you control how far the agent goes. Include: what the agent is for, what tools it is allowed to use, and what done looks like.

Dify - System prompt
You
You are a research assistant. When given a topic, search the web for the three most relevant recent sources and return a 150-word summary with citations. Stop after the summary.
A scoped system prompt stops the agent from over-reaching.

Step 3: Enable tools

In the Tools panel on the right, toggle on Web Search. Dify routes each search call through its built-in connector — no API key needed for the basic tier. You can also add Google Search, Bing, or any custom tool you build via the Tool definition editor.

Step 4: Set iteration limits

In Agent Settings, set Max Iterations to 5. This stops a confused agent from looping forever. For most research tasks, three iterations is enough: one search, one follow-up, one synthesis.

Step 5: Test and publish

Hit Debug in the top bar and type a research question. Watch the Thought panel on the left to see which tools the agent calls and what it reads. Adjust the system prompt based on what you see, then publish when the output looks right.

Debugging tip
If the agent answers without calling any tools, it means the system prompt did not make tool use mandatory. Add: 'Always call the web search tool at least once before writing your answer.'

Watch related tutorials

Free weekly email

New guides in your inbox

Fresh step-by-step how-to guides as we publish them. One email a week, no more.

Tags
#dify#dify agent#dify ai agent#tools#agent#llm