From c4133e58c233028d081ca5384ebcf5e489a8233e Mon Sep 17 00:00:00 2001 From: "Cameron O." Date: Tue, 26 May 2026 17:32:47 -0700 Subject: [PATCH] feat(agent): name the dropped tool when _init_prompt_tools swallows a conversion exception MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When `_convert_tool_to_prompt_message_tool` raises, the tool is silently omitted from the LLM payload. The current `Failed to convert tool to prompt message tool` log line doesn't say which tool, so operators have no way to tell which one disappeared from the agent's view. Most common trigger: a custom API tool provider gets recreated under the same name, its row in `tool_api_providers` gets a new UUID, and existing apps still reference the prior UUID in `agent_mode.tools[*].provider_id`. The agent then sees a partial tools list and either shortcuts or surfaces a model-side "unknown tool" rejection — easy to misread as a model defect. Adds the tool name to the log line and bumps the level to warning, since `logger.exception` defaults to ERROR but routes through a debug stream in plugin_daemon by default. --- src/dify_plugin/interfaces/agent/strategy.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/dify_plugin/interfaces/agent/strategy.py b/src/dify_plugin/interfaces/agent/strategy.py index 9d20bdef..3fb97ee4 100644 --- a/src/dify_plugin/interfaces/agent/strategy.py +++ b/src/dify_plugin/interfaces/agent/strategy.py @@ -286,8 +286,20 @@ def _init_prompt_tools( try: prompt_tool = self._convert_tool_to_prompt_message_tool(tool) except Exception: - # api tool may be deleted - logger.exception("Failed to convert tool to prompt message tool") + # api tool may be deleted (e.g. its provider was recreated and + # the app's stored provider_id no longer matches any row in + # tool_api_providers). Naming the tool lets operators grep for + # the drop in plugin_daemon logs instead of guessing why the + # model can't see it. + tool_name = getattr( + getattr(tool, "identity", None), "name", "" + ) + logger.warning( + "Dropping tool %r from prompt: conversion failed " + "(provider may be deleted or its schema is stale)", + tool_name, + exc_info=True, + ) continue # save prompt tool