Practical Examples
Three examples: a knowledge FAQ bot, a classify-then-answer flow, and a Python Service API client. Finish Quick Start and at least one model provider first.
Example 1: FAQ bot on a knowledge base
Goal: Colleagues ask policy questions in natural language. Answers must point at the doc, not at the model’s vibes.
Prepare faq.md (sample):
Steps:
- Knowledge: create a dataset, upload
faq.md, General or Parent-child chunks, High Quality + hybrid retrieval - Retrieval test: “What is the daily local-transit cap?” should hit the “80” passage
- Create a Chatbot and bind that dataset
- Freeze evidence rules in the prompt, for example:
- In preview, ask something absent (meal overtime). Expect refusal, not a made-up number
- Publish a Web App and open it in another browser
Compare LangChain’s doc Q&A: there you build a retriever; here the knowledge base replaces that indexing code.
Example 2: Classify, then answer (Workflow / Chatflow)
Goal: Policy questions retrieve; chit-chat and off-topic get a fixed refusal—do not scan the whole corpus for “hi.”
Create a Chatflow (chat UI) or Workflow (one-shot API). Canvas:
- User Input — user text as
query - Question Classifier —
policy(travel / devices / receipts),chitchat,other policy→ Knowledge Retrieval (example 1 dataset) → LLM (answer only from hits)chitchat→ LLM (short greeting + “I only answer policy”)other→ LLM or Template (fixed: “Please rephrase as a policy question”)- Join edges on Answer (Chatflow) or Output (Workflow)
Label 15 questions and watch the classifier. If it flaps, rewrite class descriptions (“asks about amounts, invoices, badge pickup”) instead of a single word policy. More compliance-friendly than a lone Agent: the path is on the graph.
Example 3: Python backend integration
Goal: Your site takes the question; the server calls Dify; the browser never sees the key.
Use a stable id from your login system as user. The second turn must send conversation_id or “that” has no antecedent. Chat apps use /v1/chat-messages; a pure Workflow uses the run endpoint on that app’s API page and passes inputs.