mirror of
https://github.com/langgenius/dify-official-plugins.git
synced 2026-07-22 01:55:27 -04:00
[Tongyi]KeyError: 'tool_calls' when using Tongyi model without tool calls #959
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Nov1c444 on GitHub (Jan 30, 2026).
Originally assigned to: @Nov1c444 on GitHub.
Self Checks
Dify version
1.11.4
Plugin version
0.1.23
Cloud or Self Hosted
Self Hosted (Source)
Description
In models/tongyi/models/llm/llm.py, the code uses getattr() to access tool_calls from the response message, but message is a dict-like object, not a regular object. This causes a KeyError when the tool_calls key is not present in the response.
✔️ Error log
No response
@dosubot[bot] commented on GitHub (Jan 30, 2026):
This KeyError happens because the code in models/tongyi/models/llm/llm.py tries to access tool_calls using getattr() on a dict-like message object, which fails if tool_calls isn't present. The correct approach is to use message.get('tool_calls', []) or check if 'tool_calls' is in the message before accessing it. This bug has been fixed in recent updates—see dify-official-plugins PR #2513 (merged 2026-01-29) and Dify PR #30083. Upgrading to the latest versions will resolve the issue.
If you can't upgrade right away, you can patch the code by replacing getattr(response.output.choices[0].message, 'tool_calls', []) with response.output.choices[0].message.get('tool_calls', []) to safely handle missing keys and prevent the KeyError. For streaming responses, the code already checks for 'tool_calls' in the message dict, so the error only affects non-streaming paths.
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other