Open Colstuwjx opened 1 month ago
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.
Self Checks
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:
It's expected to have a kind of reply like below if it's an end user chat with ChatGPT:
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?