Skip to content

fix(agentflow): handle empty form object in form-input mode#6176

Closed
octo-patch wants to merge 1 commit intoFlowiseAI:mainfrom
octo-patch:fix/issue-6013-empty-form-handling
Closed

fix(agentflow): handle empty form object in form-input mode#6176
octo-patch wants to merge 1 commit intoFlowiseAI:mainfrom
octo-patch:fix/issue-6013-empty-form-handling

Conversation

@octo-patch
Copy link
Copy Markdown

Fixes #6013

Problem

When an AgentFlow V2 uses Form Input on the Start node, subsequent messages from the embed chat (or share link) arrive at the server with an empty form: {} payload and no question field:

{"chatId":"...","form":{},"overrideConfig":{},"streaming":true}

Because an empty object is truthy in JavaScript, the existing code branches treated form: {} as a populated form. This caused two issues:

  1. finalInput was set to "" (empty string from Object.entries({}).join('\n')) instead of falling through to the user's question
  2. finalUserInput (the content saved to the ChatMessage table) was also set to "", causing blank user messages to be stored in the database
  3. The validation guard if (incomingInput.question && incomingInput.form) would erroneously throw if a caller sent question alongside an empty form: {}

Solution

Introduce an explicit incomingFormHasData check (Object.keys(form).length > 0) instead of relying on bare object truthiness:

  • Only treat incomingInput.form as real form data when it actually contains keys
  • Apply the same guard when computing finalUserInput for formInput flows
  • Relax the mutual-exclusion validation so it only fires when both question and a non-empty form are present simultaneously

This allows the server to correctly fall back to the question field when an empty form: {} is sent, and stores a meaningful user message in the database.

Testing

  • Verified the logic change with the three affected code paths in buildAgentflow.ts
  • Existing form-input behaviour (non-empty form) is preserved: the new guard evaluates identically to the old truthy check for populated form objects

…owiseAI#6013)

When an AgentFlow V2 uses Form Input on the Start node, subsequent
messages from the embed chat arrive with an empty form payload and no
question field. Because an empty object is truthy in JavaScript, the
previous code treated it as a populated form, producing an empty string
as both finalInput and finalUserInput. This caused chat messages stored
in the database to appear blank and prevented the flow from receiving
any user input after the initial form submission.

Changes:
- Use an explicit incomingFormHasData guard (checking Object.keys
  length) instead of bare truthiness checks before using incomingInput.form
- Apply the same guard when computing finalUserInput for formInput flows
- The question-and-form validation now only fires when the form actually
  contains data, allowing callers to send question alongside empty form
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request refactors form input handling in buildAgentflow.ts by introducing explicit checks for non-empty form data before processing. This includes creating incomingFormHasData in executeNode and adding Object.keys(form).length > 0 in executeAgentFlow, along with removing a redundant nullish coalescing in the latter. A review comment suggests that the || {} in executeNode is now also redundant and should be removed for consistency.

finalInput = uploadedFilesContent ? `${uploadedFilesContent}\n\n${incomingInput.question}` : incomingInput.question
} else if (incomingInput.form) {
} else if (incomingFormHasData) {
finalInput = Object.entries(incomingInput.form || {})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since incomingFormHasData already ensures that incomingInput.form is a non-null object, the nullish coalescing with {} is no longer necessary here. Removing it would also make this code consistent with the change in executeAgentFlow where a similar || {} was removed.

            finalInput = Object.entries(incomingInput.form)

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.

Chat messages (question field) not sent in prediction request body when Start node uses Form Input — AgentFlow V2

2 participants