mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-11 22:25:41 +08:00
### What problem does this PR solve? Issue [#16758](https://github.com/infiniflow/ragflow/issues/16758) — clicking a chunk whose data references a single-line variable from an Await-Response (UserFillUp) component, the Agent's `user_prompt` is being resolved against the **previous** canvas run's captured value instead of the current run's value. The system-prompt path works only because the system prompt is computed upstream and re-reads the value on the new run. ### Root cause `Canvas._run_impl` reset every path component with `only_output=True`, so `_param.inputs` was never cleared between runs. `ComponentBase.get_input()` calls `set_input_value(var, resolved)` at line 482, which writes the resolved variable into `self._param.inputs[var]["value"]`. On the next canvas run, that input was never cleared, so the previous run's resolved value stuck around. The Agent's `kwargs.get("user_prompt")` then read the stale string and forwarded it to the LLM, which produced the "Understood. Please provide the text..." fallback because the prompt looked empty. ### What changed? - `agent/canvas.py` — differentiate `begin` (still `only_output=True`, since it has no inputs and the webhook payload branch below populates `request` explicitly) from non-begin path components (reset with `only_output=False`, which clears both `inputs` and `outputs`). - `test/unit_test/agent/test_canvas_input_reset.py` — new pytest module. Pinned the contract: non-begin path components receive `only_output=False`. The fix is small enough to verify with a stub canvas rather than a full canvas-runtime test (the existing agent conftest hits an unrelated `scholarly` import on Python 3.13, so a real canvas import would require fixing that first). ### Backward compatibility - `Begin` behaviour unchanged. - All non-begin path components: previously persisted inputs across runs (the bug); now reset between runs. Components that were relying on stale inputs (none found in the existing test suite) would lose that as a side effect, but that is the entire point of the fix. - No API surface change. No backend change. ### Testing ``` $ uv run pytest test/unit_test/agent/test_canvas_input_reset.py -v collected 4 items test/unit_test/agent/test_canvas_input_reset.py::test_begin_is_reset_with_only_output_true PASSED test/unit_test/agent/test_canvas_input_reset.py::test_non_begin_path_components_are_reset_with_only_output_false PASSED test/unit_test/agent/test_canvas_input_reset.py::test_only_path_components_are_reset PASSED test/unit_test/agent/test_canvas_input_reset.py::test_inputs_reset_flag_is_passed_to_non_begin_components PASSED 4 passed in 0.14s ``` `python3 -m py_compile agent/canvas.py` clean. Existing agent test files (`test_switch.py`, `test_llm_prompt.py`) hit a pre-existing `scholarly` import error on Python 3.13 (unrelated to this PR), so I couldn't run the full agent suite. Recommend fixing the `scholarly` import separately. ### Files changed - `agent/canvas.py` (+9 / −1) - `test/unit_test/agent/test_canvas_input_reset.py` (new, +104) Fixes #16758 --------- Co-authored-by: Harsh Kashyap <harshkashyap@Harshs-MacBook-Pro.local> Co-authored-by: Zhichang Yu <yuzhichang@gmail.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
(1). Deploy RAGFlow services and images
https://ragflow.io/docs/build_docker_image
(2). Configure the required environment for testing
Install Python dependencies (including test dependencies):
uv sync --python 3.13 --only-group test --no-default-groups --frozen
Activate the environment:
source .venv/bin/activate
Install SDK:
uv pip install sdk/python
Modify the .env file: Add the following code:
COMPOSE_PROFILES=${COMPOSE_PROFILES},tei-cpu
TEI_MODEL=BAAI/bge-small-en-v1.5
RAGFLOW_IMAGE=infiniflow/ragflow:v0.26.4 #Replace with the image you are using
Start the container(wait two minutes):
docker compose -f docker/docker-compose.yml up -d
(3). Test Elasticsearch
a) Run sdk tests against Elasticsearch:
export HTTP_API_TEST_LEVEL=p2
export HOST_ADDRESS=http://127.0.0.1:9380 # Ensure that this port is the API port mapped to your localhost
pytest -s --tb=short --level=${HTTP_API_TEST_LEVEL} test/testcases/test_sdk_api
b) Run http api tests against Elasticsearch:
pytest -s --tb=short --level=${HTTP_API_TEST_LEVEL} test/testcases/test_http_api
(4). Test Infinity
Modify the .env file:
DOC_ENGINE=${DOC_ENGINE:-infinity}
Start the container:
docker compose -f docker/docker-compose.yml down -v
docker compose -f docker/docker-compose.yml up -d
a) Run sdk tests against Infinity:
DOC_ENGINE=infinity pytest -s --tb=short --level=${HTTP_API_TEST_LEVEL} test/testcases/test_sdk_api
b) Run http api tests against Infinity:
DOC_ENGINE=infinity pytest -s --tb=short --level=${HTTP_API_TEST_LEVEL} test/testcases/test_http_api