feat(agent): name the dropped tool when _init_prompt_tools swallows a conversion exception#344
Open
camerono wants to merge 1 commit into
Open
feat(agent): name the dropped tool when _init_prompt_tools swallows a conversion exception#344camerono wants to merge 1 commit into
camerono wants to merge 1 commit into
Conversation
… conversion exception 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.
Contributor
There was a problem hiding this comment.
Code Review
This pull request improves error logging in strategy.py when converting a tool to a prompt message tool fails. It safely extracts the tool's name and logs a detailed warning instead of a generic exception, making it easier to identify which tool failed to convert. There are no review comments to address.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
When
_convert_tool_to_prompt_message_toolraises inside_init_prompt_tools, the tool gets silently dropped from the LLM payload and the only trace isFailed to convert tool to prompt message tool— which doesn't name the tool. Operators trying to diagnose "why isn't my agent calling X anymore" have no log to grep for.This PR adds the tool name to the log message and bumps the level from
exception(ERROR) towarning, sinceplugin_daemonroutes ERROR through a debug stream by default. No behaviour change beyond observability.Why this matters
Burned a couple hours this week on the symptom. A custom API tool provider was recreated at some point — same name, new UUID in
tool_api_providers. Every existing app'sagent_mode.tools[*].provider_idstill pointed at the prior UUID.App.deleted_tools(inlanggenius/difyatmodels/model.py) joined on the stale IDs, marked the tools deleted, and_init_prompt_toolshere dropped them. The LLM saw a partial tools list and either shortcut-synthesized or returned its own "unknown tool" rejection in-stream. Reading the wire-level capture made it obvious; the existing log alone wouldn't have.The longer-term fix is probably either (a) a Dify-side migration that rewires stored
provider_idreferences when a provider is recreated under the same name, or (b) refusing the recreate when dependent apps exist. Both are larger changes that belong inlanggenius/dify. This PR is the small observability fix that would have shortened my session today.Diff
Compatibility Check
Available Checks
just build— haven't run it locally; happy to iterate if CI flags anything—
I'm grateful for this project's efforts and appreciate the chance to help evolve/improve it.