Skip to content

fix(agent): resolve workflow variables in knowledge metadata filters - #6

Merged
jasonfish568 merged 8 commits into
mainfrom
codex/fix-agent-metadata-variables-main
Oct 11, 2026
Merged

jasonfish568 merged 8 commits into
mainfrom
codex/fix-agent-metadata-variables-main

Conversation

@jasonfish568

@jasonfish568 jasonfish568 commented Oct 11, 2026 •

Copy link
Copy Markdown
Owner

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:

  • Backend: 345 passed across Agent v2 nodes, workflow entry, Agent composer entities, and the shared configuration override contract tests. Coverage includes runtime payload resolution, numeric values, interpolation and string lists, unchanged constants/snapshots, missing references, single-node debugging, inactive filters, and legacy Agent isolation.
  • Frontend: 31 passed across the knowledge dialog and knowledge validation suites. Coverage includes typed workflow pickers, saving/reopening, delayed metadata loading, and failed/missing metadata recovery.
  • make lint, make type-check, vp run -w check:fix, vp run -w check, and vp staged passed. 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 dynamic guide_program_id / guide_item_id inputs. 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 newer main adaptation.

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-plus model and a seeded knowledge base. They demonstrate the original release fix; the newer main adaptation 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.

Workflow variable picker Both saved dynamic filters
Workflow variable picker with guide_program_id and guide_item_id Both dynamic metadata conditions configured inside Agent v2

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.

guide_program_id guide_item_id Expected and actual output Screenshot
P100 I10 AMBER_731 Open
P100 I20 JADE_842 Open
P200 I10 COBALT_953 Open
P200 I20 CORAL_164 Open
P100 I99 NO_MATCH Open
Expand all five run screenshots

P100 / I10 → AMBER_731

P100 I10 successful retrieval

P100 / I20 → JADE_842

P100 I20 successful retrieval

P200 / I10 → COBALT_953

P200 I10 successful retrieval

P200 / I20 → CORAL_164

P200 I20 successful retrieval

P100 / I99 → NO_MATCH

P100 I99 no matching document

Checklist

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

From Codex

@jasonfish568
jasonfish568 merged commit 47174ea into main Oct 11, 2026
1 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants