Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(agent): fall back to tool name when Bedrock-bound tool description is empty (#40062)

YUKI NOMOTO8efb57f46bf2
diff --git a/dify-agent/src/dify_agent/adapters/llm/model.py b/dify-agent/src/dify_agent/adapters/llm/model.py
index 98d1ede1bef..29d46403257 100644
--- a/dify-agent/src/dify_agent/adapters/llm/model.py
+++ b/dify-agent/src/dify_agent/adapters/llm/model.py
@@ -650,7 +650,8 @@ def _map_tool_definitions_to_prompt_tools(
return [
PromptMessageTool(
name=tool_definition.name,
- description=tool_definition.description or "",
+ # Some providers (e.g. Bedrock's Converse API) reject an empty toolSpec description.
+ description=tool_definition.description or tool_definition.name,
parameters=cast(dict[str, object], tool_definition.parameters_json_schema),
)
for tool_definition in tool_definitions
diff --git a/dify-agent/tests/local/dify_agent/adapters/llm/test_model.py b/dify-agent/tests/local/dify_agent/adapters/llm/test_model.py
index 83bc1319467..b8b8567e5b8 100644
--- a/dify-agent/tests/local/dify_agent/adapters/llm/test_model.py
+++ b/dify-agent/tests/local/dify_agent/adapters/llm/test_model.py
@@ -13,6 +13,7 @@ from graphon.model_runtime.entities.message_entities import TextPromptMessageCon
from pydantic_ai.exceptions import ModelHTTPError, UnexpectedModelBehavior, UserError
from pydantic_ai.messages import (
InstructionPart,
+ ModelMessage,
ModelRequest,
ModelResponse,
RetryPromptPart,
@@ -444,6 +445,42 @@ class DifyLLMAdapterModelTests(unittest.IsolatedAsyncioTestCase):
self.assertEqual(usage.time_to_first_token, 0.2)
self.assertEqual(usage.time_to_generate, 0.6)
+ async def test_request_falls_back_to_tool_name_when_description_is_missing(self) -> None:
+ """Some providers (e.g. Bedrock's Converse API) reject an empty toolSpec description."""
+ messages: list[ModelMessage] = [ModelRequest(parts=[UserPromptPart("hello")])]
+ request_parameters = ModelRequestParameters(
+ function_tools=[
+ ToolDefinition(
+ name="weather",
+ description=None,
+ parameters_json_schema={"type": "object", "properties": {}},
+ )
+ ],
+ )
+
+ def handler(request: httpx.Request) -> httpx.Response:
+ payload = json.loads(request.content.decode("utf-8"))
+ tools_by_name = {tool["name"]: tool for tool in payload["target"]["tools"]}
+ self.assertEqual(tools_by_name["weather"]["description"], "weather")
+ return build_stream_response(
+ LLMResultChunk(
+ model="demo-model",
+ delta=LLMResultChunkDelta(
+ index=0,
+ message=AssistantPromptMessage(content="ok", tool_calls=[]),
+ usage=make_usage(prompt_tokens=1, completion_tokens=1),
+ ),
+ )
+ )
+
+ async with self.mock_gateway_stream(httpx.MockTransport(handler)):
+ adapter = DifyLLMAdapterModel(
+ "demo-model",
+ self.make_provider(),
+ model_provider="openai",
+ )
+ await adapter.request(messages, model_settings=None, model_request_parameters=request_parameters)
+
async def test_request_merges_system_messages_before_history(self) -> None:
messages = [
ModelRequest(parts=[UserPromptPart("previous user")]),