Skip to content

feat(agentflow): ConditionBuilder + dynamic output ports (FLOWISE-261)#5957

Merged
jocelynlin-wd merged 4 commits intomainfrom
feat/agentflow-condition-builder
Mar 12, 2026
Merged

feat(agentflow): ConditionBuilder + dynamic output ports (FLOWISE-261)#5957
jocelynlin-wd merged 4 commits intomainfrom
feat/agentflow-condition-builder

Conversation

@jocelynlin-wd
Copy link
Contributor

@jocelynlin-wd jocelynlin-wd commented Mar 11, 2026

  • Add ConditionBuilder atom for editing condition arrays with labeled items (Condition 0, 1, ...) and Else indicator
  • Add buildDynamicOutputAnchors utility (parameterized with labelPrefix and includeElse for reuse by FLOWISE-262)
  • Add useDynamicOutputPorts hook that syncs output anchors and cleans up orphaned edges when conditions are deleted
  • Integrate into EditNodeDialog for conditionAgentflow nodes with enabled guard for non-condition nodes
  • Stable keys via idCounterRef to avoid React reconciliation bugs on mid-list deletion
condition-builder-type-ops.mov
condition-builder-add-remove-conditions.mov

…rts (FLOWISE-261)

Implement condition node editing UI with dynamic output port syncing:
- ConditionBuilder atom for rendering condition arrays with Else indicator
- buildDynamicOutputAnchors utility (parameterized for reuse by FLOWISE-262)
- useDynamicOutputPorts hook with orphaned edge cleanup on condition deletion
- EditNodeDialog integration for conditionAgentflow nodes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the user experience for managing conditional nodes within agentflows. It introduces a specialized UI component for building conditions, along with robust utilities and hooks to dynamically manage the corresponding output ports. This ensures that the visual representation of conditional logic accurately reflects the underlying data, including automatic cleanup of connections when conditions are altered or removed, leading to a more intuitive and stable editing environment.

Highlights

  • ConditionBuilder Atom: Added a new ConditionBuilder UI component for editing condition arrays, featuring labeled items (Condition 0, 1, ...) and an 'Else' indicator.
  • Dynamic Output Anchors Utility: Introduced buildDynamicOutputAnchors, a utility function that generates output anchors based on a dynamic item count, supporting custom labels and an optional 'Else' anchor.
  • Dynamic Output Ports Hook: Created useDynamicOutputPorts hook to synchronize node output anchors with changes in condition counts and automatically clean up orphaned edges when conditions are removed.
  • EditNodeDialog Integration: Integrated the ConditionBuilder and useDynamicOutputPorts hook into the EditNodeDialog specifically for conditionAgentflow nodes, with an enabled guard for other node types.
  • Stable Keys for React Reconciliation: Implemented stable keys using idCounterRef within ConditionBuilder to prevent React reconciliation bugs when items are deleted from the middle of a list.
Changelog
  • packages/agentflow/src/atoms/index.ts
    • Exported ConditionBuilder component and its props.
  • packages/agentflow/src/atoms/inputs/ConditionBuilder.test.tsx
    • Added comprehensive test suite for ConditionBuilder covering rendering, adding/deleting items, nested field changes, disabled states, minItems constraint, and field visibility.
  • packages/agentflow/src/atoms/inputs/ConditionBuilder.tsx
    • Added ConditionBuilder component, a specialized array input for condition nodes, which renders conditions with indexed labels and an 'Else' indicator.
    • Implemented logic for adding and deleting condition items, including default value assignment for new items.
    • Ensured stable keys for condition items using idCounterRef to prevent React reconciliation issues.
  • packages/agentflow/src/core/utils/dynamicOutputAnchors.test.ts
    • Added tests for buildDynamicOutputAnchors covering single/multiple/zero conditions, custom prefixes, and the includeElse option.
  • packages/agentflow/src/core/utils/dynamicOutputAnchors.ts
    • Added buildDynamicOutputAnchors utility function to programmatically create output anchors based on a count, label prefix, and an option to include an 'Else' anchor.
  • packages/agentflow/src/core/utils/index.ts
    • Exported buildDynamicOutputAnchors from the core utilities index.
  • packages/agentflow/src/features/node-editor/EditNodeDialog.test.tsx
    • Updated EditNodeDialog tests to mock useDynamicOutputPorts and ConditionBuilder.
    • Added tests to verify ConditionBuilder renders correctly for conditionAgentflow nodes.
    • Added tests to confirm syncOutputPorts is called when conditions change in a condition node.
  • packages/agentflow/src/features/node-editor/EditNodeDialog.tsx
    • Imported ConditionBuilder and useDynamicOutputPorts.
    • Integrated useDynamicOutputPorts hook to manage output anchors for conditionAgentflow nodes.
    • Conditionally rendered ConditionBuilder for 'conditions' array input in conditionAgentflow nodes, replacing the generic NodeInputHandler.
    • Added logic to call syncOutputPorts when the 'conditions' array is modified for conditionAgentflow nodes.
  • packages/agentflow/src/infrastructure/store/index.ts
    • Exported useDynamicOutputPorts from the store index.
  • packages/agentflow/src/infrastructure/store/useDynamicOutputPorts.test.tsx
    • Added tests for useDynamicOutputPorts covering anchor synchronization, no-op on same count, custom prefixes, disabled state, and orphaned edge cleanup.
  • packages/agentflow/src/infrastructure/store/useDynamicOutputPorts.ts
    • Added useDynamicOutputPorts hook to dynamically update a node's output anchors and clean up associated edges when the anchor count decreases.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
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

This pull request introduces a ConditionBuilder component for editing conditions and a useDynamicOutputPorts hook to dynamically manage output ports on nodes, which is a significant feature enhancement. The implementation is well-structured, with new components, utilities, and hooks placed in appropriate locations within the architecture. The code is accompanied by a comprehensive set of tests covering various scenarios and edge cases.

My review focuses on improving maintainability and readability. I've suggested abstracting the creation and parsing of dynamic handle IDs to avoid magic strings and tight coupling between different parts of the system, aligning with the principle of prioritizing code readability and understandability. I also pointed out a small redundancy in the ConditionBuilder component that can be removed to simplify the logic. Overall, this is a high-quality contribution.

@jocelynlin-wd
Copy link
Contributor Author

/gemini review

Copy link
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

This pull request introduces a new ConditionBuilder component for managing conditional logic in agent flows, along with a useDynamicOutputPorts hook to dynamically adjust node output anchors. The changes are well-structured, with clear separation of concerns into new components, hooks, and utility functions, each accompanied by thorough tests. The integration into EditNodeDialog is clean and correctly uses a feature flag isConditionNode to apply the new functionality only to relevant nodes.

I've found one critical issue in the ConditionBuilder component related to how it manages stable keys for list items, which could lead to UI bugs on deletion. My review includes a detailed comment with a suggested fix for this issue. Once that's addressed, this will be a great addition.

…update

- Add ConditionBuilder atom with stable keys and Else indicator
- Add buildDynamicOutputAnchors utility with v2-compatible format (numeric label + description)
- Add useDynamicOutputPorts hook for orphaned edge cleanup on condition deletion
- Integrate into EditNodeDialog with merged updateNodeData to avoid stale-closure overwrites
- Generate condition output anchors at node creation time in nodeFactory
- Add registerOnFlowChange to AgentflowContext for context-level change notification
@jocelynlin-wd
Copy link
Contributor Author

/gemini review

Copy link
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

This pull request introduces a ConditionBuilder component for editing conditions in agentflow nodes and adds support for dynamic output ports. The changes are well-structured, including a new useDynamicOutputPorts hook to manage edge cleanup when ports are removed, and utility functions for creating dynamic anchors. The integration into EditNodeDialog and AgentflowContext is handled correctly to ensure atomic updates and prevent race conditions. A suggestion to improve the nullish check for default values in the new ConditionBuilder component for better consistency and robustness has been retained.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

return (
<Box
key={itemKeysRef.current[index]}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a comment! I will take the same approach instead of using index as key in ArrayInput PR - https://github.com/FlowiseAI/Flowise/pull/5887/changes#diff-071d9f90d936310bd2a5e0accf076a2b6cde8ef132145692b9dd80025efdb63d

@jocelynlin-wd jocelynlin-wd merged commit 4ed8a57 into main Mar 12, 2026
7 checks passed
@jocelynlin-wd jocelynlin-wd deleted the feat/agentflow-condition-builder branch March 12, 2026 16:58
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.

2 participants