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
45.7k stars 6.43k forks source link

The 'inputs' field in /chat-messages takes effect only for the first time #7952

Open Wu-Jiayang opened 2 weeks ago

Wu-Jiayang commented 2 weeks ago

Self Checks

Dify version

0.7.3

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

run API '/chat-messages' twice with different 'inputs' and same 'conversation_id'

✔️ Expected Behavior

Run with the correct 'inputs'

❌ Actual Behavior

Run with the first 'inputs'.

This is caused by https://github.com/langgenius/dify/blob/fee4d3f6ca818bf150278fb6771c95bc6a257cbe/api/core/app/apps/advanced_chat/app_generator.py#L132

dosubot[bot] commented 2 weeks ago

@Wu-Jiayang Hello! I'm here to help you with bug fixes, answer questions, and support you in becoming a contributor. Let me know how I can assist you while you wait for a human maintainer.

I found a similar closed issue: Why doesn't the /chat-messages API allow passes context messages as a list?. However, it has no comments or solution and was last updated on April 26, 2024 [1].

The behavior you're experiencing is due to how the conversation_id is used to maintain the context of the conversation. Once a conversation is initiated with a specific conversation_id, subsequent messages within the same conversation continue the context from the initial message, and the inputs field from the first message is retained [2].

There is a state management system in place that might cause the inputs to be reused for the same conversation_id. The session is maintained by continuously passing in the returned conversation_id, which implies that the state of the conversation, including inputs, is managed and reused based on the conversation_id [3][4][5][6].

Recent changes in the app_generator.py file could also affect the handling of inputs. Specifically, the inputs are processed and cleaned using the _get_cleaned_inputs method before being used in the AgentChatAppGenerateEntity initialization [7][8][9].

To continue talking to Dosu, mention @dosu.