dify icon indicating copy to clipboard operation
dify copied to clipboard

Tool Returns No Results When Run By Agent

Open user905 opened this issue 8 months ago • 12 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.2.0

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

My custom tool returns no results when run by an agent, even though on its own it works as expected.

The tool requires no input, and when run, output is: Image

Here is the Round 1 Data following a test run through an agent using 'FunctionCalling':

Image

Image

The custom tool is set up as described in the documentation, using the OpenAI Swagger Specification: { "openapi": "3.1.1", "info": { "title": "Projects API", "description": "API for retrieving project information", "version": "1.0.0" }, "servers": [ { "url": "[URL OBSCURED]", "description": "API Dify" } ], "components": { "securitySchemes": { "bearerAuth": { "type": "http", "scheme": "bearer", "bearerFormat": "API Key" } }, "schemas": { "Project": { "type": "object", "properties": { "id": { "type": "integer", "description": "The project ID (PARSID)" }, "name": { "type": "string", "description": "The project name", "nullable": true }, "acronym": { "type": "string", "description": "The project acronym", "nullable": true }, "siteCode": { "type": "string", "description": "The site code", "nullable": true }, "program": { "type": "string", "description": "The program name", "nullable": true } } }, "ProjectsResponse": { "type": "object", "properties": { "projects": { "type": "array", "items": { "$ref": "#/components/schemas/Project" } } } }, "ErrorResponse": { "type": "object", "properties": { "error_code": { "type": "integer", "description": "Error code identifier" }, "error_msg": { "type": "string", "description": "Error message description" } } }, "InternalErrorResponse": { "type": "object", "properties": { "error": { "type": "string", "description": "Error type" }, "message": { "type": "string", "description": "Error message" } } } } }, "paths": { "/projects": { "get": { "summary": "Retrieve a list of projects", "description": "Returns a list of projects with basic identification information", "tags": ["Projects"], "security": [ { "bearerAuth": [] } ], "responses": { "200": { "description": "A list of projects", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ProjectsResponse" }, "example": { "projects": [ { "id": 123, "name": "Example Project", "acronym": "EP", "siteCode": "SC1", "program": "Program A" }, { "id": 456, "name": "Another Project", "acronym": "AP", "siteCode": "SC2", "program": "Program B" } ] } } } }, "403": { "description": "Unauthorized - Invalid or missing API key", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/ErrorResponse" }, "examples": { "missingAuth": { "value": { "error_code": 1001, "error_msg": "Invalid Authorization header format. Authorization header is required." } }, "invalidKey": { "value": { "error_code": 1002, "error_msg": "Authorization failed. Invalid API key." } } } } } }, "500": { "description": "Internal server error", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/InternalErrorResponse" }, "example": { "error": "Internal Server Error", "message": "An error occurred while fetching projects" } } } } } } } } }

✔️ Expected Behavior

The agent to receive tool results.

❌ Actual Behavior

Result set is empty.

user905 avatar Apr 21 '25 18:04 user905

Hello @user905! I'm Dosu, your friendly bot here to help you tackle bugs, answer questions, and assist you in becoming a contributor while you wait for a human maintainer. Let's unravel this issue together! 🚀

There are a few similar threads that might be relevant to your issue:

  1. Help:Agent NEVER get any result from workflow tool - This discussion suggests checking error handling, expected data format, configuration settings, and using logging and debugging features to trace interactions [1].

  2. Why does an agent not call a published workflow tool? - This issue highlights that the AI model's decision-making patterns might affect tool usage, and suggests creating a new agent and adding the workflow tool again as a potential solution [2].

  3. Why is my agent unable to read custom workflow tool responses in Dify 15.3? - This issue indicates that there might be a configuration or prompt instruction issue preventing the agent from processing the output from custom tools [3].

For your specific issue, ensure that the tool's output format is correctly set up to be recognized by the agent. Verify that the security settings, such as bearer authentication, are correctly configured and that the agent has the necessary permissions to access the tool. Additionally, check if there are any configuration settings in the function_calling.yaml file that might need adjustment, such as the model selection and tool parameters [4].

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 Apr 21 '25 18:04 dosubot[bot]

@dosu - See the screenshot below. The Agent makes the tool call. That is not the problem. The linked issues are either unresolved or not related to my set up. I am using GPT-4o, for what it's worth.

Image

user905 avatar Apr 21 '25 18:04 user905

To address the issue of receiving an empty response from the tool when using GPT-4o, ensure that the tool's output format is correctly configured to be recognized by the agent. The tool should return either a text message or a link message using the methods create_text_message for text results and create_link_message for link results [1].

Additionally, check the function_calling.yaml file to ensure that all critical parameters are correctly set. These include specifying the model, tools, and query, as well as setting the max_iterations parameter appropriately [2].

If the problem persists, verify that the input and output configurations in the LLM node are correctly set up, as missing configurations can lead to empty responses [3].

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 Apr 21 '25 18:04 dosubot[bot]

@dosu - Can you clarify? It seems 'Tools' and 'Plugin Tools' are distinct. Can you confirm? Also, are the former usable by Agents?

user905 avatar Apr 21 '25 19:04 user905

Yes, 'Tools' and 'Plugin Tools' are distinct in the Dify framework. The ToolManager class differentiates between built-in tools and plugin tools, using methods like get_builtin_provider and get_plugin_provider to manage them. Additionally, 'Tools' can be used by Agents, as indicated by the get_agent_tool_runtime method, which retrieves the agent tool runtime using the ToolInvokeFrom.AGENT parameter [1].

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 Apr 21 '25 19:04 dosubot[bot]

To address the issue of receiving an empty response from the tool when using GPT-4o, ensure that the tool's output format is correctly configured to be recognized by the agent. The tool should return either a text message or a link message using the methods create_text_message for text results and create_link_message for link results [1].

Additionally, check the function_calling.yaml file to ensure that all critical parameters are correctly set. These include specifying the model, tools, and query, as well as setting the max_iterations parameter appropriately [2].

If the problem persists, verify that the input and output configurations in the LLM node are correctly set up, as missing configurations can lead to empty responses [3].

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

@dosu - The custom Tool was built inside of the Dify UI and outputs data in the format shown. No yaml was ever generated by me, so the solutions to review the various methords or yaml files doesn't make sense. Here is a sample of what the tool returns, which looks correct: { "text": "{"projects": [{"id": 389, "name": "Salt Waste Processing Facility", "acronym": "SWPF", etc. } }

user905 avatar Apr 21 '25 19:04 user905

If your custom tool was built within the Dify UI and outputs data in the format you've shown, it's important to ensure that the output is correctly formatted for agent recognition. The tool's output should be structured in a way that the agent can interpret, typically as a JSON object or string that the agent is configured to handle.

Since you mentioned that no YAML was generated by you, focus on verifying the following:

  1. Output Format: Ensure that the output is a valid JSON string and that it matches the expected schema that the agent can process. The agent might expect specific keys or structures to parse the response correctly.

  2. Agent Configuration: Check the agent's configuration in the Dify UI to ensure it is set up to handle the type of output your tool provides. This includes verifying any settings related to output parsing or expected data formats.

  3. Tool and Agent Integration: Make sure that the tool is properly integrated with the agent. This involves checking that the tool is correctly registered and that the agent has the necessary permissions and configurations to invoke the tool and process its output.

If the tool's output format and agent configuration are correct, but the issue persists, consider reviewing any logs or debugging information available in Dify to trace the interaction between the agent and the tool. This can help identify any discrepancies or errors in the data flow.

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 Apr 21 '25 19:04 dosubot[bot]

Note that I have created a Plugin Tool and the results are the same. As with the custom Tool, the plugin tool makes an API call, only here it parses it in the exact same way that the documentation suggests. Yet the Agent is still returning empty results.

Note that create_text_message appears to be outdated, as its originating document even tells us that '"Tools" has been fully upgraded to the "Plugins".'

Furthermore, function_calling.yaml relates to Agent Strategy plugins, which is not what I'm using. The built-in Agents that already can use FunctionCalling should work without having to define custom outputs, especially in trivial cases like mine where the Tools already work and Plugin Tools return the exact same results as the samples in the documentation.

user905 avatar Apr 21 '25 22:04 user905

maybe your tool response is too long. #18731

EcoleKeine avatar Apr 25 '25 02:04 EcoleKeine

maybe your tool response is too long. #18731

Interesting. Didn't realize this was a thing. I'll give it a go. Thanks for the heads up.

user905 avatar Apr 25 '25 15:04 user905

Unfortunately this didn't work. Here are my variables in /dify/docker/.env: Image

I restarted the VM after changing these. The tool/plugin returns 601 results, which is < 1000.

The Agent still returns: Image

With the following results in the Agentic Strategy:

{
  "output": {
    "llm_response": "",
    "tool_responses": [
      {
        "tool_call_id": "call_P1EaP4L7QVwVTpTUA6atI31s",
        "tool_call_input": {},
        "tool_call_name": "projects_get",
        "tool_response": ""
      }
    ]
  }
}

user905 avatar Apr 25 '25 16:04 user905

I encountered the same issue where no result was returned. I spent several days debugging it. The tool itself was able to return results correctly, but in the chatflow, the agent in ROUND 1 couldn’t retrieve the tool’s return value. During debugging, I found that it was caused by inconsistent nodeids, but I don’t know how to fix this bug.

this logs: [on_tool_execution] Tool: wencaiStockInfo Outputs: {"type":"json","message":{"json_object":{"text":"## 简介和看点\n\n  协创数据技术股份有限公司的主营业务是通过研发先进的硬件和软件解决方案,提供一体化的产品和服务。公司的主要产品是物联网智能终端、数据存储设备。\n\n| 看点 | 影响 | 类型 |\n|:-------------|:-----|:------|\n| 机构预测净利润连续大增 | 利好 | 分析师观点 |\n| 过去5年营业收入持续增长 | 利好 | 成长能力 |\n| 近期有减持公告 | 利空 | 中期资金 |\n| 近期走势显著弱于市场总体 | 利空 | 短期趋势 |\n\n## 支撑位压力位\n\n协创数据(300857)在支撑位72.44附近已经开始有止跌企稳的迹象,股价或有反弹需求。\n\n| 时间 | 股票代码 | 止盈止损(支撑位) | 止盈止损(压力位) | 股票简称 | 股票代码 |\n|---------:|-------:|------------:|------------:|:-------|:----------|\n| 20250520 | 300857 | 72.44 | 83.00 | 协创数据 | 300857.SZ |\n\n## 近期重要事件\n| 股票简称 | 重要事件名称 | 重要事件内容 | 重要事件公告时间 | 股票代码 |\n|:-------|:---------|:---------------------------------------------------------|-----------:|-------:|\n| 协创数据 | 分红实施 | 10转4股派2.93元(含税),股权登记日20250509,除权除息日20250512,派息日20250512。 | 20250401 | 300857 |\n\n## 所属概念列表\n| 诊股概念分类纳入日期 | 诊股概念分类内容 | 诊股概念分类名称 | 股票简称 | 诊股概念分类类型 | 诊股概念分类属性 | 概念生成时间 | 时间区间 | 股票代码 | 诊股概念分类贴合度排名 | 诊股概念分类贴合度 |\n|-------------:|:---------------------------------------------

Image

homeant avatar May 20 '25 14:05 homeant