Flowise

repository·main·Indexed 13 days ago

https://github.com/FlowiseAI/Flowise

A low-code visual tool for building AI agents and workflows, allowing users to orchestrate LLMs, tools, and memory components. Version 3.1.4 includes support for horizontal scaling via a worker-based queue mode using Redis and a dedicated @flowiseai/agentflow React component for embedding the flow editor.

Tokens
137.1K
Snippets
494
Records
725
Agent score
99%

What's inside Flowise

  1. What is @flowiseai/agentflow?

    main
    @flowiseai/agentflow is an embeddable React-based flow editor designed for building and visualizing AI agent workflows. It is built on top of ReactFlow and provides a visual canvas to connect LLMs, agents, tools, and logic nodes. It is currently in Dev status (version 0.0.0-dev.13), meaning the public API may change.
  2. How dependency flow works in @flowiseai/agentflow

    main

    To maintain modularity, dependencies in @flowiseai/agentflow must only flow downwards. Following these rules prevents circular dependencies and ensures that low-level layers remain decoupled from high-level features.

    Import Permissions

    • features/: Can import from atoms/, infrastructure/, and core/.
    • infrastructure/: Can import from core/.
    • atoms/: Can only import from core/types, core/theme, and core/primitives.
    • core/: Is a leaf node and cannot import from any other layer.

    Forbidden Imports

    • atoms/ must never import from features/ or infrastructure/.
    • features/ must never import from other features/ directly. If logic is shared between features, it must be moved to core/.
  3. Follow @flowiseai/agentflow development principles

    main

    To maintain consistency within the @flowiseai/agentflow codebase, adhere to these architectural patterns:

    Barrel Exports (Gatekeeper Pattern)

    Every directory must have an index.ts file. You should always import from the directory alias or the barrel file, never deep-link into specific files.

    • ✅ Good: import { Button } from '@atoms'
    • ❌ Bad: import { Button } from '@atoms/Button/Button'

    Data Flow

    • Atoms: Use props for all configuration.
    • Features: Use context or state for shared data.

    Naming Conventions

    TypeConventionExample
    ComponentPascalCase.tsxAgentFlowNode.tsx
    HookcamelCase.ts (with use prefix)useFlowHandlers.ts
    Logic/TypescamelCase.tsflowValidation.ts
    Styleskebab-case (co-located)canvas.css
  4. Distinguish between core/primitives and core/utils

    main

    The core/ directory contains two types of utility folders with different import permissions. When adding a new utility, determine its dependency on domain concepts to choose the correct location:

    • core/primitives/: Contains domain-free, general-purpose functions (e.g., pure data transformations like getDefaultValueForType). These have no knowledge of nodes or flows and are safe to import from atoms/.
    • core/utils/: Contains domain-aware utilities that understand node structures, flow data, or validation logic (e.g., initNode, getUniqueNodeId). These are only importable by features/ and infrastructure/.
  5. How Flowise Worker scaling works

    main

    Flowise supports horizontal scaling through a worker-based queue mode. This allows you to handle increased workloads by adding more worker instances.

    The workflow is as follows:

    1. The Main Server sends an execution ID to a Redis message broker, which maintains a queue of pending executions.
    2. An available Worker from the pool retrieves the message from Redis and begins executing the job.
    3. Upon completion, the Worker notifies the Main Server that the execution is finished.
  6. Understand the @flowiseai/observe test strategy

    main

    Tests are categorized into three tiers based on their impact and risk. When modifying code, you should add or update tests in the same Pull Request.

    Tier 1: Core Logic (High Risk)

    Must test. Includes pure business logic in infrastructure/ and critical hooks. Bugs here affect all SDK consumers.

    • Examples: API client methods, context/store, data-transformation hooks (e.g., useExecutionTree).

    Tier 2: Feature Hooks (Medium Risk)

    Test when changing. Includes hooks that orchestrate polling and UI state.

    • Examples: useExecutionPoll, pagination, or filter hooks.

    Tier 3: UI Components (Low Risk)

    Test if logic exists. Presentational components that are mostly JSX do not require tests. Only add tests if the component contains meaningful business logic (e.g., branching logic, filter predicates, or debounced handlers).

  7. How features and atoms interact

    main

    To maintain visual consistency and modularity, follow these interaction rules:

    • Atoms are the building blocks. They must be stateless and contain no business logic or API calls. They are imported by features to build complex UIs.
    • Features are self-contained modules. A feature (like executions) should own its specific components (e.g., ExecutionsViewer.tsx) and hooks (e.g., useExecutionPoll.ts).
    • Isolation: Features must never import from other features directly. If logic is shared between two features, it must be moved to core/.
  8. Implement the Gatekeeper Pattern for modules

    main

    Each module (especially within features/) should use an index.ts file as a "Gatekeeper" to define its public API. This pattern enables encapsulation and improves tree-shaking by only exposing necessary symbols and keeping internal sub-components private.

    Example features/canvas/index.ts implementation:

    // ✅ Public API
    export const nodeTypes = { ... }
    export const edgeTypes = { ... }
    export { ConnectionLine, AgentflowHeader, createHeaderProps }
    export { useFlowNodes, useFlowHandlers, useDragAndDrop }
    
    // Container components are re-exported for advanced usage
    export { AgentFlowNode, AgentFlowEdge, StickyNote, IterationNode }
    
    // ❌ Internal sub-components stay private within containers/components
    // features/canvas/index.ts
    // ✅ Public API
    export const nodeTypes = { ... }
    export const edgeTypes = { ... }
    export { ConnectionLine, AgentflowHeader, createHeaderProps }
    export { useFlowNodes, useFlowHandlers, useDragAndDrop }
    
    // Container components are re-exported for advanced usage
    export { AgentFlowNode, AgentFlowEdge, StickyNote, IterationNode }
    
    // ❌ Internal sub-components stay private within containers/components
  9. Compare Basic Usage vs E2E Live Instance examples

    main

    The @flowiseai/agentflow examples provide two primary modes of operation:

    Basic Usage (BasicExample.tsx)

    Designed for minimal canvas integration without a database connection.

    • Renders canvas with a hardcoded initialFlow.
    • Tracks changes via onFlowChange.
    • Supports local-only saving via onSave.
    • Provides imperative control over the view via fitView and clear refs.

    E2E — Live Instance (E2eExample.tsx)

    Designed for full integration with a running Flowise instance. Requires VITE_FLOW_ID for optimal behavior.

    • Database Sync: Loads saved flows on startup and syncs editable titles to the DB on save.
    • CRUD Operations: Supports creating, renaming, and deleting chatflows in the database.
    • Execution: Supports Test Run via POST /api/v1/internal-prediction (with markdown rendering) and a Run Status panel for per-node execution results.
    • Permissions: The VITE_API_TOKEN must have Create, Update, and Delete permissions for Agentflows.
  10. How auto-polling works with useExecutionPoll

    main

    The useExecutionPoll hook manages automatic polling of execution states using setInterval.

    Polling Logic:

    • While execution.state === 'INPROGRESS': Polls every pollInterval ms.
    • When state becomes FINISHED, ERROR, TERMINATED, TIMEOUT, or STOPPED: The interval is cleared immediately.

    Options:

    • pollInterval={0}: Disables auto-poll entirely.
    • refresh(): The hook returns a refresh function for manual trigger (e.g., for a refresh button).
    • The hook automatically clears the interval when the component unmounts.
  11. Understand the @flowiseai/agentflow test strategy

    main

    Tests are prioritized into three tiers based on risk and impact. When modifying a file, you should add or update tests in the same Pull Request.

    Tier 1: Core Logic (Must Test)

    High-risk business logic located in core/, infrastructure/, and critical hooks. A bug here affects all users.

    • Examples: Validation rules, node utilities, API clients, state management (reducers, context actions), and flow data hooks like useFlowHandlers.

    Tier 2: Feature Hooks & Dialogs (Test when changing)

    Orchestration logic for UI behavior.

    • Examples: Search logic, drag-and-drop, node color calculations, dialog state machines, and theme detection.

    Tier 3: UI Components (Test if logic exists)

    Presentational components. Only test if they contain meaningful business logic or exported helper functions. Pure styling components (e.g., styled.ts, MainCard.tsx) do not require tests.

  12. How the execution tree is constructed with useExecutionTree

    main

    The useExecutionTree hook transforms a flat array of NodeExecutionData[] (from execution.executionData) into a hierarchical ExecutionTreeNode[]. It uses two sequential mechanisms:

    1. previousNodeIds parent→child: Each non-iteration node attaches to the most recent instance of any node listed in its previousNodeIds. Nodes with empty or unmatched IDs become roots.
    2. Iteration grouping: Children with a parentNodeId and iterationIndex are grouped into virtual container nodes (isVirtualNode: true) under the iteration agent's most recent instance.

    Tree-node IDs are formatted as ${nodeId}_${arrayIndex} to ensure uniqueness when the same node runs multiple times (e.g., in a loop).