Skip to content

Agent node fails after clearing an optional variable parameter #44579

Description

@ZhXZhao

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • This is only a bug report, not a question or feature request.
  • I have searched existing open and closed issues.
  • I am submitting this report in English.
  • All required bug-report fields are filled in below.

Dify version

1.17.1, self-hosted downstream build. The affected Agent serialization and runtime paths are also present in upstream main at 8c41d45dd895e819ede54c034a1ccaaa9a443aaf (2026-10-23).

The failure was observed on the downstream deployment; the upstream comparison is source inspection, not a claim that we executed an unmodified upstream checkout.

Cloud or Self Hosted

Self Hosted (Docker images deployed through Kubernetes/Helm).

Steps to reproduce

This concerns the legacy Agent node in Workflow/Chatflow, not Agent V2 or a standalone Tool node.

Use an Agent strategy exposing an optional variable-selector parameter, for example:

parameters:
  - name: context
    type: any
    required: false
    label:
      en_US: Context
  1. Create a Workflow with Start -> Agent -> End. Add a text input to Start and select the strategy above in Agent.
  2. Leave context untouched. It is absent from agent_parameters, and the node runs normally.
  3. Select the Start text input for context. The saved graph contains:
    {"context":{"type":"variable","value":["start","text"]}}
  4. Hover over the selected variable and click Clear.
  5. Save/run the draft, or publish and invoke the workflow again.

The cleared field looks unset, but the parameter remains in the graph:

{"context":{"type":"variable","value":""}}

An empty selector list ([]) produces the same Agent runtime failure. This also applies to optional files parameters declared as any.

Expected Behavior

  • Clearing an optional Agent variable parameter restores its unset state, rather than persisting an invalid variable reference. For these strategy parameters, removing the corresponding agent_parameters entry matches the untouched state.
  • Existing drafts and published versions containing an empty optional selector ("", [], or null) run as if that parameter were unset.
  • Required parameters still fail clearly when no variable is selected.
  • Non-empty invalid/missing references remain errors. A valid reference resolving to an empty value or numeric 0 must not be mistaken for an empty selector.

Actual Behavior

The Agent fails before strategy invocation, even though the parameter is optional:

File "/app/api/core/workflow/nodes/agent/agent_node.py", line 124, in _run
    parameters = self._runtime_support.build_parameters(...)
File "/app/api/core/workflow/nodes/agent/runtime_support.py", line 60, in build_parameters
    raise AgentVariableNotFoundError(str(agent_input.value))
core.workflow.nodes.agent.exceptions.AgentVariableNotFoundError: Variable '' does not exist

Every execution reaching this node fails until the parameter is actually removed or a valid reference is selected. Clearing it in the editor again does not remove the configuration entry.

Affected source paths

At the upstream commit noted above:

  • Form.tsx:579-606: any parameters use VarReferencePicker without overriding its default variable-kind state.
  • var-reference-picker.tsx:251-254: clearing emits '' or [].
  • use-config.ts: onFormChange retains the cleared entry and marks any inputs as type: variable.
  • runtime_support.py:55-61: every variable input is resolved; the missing-variable exception does not distinguish optional parameters.
  • agent_node.py: selector extraction also includes cleared references, affecting single-node draft execution before parameter building.

Related Agent tool-parameter path

An Agent's selected tools have a separate manual-parameter path. If a numeric/object/array/date parameter is switched to variable mode, or a file parameter is selected, clearing it can likewise retain an empty reference with auto: 0. For example:

{"count":{"auto":0,"value":{"type":"variable","value":""}}}

runtime_support.py:98-105 raises ValueError: Variable selector is missing for a variable-type parameter. without distinguishing whether that tool parameter is optional. Thus the broader Agent issue is not limited to a strategy's any fields.

Local fix verification

We verified a local fix in a disposable Kubernetes instance with independent PostgreSQL/Redis and real installed deterministic Python strategy/tool plugins. No LLM credentials or production workflow data were used.

  • Browser actions: select, clear, autosave, refresh, and reopen context and files; persisted strategy entries were removed.
  • Browser actions: clear and reselect/clear an optional manual numeric tool parameter; its value became null while auto remained 0.
  • 16 real Console API cases covered legacy empty forms, required strategy/tool parameters, missing non-empty references, valid references, and numeric 0; outcomes matched the expectations above.
  • The complete Start -> Agent -> End workflow was launched through the editor twice and returned workflow_finished with status: succeeded and visible output.

These observations validate the local fix only; it has not been submitted or merged upstream. The fix normalizes clearing in the Agent-specific frontend owners and handles existing empty optional references in the backend, including single-node selector extraction. Changing the shared picker alone would not repair existing saved workflows, and replacing '' with [] alone would still fail in Agent.

Related reports

Activity

  1. rome-xi commented on Oct 23, 2026

    @rome-xi

    I can confirm this on 530d8300c: AgentRuntimeSupport.build_parameters raises AgentVariableNotFoundError for an empty selector ('', [], None) even when the strategy parameter is optional. Working on a small backend fix with tests, so existing drafts and published versions run as if the parameter were unset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions