dify icon indicating copy to clipboard operation
dify copied to clipboard

Agent Strategy does't work when tool-call from my workflows.

Open AnyaParry opened this issue 11 months ago • 2 comments

Self Checks

  • [x] This is only for bug report, if you would like to ask a question, please head to Discussions.
  • [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] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • [x] Please do not modify this template :) and fill in all the required fields.

Dify version

1.0.1

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

  1. Create a chatflow.
  2. Add agent strategy node and select my strategy (source from https://docs.dify.ai/zh-hans/plugins/quick-start/develop-plugins/agent-strategy-plugin Example of a complete function code)
  3. Add workflow tool in this node Image
  4. Run failed: Failed to transform agent message: PluginInvokeError: {"args":{},"error_type":"Exception","message":"invoke tool failed: request failed with status code: 500 and respond with: {\n "message": "Internal Server Error",\n "code": "unknown"\n}\n"}

Image

  1. Plugin print error: <generator object BackwardsInvocation._full_duplex_backwards_invoke at 0x7f406b255ea0> Unexpected error occurred when executing request Traceback (most recent call last): File "/home/vscode/.local/lib/python3.12/site-packages/dify_plugin/core/server/io_server.py", line 92, in _execute_request_in_thread self._execute_request( File "/home/vscode/.local/lib/python3.12/site-packages/dify_plugin/plugin.py", line 333, in _execute_request for message in response: ^^^^^^^^ File "/home/vscode/.local/lib/python3.12/site-packages/dify_plugin/core/plugin_executor.py", line 86, in invoke_agent_strategy yield from agent.invoke(request.agent_strategy_params) File "/workspaces/dify/plugins/tools/0.4/futurecreative_function/strategies/futurecreative_function.py", line 158, in _invoke for tool_invoke_response in tool_invoke_responses: ^^^^^^^^^^^^^^^^^^^^^ File "/home/vscode/.local/lib/python3.12/site-packages/dify_plugin/core/runtime.py", line 311, in _full_duplex_backwards_invoke yield from self._line_converter_wrapper(reader.read(timeout_for_round=1), data_type) File "/home/vscode/.local/lib/python3.12/site-packages/dify_plugin/core/runtime.py", line 213, in _line_converter_wrapper raise Exception(event.message) Exception: invoke tool failed: request failed with status code: 500 and respond with: { "message": "Internal Server Error", "code": "unknown" } 6.Plugin daemn logs: 2025/03/17 10:03:22 /app/internal/db/pgsql.go:259 record not found [1.005ms] [rows:0] SELECT * FROM "tool_installations" WHERE tenant_id = '8bdcc663-e0f7-4f5f-a91c-be869b9edaeb' AND plugin_id = 'langgenius/f7d3fb0e-1442-458d-bebd-26ad2d57bde6' ORDER BY "tool_installations"."id" LIMIT 1

Image

✔️ Expected Behavior

I hole my plugin can work.

❌ Actual Behavior

Why select tool_installations table ?

AnyaParry avatar Mar 17 '25 10:03 AnyaParry

I found some similar discussions that might be relevant to your issue:

  1. When using our own Deepseek API, the agent cannot trigger tool calls - This discussion is still open and might provide insights into issues with tool invocation when using custom APIs [1].

  2. An agent project has been created in the community version of DIY, without calling the tools under the agent - This is another open discussion that deals with issues related to tool invocation in agent projects [2].

  3. Help:Agent NEVER get any result from workflow tool - This discussion is also open and addresses problems with agents not receiving results from workflow tools [3].

Regarding the error you're encountering, a 'PluginInvokeError' with a status code 500 can be caused by several issues, such as rate limits, authorization problems, bad requests, connection errors, server unavailability, or credential validation failures [4]. You might want to check these potential causes in your setup.

Additionally, ensure that your tool installations are correctly configured in the database, as the logs indicate a "record not found" error for a specific tenant and plugin ID. This could be related to the tool not being properly registered or available for the agent strategy to invoke.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

dosubot[bot] avatar Mar 17 '25 10:03 dosubot[bot]

Hi @AnyaParry

From what I can see, the core problem isn't with your agent strategy logic itself, but rather with Dify finding the installed tool. That SQL query in your logs is the giveaway:

SELECT * FROM "tool_installations" WHERE tenant_id = '...' AND plugin_id = '...'

It's searching the tool_installations table and coming up empty. This explains the record not found error and the subsequent 500 Internal Server Error when the agent strategy tries to invoke the tool. Basically, Dify can't find the tool installation associated with your tenant and plugin, so it can't execute the workflow.

I've run into this before with self-hosted installations. Double check a few things:

  1. Database Connection: Is your Dify instance properly connected to the PostgreSQL database? A connection hiccup could explain why the query fails. Restarting your Dify services might help.

  2. Tool Installation ID: Make absolutely sure the plugin_id ('langgenius/f7d3fb0e-1442-458d-bebd-26ad2d57bde6' in your logs) in your workflow configuration exactly matches the ID of your installed tool. Even a small typo can cause this. You can verify the correct ID in your Dify’s plugin management section.

  3. Tenant ID: Similarly, ensure the tenant_id ('8bdcc663-e0f7-4f5f-a91c-be869b9edaeb') is correct for your setup. If you’re working with multiple tenants, it's easy to get these mixed up.

  4. Reinstall the Tool: Sometimes the tool installation itself can get corrupted. Try uninstalling and reinstalling the tool within your Dify instance. This often clears up weird database inconsistencies.

If you've checked all these and it's still failing, run the SQL query directly against your database to see what's up. That might give you more clues.

Let me know how it goes!

Mizokuiam avatar Mar 22 '25 03:03 Mizokuiam

Hi, @AnyaParry. I'm Dosu, and I'm helping the Dify team manage their backlog. I'm marking this issue as stale.

Issue Summary

  • You reported a "PluginInvokeError" and a 500 Internal Server Error when executing an agent strategy in Dify version 1.0.1.
  • The error logs indicate a "record not found" issue, suggesting Dify can't locate the installed tool.
  • User Mizokuiam recommended checking the database connection, tool and tenant IDs, and possibly reinstalling the tool.
  • I provided links to discussions on similar issues, pointing to potential causes like authorization problems or server unavailability.

Next Steps

  • Please confirm if this issue is still relevant with the latest version of Dify. If it is, feel free to comment to keep the discussion open.
  • If there is no further activity, this issue will be automatically closed in 15 days.

Thank you for your understanding and contribution!

dosubot[bot] avatar Apr 22 '25 16:04 dosubot[bot]