langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
49.81k stars 7.12k forks source link

How does dify manager the chat history? #4121

Closed lx1054331851 closed 5 months ago

lx1054331851 commented 5 months ago

Self Checks

Provide a description of requested docs changes

  1. I want to know the way that dify manages the chat history in a default chat bot:

    • Send all historical information to LLM.
    • Summarize the previous conversation history and then send it to LLM.
    • Maintain a constant number of historical conversations.
  2. In agent bot, the way that dify manages the chat history, Especially web information collected through web scraping.

    • Send all historical information to LLM.
    • Summarize the previous conversation history and then send it to LLM.
    • Maintain a constant number of historical conversations.
dosubot[bot] commented 5 months ago

Dify manages chat history in both default chat bots and agent bots through a combination of strategies to ensure efficient and context-aware interactions with the Language Learning Model (LLM):

  1. For Default Chat Bots:

    • Sending Historical Information: Dify can send all historical information to the LLM, leveraging a detailed process that includes model configuration, input preparation, and memory management. This ensures that the LLM has access to previous conversations for context.
    • Summarizing Previous Conversations: When necessary, Dify summarizes previous conversation history before sending it to the LLM, especially if the conversation length exceeds certain limits. This is done by truncating and cleaning the query to fit the model's requirements.
    • Maintaining Historical Conversations: The system uses pagination mechanisms to manage the number of historical conversations, allowing for a flexible approach to data retrieval and memory management.
  2. For Agent Bots and Web Information:

    • Dify enhances chat history with web information collected through web scraping by utilizing plugins like Google Search, Web Reader, and Wikipedia. This allows the chat application to provide up-to-date information from the web, enriching the conversation history with relevant external data.

These strategies ensure that Dify maintains a balance between providing comprehensive historical context to the LLM and managing system resources efficiently. If you have further questions or need more details, feel free to ask.

#### Details **Sources** - [Self prompting agent](https://github.com/langgenius/dify/issues/2790) - [chatglm2 couldn't remember chat history, cause the lack of ability of multi-turn conversations](https://github.com/langgenius/dify/issues/1595) - [增加使用历史对话内容作为新上下文的能力](https://github.com/langgenius/dify/issues/403) - [sdks/python-client/dify_client/client.py](https://github.com/langgenius/dify/blob/main/sdks/python-client/dify_client/client.py) - [en/features/workflow/nodes/llm.md](https://github.com/langgenius/dify-docs/blob/main/en/features/workflow/nodes/llm.md) - [en/features/workflow/node/llm.md](https://github.com/langgenius/dify-docs/blob/main/en/features/workflow/node/llm.md) - [api/core/workflow/nodes/llm/llm_node.py](https://github.com/langgenius/dify/blob/main/api/core/workflow/nodes/llm/llm_node.py) - [api/core/llm_generator/llm_generator.py](https://github.com/langgenius/dify/blob/main/api/core/llm_generator/llm_generator.py) - [api/services/message_service.py](https://github.com/langgenius/dify/blob/main/api/services/message_service.py) - [en/user-guide/using-dify-apps/chat.md](https://github.com/langgenius/dify-docs/blob/main/en/user-guide/using-dify-apps/chat.md) - [en/user-agreement/data-security.md](https://github.com/langgenius/dify-docs/blob/main/en/user-agreement/data-security.md) - [zh_CN/guides/workspace/app/chat.md](https://github.com/langgenius/dify-docs/blob/main/zh_CN/guides/workspace/app/chat.md) - [web/app/components/develop/template/template_advanced_chat.en.mdx](https://github.com/langgenius/dify/blob/main/web/app/components/develop/template/template_advanced_chat.en.mdx)
**About Dosu** This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.