Build LLM applications using Dify's visual workflow platform...
Use this skill when you need to work with Dify, including:
Dify (Do It For You) is an open-source platform for building agentic workflows and LLM applications. It provides a visual interface for designing complex AI processes without extensive coding, supporting integration with hundreds of LLM models and existing tools.
Key Resources:
Platform Name: Do It For You - reflecting its purpose of simplifying LLM application development.
System Requirements:
# Clone the repository
git clone https://github.com/langgenius/dify.git
cd dify
# Navigate to docker directory
cd docker
# Copy environment example
cp .env.example .env
# Edit .env with your configuration
vim .env
# Start Dify
docker compose up -d
# Access the dashboard
open http://localhost/install
# Sign up at https://cloud.dify.ai
# Get 200 free GPT-4 calls
# No installation required
Kubernetes:
helm repo add dify https://langgenius.github.io/dify-helm
helm install dify dify/dify
AWS:
# Using AWS CDK
cdk deploy DifyStack
Azure/Google Cloud/Alibaba Cloud: See deployment guides in official documentation.
Key environment variables in .env:
# API Service
API_URL=http://localhost:5001
# Web Service
WEB_URL=http://localhost:3000
# Database
DB_USERNAME=postgres
DB_PASSWORD=your_password
DB_HOST=db
DB_PORT=5432
DB_DATABASE=dify
# Redis
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_PASSWORD=your_redis_password
# Storage (S3, Azure Blob, or local)
STORAGE_TYPE=local
STORAGE_LOCAL_PATH=storage
# Vector Database
VECTOR_STORE=weaviate # or pgvector, qdrant, milvus
# API Keys for LLM Providers
OPENAI_API_KEY=your_openai_key
ANTHROPIC_API_KEY=your_anthropic_key
# After installation, access http://localhost/install
# Complete initial setup wizard
# Create your first workspace
Application Types:
Via Web Interface:
Example System Prompt:
You are a helpful customer service assistant for TechCorp.
You can help users with:
- Product information
- Order tracking
- Technical support
- Account management
Be friendly, professional, and concise.
Create Knowledge Base:
Connect to Application:
Python Example:
import requests
API_KEY = "your_dify_api_key"
API_URL = "http://localhost/v1"
# Send a chat message
response = requests.post(
f"{API_URL}/chat-messages",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
},
json={
"inputs": {},
"query": "What are your business hours?",
"response_mode": "streaming",
"conversation_id": "",
"user": "user-123"
}
)
for line in response.iter_lines():
if line:
print(line.decode('utf-8'))
Node.js Example:
const fetch = require('node-fetch');
const API_KEY = 'your_dify_api_key';
const API_URL = 'http://localhost/v1';
async function sendMessage(query) {
const response = await fetch(`${API_URL}/chat-messages`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
inputs: {},
query: query,
response_mode: 'blocking',
user: 'user-123'
})
});
return await response.json();
}
sendMessage('Hello!').then(console.log);
Core Nodes:
Workflow Steps:
1. Start → User Message
2. Knowledge Retrieval → Search documentation
3. Conditional Branch:
- If relevant docs found → Use context
- If not found → Use general knowledge
4. LLM Node → Generate response
5. Tool Node → Create ticket (if needed)
6. End → Return response
Implementation:
{{retrieval.score}} > 0.7
Context: {{retrieval.context}}
User question: {{user.query}}
Provide a helpful answer based on the context.
If the context doesn't contain the answer, say so politely.
Python Code Node:
def main(data: dict) -> dict:
# Access workflow variables
user_query = data.get('query', '')
# Custom processing
processed = user_query.upper()
# Return results
return {
'result': processed,
'length': len(user_query)
}
JavaScript Code Node:
function main(data) {
const query = data.query || '';
// Process data
const words = query.split(' ');
return {
word_count: words.length,
first_word: words[0]
};
}
Built-in Tools:
Example: Research Agent
Agent Configuration:
Model: gpt-4
Reasoning Mode: ReAct
Tools:
- Google Search
- Wikipedia
- Web Scraper
System Prompt: |
You are a research assistant that helps users find
accurate information from reliable sources.
Always:
1. Search for current information
2. Cite your sources
3. Verify facts from multiple sources
Custom Tool Definition:
# Define custom tool for Dify
{
"name": "check_inventory",
"description": "Check product inventory levels",
"parameters": {
"type": "object",
"properties": {
"product_id": {
"type": "string",
"description": "Product identifier"
}
},
"required": ["product_id"]
}
}
Supported Formats:
1. Fixed Size Chunking:
Strategy: fixed_size
Chunk Size: 500 tokens
Overlap: 50 tokens
Use Case: General documents, articles
2. Paragraph Chunking:
Strategy: paragraph
Min Size: 100 tokens
Max Size: 800 tokens
Use Case: Well-formatted documents
3. Semantic Chunking:
Strategy: semantic
Model: text-embedding-ada-002
Similarity Threshold: 0.8
Use Case: Complex technical documents
Vector Search:
Type: vector
Top K: 5
Score Threshold: 0.7
Embedding Model: text-embedding-3-large
Hybrid Retrieval:
Type: hybrid
Vector Weight: 0.7
Keyword Weight: 0.3
Reranking: enabled
Reranking Model: cross-encoder/ms-marco-MiniLM-L-12-v2
Chat Messages:
POST /v1/chat-messages
Content-Type: application/json
Authorization: Bearer {api_key}
{
"inputs": {},
"query": "Your question here",
"response_mode": "streaming",
"user": "user-identifier"
}
Completion Messages:
POST /v1/completion-messages
Content-Type: application/json
Authorization: Bearer {api_key}
{
"inputs": {
"name": "John",
"topic": "AI"
},
"response_mode": "blocking",
"user": "user-123"
}
Feedback:
POST /v1/messages/{message_id}/feedbacks
Content-Type: application/json
Authorization: Bearer {api_key}
{
"rating": "like",
"user": "user-123"
}
Python SDK:
from dify_client import DifyClient
client = DifyClient(api_key="your_api_key")
# Chat completion
response = client.chat(
query="What is Dify?",
user="user-123",
conversation_id=None
)
print(response.answer)
Streaming Response:
for chunk in client.chat_stream(
query="Explain quantum computing",
user="user-123"
):
print(chunk.delta, end="", flush=True)
Security:
Performance:
Monitoring:
Metrics to Track:
- Response latency
- Token usage
- Error rates
- User satisfaction scores
- Knowledge retrieval accuracy
Scalability:
Document Quality:
Chunking:
Retrieval Tuning:
Symptoms:
docker compose up failsSolutions:
# Check logs
docker compose logs
# Verify environment variables
cat .env
# Ensure ports are available
lsof -i :3000
lsof -i :5001
# Reset and restart
docker compose down -v
docker compose up -d
Symptoms:
Solutions:
# Via API - trigger reindex
POST /v1/datasets/{dataset_id}/documents/{document_id}/processing
Symptoms:
Solutions:
Enable caching:
cache:
enabled: true
ttl: 3600
Use streaming mode:
response_mode: "streaming"
Optimize LLM settings:
max_tokens: 500 # Reduce if possible
temperature: 0.7
top_p: 0.9
Check database performance:
# Monitor PostgreSQL
docker exec -it dify-db psql -U postgres -c "\
SELECT pid, query, state, wait_event_type \
FROM pg_stat_activity WHERE state != 'idle';"
Symptoms:
Solutions:
# Verify API keys in .env
cat .env | grep API_KEY
# Check provider status
curl https://status.openai.com/api/v2/status.json
# Implement retry logic
max_retries: 3
retry_delay: 1000 # milliseconds
Use Workflow Debugger:
Enable Detailed Logging:
# In .env
LOG_LEVEL=DEBUG
Test Components Individually:
Monitor System Resources:
docker stats
Add custom LLM providers:
# model_providers/custom_provider.py
from dify.core.model_runtime import ModelProvider
class CustomProvider(ModelProvider):
def get_models(self):
return [
{
'model': 'custom-gpt',
'label': 'Custom GPT Model',
'model_type': 'llm'
}
]
def invoke(self, model, credentials, prompt, **kwargs):
# Custom API call logic
response = your_api_call(prompt)
return response
Parallel Execution:
Workflow:
- Node1: LLM Call
- Parallel:
- Node2a: Knowledge Retrieval
- Node2b: External API Call
- Node3: Combine Results
Conditional Caching:
# Cache expensive operations
if cache.exists(query_hash):
return cache.get(query_hash)
else:
result = expensive_operation()
cache.set(query_hash, result, ttl=3600)
return result
High Availability Setup:
Services:
API:
replicas: 3
load_balancer: nginx
Worker:
replicas: 5
queue: redis
Database:
primary: postgres-main
replicas: 2
backup: daily
Monitoring Stack:
Monitoring:
- Prometheus: Metrics collection
- Grafana: Visualization
- Loki: Log aggregation
- Alertmanager: Alerts
Dify is an active open-source project with 8,220+ commits.
Ways to Contribute:
Development Setup:
# Clone repository
git clone https://github.com/langgenius/dify.git
cd dify
# See deployment guide
# https://docs.dify.ai/development/deploy-from-source
Security Issues: Email: security@dify.ai
Last Updated: 2025-12-15 Skill Version: 1.0.0 Dify GitHub: 8,220+ commits, actively maintained
Note: Dify is rapidly evolving. Always check the official documentation for the latest features and best practices. This skill is based on official documentation and repository information as of December 2025.