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
46.11k stars 6.5k forks source link

The Chatflow parameter extraction node can not extract multiple variables in multiple rounds of conversations? #8626

Open BingGo-1 opened 2 hours ago

BingGo-1 commented 2 hours ago

Self Checks

Dify version

0.7.3

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

How can The Chatflow parameter extraction node extract multiple variables in multiple rounds of conversations? Even if I turn on memory, it can only extract the most recent question parameter in each conversation, and cannot combine historical conversations. I did a simple test as belows:

  1. i create a simple chatflow, like this

    image
  2. the parameter extraction node was configured like this

    image

    this node will get three params.

  3. when i asked "the data in 2024 of Coca Cola",the node could get params normally,like this

    image
  4. now, i ask" the data of Coca Cola",the node could get the keyword param,like this

    image

    Because lack of the date, so the answer node ask for the date info. and i replied "2024".

  5. Ideally, the parameter extraction node would be able to get information about both conversations and extract the three parameters, but it didn’t do that. This time it only returned the date‘2024’, leaving the previous keyword ‘Coca Cola’ behind. like this

    image

Therefore, the problem here is that when the user does not provide all the required parameters at once, multiple rounds of dialogue will be generated. How can the parameter extraction node extract all the required parameters in multiple rounds of dialogue so that the subsequent nodes can run normally?

And i tried changing the extraction node's Reasoning Mode to ‘Function Calling’,No parameters were obtained. I still don't understand this phenomenon. I was using the qwen-max model.

✔️ Expected Behavior

The Chatflow parameter extraction node extract multiple variables in multiple rounds of conversations

❌ Actual Behavior

Only the most recent query was extracted.

dosubot[bot] commented 2 hours ago

I found some similar discussions and issues that might be relevant to your problem:

  1. How to pass variables to chatflow from chatbot - This discussion is still open and might provide some insights.
  2. Can a variable pool like node (or component) be added to the chat workflow, and any node can access and modify these variable values? - This issue is closed but was referenced by another issue.
  3. Enabling Multi-Turn Scenarios in Chatbot Workflows - This issue is also closed but might have some useful information.

To ensure that the Chatflow parameter extraction node can extract multiple variables in multiple rounds of conversations and combine them from historical conversations, you need to enable the memory feature. This feature allows the LLM to include the chat history in each input, helping it understand the context and improve question comprehension during interactive dialogues.

Here is how you can configure it:

  1. Select the input variable: Choose the variable input for parameter extraction.
  2. Choose the model: Select the model that the parameter extractor will use for inference and structured generation.
  3. Define the parameters to extract: Manually add the parameters or quickly import them from existing tools.
  4. Write instructions: Provide examples to help the LLM improve the effectiveness and stability of extracting complex parameters.
  5. Enable Memory: This ensures that each input to the question classifier includes the chat history, allowing the LLM to combine parameters from historical conversations.

The memory feature works by including the chat history within specific tags, as shown in the following prompt structure:

### Memory
Here is the chat history between the human and assistant, provided within <histories> tags:
<histories>
{histories}
</histories>

The assistant then follows these steps to extract and combine parameters:

  1. Review the chat history provided within the <histories> tags.
  2. Extract the relevant information based on the criteria given, outputting multiple values if there is multiple relevant information that matches the criteria in the given text.
  3. Generate a well-formatted output using the defined functions and arguments.
  4. Use the extract_parameter function to create structured outputs with appropriate parameters.
  5. Ensure the output is a valid JSON object without any XML tags.

Additionally, you can configure the parameter extractor node with specific settings to handle memory and reasoning modes, as demonstrated in the integration tests. For example, you can set the reasoning_mode to "function_call" or "prompt" and configure the memory window size to control how much historical data is considered:

node = init_parameter_extractor_node(
    config={
        "id": "llm",
        "data": {
            "title": "123",
            "type": "parameter-extractor",
            "model": {"provider": "anthropic", "name": "claude-2", "mode": "chat", "completion_params": {}},
            "query": ["sys", "query"],
            "parameters": [{"name": "location", "type": "string", "description": "location", "required": True}],
            "reasoning_mode": "prompt",
            "instruction": "",
            "memory": {"window": {"enabled": True, "size": 50}},
        },
    },
)

By following these steps and utilizing the memory feature, the parameter extraction node will be able to extract and combine all required parameters from multiple rounds of conversations [1][2][3].

Limitations or Constraints of the Memory Feature

  1. Token Limit: The memory feature has a maximum token limit that it can handle.
  2. Message Limit: The memory feature also has a limit on the number of messages it can store.
  3. Model Mode Compatibility: The memory feature is only compatible with certain model modes, specifically the CHAT model mode.
  4. Reasoning Mode: The memory feature is only utilized when the reasoning mode is set to prompt. If the reasoning mode is set to function_call, the memory feature is not used [4][3][1].

These constraints ensure that the memory feature operates within the defined limits and is compatible with the supported model modes and reasoning modes.

To continue talking to Dosu, mention @dosu.