mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-06-29 23:41:12 +08:00
## Summary Fixes the agent `Switch` component matching an **empty/all-skipped condition** unconditionally because `all([]) is True`. ## Root cause `res` only accumulates for items with a non-empty `cpn_id` (blank ones `continue`). For a condition with empty `items` (or all-blank `cpn_id`), `res == []`, and `if all(res):` is `True`, so the Switch routes to that condition's `to` target before reaching the else/`end_cpn_ids` branch. ## Fix ```diff - if all(res): + if res and all(res): ``` An empty result set no longer counts as a match; genuinely-satisfied "and" conditions still route (the real `all(res)` path is preserved). ## Files changed - `agent/component/switch.py` - `test/unit_test/agent/component/test_switch_empty_condition.py` (new) ## Verification - `ruff check` / `ruff format --check` — clean - Added unit tests (mirroring the existing `_FakeCanvas` component-test pattern): an empty/all-skipped "and" condition now falls through to `end_cpn_ids`; a genuinely-satisfied "and" condition still routes to its target. - Local full pytest not run (heavy RAG deps); CI validates. ## Note Implemented with LLM assistance (model: claude-opus-4-8). Closes #15643 --------- Co-authored-by: seekmistar01 <seekmistar01@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: Zhichang Yu <yuzhichang@gmail.com>