dify Agent bot缺乏历史对话消息,

4ktjp1zp  于 2个月前  发布在  其他
关注(0)|答案(5)|浏览(34)

自检

  • 我已搜索现有问题 search for existing issues ,包括已关闭的问题。
  • 我确认我使用英文提交报告(我已阅读并同意 Language Policy )。
  • 请务必使用英文提交问题,否则会被关闭。谢谢!:)
  • 请不要修改此模板 :) 并填写所有必需的字段。

提供所需文档更改的描述

大家好,感谢创建这个很棒的平台,我在本地尝试了 Dify,发现了一个问题,不确定它是文档问题还是需要增强的功能:
如果我定义一个 LLM 机器人并设置提示,例如:“您是一个基础设施故障排除机器人,如果用户已经提供了足够的信息,您可以进行检查并生成分析报告,否则您应该要求用户输入所需的信息”。对话如下:

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.

如果这是与 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).

是否有任何引用变量可作为每次代理查询的上下文?或者它是一种某种配置吗?

ocebsuys

ocebsuys1#

你可以使用 ContextHistory 变量来维护每个代理查询的上下文。这些变量允许你分别引用内容和历史对话记录,以生成响应。
你可以修改内置提示,重新安排 ContextHistory 的位置,设置必要的参数等。对话历史仅在对话应用程序的文本补全模型中可用。在对话应用程序中进行多轮对话时,Dify 将根据内置规则组装和连接历史对话记录,并替换“对话历史”变量。
以下是使用文本补全模型构建对话应用程序的模板结构:

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:

此模板确保在每个代理查询 1(https://github.com/langgenius/dify-docs/blob/main/en/guides/application-orchestrate/prompt-engineering/prompt-engineering-expert-mode.md)2(https://github.com/langgenius/dify-docs/blob/main/en/learn-more/prompt-engineering/prompt-engineering-1/prompt-engineering-template.md) 中正确维护和引用上下文和历史对话记录。
此外, api/core/app/apps/agent_chat/app_runner.py 文件中的 Dify 的 AgentChatAppRunner 类演示了如何以编程方式管理和利用这些变量。该类包括从数据库加载工具变量、将它们转换为运行时变量以及组织提示消息(包括上下文、记忆和历史对话)的方法。这确保在整个对话过程中保持上下文不变 3(https://github.com/langgenius/dify/blob/main/api/core/app/apps/agent_chat/app_runner.py)。

  • 要继续与 Dosu 交谈,请提及 @dosu。*
qkf9rpyu

qkf9rpyu2#

历史变量不起作用。这仅适用于完成模型,无用。

klsxnrf1

klsxnrf13#

是的,似乎只适用于文本补全模型,请参阅文档:https://docs.dify.ai/guides/workflow/node/llm#explanation-of-special-variables

s2j5cfk0

s2j5cfk04#

我也遇到过这个问题。如果我只部署了web和api来使用它,就会出现这种情况。好像代理无法记住我之前说过的话。但是如果我使用docker-compose来运行dify,就可以正常工作!

你是如何部署你的dify的?

syqv5f0l

syqv5f0l5#

看起来我的预设提示太长了。如果使用短的预设提示,就不会出现这种情况。希望这能帮到你。

相关问题