diff --git a/src/dify_plugin/entities/tool.py b/src/dify_plugin/entities/tool.py index 5fda0019..3bf34a71 100644 --- a/src/dify_plugin/entities/tool.py +++ b/src/dify_plugin/entities/tool.py @@ -359,7 +359,7 @@ def to_prompt_message(self) -> PromptMessageTool: for name, parameter in self.tool_parameters.items(): tool.parameters[name] = { "type": parameter.type.value, - "description": parameter.description, + "description": parameter.description or "", } if parameter.required: diff --git a/src/dify_plugin/interfaces/agent/strategy.py b/src/dify_plugin/interfaces/agent/strategy.py index 9d20bdef..eed44d29 100644 --- a/src/dify_plugin/interfaces/agent/strategy.py +++ b/src/dify_plugin/interfaces/agent/strategy.py @@ -302,7 +302,7 @@ def _convert_tool_to_prompt_message_tool( """Convert tool to prompt message tool""" message_tool = PromptMessageTool( name=tool.identity.name, - description=tool.description.llm if tool.description else "", + description=(tool.description.llm or "") if tool.description else "", parameters={ "type": "object", "properties": {}, diff --git a/src/dify_plugin/interfaces/model/openai_compatible/llm.py b/src/dify_plugin/interfaces/model/openai_compatible/llm.py index c5a1f46f..6b7a1d9a 100644 --- a/src/dify_plugin/interfaces/model/openai_compatible/llm.py +++ b/src/dify_plugin/interfaces/model/openai_compatible/llm.py @@ -598,7 +598,7 @@ def _generate( data["functions"] = [ { "name": tool.name, - "description": tool.description, + "description": tool.description or "", "parameters": tool.parameters, } for tool in tools @@ -1127,7 +1127,7 @@ def _num_tokens_for_tools(self, tools: list[PromptMessageTool]) -> int: num_tokens += self._get_num_tokens_by_gpt2(tool.name) num_tokens += self._get_num_tokens_by_gpt2("description") if hasattr(tool, "description"): - num_tokens += self._get_num_tokens_by_gpt2(tool.description) + num_tokens += self._get_num_tokens_by_gpt2(tool.description or "") if hasattr(tool, "parameters"): parameters = tool.parameters num_tokens += self._get_num_tokens_by_gpt2("parameters")