dify icon indicating copy to clipboard operation
dify copied to clipboard

Cannot use the same tool multiple times, prompt will fall into a dead loop

Open winstonsias opened this issue 10 months ago • 8 comments

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 this report (我已阅读并同意 Language Policy).
  • [X] Pleas do not modify this template :) and fill in all the required fields.

Dify version

<=0.5.11

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

prompt: Directly use tools to generate images without answering useless content image

✔️ Expected Behavior

Can call the tool normally every time to reply.

Or tell me how to set prompt to call the tool multiple times

❌ Actual Behavior

Only replied once

winstonsias avatar Apr 01 '24 07:04 winstonsias

Hey @winstonsias! Great to see you diving into the depths of Dify again. Hope you've been well since our last code adventure! 🚀

Based on the information you've provided, it seems like you're encountering a dead loop when trying to use the same tool multiple times in Dify v0.5.11 for generating images with a stable diffusion model in a self-hosted Docker environment. Here are some steps you can take to diagnose and potentially resolve the issue:

  1. Identify the Problematic Service: The issue might be related to the docker-worker-1 service, which handles image generation tasks. Identifying the problematic service is the first step towards resolving the issue.

  2. Check Logs for Errors: You can use the command docker compose logs <service-name> to check the logs of the problematic service. Replace <service-name> with the name of the service you suspect is causing the issue, such as worker. This can give you insights into what might be causing the dead loop.

    docker compose logs worker
    
  3. Restart the Problematic Service: Sometimes, simply restarting the service can resolve temporary issues. Use the following command to restart the service:

    docker compose restart worker
    
  4. Increase Resources: If the issue persists, it might be due to insufficient resources allocated to Docker, especially if you're generating multiple images simultaneously. Increase the Docker VM's resources (CPU and memory) as per the prerequisites mentioned in the context. For Docker Desktop on macOS, you can adjust these settings in Docker Desktop > Preferences > Resources.

  5. Update Dify and Dependencies: Ensure that Dify and all its dependencies are up to date. Sometimes, bugs causing such issues are fixed in newer versions. Use the upgrade instructions provided in the context to update Dify:

    cd dify/docker
    git pull origin main
    docker compose down
    docker compose pull
    docker compose up -d
    

As for the specific code in Dify v0.5.11 that handles the invocation of tools for image generation, it's found in the DallE3Tool class. This class uses the OpenAI API to generate images based on a text prompt. You can find the relevant code snippet in the advanced-tool-integration.md document.

Unfortunately, I wasn't able to find any information about a limit set in the Dify v0.5.11 codebase for the number of times a tool can be invoked consecutively, or a specific error message or log output that is associated with the dead loop issue when using the same tool multiple times. It's possible that this information might be available elsewhere, or I might have missed it. If you have any additional information or context that could help in diagnosing the issue, please provide it.

Sources

About Dosu

This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

dosubot[bot] avatar Apr 01 '24 07:04 dosubot[bot]

是不是调用完一个工具就停住了不回复了,我现在用的是通义千问的模型,请问下你用的是什么模型呢,不知道是不是模型的问题

deepblue-star avatar Apr 01 '24 10:04 deepblue-star

我也用的千问,各种prompt都试了也不行,感觉是调用链里面封装的prompt一直在重复。我提的issue也有截图。必须重新再开一个新会话,新会话用一次sd生成后,就又用不成了。您可以多试几次指令:【再生成一张】。

---Original--- From: @.> Date: Mon, Apr 1, 2024 18:00 PM To: @.>; Cc: @.@.>; Subject: Re: [langgenius/dify] Cannot use the same tool multiple times, promptwill fall into a dead loop (Issue #3061)

是不是调用完一个工具就停住了不回复了,我现在用的是通义千问的模型,请问下你用的是什么模型呢,不知道是不是模型的问题

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

winstonsias avatar Apr 01 '24 10:04 winstonsias

image 正常的action是直接再次调用sd,但是截图的地方看着是把thought也带进去了, 后面再提问 也同样的回复内容

winstonsias avatar Apr 01 '24 10:04 winstonsias

image 正常的action是直接再次调用sd,但是截图的地方看着是把thought也带进去了, 后面再提问 也同样的回复内容

我刚刚换了gpt3.5,表现比千问好很多,之前千问连续调用多个工具会卡住,现在基本不会了

deepblue-star avatar Apr 01 '24 11:04 deepblue-star

I'm considering refactoring the ReACT Agent mode, as it always results a bad response, for now, use a model supports Function Calling is a better choice.

Yeuoly avatar Apr 02 '24 10:04 Yeuoly

When it is possible to customize logic of ReACT Agent. at least change prompt? For now it's required to use gpt-4 always, because there are no function calling for open-source models.

mr-v-v-v avatar Apr 08 '24 19:04 mr-v-v-v

Hi, @winstonsias

I'm helping the Dify team manage their backlog and am marking this issue as stale. From what I understand, the issue was opened regarding the Dify tool version <=0.5.11 in a self-hosted (Docker) environment, where the prompt falls into a dead loop, only allowing a single reply. I provided detailed steps to diagnose and potentially resolve the issue, including identifying the problematic service, checking logs for errors, restarting the service, increasing resources, and updating Dify and its dependencies. There were subsequent comments from deepblue-star, winstonsias, and others discussing their experiences and potential solutions. Yeuoly and mr-v-v-v also mentioned considerations for refactoring the ReACT Agent mode and customizing the logic of ReACT Agent.

Could you please confirm if this issue is still relevant to the latest version of the Dify repository? If it is, please let the Dify team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or the issue will be automatically closed in 7 days.

Thank you!

dosubot[bot] avatar May 09 '24 16:05 dosubot[bot]

Please upgrade to latest version to see if this issue persists. :)

crazywoola avatar May 28 '24 07:05 crazywoola

I am using version 0.6.10 but has the same problem. I make a very simple Agent with only one tool, Stable Diffusion WebUI, but it cannot be used twice. But when I didn't use SD, it also had the same problem. I think there should be some problems about the Agent configuration. Here I have some screenshoots. image image

czslxk avatar Jun 07 '24 11:06 czslxk