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
35.78k stars 4.83k forks source link

Issue with Inputs and variables in chatflow. #4241

Open santiagoblanco22 opened 1 month ago

santiagoblanco22 commented 1 month ago

Self Checks

Dify version

0.6.7

Cloud or Self Hosted

Cloud

Steps to reproduce

Try to send params the first time and works. But If I send the second with the conversationId in the payload for refresh the value, not works. Other thing, in my opinion is a bad idea: Variables referenced within a node can only be those from preceding process nodes to ensure coherence and avoid duplication. Maybe I want to save a variable for a future use in the first node. I don't know how to persist variables for use in the next chat iteration :(

✔️ Expected Behavior

You can send inputs params in all messages and save variables.

❌ Actual Behavior

Ignore the value of the input in the second message.

dosubot[bot] commented 1 month ago

To address the issue of persisting variables for use in subsequent chat iterations in Dify, and the challenge with input values being ignored in the second message, consider the following approach:

  1. Leverage System Variables: Utilize system variables like sys.conversation_id to maintain context across the chat session. These variables are automatically persisted and can serve as references for storing and retrieving session-specific data.

  2. Employ the VariableAssigner Node: Use the VariableAssigner node within your chatflow to create or update variables. This allows for the dynamic assignment of values based on user interactions, API call results, or predefined logic, facilitating the persistence of data across different parts of the chatflow.

  3. Strategically Pass Variables Between Nodes: Ensure your chatflow is designed to logically progress variable assignments from one node to the next. This method helps in maintaining coherence and avoiding duplication by using the output of preceding nodes as input for subsequent ones.

  4. External Persistence for Cross-Iteration Variables: For variables you wish to persist across chat iterations beyond the current session, consider integrating an external database or service. By keying this external storage with sys.conversation_id, you can effectively manage conversation states, retrieving and updating them as needed.

This approach should help overcome the limitations you've encountered with variable persistence and input handling in Dify version 0.6.7. For more detailed guidance on using the VariableAssigner node and system variables, refer to the Dify documentation or the specific components within the repository.

#### Details **Sources** - [web/app/components/workflow/nodes/_base/components/variable/utils.ts](https://github.com/langgenius/dify/blob/main/web/app/components/workflow/nodes/_base/components/variable/utils.ts)
**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.

santiagoblanco22 commented 1 month ago

@dosu let me know if you understand the problem.

dosubot[bot] commented 1 month ago

Yes, I understand the problem. You're facing two main issues: first, input values sent in the second message are being ignored, and second, you're looking for a way to persist variables across chat iterations for future use. The solutions provided aim to address both concerns by suggesting the use of system variables and the VariableAssigner node for maintaining context and persisting data across chat sessions. Additionally, integrating an external storage solution for variables that need to be accessed in future chat iterations can help manage conversation states effectively. If these solutions do not resolve your issue or if there's a specific aspect of the problem that hasn't been addressed, please provide more details so I can offer further assistance.

#### Details **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.

santiagoblanco22 commented 1 month ago

@dosu but manage a external storage for a state is a lot of work.

dosubot[bot] commented 1 month ago

To streamline the management of input parameters and variable persistence in Dify without the need for external databases, consider leveraging Dify's built-in features for conversation applications. Here's a more focused approach:

  1. Utilize Expert Mode for Advanced Control: When composing your application, switch to Expert Mode. This gives you precise control over prompts, allowing for effective management of variables and context to ensure input parameters are recognized across messages.

  2. Employ Form Variables in Prompts: Use form variables within your prompts to dynamically incorporate user input. This method ensures that the AI consistently recognizes and utilizes input parameters throughout the conversation.

  3. Incorporate Opening Dialogue and Context: Add an opening dialogue to set the stage for the interaction and use the "Conversation remarkers" feature to acknowledge user input from the start. If needed, include a knowledge base in the context section to inform the AI's responses based on previous interactions.

  4. Debug and Adjust: Leverage the debugging feature to test and refine your prompts and model parameters. This helps ensure that variables are correctly persisted and input parameters are accurately recognized throughout the conversation.

  5. Publish and Share: Once your application meets your requirements, publish it and share it with others for easy access. For customization, consider forking the open-source WebApp template.

For detailed guidance, refer to the Dify documentation and the Prompt Engineering guide. The Node.js client SDK can also provide insights into interacting with Dify's API.

This approach should help you manage input parameters and persist variables effectively within your Dify chat applications, streamlining the process and enhancing user interactions.

#### Details **Sources** - [sdks/nodejs-client/index.js](https://github.com/langgenius/dify/blob/main/sdks/nodejs-client/index.js) - [en/features/prompt-engineering/README.md](https://github.com/langgenius/dify-docs/blob/main/en/features/prompt-engineering/README.md) - [en/user-guide/creating-dify-apps/prompt-engineering/conversation-application.md](https://github.com/langgenius/dify-docs/blob/main/en/user-guide/creating-dify-apps/prompt-engineering/conversation-application.md)
**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.

iamjoel commented 1 month ago

@santiagoblanco22 Can you describe the specific scenario where this feature is required?

ywuanchai commented 2 weeks ago

Hi @dosu, so has this problem been solved or it has a workaround? Because I'm also facing this issue.

This is my use case,

  1. A user starts a conversation with 1st setting via "inputs"
  2. Chatbot returns 3 settings
  3. The user chooses 3rd setting and asks for generating X based on 3rd setting
  4. Pass 3rd setting as "inputs" to Chatbot and generate X, return to the user
  5. The user regret and chooses 2nd setting, and asks for generate X based on 2nd setting
  6. Pass 2nd setting as "inputs" to Chatbot ...

if fails on step 3 since we cannot override the "inputs"

Is there any solutions for this?

Thanks!