diff --git a/api/core/model_runtime/model_providers/openai_api_compatible/llm/llm.py b/api/core/model_runtime/model_providers/openai_api_compatible/llm/llm.py index 734cf28b15..2fd0c4ec1f 100644 --- a/api/core/model_runtime/model_providers/openai_api_compatible/llm/llm.py +++ b/api/core/model_runtime/model_providers/openai_api_compatible/llm/llm.py @@ -377,7 +377,10 @@ class OAIAPICompatLargeLanguageModel(_CommonOaiApiCompat, LargeLanguageModel): for tool in tools: formatted_tools.append(helper.dump_model(PromptMessageFunction(function=tool))) - data["tools"] = formatted_tools + if prompt_messages[-1].role.value == "tool": + data["tools"] = None + else: + data["tools"] = formatted_tools if stop: data["stop"] = stop