Skip to content

refactor(api): use the session factory for agent thought writes - #46464

Closed
vaibhav375 wants to merge 1 commit into
langgenius:mainfrom
vaibhav375:refactor/agent-thought-session-factory
Closed

vaibhav375 wants to merge 1 commit into
langgenius:mainfrom
vaibhav375:refactor/agent-thought-session-factory

Conversation

@vaibhav375

Copy link
Copy Markdown
Contributor

Summary

Part of #45584

create_agent_thought and save_agent_thought were the last two places in api/core/agent/base_agent_runner.py that used the global db.session. Each now opens its own session with create_session() from core.db.session_factory, so the extensions.ext_database import is gone from the module.

I didn't switch these two to the request session. #38559 moved the rest of this file to explicit sessions but left thought persistence off it, and test_fc_agent_runner.py / test_cot_agent_runner.py assert that session is not passed to either method. This change keeps that as it is. Each call still commits and closes the same way as before. If you'd rather they take the caller's session, I can switch it and update those assertions.

Tests (tests/unit_tests/core/agent/test_base_agent_runner.py):

  • Removed the database_session fixture that patched module.db.session.
  • Rows are seeded with sqlite_session and read back through a new session from sqlite_session_factory. The assertions now check what the runner committed, not objects held in a shared identity map.

One thing I noticed while testing: TokenBufferMemory.get_history_prompt_messages (core/memory/token_buffer_memory.py:341) opens db.session() and never closes it. Before this change, the db.session.close() calls in these two methods happened to release that session during the agent-chat runner tests. With them gone, tests/unit_tests/core/app/apps/agent_chat/test_app_runner.py shows two ResourceWarning: unclosed database warnings (the tests still pass). Main shows none. I've left that file alone here since it's a separate slice. Happy to take it next if that's useful.

Local results on this branch (rebased on main 5ebb1923):

  • pytest tests/unit_tests/core/agent/ tests/unit_tests/core/app/apps/agent_chat/ tests/unit_tests/core/app/apps/agent_app/: 487 passed, same as main
  • make lint: passed, no files changed, 102 import contracts kept
  • make type-check: passed

Screenshots

N/A (no UI change)

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've verified the change and added or updated tests where meaningful regression risk justifies coverage.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and vp staged (frontend) to appease the lint gods

From Claude Code

create_agent_thought and save_agent_thought were the last users of the
global db.session in base_agent_runner. Each now opens its own session
with create_session(), so the extensions.ext_database import goes away.

They still do not take the request session: langgenius#38559 deliberately kept
thought persistence off it and the fc/cot runner tests assert that.
Commit and close behaviour per call is unchanged.

The tests drop the fixture that patched module.db.session. They seed
rows with sqlite_session and read them back through a new session, so
the assertions check committed data rather than a shared identity map.

Part of langgenius#45584
@github-actions github-actions Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Nov 15, 2026
@asukaminato0721 asukaminato0721 self-assigned this Nov 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-11-16 11:37:34.573952815 +0000
+++ /tmp/pyrefly_pr.txt	2026-11-16 11:37:16.477861445 +0000
@@ -172,44 +172,6 @@
   --> providers/vdb/vdb-tencent/tests/e2e_tests/conftest.py:95:33
 ERROR Object of class `ModuleType` has no attribute `VectorType` [missing-attribute]
   --> providers/vdb/vdb-tidb-vector/tests/unit_tests/src/dify_vdb_tidb_vector/test_tidb_vector.py:77:5
-ERROR Cannot find module `deepeval.metrics` [missing-import]
-   --> core/evaluation/frameworks/deepeval/deepeval_evaluator.py:259:5
-ERROR Cannot find module `deepeval.test_case` [missing-import]
-   --> core/evaluation/frameworks/deepeval/deepeval_evaluator.py:268:5
-ERROR Cannot find module `deepeval.models` [missing-import]
-  --> core/evaluation/frameworks/deepeval/deepeval_model_wrapper.py:16:1
-ERROR Class member `DifyDeepEvalModel.supports_structured_outputs` is marked as an override, but no parent class has a matching attribute [bad-override]
-  --> core/evaluation/frameworks/deepeval/deepeval_model_wrapper.py:94:9
-ERROR Class member `DifyDeepEvalModel.supports_temperature` is marked as an override, but no parent class has a matching attribute [bad-override]
-  --> core/evaluation/frameworks/deepeval/deepeval_model_wrapper.py:98:9
-ERROR Cannot find module `langchain_core.embeddings` [missing-import]
- --> core/evaluation/frameworks/ragas/ragas_embeddings_wrapper.py:4:1
-ERROR Class member `DifyEmbeddingsWrapper.aembed_query` is marked as an override, but no parent class has a matching attribute [bad-override]
-  --> core/evaluation/frameworks/ragas/ragas_embeddings_wrapper.py:83:15
-ERROR Class member `DifyEmbeddingsWrapper.aembed_documents` is marked as an override, but no parent class has a matching attribute [bad-override]
-  --> core/evaluation/frameworks/ragas/ragas_embeddings_wrapper.py:87:15
-ERROR Cannot find module `ragas` [missing-import]
-   --> core/evaluation/frameworks/ragas/ragas_evaluator.py:275:9
-ERROR Cannot find module `ragas.dataset_schema` [missing-import]
-   --> core/evaluation/frameworks/ragas/ragas_evaluator.py:276:9
-ERROR Cannot find module `ragas.run_config` [missing-import]
-   --> core/evaluation/frameworks/ragas/ragas_evaluator.py:277:9
-ERROR Cannot find module `ragas.dataset_schema` [missing-import]
-   --> core/evaluation/frameworks/ragas/ragas_evaluator.py:338:9
-ERROR Cannot find module `ragas.dataset_schema` [missing-import]
-   --> core/evaluation/frameworks/ragas/ragas_evaluator.py:415:5
-ERROR Cannot find module `ragas.messages` [missing-import]
-   --> core/evaluation/frameworks/ragas/ragas_evaluator.py:416:5
-ERROR Cannot find module `ragas.metrics` [missing-import]
-   --> core/evaluation/frameworks/ragas/ragas_evaluator.py:417:5
-ERROR Cannot find module `langchain_core.messages` [missing-import]
- --> core/evaluation/frameworks/ragas/ragas_model_wrapper.py:5:1
-ERROR Cannot find module `langchain_core.outputs` [missing-import]
- --> core/evaluation/frameworks/ragas/ragas_model_wrapper.py:6:1
-ERROR Cannot find module `langchain_core.prompt_values` [missing-import]
- --> core/evaluation/frameworks/ragas/ragas_model_wrapper.py:7:1
-ERROR Cannot find module `ragas.llms.base` [missing-import]
- --> core/evaluation/frameworks/ragas/ragas_model_wrapper.py:8:1
 ERROR Unpacked keyword argument `str` is not assignable to parameter `port` with type `int | None` in function `qdrant_client.qdrant_client.QdrantClient.__init__` [bad-argument-type]
   --> providers/vdb/vdb-tidb-on-qdrant/src/dify_vdb_tidb_on_qdrant/tidb_on_qdrant_vector.py:93:51
 ERROR Unpacked keyword argument `str` is not assignable to parameter `grpc_port` with type `int` in function `qdrant_client.qdrant_client.QdrantClient.__init__` [bad-argument-type]
@@ -2016,18 +1978,14 @@
    --> tests/unit_tests/controllers/console/app/test_model_config.py:794:13
 ERROR Argument `str | None` is not assignable to parameter `s` with type `bytearray | bytes | str` in function `json.loads` [bad-argument-type]
    --> tests/unit_tests/controllers/console/app/test_model_config.py:891:36
-ERROR Missing argument `app_model` in function `controllers.console.app.workflow.EvaluationPublishedWorkflowApi.post` [missing-argument]
-    --> tests/unit_tests/controllers/console/app/test_workflow.py:1419:30
-ERROR Missing argument `app_model` in function `controllers.console.app.workflow.WorkflowKindConvertApi.post` [missing-argument]
-    --> tests/unit_tests/controllers/console/app/test_workflow.py:1419:30
 ERROR Missing argument `app_model` in function `controllers.console.app.workflow.WorkflowDraftHumanInputDeliveryTestApi.post` [missing-argument]
-    --> tests/unit_tests/controllers/console/app/test_workflow.py:1674:78
+    --> tests/unit_tests/controllers/console/app/test_workflow.py:1656:78
 ERROR Unexpected keyword argument `app_id` in function `controllers.console.app.workflow.WorkflowDraftHumanInputDeliveryTestApi.post` [unexpected-keyword]
-    --> tests/unit_tests/controllers/console/app/test_workflow.py:1674:79
+    --> tests/unit_tests/controllers/console/app/test_workflow.py:1656:79
 ERROR Missing argument `app_model` in function `controllers.console.app.workflow.AdvancedChatDraftHumanInputFormPreviewApi.post` [missing-argument]
-    --> tests/unit_tests/controllers/console/app/test_workflow.py:1688:81
+    --> tests/unit_tests/controllers/console/app/test_workflow.py:1670:81
 ERROR Unexpected keyword argument `app_id` in function `controllers.console.app.workflow.AdvancedChatDraftHumanInputFormPreviewApi.post` [unexpected-keyword]
-    --> tests/unit_tests/controllers/console/app/test_workflow.py:1688:82
+    --> tests/unit_tests/controllers/console/app/test_workflow.py:1670:82
 ERROR Object of class `FunctionType` has no attribute `return_value` [missing-attribute]
   --> tests/unit_tests/controllers/console/auth/test_activate.py:71:9
 ERROR Object of class `FunctionType` has no attribute `assert_called_once_with` [missing-attribute]
@@ -2127,9 +2085,7 @@
 ERROR Argument `Literal['account']` is not assignable to parameter `created_by_role` with type `CreatorUserRole` in function `models.model.UploadFile.__init__` [bad-argument-type]
    --> tests/unit_tests/controllers/console/datasets/test_datasets_document.py:646:33
 ERROR Type `Response` is not iterable [not-iterable]
-   --> tests/unit_tests/controllers/console/test_wraps.py:313:17
-ERROR `None` is not subscriptable [unsupported-operation]
-    --> tests/unit_tests/controllers/console/test_wraps.py:1030:16
+   --> tests/unit_tests/controllers/console/test_wraps.py:306:17
 ERROR Argument value `Literal[0]` violates Pydantic `ge` constraint `Literal[1]` for field `page` [bad-argument-type]
    --> tests/unit_tests/controllers/console/workspace/test_endpoint.py:235:47
 ERROR Missing argument `plugin_id` in function `controllers.console.workspace.endpoint.EndpointListForPluginQuery.__init__` [missing-argument]
@@ -2159,25 +2115,29 @@
 ERROR Argument `list[object]` is not assignable to parameter `parameters` with type `Iterable[Mapping[str, Any] | WorkflowToolParameterConfiguration]` in function `controllers.console.workspace.tool_providers.WorkflowToolCreatePayload.__init__` [bad-argument-type]
    --> tests/unit_tests/controllers/console/workspace/test_tool_providers.py:606:62
 ERROR Argument `Literal['file-id']` is not assignable to parameter `file_id` with type `UUID` in function `controllers.files.upload_file_delivery.ImagePreviewApi.get` [bad-argument-type]
-   --> tests/unit_tests/controllers/files/test_upload_file_delivery.py:101:53
+  --> tests/unit_tests/controllers/files/test_upload_file_delivery.py:47:53
 ERROR Argument `Literal['file-id']` is not assignable to parameter `file_id` with type `UUID` in function `controllers.files.upload_file_delivery.ImagePreviewApi.get` [bad-argument-type]
-   --> tests/unit_tests/controllers/files/test_upload_file_delivery.py:122:42
+  --> tests/unit_tests/controllers/files/test_upload_file_delivery.py:68:42
 ERROR Argument `Literal['file-id']` is not assignable to parameter `file_id` with type `UUID` in function `controllers.files.upload_file_delivery.ImagePreviewApi.get` [bad-argument-type]
-   --> tests/unit_tests/controllers/files/test_upload_file_delivery.py:130:42
+  --> tests/unit_tests/controllers/files/test_upload_file_delivery.py:76:42
 ERROR Argument `Literal['file-id']` is not assignable to parameter `file_id` with type `UUID` in function `controllers.files.upload_file_delivery.ImagePreviewApi.get` [bad-argument-type]
-   --> tests/unit_tests/controllers/files/test_upload_file_delivery.py:136:42
+  --> tests/unit_tests/controllers/files/test_upload_file_delivery.py:82:42
+ERROR Argument `Literal['file-id']` is not assignable to parameter `file_id` with type `UUID` in function `controllers.files.upload_file_delivery.FilePreviewApi.get` [bad-argument-type]
+   --> tests/unit_tests/controllers/files/test_upload_file_delivery.py:100:52
 ERROR Argument `Literal['file-id']` is not assignable to parameter `file_id` with type `UUID` in function `controllers.files.upload_file_delivery.FilePreviewApi.get` [bad-argument-type]
-   --> tests/unit_tests/controllers/files/test_upload_file_delivery.py:168:52
+   --> tests/unit_tests/controllers/files/test_upload_file_delivery.py:121:52
 ERROR Argument `Literal['file-id']` is not assignable to parameter `file_id` with type `UUID` in function `controllers.files.upload_file_delivery.FilePreviewApi.get` [bad-argument-type]
-   --> tests/unit_tests/controllers/files/test_upload_file_delivery.py:179:52
+   --> tests/unit_tests/controllers/files/test_upload_file_delivery.py:132:52
 ERROR Argument `Literal['file-id']` is not assignable to parameter `file_id` with type `UUID` in function `controllers.files.upload_file_delivery.FilePreviewApi.get` [bad-argument-type]
-   --> tests/unit_tests/controllers/files/test_upload_file_delivery.py:222:52
+   --> tests/unit_tests/controllers/files/test_upload_file_delivery.py:155:52
 ERROR Argument `Literal['file-id']` is not assignable to parameter `file_id` with type `UUID` in function `controllers.files.upload_file_delivery.FilePreviewApi.get` [bad-argument-type]
-   --> tests/unit_tests/controllers/files/test_upload_file_delivery.py:237:52
+   --> tests/unit_tests/controllers/files/test_upload_file_delivery.py:171:52
 ERROR Argument `Literal['file-id']` is not assignable to parameter `file_id` with type `UUID` in function `controllers.files.upload_file_delivery.FilePreviewApi.get` [bad-argument-type]
-   --> tests/unit_tests/controllers/files/test_upload_file_delivery.py:252:41
+   --> tests/unit_tests/controllers/files/test_upload_file_delivery.py:186:52
 ERROR Argument `Literal['file-id']` is not assignable to parameter `file_id` with type `UUID` in function `controllers.files.upload_file_delivery.FilePreviewApi.get` [bad-argument-type]
-   --> tests/unit_tests/controllers/files/test_upload_file_delivery.py:258:41
+   --> tests/unit_tests/controllers/files/test_upload_file_delivery.py:201:41
+ERROR Argument `Literal['file-id']` is not assignable to parameter `file_id` with type `UUID` in function `controllers.files.upload_file_delivery.FilePreviewApi.get` [bad-argument-type]
+   --> tests/unit_tests/controllers/files/test_upload_file_delivery.py:207:41
 ERROR Missing argument `tenant_model` in function `protected_view` [missing-argument]
    --> tests/unit_tests/controllers/inner_api/plugin/test_wraps.py:292:40
 ERROR Missing argument `user_model` in function `protected_view` [missing-argument]
@@ -3061,91 +3021,91 @@
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
    --> tests/unit_tests/core/app/apps/agent_app/test_app_generator.py:782:20
 ERROR Object of class `list` has no attribute `startswith` [missing-attribute]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:613:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:611:16
 ERROR Object of class `NoneType` has no attribute `kind` [missing-attribute]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:634:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:632:16
 ERROR `list[dict[str, str]]` is not assignable to attribute `dify_tools` with type `list[AgentSoulDifyToolConfig]` [bad-assignment]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:638:33
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:636:33
 ERROR `list[dict[str, str]]` is not assignable to attribute `dify_tools` with type `list[AgentSoulDifyToolConfig]` [bad-assignment]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:663:33
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:656:33
 ERROR `list[dict[str, str]]` is not assignable to attribute `dify_tools` with type `list[AgentSoulDifyToolConfig]` [bad-assignment]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:684:33
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:676:33
 ERROR Object of class `NoneType` has no attribute `plugin_id` [missing-attribute]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:705:9
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:695:9
 ERROR Object of class `NoneType` has no attribute `plugin_id` [missing-attribute]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:721:9
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:710:9
 ERROR Cannot index into `bool` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:766:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:755:16
 ERROR Cannot index into `float` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:766:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:755:16
 ERROR Cannot index into `int` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:766:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:755:16
 ERROR `None` is not subscriptable [unsupported-operation]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:766:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:755:16
 ERROR Cannot index into `str` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:766:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:755:16
 ERROR Cannot index into `bool` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:766:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:755:16
 ERROR Cannot index into `float` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:766:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:755:16
 ERROR Cannot index into `int` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:766:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:755:16
 ERROR Cannot index into `list[JsonValue]` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:766:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:755:16
 ERROR `None` is not subscriptable [unsupported-operation]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:766:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:755:16
 ERROR Cannot index into `dict[str, JsonValue]` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:766:51
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:755:51
 ERROR Cannot index into `bool` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:806:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:795:16
 ERROR Cannot index into `float` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:806:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:795:16
 ERROR Cannot index into `int` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:806:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:795:16
 ERROR `None` is not subscriptable [unsupported-operation]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:806:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:795:16
 ERROR Cannot index into `str` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:806:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:795:16
 ERROR Cannot index into `bool` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:806:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:795:16
 ERROR Cannot index into `float` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:806:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:795:16
 ERROR Cannot index into `int` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:806:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:795:16
 ERROR Cannot index into `list[JsonValue]` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:806:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:795:16
 ERROR `None` is not subscriptable [unsupported-operation]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:806:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:795:16
 ERROR Cannot index into `dict[str, JsonValue]` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:806:51
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:795:51
 ERROR Cannot index into `bool` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:807:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:796:16
 ERROR Cannot index into `float` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:807:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:796:16
 ERROR Cannot index into `int` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:807:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:796:16
 ERROR `None` is not subscriptable [unsupported-operation]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:807:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:796:16
 ERROR Cannot index into `str` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:807:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:796:16
 ERROR Cannot index into `bool` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:807:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:796:16
 ERROR Cannot index into `float` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:807:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:796:16
 ERROR Cannot index into `int` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:807:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:796:16
 ERROR Cannot index into `list[JsonValue]` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:807:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:796:16
 ERROR `None` is not subscriptable [unsupported-operation]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:807:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:796:16
 ERROR Cannot index into `dict[str, JsonValue]` [bad-index]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:807:56
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:796:56
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:946:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:929:16
 ERROR Object of class `NoneType` has no attribute `kind` [missing-attribute]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:947:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:930:16
 ERROR Object of class `NoneType` has no attribute `writable` [missing-attribute]
-   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:948:16
+   --> tests/unit_tests/core/app/apps/agent_app/test_runtime_request_builder.py:931:16
 ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `ConversationStatus | SQLCoreOperations[ConversationStatus]` in function `models.model.Conversation.__init__` [bad-argument-type]
   --> tests/unit_tests/core/app/apps/chat/test_app_generator.py:94:16
 ERROR Argument `Literal[core.app.entities.app_invoke_entities.InvokeFrom.SERVICE_API]` is not assignable to parameter `invoke_from` with type `models.enums.InvokeFrom | SQLCoreOperations[models.enums.InvokeFrom | None] | None` in function `models.model.Conversation.__init__` [bad-argument-type]
@@ -3525,21 +3485,21 @@
 ERROR Argument `(**kwargs: Unknown) -> None` is not assignable to parameter `draft_var_saver_factory` with type `DraftVariableSaverFactory` in function `core.app.apps.workflow.app_generator.WorkflowAppGenerator._handle_response` [bad-argument-type]
     --> tests/unit_tests/core/app/apps/workflow/test_app_generator.py:1483:45
 ERROR Argument `SimpleNamespace` is not assignable to parameter `graph_runtime_state` with type `RuntimeState` in function `core.app.apps.workflow.app_generator.WorkflowAppGenerator.resume` [bad-argument-type]
-    --> tests/unit_tests/core/app/apps/workflow/test_app_generator.py:1648:37
+    --> tests/unit_tests/core/app/apps/workflow/test_app_generator.py:1626:37
 ERROR Object of type `Generator[Mapping[str, Any] | str] | Mapping[str, Any]` has no attribute `ok` [missing-attribute]
-    --> tests/unit_tests/core/app/apps/workflow/test_app_generator.py:1653:20
+    --> tests/unit_tests/core/app/apps/workflow/test_app_generator.py:1631:20
 ERROR Argument `SimpleNamespace` is not assignable to parameter `graph_runtime_state` with type `RuntimeState` in function `core.app.apps.workflow.app_generator.WorkflowAppGenerator.resume` [bad-argument-type]
-    --> tests/unit_tests/core/app/apps/workflow/test_app_generator.py:1706:37
+    --> tests/unit_tests/core/app/apps/workflow/test_app_generator.py:1684:37
 ERROR Object of type `Generator[Mapping[str, Any] | str] | Mapping[str, Any]` has no attribute `ok` [missing-attribute]
-    --> tests/unit_tests/core/app/apps/workflow/test_app_generator.py:1711:20
+    --> tests/unit_tests/core/app/apps/workflow/test_app_generator.py:1689:20
 ERROR Argument `SimpleNamespace` is not assignable to parameter `flask_app` with type `Flask` in function `core.app.apps.workflow.app_generator.WorkflowAppGenerator._generate_worker` [bad-argument-type]
-    --> tests/unit_tests/core/app/apps/workflow/test_app_generator.py:1768:27
+    --> tests/unit_tests/core/app/apps/workflow/test_app_generator.py:1746:27
 ERROR Argument `SimpleNamespace` is not assignable to parameter `queue_manager` with type `AppQueueManager` in function `core.app.apps.workflow.app_generator.WorkflowAppGenerator._generate_worker` [bad-argument-type]
-    --> tests/unit_tests/core/app/apps/workflow/test_app_generator.py:1770:31
+    --> tests/unit_tests/core/app/apps/workflow/test_app_generator.py:1748:31
 ERROR Argument `SimpleNamespace` is not assignable to parameter `context` with type `Context` in function `core.app.apps.workflow.app_generator.WorkflowAppGenerator._generate_worker` [bad-argument-type]
-    --> tests/unit_tests/core/app/apps/workflow/test_app_generator.py:1771:25
+    --> tests/unit_tests/core/app/apps/workflow/test_app_generator.py:1749:25
 ERROR Argument `SimpleNamespace` is not assignable to parameter `graph_runtime_state` with type `RuntimeState | None` in function `core.app.apps.workflow.app_generator.WorkflowAppGenerator._generate_worker` [bad-argument-type]
-    --> tests/unit_tests/core/app/apps/workflow/test_app_generator.py:1775:37
+    --> tests/unit_tests/core/app/apps/workflow/test_app_generator.py:1753:37
 ERROR Cannot index into `str` [bad-index]
   --> tests/unit_tests/core/app/apps/workflow/test_generate_response_converter.py:75:16
 ERROR Cannot index into `str` [bad-index]
@@ -3750,10 +3710,6 @@
   --> tests/unit_tests/core/callback_handler/test_workflow_tool_callback_handler.py:90:30
 ERROR Argument `list[DummyToolInvokeMessage]` is not assignable to parameter `tool_outputs` with type `Iterable[ToolInvokeMessage]` in function `core.callback_handler.workflow_tool_callback_handler.DifyWorkflowCallbackHandler.on_tool_execution` [bad-argument-type]
    --> tests/unit_tests/core/callback_handler/test_workflow_tool_callback_handler.py:178:30
-ERROR Cannot find module `langchain_core.messages` [missing-import]
- --> tests/unit_tests/core/evaluation/frameworks/ragas/test_ragas_model_wrapper.py:9:1
-ERROR Cannot find module `langchain_core.prompt_values` [missing-import]
-  --> tests/unit_tests/core/evaluation/frameworks/ragas/test_ragas_model_wrapper.py:10:1
 ERROR Class member `_ModelInstance.invoke_llm` overrides parent class `ModelInstance` in an inconsistent manner [bad-override]
   --> tests/unit_tests/core/llm_generator/output_parser/test_structured_output.py:68:9
 ERROR Class member `_ModelInstance.invoke_llm` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
@@ -4344,25 +4300,25 @@
 ERROR Class member `CancelFailingStreamBackendClient.cancel_run` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py:580:9
 ERROR Argument `dict[str, str]` is not assignable to parameter `node_data` with type `DifyAgentNodeData` in function `core.workflow.nodes.agent_v2.agent_node.DifyAgentNode._extract_variable_selector_to_variable_mapping` [bad-argument-type]
-   --> tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py:701:19
+   --> tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py:699:19
 ERROR Class member `_UnavailableParticipantStore.load_existing_node_execution_scope` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
-   --> tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py:877:13
+   --> tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py:854:13
 ERROR Class member `_FailingSessionStore.load_or_create_node_execution_session` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py:1146:13
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py:1123:13
 ERROR Attribute `graph_execution` of class `RuntimeState` is a read-only property and cannot be set [read-only]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py:1224:5
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py:1201:5
 ERROR Object of class `NodeEventPayload` has no attribute `node_run_result` [missing-attribute]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py:1551:14
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py:1528:14
 ERROR Class member `RetryingBackendClient._events` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py:1608:13
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py:1585:13
 ERROR `dict[str, int | str] | dict[str, str]` is not assignable to attribute `output_payload` with type `dict[str, object]` [bad-assignment]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py:1609:35
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py:1586:35
 ERROR Object of class `NodeEventPayload` has no attribute `node_run_result` [missing-attribute]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py:1629:14
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py:1606:14
 ERROR Object of class `NodeEventPayload` has no attribute `node_run_result` [missing-attribute]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py:1674:14
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py:1651:14
 ERROR Argument `dict[str, dict[str, list[dict[str, str]] | Unknown]]` is not assignable to parameter `node_data` with type `DifyAgentNodeData` in function `core.workflow.nodes.agent_v2.agent_node.DifyAgentNode._extract_variable_selector_to_variable_mapping` [bad-argument-type]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py:1697:19
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_agent_node.py:1674:19
 ERROR Cannot index into `bool` [bad-index]
    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_dify_tools_builder.py:269:12
 ERROR Cannot index into `float` [bad-index]
@@ -4732,85 +4688,85 @@
 ERROR Cannot index into `object` [bad-index]
    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:509:22
 ERROR Argument `CapturingPluginLayerBuilder` is not assignable to parameter `dify_tools_builder` with type `WorkflowAgentDifyToolLayersBuilder | None` in function `core.workflow.nodes.agent_v2.runtime_request_builder.WorkflowAgentRuntimeRequestBuilder.__init__` [bad-argument-type]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1281:68
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1242:68
 ERROR Cannot index into `bool` [bad-index]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1286:12
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1247:12
 ERROR Cannot index into `float` [bad-index]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1286:12
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1247:12
 ERROR Cannot index into `int` [bad-index]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1286:12
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1247:12
 ERROR `None` is not subscriptable [unsupported-operation]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1286:12
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1247:12
 ERROR Cannot index into `str` [bad-index]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1286:12
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1247:12
 ERROR Cannot index into `bool` [bad-index]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1286:12
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1247:12
 ERROR Cannot index into `float` [bad-index]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1286:12
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1247:12
 ERROR Cannot index into `int` [bad-index]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1286:12
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1247:12
 ERROR Cannot index into `list[JsonValue]` [bad-index]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1286:12
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1247:12
 ERROR `None` is not subscriptable [unsupported-operation]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1286:12
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1247:12
 ERROR Cannot index into `dict[str, JsonValue]` [bad-index]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1286:47
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1247:47
 ERROR Cannot index into `bool` [bad-index]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1287:12
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1248:12
 ERROR Cannot index into `float` [bad-index]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1287:12
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1248:12
 ERROR Cannot index into `int` [bad-index]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1287:12
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1248:12
 ERROR `None` is not subscriptable [unsupported-operation]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1287:12
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1248:12
 ERROR Cannot index into `str` [bad-index]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1287:12
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1248:12
 ERROR Cannot index into `bool` [bad-index]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1287:12
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1248:12
 ERROR Cannot index into `float` [bad-index]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1287:12
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1248:12
 ERROR Cannot index into `int` [bad-index]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1287:12
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1248:12
 ERROR Cannot index into `list[JsonValue]` [bad-index]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1287:12
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1248:12
 ERROR `None` is not subscriptable [unsupported-operation]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1287:12
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1248:12
 ERROR Cannot index into `dict[str, JsonValue]` [bad-index]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1287:52
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1248:52
 ERROR Cannot index into `object` [bad-index]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1512:25
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1473:25
 ERROR Cannot index into `object` [bad-index]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1513:18
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1474:18
 ERROR Class member `FileVariablePool.get` overrides parent class `FakeVariablePool` in an inconsistent manner [bad-override]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1530:13
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1491:13
 ERROR Class member `FileVariablePool.get` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1530:13
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1491:13
 ERROR Cannot index into `object` [bad-index]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1555:12
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1516:12
 ERROR Class member `FileMappingVariablePool.get` overrides parent class `FakeVariablePool` in an inconsistent manner [bad-override]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1568:13
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1529:13
 ERROR Class member `FileMappingVariablePool.get` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1568:13
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1529:13
 ERROR Argument `test_previous_node_file_mapping_strips_extra_fields_in_workflow_context.FileMappingVariablePool` is not assignable to parameter `variable_pool` with type `VariablePoolReader` in function `core.workflow.nodes.agent_v2.runtime_request_builder.WorkflowAgentRuntimeBuildContext.__replace__` [bad-argument-type]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1580:49
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1541:49
 ERROR Cannot index into `object` [bad-index]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1622:12
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1583:12
 ERROR Class member `FileArrayVariablePool.get` overrides parent class `FakeVariablePool` in an inconsistent manner [bad-override]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1633:13
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1594:13
 ERROR Class member `FileArrayVariablePool.get` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1633:13
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1594:13
 ERROR Class member `UploadedFilesVariablePool.get` overrides parent class `FakeVariablePool` in an inconsistent manner [bad-override]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1686:13
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1647:13
 ERROR Class member `UploadedFilesVariablePool.get` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1686:13
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1647:13
 ERROR Class member `LongRemoteUrlVariablePool.get` overrides parent class `FakeVariablePool` in an inconsistent manner [bad-override]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1815:13
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1776:13
 ERROR Class member `LongRemoteUrlVariablePool.get` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1815:13
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:1776:13
 ERROR Argument `CapturingPluginLayerBuilder` is not assignable to parameter `dify_tools_builder` with type `WorkflowAgentDifyToolLayersBuilder | None` in function `core.workflow.nodes.agent_v2.runtime_request_builder.WorkflowAgentRuntimeRequestBuilder.__init__` [bad-argument-type]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:2163:68
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:2124:68
 ERROR Cannot index into `object` [bad-index]
-    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:2164:14
+    --> tests/unit_tests/core/workflow/nodes/agent_v2/test_runtime_request_builder.py:2125:14
 ERROR Class member `InMemoryHumanInputFormRepository.get_form` overrides parent class `HumanInputFormRepository` in an inconsistent manner [bad-override]
    --> tests/unit_tests/core/workflow/nodes/human_input/test_entities.py:326:9
 ERROR Argument `_EntitiesTestfilereferencefactory` is not assignable to parameter `file_reference_factory` with type `DifyFileReferenceFactory | None` in function `core.workflow.nodes.human_input.callback.DifyHITLCallback.__init__` [bad-argument-type]
@@ -5364,55 +5320,53 @@
 ERROR Argument `Literal['invalid']` is not assignable to parameter `session_factory` with type `Engine | sessionmaker[Unknown] | None` in function `services.file_service.FileService.__init__` [bad-argument-type]
   --> tests/unit_tests/services/test_file_service.py:92:45
 ERROR Argument `Iterator[dict[str, str | dict[str, str]] | str]` is not assignable to parameter `response` with type `Generator[Mapping[str, Any] | str] | Mapping[str, Any]` in function `services.snippet_generate_service.SnippetGenerateService._filter_virtual_start_events` [bad-argument-type]
-  --> tests/unit_tests/services/test_snippet_generate_service.py:88:68
+  --> tests/unit_tests/services/test_snippet_generate_service.py:80:68
 ERROR Keyword argument `loop_count` with type `Literal[1]` is not assignable to parameter `**kwargs` with type `str` in function `typing.MutableMapping.update` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:156:36
+   --> tests/unit_tests/services/test_snippet_generate_service.py:147:36
 ERROR Keyword argument `break_conditions` with type `list[@_]` is not assignable to parameter `**kwargs` with type `str` in function `typing.MutableMapping.update` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:156:56
+   --> tests/unit_tests/services/test_snippet_generate_service.py:147:56
 ERROR Keyword argument `iterator_selector` with type `list[str]` is not assignable to parameter `**kwargs` with type `str` in function `typing.MutableMapping.update` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:158:43
+   --> tests/unit_tests/services/test_snippet_generate_service.py:149:43
 ERROR Keyword argument `output_selector` with type `list[str]` is not assignable to parameter `**kwargs` with type `str` in function `typing.MutableMapping.update` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:158:79
+   --> tests/unit_tests/services/test_snippet_generate_service.py:149:79
 ERROR `list[@_]` is not assignable to dict value type `str` [bad-assignment]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:165:89
+   --> tests/unit_tests/services/test_snippet_generate_service.py:156:89
 ERROR No matching overload found for function `dict.get` called with arguments: (dict[str, str] | str, Literal['']) [no-matching-overload]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:168:27
+   --> tests/unit_tests/services/test_snippet_generate_service.py:159:27
 ERROR Cannot set item in `str` [unsupported-operation]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:170:13
+   --> tests/unit_tests/services/test_snippet_generate_service.py:161:13
 ERROR Object of class `str` has no attribute `update` [missing-attribute]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:172:13
+   --> tests/unit_tests/services/test_snippet_generate_service.py:163:13
 ERROR Cannot set item in `str` [unsupported-operation]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:177:13
+   --> tests/unit_tests/services/test_snippet_generate_service.py:168:13
 ERROR Cannot set item in `str` [unsupported-operation]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:179:17
+   --> tests/unit_tests/services/test_snippet_generate_service.py:170:17
 ERROR Argument `Mapping[str, Any] | None` is not assignable to parameter `graph_config` with type `Mapping[str, Any]` in function `graphon.graph.graph.Graph.init` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:205:26
+   --> tests/unit_tests/services/test_snippet_generate_service.py:196:26
 ERROR Argument `NodeFactory | None` is not assignable to parameter `node_factory` with type `NodeFactory` in function `graphon.graph.graph.Graph.init` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:206:26
+   --> tests/unit_tests/services/test_snippet_generate_service.py:197:26
 ERROR Missing argument `type` in function `graphon.file.models.File.model_construct` [missing-argument]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:287:34
+   --> tests/unit_tests/services/test_snippet_generate_service.py:278:34
 ERROR Missing argument `transfer_method` in function `graphon.file.models.File.model_construct` [missing-argument]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:287:34
+   --> tests/unit_tests/services/test_snippet_generate_service.py:278:34
 ERROR Argument `Literal['debugger']` is not assignable to parameter `invoke_from` with type `InvokeFrom` in function `services.snippet_generate_service.SnippetGenerateService.generate` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:320:25
+   --> tests/unit_tests/services/test_snippet_generate_service.py:311:25
 ERROR Argument `Literal['debugger']` is not assignable to parameter `invoke_from` with type `InvokeFrom` in function `services.snippet_generate_service.SnippetGenerateService.generate` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:363:21
+   --> tests/unit_tests/services/test_snippet_generate_service.py:354:21
 ERROR Object of class `object` has no attribute `id` [missing-attribute]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:370:12
+   --> tests/unit_tests/services/test_snippet_generate_service.py:361:12
 ERROR Argument `Literal['service-api']` is not assignable to parameter `invoke_from` with type `InvokeFrom` in function `services.snippet_generate_service.SnippetGenerateService.run_published` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:404:21
+   --> tests/unit_tests/services/test_snippet_generate_service.py:395:21
 ERROR Object of class `object` has no attribute `id` [missing-attribute]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:411:12
-ERROR Argument `Literal['service-api']` is not assignable to parameter `invoke_from` with type `InvokeFrom` in function `services.snippet_generate_service.SnippetGenerateService.run_published` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:448:21
+   --> tests/unit_tests/services/test_snippet_generate_service.py:402:12
 ERROR Object of class `object` has no attribute `id` [missing-attribute]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:508:12
+   --> tests/unit_tests/services/test_snippet_generate_service.py:455:12
 ERROR Object of class `object` has no attribute `id` [missing-attribute]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:566:12
+   --> tests/unit_tests/services/test_snippet_generate_service.py:513:12
 ERROR Object of class `object` has no attribute `id` [missing-attribute]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:623:12
+   --> tests/unit_tests/services/test_snippet_generate_service.py:570:12
 ERROR Argument `Literal['service-api']` is not assignable to parameter `invoke_from` with type `InvokeFrom` in function `services.snippet_generate_service.SnippetGenerateService.run_published` [bad-argument-type]
-   --> tests/unit_tests/services/test_snippet_generate_service.py:658:25
+   --> tests/unit_tests/services/test_snippet_generate_service.py:605:25
 ERROR Argument `list[FromClause]` is not assignable to parameter `tables` with type `Sequence[Table] | None` in function `sqlalchemy.sql.schema.MetaData.create_all` [bad-argument-type]
   --> tests/unit_tests/services/test_workflow_collaboration_service.py:52:56
 ERROR Argument `list[dict[Unknown, Unknown]]` is not assignable to parameter `sessions` with type `Sequence[WorkflowSessionInfo]` in function `tests.helpers.unit.services.workflow_collaboration_fixtures.seed_sessions` [bad-argument-type]

@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 86.44% 86.29% -0.16%
Strict coverage 86.10% 85.95% -0.15%
Typed symbols 93,593 92,129 -1,464
Untyped symbols 14,735 14,698 -37
Modules 4599 4526 -73

@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.66667% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.41%. Comparing base (5ebb192) to head (f0c8690).
⚠️ Report is 27 commits behind head on main.

Files with missing lines Patch % Lines
api/core/agent/base_agent_runner.py 96.66% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #46464      +/-   ##
==========================================
- Coverage   90.41%   90.41%   -0.01%     
==========================================
  Files        6334     6334              
  Lines      396673   396673              
  Branches    79711    79711              
==========================================
- Hits       358638   358634       -4     
- Misses      31928    31930       +2     
- Partials     6107     6109       +2     
Flag Coverage Δ
api 90.11% <96.66%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@asukaminato0721 asukaminato0721 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 inline suggestion at f0c86909fa, from a rule learned from earlier reviews in this repository. Reply on the comment if it is wrong.

dify-codereview

agent_thought.tool = tool_name

if tool_input:
if isinstance(tool_input, dict):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parse, don't validate (https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/): model this data once at the boundary as a pydantic model / dataclass / TypedDict (Model.model_validate(raw)), and pass the typed value on, instead of passing dicts around and re-checking keys and types where they are used. In a test, don't build this as an ad hoc dict[str, object]: define the shape (TypedDict / model) in the production code and import it here.

dify-codereview · parse-dont-validate Learned from an earlier review. Reply here if this is wrong.

@asukaminato0721 asukaminato0721 added the waiting-for-author dify-codereview: the author has suggestions, a conflict, failing CI or unresolved threads to address label Nov 16, 2026
@vaibhav375

Copy link
Copy Markdown
Contributor Author

Closing in favour of #45775, which makes the same change to base_agent_runner.py and was opened first. Sorry for the overlap, I missed it when I picked this slice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L This PR changes 100-499 lines, ignoring generated files. waiting-for-author dify-codereview: the author has suggestions, a conflict, failing CI or unresolved threads to address

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants