Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Dify graph workflow by introducing the capability for LLM nodes to process files as context. This allows for more dynamic and data-rich interactions, where the LLM can directly utilize information from provided files, thereby expanding the range of problems it can address. The changes also include improved error visibility in tool nodes through added logging. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces support for using files as context in LLM nodes, a valuable enhancement. The core logic in llm/node.py appears correct, and the new tests in test_node.py provide good coverage for this functionality. However, I've identified a critical syntax error in the test file due to incorrect indentation that needs to be addressed. Additionally, there are a few opportunities for minor improvements, such as removing redundant checks and updating test decorators now that the feature is implemented. The logging enhancements in tool_node.py are also a welcome addition for better observability.
There was a problem hiding this comment.
Pull request overview
This PR aims to add support for using uploaded/attached files as “context” for the LLM node (so context variables can include file objects/dicts, not only text / retrieval chunks), addressing issue #33340.
Changes:
- Extend
LLMNode._fetch_context()to treatFileobjects anddify_model_identityfile dicts inside context arrays ascontext_files. - Add unit tests intended to cover the new
_fetch_contextbehavior for file objects and file dicts. - Add warning-level exception logging in
ToolNodeerror paths.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| api/dify_graph/nodes/llm/node.py | Adds handling for File objects and file-like dicts when building LLM context. |
| api/tests/unit_tests/core/workflow/nodes/llm/test_node.py | Adds tests for _fetch_context accepting files in context arrays (currently marked xfail and with structural issues). |
| api/dify_graph/nodes/tool/tool_node.py | Adds logger.warning(..., exc_info=True) in several exception handlers for better diagnosability. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-03-12 03:33:09.261578592 +0000
+++ /tmp/pyrefly_pr.txt 2026-03-12 03:33:00.699537594 +0000
@@ -488,13 +488,13 @@
ERROR Object of class `BaseOxmlElement` has no attribute `body` [missing-attribute]
--> dify_graph/nodes/document_extractor/node.py:446:19
ERROR `+` is not supported between `list[Unknown]` and `str` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:881:65
+ --> dify_graph/nodes/llm/node.py:893:65
ERROR `+` is not supported between `list[Unknown]` and `None` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:881:65
+ --> dify_graph/nodes/llm/node.py:893:65
ERROR `+` is not supported between `list[Unknown]` and `str` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:898:65
+ --> dify_graph/nodes/llm/node.py:910:65
ERROR `+` is not supported between `list[Unknown]` and `None` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:898:65
+ --> dify_graph/nodes/llm/node.py:910:65
ERROR Expected a callable, got `Literal[SegmentType.get_zero_value]` [not-callable]
--> dify_graph/nodes/variable_assigner/v1/node.py:92:32
ERROR `updated_variable` may be uninitialized [unbound-name]
@@ -4495,6 +4495,10 @@
--> tests/unit_tests/core/workflow/nodes/llm/test_node.py:680:9
ERROR Object of class `FunctionType` has no attribute `assert_called_once_with` [missing-attribute]
--> tests/unit_tests/core/workflow/nodes/llm/test_node.py:711:9
+ERROR `tuple[Literal['nodeA'], Literal['ctx']]` is not assignable to attribute `variable_selector` with type `list[str] | None` [bad-assignment]
+ --> tests/unit_tests/core/workflow/nodes/llm/test_node.py:794:52
+ERROR `tuple[Literal['nodeB'], Literal['ctx']]` is not assignable to attribute `variable_selector` with type `list[str] | None` [bad-assignment]
+ --> tests/unit_tests/core/workflow/nodes/llm/test_node.py:827:52
ERROR Object of class `RetryConfig` has no attribute `enabled` [missing-attribute]
--> tests/unit_tests/core/workflow/nodes/template_transform/entities_spec.py:92:16
ERROR `dict[str, list[Unknown] | str]` is not assignable to TypedDict key `data` with type `BaseNodeData` [bad-typed-dict-key]
|
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-03-12 04:32:56.682624191 +0000
+++ /tmp/pyrefly_pr.txt 2026-03-12 04:32:47.515651143 +0000
@@ -488,13 +488,13 @@
ERROR Object of class `BaseOxmlElement` has no attribute `body` [missing-attribute]
--> dify_graph/nodes/document_extractor/node.py:446:19
ERROR `+` is not supported between `list[Unknown]` and `str` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:881:65
+ --> dify_graph/nodes/llm/node.py:893:65
ERROR `+` is not supported between `list[Unknown]` and `None` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:881:65
+ --> dify_graph/nodes/llm/node.py:893:65
ERROR `+` is not supported between `list[Unknown]` and `str` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:898:65
+ --> dify_graph/nodes/llm/node.py:910:65
ERROR `+` is not supported between `list[Unknown]` and `None` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:898:65
+ --> dify_graph/nodes/llm/node.py:910:65
ERROR Expected a callable, got `Literal[SegmentType.get_zero_value]` [not-callable]
--> dify_graph/nodes/variable_assigner/v1/node.py:92:32
ERROR `updated_variable` may be uninitialized [unbound-name]
@@ -4735,6 +4735,10 @@
--> tests/unit_tests/core/workflow/nodes/llm/test_node.py:680:9
ERROR Object of class `FunctionType` has no attribute `assert_called_once_with` [missing-attribute]
--> tests/unit_tests/core/workflow/nodes/llm/test_node.py:711:9
+ERROR `tuple[Literal['nodeA'], Literal['ctx']]` is not assignable to attribute `variable_selector` with type `list[str] | None` [bad-assignment]
+ --> tests/unit_tests/core/workflow/nodes/llm/test_node.py:794:52
+ERROR `tuple[Literal['nodeB'], Literal['ctx']]` is not assignable to attribute `variable_selector` with type `list[str] | None` [bad-assignment]
+ --> tests/unit_tests/core/workflow/nodes/llm/test_node.py:827:52
ERROR Object of class `RetryConfig` has no attribute `enabled` [missing-attribute]
--> tests/unit_tests/core/workflow/nodes/template_transform/entities_spec.py:92:16
ERROR `dict[str, list[Unknown] | str]` is not assignable to TypedDict key `data` with type `BaseNodeData` [bad-typed-dict-key]
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-03-12 14:14:05.157013624 +0000
+++ /tmp/pyrefly_pr.txt 2026-03-12 14:13:56.391108236 +0000
@@ -488,13 +488,13 @@
ERROR Object of class `BaseOxmlElement` has no attribute `body` [missing-attribute]
--> dify_graph/nodes/document_extractor/node.py:446:19
ERROR `+` is not supported between `list[Unknown]` and `str` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:881:65
+ --> dify_graph/nodes/llm/node.py:893:65
ERROR `+` is not supported between `list[Unknown]` and `None` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:881:65
+ --> dify_graph/nodes/llm/node.py:893:65
ERROR `+` is not supported between `list[Unknown]` and `str` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:898:65
+ --> dify_graph/nodes/llm/node.py:910:65
ERROR `+` is not supported between `list[Unknown]` and `None` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:898:65
+ --> dify_graph/nodes/llm/node.py:910:65
ERROR Expected a callable, got `Literal[SegmentType.get_zero_value]` [not-callable]
--> dify_graph/nodes/variable_assigner/v1/node.py:92:32
ERROR `updated_variable` may be uninitialized [unbound-name]
@@ -4911,6 +4911,10 @@
--> tests/unit_tests/core/workflow/nodes/llm/test_node.py:680:9
ERROR Object of class `FunctionType` has no attribute `assert_called_once_with` [missing-attribute]
--> tests/unit_tests/core/workflow/nodes/llm/test_node.py:711:9
+ERROR `tuple[Literal['nodeA'], Literal['ctx']]` is not assignable to attribute `variable_selector` with type `list[str] | None` [bad-assignment]
+ --> tests/unit_tests/core/workflow/nodes/llm/test_node.py:794:52
+ERROR `tuple[Literal['nodeB'], Literal['ctx']]` is not assignable to attribute `variable_selector` with type `list[str] | None` [bad-assignment]
+ --> tests/unit_tests/core/workflow/nodes/llm/test_node.py:827:52
ERROR Object of class `RetryConfig` has no attribute `enabled` [missing-attribute]
--> tests/unit_tests/core/workflow/nodes/template_transform/entities_spec.py:92:16
ERROR `dict[str, list[Unknown] | str]` is not assignable to TypedDict key `data` with type `BaseNodeData` [bad-typed-dict-key]
|
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-03-13 01:33:06.619371501 +0000
+++ /tmp/pyrefly_pr.txt 2026-03-13 01:32:57.334319137 +0000
@@ -488,13 +488,13 @@
ERROR Object of class `BaseOxmlElement` has no attribute `body` [missing-attribute]
--> dify_graph/nodes/document_extractor/node.py:446:19
ERROR `+` is not supported between `list[Unknown]` and `str` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:881:65
+ --> dify_graph/nodes/llm/node.py:894:65
ERROR `+` is not supported between `list[Unknown]` and `None` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:881:65
+ --> dify_graph/nodes/llm/node.py:894:65
ERROR `+` is not supported between `list[Unknown]` and `str` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:898:65
+ --> dify_graph/nodes/llm/node.py:911:65
ERROR `+` is not supported between `list[Unknown]` and `None` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:898:65
+ --> dify_graph/nodes/llm/node.py:911:65
ERROR Expected a callable, got `Literal[SegmentType.get_zero_value]` [not-callable]
--> dify_graph/nodes/variable_assigner/v1/node.py:92:32
ERROR `updated_variable` may be uninitialized [unbound-name]
@@ -4911,6 +4911,10 @@
--> tests/unit_tests/core/workflow/nodes/llm/test_node.py:680:9
ERROR Object of class `FunctionType` has no attribute `assert_called_once_with` [missing-attribute]
--> tests/unit_tests/core/workflow/nodes/llm/test_node.py:711:9
+ERROR `tuple[Literal['nodeA'], Literal['ctx']]` is not assignable to attribute `variable_selector` with type `list[str] | None` [bad-assignment]
+ --> tests/unit_tests/core/workflow/nodes/llm/test_node.py:794:52
+ERROR `tuple[Literal['nodeB'], Literal['ctx']]` is not assignable to attribute `variable_selector` with type `list[str] | None` [bad-assignment]
+ --> tests/unit_tests/core/workflow/nodes/llm/test_node.py:827:52
ERROR Object of class `RetryConfig` has no attribute `enabled` [missing-attribute]
--> tests/unit_tests/core/workflow/nodes/template_transform/entities_spec.py:92:16
ERROR `dict[str, list[Unknown] | str]` is not assignable to TypedDict key `data` with type `BaseNodeData` [bad-typed-dict-key]
|
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-03-13 01:35:24.341715579 +0000
+++ /tmp/pyrefly_pr.txt 2026-03-13 01:35:14.452869574 +0000
@@ -488,13 +488,13 @@
ERROR Object of class `BaseOxmlElement` has no attribute `body` [missing-attribute]
--> dify_graph/nodes/document_extractor/node.py:446:19
ERROR `+` is not supported between `list[Unknown]` and `str` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:881:65
+ --> dify_graph/nodes/llm/node.py:892:65
ERROR `+` is not supported between `list[Unknown]` and `None` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:881:65
+ --> dify_graph/nodes/llm/node.py:892:65
ERROR `+` is not supported between `list[Unknown]` and `str` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:898:65
+ --> dify_graph/nodes/llm/node.py:909:65
ERROR `+` is not supported between `list[Unknown]` and `None` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:898:65
+ --> dify_graph/nodes/llm/node.py:909:65
ERROR Expected a callable, got `Literal[SegmentType.get_zero_value]` [not-callable]
--> dify_graph/nodes/variable_assigner/v1/node.py:92:32
ERROR `updated_variable` may be uninitialized [unbound-name]
@@ -4911,6 +4911,10 @@
--> tests/unit_tests/core/workflow/nodes/llm/test_node.py:680:9
ERROR Object of class `FunctionType` has no attribute `assert_called_once_with` [missing-attribute]
--> tests/unit_tests/core/workflow/nodes/llm/test_node.py:711:9
+ERROR `tuple[Literal['nodeA'], Literal['ctx']]` is not assignable to attribute `variable_selector` with type `list[str] | None` [bad-assignment]
+ --> tests/unit_tests/core/workflow/nodes/llm/test_node.py:794:52
+ERROR `tuple[Literal['nodeB'], Literal['ctx']]` is not assignable to attribute `variable_selector` with type `list[str] | None` [bad-assignment]
+ --> tests/unit_tests/core/workflow/nodes/llm/test_node.py:827:52
ERROR Object of class `RetryConfig` has no attribute `enabled` [missing-attribute]
--> tests/unit_tests/core/workflow/nodes/template_transform/entities_spec.py:92:16
ERROR `dict[str, list[Unknown] | str]` is not assignable to TypedDict key `data` with type `BaseNodeData` [bad-typed-dict-key]
|
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-03-13 01:35:55.567512520 +0000
+++ /tmp/pyrefly_pr.txt 2026-03-13 01:35:46.459424979 +0000
@@ -488,13 +488,13 @@
ERROR Object of class `BaseOxmlElement` has no attribute `body` [missing-attribute]
--> dify_graph/nodes/document_extractor/node.py:446:19
ERROR `+` is not supported between `list[Unknown]` and `str` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:881:65
+ --> dify_graph/nodes/llm/node.py:892:65
ERROR `+` is not supported between `list[Unknown]` and `None` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:881:65
+ --> dify_graph/nodes/llm/node.py:892:65
ERROR `+` is not supported between `list[Unknown]` and `str` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:898:65
+ --> dify_graph/nodes/llm/node.py:909:65
ERROR `+` is not supported between `list[Unknown]` and `None` [unsupported-operation]
- --> dify_graph/nodes/llm/node.py:898:65
+ --> dify_graph/nodes/llm/node.py:909:65
ERROR Expected a callable, got `Literal[SegmentType.get_zero_value]` [not-callable]
--> dify_graph/nodes/variable_assigner/v1/node.py:92:32
ERROR `updated_variable` may be uninitialized [unbound-name]
@@ -4911,6 +4911,10 @@
--> tests/unit_tests/core/workflow/nodes/llm/test_node.py:680:9
ERROR Object of class `FunctionType` has no attribute `assert_called_once_with` [missing-attribute]
--> tests/unit_tests/core/workflow/nodes/llm/test_node.py:711:9
+ERROR `tuple[Literal['nodeA'], Literal['ctx']]` is not assignable to attribute `variable_selector` with type `list[str] | None` [bad-assignment]
+ --> tests/unit_tests/core/workflow/nodes/llm/test_node.py:794:52
+ERROR `tuple[Literal['nodeB'], Literal['ctx']]` is not assignable to attribute `variable_selector` with type `list[str] | None` [bad-assignment]
+ --> tests/unit_tests/core/workflow/nodes/llm/test_node.py:827:52
ERROR Object of class `RetryConfig` has no attribute `enabled` [missing-attribute]
--> tests/unit_tests/core/workflow/nodes/template_transform/entities_spec.py:92:16
ERROR `dict[str, list[Unknown] | str]` is not assignable to TypedDict key `data` with type `BaseNodeData` [bad-typed-dict-key]
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Important
Fixes #<issue number>.Summary
fix #33340
Screenshots
Checklist
make lintandmake type-check(backend) andcd web && npx lint-staged(frontend) to appease the lint gods