You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gcgj-dify-1.7.0/README.md

21 KiB

cover-v5-optimized

📌 Introducing Dify Workflow File Upload: Recreate Google NotebookLM Podcast

Dify Cloud · Self-hosting · Documentation · Dify edition overview

Static Badge Static Badge chat on Discord join Reddit follow on X(Twitter) follow on LinkedIn Docker Pulls Commits last month Issues closed Discussion posts

README in English 繁體中文文件 简体中文版自述文件 日本語のREADME README en Español README en Français README tlhIngan Hol README in Korean README بالعربية Türkçe README README Tiếng Việt README in Deutsch README in বাংলা

Dify is an open-source LLM app development platform. Its intuitive interface combines agentic AI workflow, RAG pipeline, agent capabilities, model management, observability features, and more, allowing you to quickly move from prototype to production.

Quick start

Before installing Dify, make sure your machine meets the following minimum system requirements:

  • CPU >= 2 Core
  • RAM >= 4 GiB

The easiest way to start the Dify server is through docker compose. Before running Dify with the following commands, make sure that Docker and Docker Compose are installed on your machine:

cd dify
cd docker
cp .env.example .env
docker compose up -d

After running, you can access the Dify dashboard in your browser at http://localhost/install and start the initialization process.

Seeking help

Please refer to our FAQ if you encounter problems setting up Dify. Reach out to the community and us if you are still having issues.

If you'd like to contribute to Dify or do additional development, refer to our guide to deploying from source code

Key features

1. Workflow: Build and test powerful AI workflows on a visual canvas, leveraging all the following features and beyond.

2. Comprehensive model support: Seamless integration with hundreds of proprietary / open-source LLMs from dozens of inference providers and self-hosted solutions, covering GPT, Mistral, Llama3, and any OpenAI API-compatible models. A full list of supported model providers can be found here.

providers-v5

3. Prompt IDE: Intuitive interface for crafting prompts, comparing model performance, and adding additional features such as text-to-speech to a chat-based app.

4. RAG Pipeline: Extensive RAG capabilities that cover everything from document ingestion to retrieval, with out-of-box support for text extraction from PDFs, PPTs, and other common document formats.

5. Agent capabilities: You can define agents based on LLM Function Calling or ReAct, and add pre-built or custom tools for the agent. Dify provides 50+ built-in tools for AI agents, such as Google Search, DALL·E, Stable Diffusion and WolframAlpha.

6. LLMOps: Monitor and analyze application logs and performance over time. You could continuously improve prompts, datasets, and models based on production data and annotations.

7. Backend-as-a-Service: All of Dify's offerings come with corresponding APIs, so you could effortlessly integrate Dify into your own business logic.

Feature Comparison

Feature Dify.AI LangChain Flowise OpenAI Assistants API
Programming Approach API + App-oriented Python Code App-oriented API-oriented
Supported LLMs Rich Variety Rich Variety Rich Variety OpenAI-only
RAG Engine
Agent
Workflow
Observability
Enterprise Feature (SSO/Access control)
Local Deployment

Using Dify

  • Cloud
    We host a Dify Cloud service for anyone to try with zero setup. It provides all the capabilities of the self-deployed version, and includes 200 free GPT-4 calls in the sandbox plan.

  • Self-hosting Dify Community Edition
    Quickly get Dify running in your environment with this starter guide. Use our documentation for further references and more in-depth instructions.

  • Dify for enterprise / organizations
    We provide additional enterprise-centric features. Log your questions for us through this chatbot or send us an email to discuss enterprise needs.

    For startups and small businesses using AWS, check out Dify Premium on AWS Marketplace and deploy it to your own AWS VPC with one click. It's an affordable AMI offering with the option to create apps with custom logo and branding.

Staying ahead

Star Dify on GitHub and be instantly notified of new releases.

star-us

Advanced Setup

If you need to customize the configuration, please refer to the comments in our .env.example file and update the corresponding values in your .env file. Additionally, you might need to make adjustments to the docker-compose.yaml file itself, such as changing image versions, port mappings, or volume mounts, based on your specific deployment environment and requirements. After making any changes, please re-run docker-compose up -d. You can find the full list of available environment variables here.

If you'd like to configure a highly-available setup, there are community-contributed Helm Charts and YAML files which allow Dify to be deployed on Kubernetes.

Using Terraform for Deployment

Deploy Dify to Cloud Platform with a single click using terraform

Azure Global
Google Cloud

Using AWS CDK for Deployment

Deploy Dify to AWS with CDK

AWS

Using Alibaba Cloud Computing Nest

Quickly deploy Dify to Alibaba cloud with Alibaba Cloud Computing Nest

Using Alibaba Cloud Data Management

One-Click deploy Dify to Alibaba Cloud with Alibaba Cloud Data Management

Contributing

For those who'd like to contribute code, see our Contribution Guide. At the same time, please consider supporting Dify by sharing it on social media and at events and conferences.

We are looking for contributors to help translate Dify into languages other than Mandarin or English. If you are interested in helping, please see the i18n README for more information, and leave us a comment in the global-users channel of our Discord Community Server.

Community & contact

  • GitHub Discussion. Best for: sharing feedback and asking questions.
  • GitHub Issues. Best for: bugs you encounter using Dify.AI, and feature proposals. See our Contribution Guide.
  • Discord. Best for: sharing your applications and hanging out with the community.
  • X(Twitter). Best for: sharing your applications and hanging out with the community.

Contributors

Star history

Star History Chart

Security disclosure

To protect your privacy, please avoid posting security issues on GitHub. Instead, send your questions to security@dify.ai and we will provide you with a more detailed answer.

License

This repository is available under the Dify Open Source License, which is essentially Apache 2.0 with a few additional restrictions.

Dify 多智能体记忆问题复现方案

问题概述

根据 GitHub Issue #21640,在多智能体聊天流程系统中存在记忆隔离问题:

  • 每个智能体都有记忆功能10条消息
  • 当对话流程切换到不同智能体时,新智能体会看到来自其他智能体的聊天历史
  • 这导致智能体产生"幻觉"hallucination回答不准确

复现方法

方法1手动复现推荐

  1. 登录Dify控制台

    • 访问您的Dify实例
    • 登录管理员账户
  2. 创建工作流应用

    • 创建新的工作流应用
    • 选择"工作流"模式
  3. 添加节点

    Start节点 → 问题分类器 → Agent A (技术) / Agent B (商业) → End节点
    
  4. 配置智能体

    • Agent A
      • 系统提示词:"你是Agent A专门处理技术问题"
      • 启用记忆窗口大小10
    • Agent B
      • 系统提示词:"你是Agent B专门处理商业问题"
      • 启用记忆窗口大小10
  5. 配置路由逻辑

    • 使用问题分类器根据内容类型路由
    • 技术问题 → Agent A
    • 商业问题 → Agent B
  6. 测试场景

    用户: "如何配置Docker容器" → Agent A回答
    用户: "什么是Kubernetes" → Agent A回答  
    用户: "如何制定营销策略?" → Agent B回答可能引用技术内容
    用户: "如何提高客户满意度?" → Agent B回答可能引用技术内容
    
  7. 观察问题

    • 检查Agent B的回答是否包含Docker、Kubernetes等技术相关内容
    • 如果包含,说明存在记忆隔离问题

方法2使用复现脚本

  1. 配置脚本

    # 编辑 reproduction_script.py
    DIFY_BASE_URL = "http://your-dify-instance.com"
    DIFY_API_KEY = "your_api_key_here"
    
  2. 运行脚本

    python reproduction_script.py
    
  3. 分析结果

    • 脚本会自动检测Agent B回答中的技术关键词
    • 如果发现技术相关内容,说明存在记忆隔离问题

问题分析

当前实现机制

  1. 记忆存储所有节点共享同一个对话ID
  2. 记忆获取:基于整个对话获取历史消息
  3. 记忆配置:每个节点可独立配置,但都基于同一对话

核心问题

# 当前记忆获取逻辑 (api/core/workflow/nodes/llm/llm_utils.py)
def fetch_memory(variable_pool, app_id, node_data_memory, model_instance):
    # 获取对话ID
    conversation_id = variable_pool.get(["sys", "CONVERSATION_ID"])
    
    # 基于整个对话获取记忆 - 问题所在
    conversation = session.scalar(stmt)
    memory = TokenBufferMemory(conversation=conversation, model_instance=model_instance)

解决方案

方案1节点特定记忆推荐

  1. 修改MemoryConfig

    class MemoryConfig(BaseModel):
        window: WindowConfig
        role_prefix: Optional[RolePrefix] = None
        query_prompt_template: Optional[str] = None
        # 新增:节点特定记忆开关
        node_specific_memory: bool = False
    
  2. 修改记忆获取逻辑

    def fetch_memory(variable_pool, app_id, node_data_memory, model_instance, node_id):
        # 如果启用节点特定记忆,只获取该节点的历史
        if node_data_memory and node_data_memory.node_specific_memory:
            # 过滤该节点的消息历史
            pass
    
  3. 前端UI修改

    • 在记忆配置中添加"节点特定记忆"开关
    • 提供用户友好的说明文字

方案2记忆过滤

  1. 数据库层面过滤

    • 在Message表中添加node_id字段
    • 根据节点ID过滤历史消息
  2. 应用层面过滤

    • 在记忆获取时添加节点过滤条件
    • 只包含特定节点参与的消息

方案3记忆上下文切换

  1. 动态记忆管理
    • 在节点切换时调整记忆上下文
    • 根据节点类型选择性地包含历史

实施步骤

后端修改

  1. 修改数据模型

    -- 可选在Message表中添加node_id字段
    ALTER TABLE messages ADD COLUMN node_id VARCHAR(255);
    CREATE INDEX idx_messages_node_id ON messages(node_id);
    
  2. 修改核心代码

    • api/core/prompt/entities/advanced_prompt_entities.py
    • api/core/memory/token_buffer_memory.py
    • api/core/workflow/nodes/llm/llm_utils.py
  3. 添加测试用例

    • 单元测试验证记忆隔离功能
    • 集成测试验证多智能体场景

前端修改

  1. UI组件更新

    • web/app/components/workflow/nodes/_base/components/memory-config.tsx
    • 添加节点特定记忆开关
  2. 国际化支持

    • web/i18n/zh-Hans/workflow.ts 中添加相关文本
  3. 类型定义更新

    • 更新TypeScript类型定义

测试验证

功能测试

  1. 记忆隔离测试

    • 验证节点特定记忆开关是否正常工作
    • 验证不同节点的记忆是否隔离
  2. 多智能体测试

    • 测试技术Agent和商业Agent的记忆隔离
    • 验证回答的准确性和相关性

性能测试

  1. 记忆过滤性能

    • 验证记忆过滤对性能的影响
    • 确保在大规模对话中的稳定性
  2. 数据库查询优化

    • 验证节点过滤查询的性能
    • 确保索引的有效性

用户体验测试

  1. 功能易用性

    • 验证用户是否能够理解和使用新功能
    • 确保配置界面的友好性
  2. 向后兼容性

    • 验证现有工作流是否正常工作
    • 确保默认行为保持不变

预期效果

问题解决

  1. 消除幻觉Agent B不再看到Agent A的技术对话历史
  2. 提高准确性:每个智能体只基于自己的专业领域回答
  3. 改善用户体验:多智能体对话更加准确和连贯

功能增强

  1. 灵活配置:用户可以选择是否启用节点特定记忆
  2. 向后兼容:现有工作流无需修改即可正常工作
  3. 性能优化:通过记忆过滤减少不必要的上下文

相关文件

  • reproduction_steps.md - 详细的复现步骤
  • implementation_example.py - 实现示例代码
  • reproduction_script.py - 自动化复现脚本

贡献指南

如果您想为这个功能做出贡献:

  1. Fork Dify仓库
  2. 创建功能分支
  3. 实现节点特定记忆功能
  4. 添加测试用例
  5. 提交Pull Request

联系方式