Agent bot was lack of history conversation messages #4483

Closed
opened 2026-02-21 18:06:44 -05:00 by yindo · 5 comments
Owner

Originally created by @Colstuwjx on GitHub (Jul 7, 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).
  • 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • 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?

Originally created by @Colstuwjx on GitHub (Jul 7, 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] 请务必使用英文提交 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?
yindo added the 🤖 feat:agent label 2026-02-21 18:06:44 -05:00
yindo closed this issue 2026-02-21 18:06:44 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jul 7, 2024):

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.

@dosubot[bot] commented on GitHub (Jul 7, 2024): <!-- Answer --> 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: ```Python 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 <sup>[[1]](https://github.com/langgenius/dify-docs/blob/main/en/guides/application-orchestrate/prompt-engineering/prompt-engineering-expert-mode.md)</sup><sup>[[2]](https://github.com/langgenius/dify-docs/blob/main/en/learn-more/prompt-engineering/prompt-engineering-1/prompt-engineering-template.md)</sup>. 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 <sup>[[3]](https://github.com/langgenius/dify/blob/main/api/core/app/apps/agent_chat/app_runner.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@simplast commented on GitHub (Jul 8, 2024):

History variable not working. that’s only for completion models, USELESS

@simplast commented on GitHub (Jul 8, 2024): History variable not working. that’s only for completion models, USELESS
Author
Owner

@Colstuwjx commented on GitHub (Jul 9, 2024):

Yes, seems like ONLY work for text completion models, see docs: https://docs.dify.ai/guides/workflow/node/llm#explanation-of-special-variables

截屏2024-07-09 08 54 29
@Colstuwjx commented on GitHub (Jul 9, 2024): Yes, seems like ONLY work for text completion models, see docs: https://docs.dify.ai/guides/workflow/node/llm#explanation-of-special-variables <img width="826" alt="截屏2024-07-09 08 54 29" src="https://github.com/langgenius/dify/assets/3972545/8c12802f-61bc-4911-b177-8caf614c4c6c">
Author
Owner

@liuminxuan commented on GitHub (Jul 27, 2024):

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?

@liuminxuan commented on GitHub (Jul 27, 2024): 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?
Author
Owner

@liuminxuan commented on GitHub (Jul 27, 2024):

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.

@liuminxuan commented on GitHub (Jul 27, 2024): 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.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#4483