After the LLM node in the workflow enables the memory, the subsequent questions will get new content through the knowledge retrieval node again and bring it into the prompt, which will cause the exception when the LLM answers the subsequent questions. … #5186

Closed
opened 2026-02-21 18:09:47 -05:00 by yindo · 2 comments
Owner

Originally created by @chaoyuezhao1 on GitHub (Aug 23, 2024).

Self Checks

  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Provide a description of requested docs changes

After the LLM node in the workflow enables the memory, the subsequent questions will get new content through the knowledge retrieval node again and bring it into the prompt, which will cause the exception when the LLM answers the subsequent questions. How to solve it
企业微信截图_1724398404278

Originally created by @chaoyuezhao1 on GitHub (Aug 23, 2024). ### Self Checks - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Provide a description of requested docs changes After the LLM node in the workflow enables the memory, the subsequent questions will get new content through the knowledge retrieval node again and bring it into the prompt, which will cause the exception when the LLM answers the subsequent questions. How to solve it ![企业微信截图_1724398404278](https://github.com/user-attachments/assets/9bf62941-5355-41c8-aeb2-7814d155fc50)
yindo closed this issue 2026-02-21 18:09:47 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 23, 2024):

Hello, @chaoyuezhao1! I'm here to help you with bug fixes, answer your questions, and guide you on becoming a contributor. Let's work together to resolve any issues you're experiencing.

To solve the issue where enabling memory in the LLM node causes exceptions when subsequent questions retrieve new content through the knowledge retrieval node and bring it into the prompt, you need to ensure proper configuration of context variables and memory settings.

  1. Context Variables Configuration: Ensure that the output variable result from the knowledge retrieval node is correctly configured in the context variable within the LLM node. This allows the retrieved knowledge to be incorporated into the prompt.

  2. Memory Settings: Adjust the memory settings to ensure that the chat history is appropriately managed. You can control the amount of chat history passed by configuring the memory window.

Here is an example configuration:

llm_node:
  model: "gpt-3.5-turbo"
  memory: true
  memory_window: 5  # Adjust based on your context window requirements
  context_variables:
    - name: "retrieved_knowledge"
      source: "knowledge_retrieval_node.result"
  prompt: |
    SYSTEM: You are a helpful assistant.
    USER: {{ user_input }}
    ASSISTANT: {{ retrieved_knowledge }}

Ensure that the retrieved_knowledge context variable is correctly associated with the result from the knowledge retrieval node. This setup helps in dynamically incorporating new content into the prompt while maintaining the conversation context.

Additionally, if you are using Dify, you can leverage its configuration hooks to manage context and memory settings more effectively. For instance, the useConfig hook in Dify's web/app/components/workflow/nodes/llm/panel.tsx file provides various utilities to handle context variables, memory settings, and prompt configurations. This can help ensure that your LLM node is properly configured to handle dynamic content retrieval and memory management without causing exceptions. The MemoryConfig component in the same file can be used to fine-tune memory settings, ensuring that the chat history and context are managed correctly [1][2][3][4].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Aug 23, 2024): <!-- Greeting --> Hello, @chaoyuezhao1! I'm here to help you with bug fixes, answer your questions, and guide you on becoming a contributor. Let's work together to resolve any issues you're experiencing. <!-- Answer --> To solve the issue where enabling memory in the LLM node causes exceptions when subsequent questions retrieve new content through the knowledge retrieval node and bring it into the prompt, you need to ensure proper configuration of context variables and memory settings. 1. **Context Variables Configuration**: Ensure that the output variable `result` from the knowledge retrieval node is correctly configured in the context variable within the LLM node. This allows the retrieved knowledge to be incorporated into the prompt. 2. **Memory Settings**: Adjust the memory settings to ensure that the chat history is appropriately managed. You can control the amount of chat history passed by configuring the memory window. Here is an example configuration: ```yaml llm_node: model: "gpt-3.5-turbo" memory: true memory_window: 5 # Adjust based on your context window requirements context_variables: - name: "retrieved_knowledge" source: "knowledge_retrieval_node.result" prompt: | SYSTEM: You are a helpful assistant. USER: {{ user_input }} ASSISTANT: {{ retrieved_knowledge }} ``` Ensure that the `retrieved_knowledge` context variable is correctly associated with the `result` from the knowledge retrieval node. This setup helps in dynamically incorporating new content into the prompt while maintaining the conversation context. Additionally, if you are using Dify, you can leverage its configuration hooks to manage context and memory settings more effectively. For instance, the `useConfig` hook in Dify's `web/app/components/workflow/nodes/llm/panel.tsx` file provides various utilities to handle context variables, memory settings, and prompt configurations. This can help ensure that your LLM node is properly configured to handle dynamic content retrieval and memory management without causing exceptions. The `MemoryConfig` component in the same file can be used to fine-tune memory settings, ensuring that the chat history and context are managed correctly <sup>[[1]](https://github.com/langgenius/dify-docs/blob/main/en/guides/workflow/node/llm.md)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/web/app/components/workflow/nodes/llm/use-config.ts)</sup><sup>[[3]](https://github.com/langgenius/dify/blob/main/web/app/components/workflow/nodes/llm/panel.tsx)</sup><sup>[[4]](https://github.com/langgenius/dify-docs/blob/main/jp/guides/workflow/node/knowledge-retrieval.md)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@crazywoola commented on GitHub (Aug 23, 2024):

This is an expected behavior, each time you send message to the workflow then every step will be executed. If you want to avoid this situation, you need to use a LLM before the knowledge retrieval node and if/else node to dispatch the behavior.

BTW, this template is requiring document changes. If you want to ask for help, please use discussion instead.

@crazywoola commented on GitHub (Aug 23, 2024): This is an expected behavior, each time you send message to the workflow then every step will be executed. If you want to avoid this situation, you need to use a LLM before the knowledge retrieval node and if/else node to dispatch the behavior. BTW, this template is requiring document changes. If you want to ask for help, please use discussion instead.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#5186