Agent bot was lack of history conversation messages
Self Checks
- [X] I have searched for existing issues search for existing issues, including closed ones.
- [X] I confirm that I am using English to submit report (我已阅读并同意 Language Policy).
- [X] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
- [X] Please do not modify this template :) and fill in all the required fields.
Provide a description of requested docs changes
Hi team, thanks for creating this great platform, I've tried out Dify on my local and found an issue that I'm not sure if it's document issue or need to be enhanced:
If I define a LLM bot and set prompt like: "You're an infra troubleshooting bot, if user has already given enough information, you can do the check and generate analysis report, otherwise you should ask users to input the required information". And the conversation would be like:
Bot (Conversation Opener): What can I help you ?
User: this ticket failed, please check.
Bot (1st time response from the agent): Please provide the detail ticket information so that I can help you to check.
User: 12345
Bot (2st time response without the previous conversation messages): Sorry, I don't know the meaning of this number.
It's expected to have a kind of reply like below if it's an end user chat with ChatGPT:
Bot (Conversation Opener): What can I help you ?
User: this ticket failed, please check.
Bot (1st time response from the agent): Please provide the detail ticket information so that I can help you to check.
User: 12345
Bot (2st time response with these previous messages): Sure, checking ticket 12345 failure reason for you (calling ticket-query-tool).
Is there any reference variable that we can use as the context of each time agent query ? Or it's a kind of configuration on somewhere?
You can use the Context and History variables to maintain the context of each agent query. These variables allow you to reference the content and historical dialogue records, respectively, for generating responses.
You can modify the built-in prompts, rearrange the placement of Context and History, set necessary parameters, and more. The conversation history is only available in the Text completion model of conversational applications. When engaging in multiple conversations in dialogue applications, Dify will assemble and concatenate the historical dialogue records according to built-in rules and replace the 'Conversation History' variable.
Here is a template structure for building conversational applications using text completion models:
Use the following context as your learned knowledge, inside <context></context> XML tags.
<context>
{{#context#}}
</context>
When answering the user:
- If you don't know, just say that you don't know.
- If you are not sure, ask for clarification.
Avoid mentioning that you obtained the information from the context.
And answer according to the language of the user's question.
{{pre_prompt}}
Here are the chat histories between human and assistant, inside <histories></histories> XML tags.
<histories>
{{#histories#}}
</histories>
Human: {{#query#}}
Assistant:
This template ensures that the context and historical dialogue are properly maintained and referenced in each agent query [1][2].
Additionally, Dify's AgentChatAppRunner class in the api/core/app/apps/agent_chat/app_runner.py file demonstrates how to manage and utilize these variables programmatically. The class includes methods to load tool variables from the database, convert them to runtime variables, and organize prompt messages, which include context, memory, and historical dialogue. This ensures that the context is maintained throughout the conversation [3].
To continue talking to Dosu, mention @dosu.
History variable not working. that’s only for completion models, USELESS
Yes, seems like ONLY work for text completion models, see docs: https://docs.dify.ai/guides/workflow/node/llm#explanation-of-special-variables
I also have this problem. If I only deploy web and api to use it. It happens. Seems like agent cannot remember what I said before. But if I use docker-compose to run dify. It works! How did you deploy your dify?
It seems like my pre-prompt is too long. It will not happen if I use a short pre-prompt. Hope it can help you.