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.88k stars 6.47k forks source link

BUG: The agent uses a tool, and if the tool returns a link, the final link replied by the agent is incorrect #8040

Open wuminghui-coder opened 1 week ago

wuminghui-coder commented 1 week ago

Self Checks

Dify version

0.7.3

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

02aa977d1339561b92cdd91ddce7bae 正确的链接http://m801.music.126.net/20240906113456/af23cec22bbd6df43053095b60b83af7/jdymusic/obj/wo3DlMOGwrbDjj7DisKw/18708866715/5eb8/dad6/61f5/42c7fc29510cc3e521bb285c54489852.flac

✔️ Expected Behavior

No response

❌ Actual Behavior

No response

wuminghui-coder commented 1 week ago

回复的错误链接http://m801.music.126.net/20240906113456/af23cec22bbd6df43053095b60b83af7/jdymusic/obj/wo3DlMOGwrbDjj7DisKw/18708866715/5eb8/dad6/61f5/42c7fc29510cc3e521bb285c54454489852.flac

wuminghui-coder commented 1 week ago

左边日志追踪输出的链接是正常的,右边回复的链接不对

dosubot[bot] commented 1 week ago

The issue with the agent replying with an incorrect link is due to the tool_icon not being set correctly when the tool_provider_type is "dataset-retrieval". In the code, tool_icon is set to an empty string in this case, which results in the agent not having the correct link to reply with.

Here's the relevant code snippet:

if tool_config.get("tool_provider_type", "") != "dataset-retrieval":
    tool_icon = ToolManager.get_tool_icon(
        tenant_id=app_model.tenant_id,
        provider_type=tool_config.get("tool_provider_type", ""),
        provider_id=tool_config.get("tool_provider", ""),
    )
    if not tool_icon:
        tool_entity = find_agent_tool(tool_name)
        if tool_entity:
            tool_icon = ToolManager.get_tool_icon(
                tenant_id=app_model.tenant_id,
                provider_type=tool_entity.provider_type,
                provider_id=tool_entity.provider_id,
            )
else:
    tool_icon = ""

To address this, you can use the create_link_message method from the Tool class to ensure the correct link is returned. Here is an example of how you can use this method:

def create_link_message(self, link: str, save_as: str = '') -> ToolInvokeMessage:
    """
        create a link message

        :param link: the url of the link
        :return: the link message
    """

By using this method, you can ensure that the correct link is generated and returned by the agent, thus resolving the issue of the agent replying with an incorrect link [1][2][3].

To continue talking to Dosu, mention @dosu.

crazywoola commented 1 week ago

Can you provide the tool's configuration?

Please attach the original output of the answer as well.

wuminghui-coder commented 1 week ago

1725601053457

Can you provide the tool's configuration?您能提供该工具的配置吗?

Please attach the original output of the answer as well.请附上答案的原始输出。

wuminghui-coder commented 1 week ago

1725601110675

Can you provide the tool's configuration?您能提供该工具的配置吗?

Please attach the original output of the answer as well.请附上答案的原始输出。

wuminghui-coder commented 1 week ago

原始输出和日志详情的歌曲链接不一样,日志详情是正常的,原始对话输出错误

Can you provide the tool's configuration?您能提供该工具的配置吗?

Please attach the original output of the answer as well.请附上答案的原始输出。

wuminghui-coder commented 1 week ago

1725601519525

# 日志详情输出:
🎵 遇见一曲,叙述着命运和相遇的美丽篇章。\n\n你可以通过点击 [这里](http://m801.music.126.net/20240906140436/744e04c5a5d7f462531841884bb68677/jdymusic/obj/wo3DlMOGwrbDjj7DisKw/18708866715/5eb8/dad6/61f5/42c7fc29510cc3e521bb285c54489852.flac) 聆听这首歌曲。享受音乐带来的温暖,仿佛在悠长的岁月中,邂逅了一段尘封已久的缘分。

# 原始输出:
🎵 遇见一曲,叙述着命运和相遇的美丽篇章。

你可以通过点击 [这里](http://m801.music.126.net/20240906140436/744e04c5a5d7f462531841884bb68677/jdymusic/obj/wo3DlMOGwrbDjj7DisKw/18708866766715/5eb8/dad6/61f5/42c7fc29510cc3e521bb285c54489852.flac) 聆听这首歌曲。享受音乐带来的温暖,仿佛在悠长的岁月中,邂逅了一段尘封已久的缘分。

你可以看这个两个输出结果的链接不一样

crazywoola commented 1 week ago

18708866715 18708866766715

看起来是这里解析出错了,我不太确是哪儿的问题,可能是 markdown 那边?

wuminghui-coder commented 1 week ago

18708866715 18708866766715

看起来是这里解析出错了,我不太确是哪儿的问题,可能是 markdown 那边?

这个不太清楚是哪里错误,其他的工具如果是链接返回,有概率会出现这个情况,这个问题不是必现的

wuminghui-coder commented 1 week ago

18708866715 18708866766715

看起来是这里解析出错了,我不太确是哪儿的问题,可能是 markdown 那边? 6b0dee84afb9789dc808b3a9af398be

是前端的问题,我看到后台的API消息,回复的消息是正确的,前端显示有问题