Dify workflow patterns — 10 we actually use in production
Ten Dify workflow patterns that survive production — KB fallback, context compression, concurrent tool calls, retries and more.
Pattern 1 — KB fallback#
Problem: top-1 retrieval below threshold shouldn’t be answered confidently.
Do: “Retrieval → conditional branch” — if score < 0.5, reply “No relevant info, handing off.”
Pattern 2 — Context compression#
Problem: long history blows up tokens.
Do: “Get context → LLM summarize → replace history with summary.” Compression ratio typically 5-10×.
Pattern 3 — Intent + routing#
Problem: pre-sales / post-sales / complaints in one bot performs poorly.
Do: front-load an LLM classifier (enum output), branch on it.
Pattern 4 — Concurrent tool calls#
Problem: looking up order + shipping + coupons serially is slow.
Do: “Iterate” or “parallel” nodes — fire three HTTP calls, merge results.
Pattern 5 — Retry on failure#
Problem: HTTP tools occasionally 500.
Do: HTTP node “3 retries with exponential backoff” + fallback branch returns a degraded answer.
Pattern 6 — Rate limiting#
Problem: promo day floods downstream ERP.
Do: Add a “rate limit” node at the start keyed by user_id; over N/min → queue.
Pattern 7 — Money values must be sourced#
Problem: user asks refund amount; LLM cannot compute it.
Do:
1. HTTP(order API) → order_amount
2. LLM → answer using `{{order_amount}}`
3. Prompt: "Use `{{order_amount}}` exactly; do not rewrite."
Pattern 8 — Human fallback#
Problem: AI can’t answer — don’t dead-end.
Do: failure branch calls Chatwoot API to open a ticket with the full context as a note.
Pattern 9 — Multi-turn form#
Problem: collecting name / email / description rarely happens in one turn.
Do: Use Conversation App, check completeness per turn, ask for whatever is missing.
Pattern 10 — A/B testing prompts#
Problem: was the new prompt actually better?
Do: random branch — 50% old prompt, 50% new — tag user_id, compare CSAT later.
General lessons#
- Keep workflow nodes atomic — easier to debug individually
- Declare key variables in the Start node, not scattered
- Use different temperatures for different LLM nodes (generation vs classification)
- Use Dify’s debug pane to step through — faster than full logs