Repository navigation
fix(agent): resolve workflow variables in knowledge metadata filters - #6
Merged
Merged
Conversation
…anggenius#43840) Co-authored-by: Keviniscool-boy <238277696+Keviniscool-boy@users.noreply.github.com>
…anggenius#43846) Co-authored-by: Keviniscool-boy <238277696+Keviniscool-boy@users.noreply.github.com>
…ata-variables-main
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Agent v2 knowledge retrievals in a workflow show an empty Variable picker. Even when a saved condition contains
{{#start.guide_item_id#}}, the request sends that template literally instead of the current input, so dynamic metadata filtering cannot work.This change connects the existing workflow String/Number variable lists to the Agent's embedded metadata editor and resolves manual filter values from the current run's variable pool. Whole numeric references retain their numeric type; interpolated text and string-list conditions remain strings. Saved Agent configuration is not mutated.
It also loads references used only by metadata filters during single-node debugging. The node discriminator keeps legacy Agent version 2 nodes on their existing execution path. Saved metadata definitions are loaded before mounting condition editors, preserving Variable mode on reopen and slow responses. Failed or missing dataset responses preserve the conditions and allow retrying or disabling filtering.
Related issue: langgenius#43837.
Addresses both gaps described in dosubot's analysis. This PR is adapted to current
main, retains the existing UI-field stripping fix, and uses the generated dataset query API. It does not require an Agent backend protocol change.Validation
On this
main-based branch:make lint,make type-check,vp run -w check:fix,vp run -w check, andvp stagedpassed. Frontend static checks report existing warnings, with zero errors.The original fix was also exercised end to end on Dify 1.16.1 with a real model and a seeded knowledge base:
Start → Agent v2 → End, Agent-decided retrieval, and AND filters bound to dynamicguide_program_id/guide_item_idinputs. Four document combinations returned their respective unique codes, and a fifth unmatched combination returned no result. This full-stack E2E run was on 1.16.1, not the newermainadaptation.Screenshot evidence — Dify 1.16.1
These are unmodified captures from the local Dify 1.16.1 + original fix end-to-end run using a real
qwen3.7-plusmodel and a seeded knowledge base. They demonstrate the original release fix; the newermainadaptation has the separate automated validation listed above.Workflow variables and saved filters
The embedded Agent retrieval exposes Start and system variables, with both guide IDs selected as Variables and joined with AND. Query mode is Agent decide.
Actual retrieval results: 5/5 passed
The workflow is
Start → Agent v2 → End, with retrieval inside the Agent. Both metadata fields and their Start inputs are String. Four seeded documents contain distinct verification codes. The same question is used for each run; only the two input IDs change. Each screenshot shows the inputs, SUCCESS status, and actual output.AMBER_731JADE_842COBALT_953CORAL_164NO_MATCHExpand all five run screenshots
P100 / I10 → AMBER_731
P100 / I20 → JADE_842
P200 / I10 → COBALT_953
P200 / I20 → CORAL_164
P100 / I99 → NO_MATCH
Checklist
make lint && make type-check(backend) andvp staged(frontend) to appease the lint gods.From Codex