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.

refactor: replace bare dict with typed annotations in core tools module (#35098)

dataCenter430fc389a54c575
diff --git a/api/core/tools/entities/tool_bundle.py b/api/core/tools/entities/tool_bundle.py
index 10710c43767..4e07b7157a8 100644
--- a/api/core/tools/entities/tool_bundle.py
+++ b/api/core/tools/entities/tool_bundle.py
@@ -1,4 +1,5 @@
from collections.abc import Mapping
+from typing import Any
from pydantic import BaseModel, Field
@@ -26,6 +27,6 @@ class ApiToolBundle(BaseModel):
# icon
icon: str | None = None
# openapi operation
- openapi: dict
+ openapi: dict[str, Any]
# output schema
output_schema: Mapping[str, object] = Field(default_factory=dict)
diff --git a/api/core/tools/tool_engine.py b/api/core/tools/tool_engine.py
index 1afaa9cfaf1..d060fa8b49b 100644
--- a/api/core/tools/tool_engine.py
+++ b/api/core/tools/tool_engine.py
@@ -47,7 +47,7 @@ class ToolEngine:
@staticmethod
def agent_invoke(
tool: Tool,
- tool_parameters: Union[str, dict],
+ tool_parameters: Union[str, dict[str, Any]],
user_id: str,
tenant_id: str,
message: Message,
@@ -85,7 +85,7 @@ class ToolEngine:
invocation_meta_dict: dict[str, ToolInvokeMeta] = {}
def message_callback(
- invocation_meta_dict: dict[str, Any],
+ invocation_meta_dict: dict[str, ToolInvokeMeta],
messages: Generator[ToolInvokeMessage | ToolInvokeMeta, None, None],
):
for message in messages:
diff --git a/api/core/tools/utils/dataset_retriever/dataset_retriever_tool.py b/api/core/tools/utils/dataset_retriever/dataset_retriever_tool.py
index 6a189fa6aa8..0d1dc7273b5 100644
--- a/api/core/tools/utils/dataset_retriever/dataset_retriever_tool.py
+++ b/api/core/tools/utils/dataset_retriever/dataset_retriever_tool.py
@@ -1,4 +1,4 @@
-from typing import cast
+from typing import Any, cast
from pydantic import BaseModel, Field
from sqlalchemy import select
@@ -39,7 +39,7 @@ class DatasetRetrieverTool(DatasetRetrieverBaseTool):
dataset_id: str
user_id: str | None = None
retrieve_config: DatasetRetrieveConfigEntity
- inputs: dict
+ inputs: dict[str, Any]
@classmethod
def from_dataset(cls, dataset: Dataset, **kwargs):
diff --git a/api/core/tools/workflow_as_tool/tool.py b/api/core/tools/workflow_as_tool/tool.py
index 552fbab1a46..7c4f8ee03a8 100644
--- a/api/core/tools/workflow_as_tool/tool.py
+++ b/api/core/tools/workflow_as_tool/tool.py
@@ -277,7 +277,7 @@ class WorkflowTool(Tool):
session.expunge(app)
return app
- def _transform_args(self, tool_parameters: dict[str, Any]) -> tuple[dict[str, Any], list[dict[str, Any]]]:
+ def _transform_args(self, tool_parameters: dict[str, Any]) -> tuple[dict[str, Any], list[dict[str, str | None]]]:
"""
transform the tool parameters
@@ -355,7 +355,7 @@ class WorkflowTool(Tool):
return result, files
- def _update_file_mapping(self, file_dict: dict[str, Any]):
+ def _update_file_mapping(self, file_dict: dict[str, Any]) -> dict[str, Any]:
file_id = resolve_file_record_id(file_dict.get("reference") or file_dict.get("related_id"))
transfer_method = FileTransferMethod.value_of(file_dict.get("transfer_method"))
match transfer_method: