Node Details

  • Name: seqCondition
  • Label: Condition
  • Version: 2.0
  • Type: Condition
  • Category: Sequential Agents

Input Parameters

  1. Condition Name (optional)
    • Type: string
    • Description: A descriptive name for the condition (e.g., “If X, then Y”)
  2. Start | Agent | LLM | Tool Node (required)
    • Type: Start | Agent | LLMNode | ToolNode
    • Description: List of predecessor nodes in the sequential flow
  3. Condition (required)
    • Type: conditionFunction
    • Description: The actual condition logic, which can be defined using either a table-based UI or custom JavaScript code

Condition Input Modes

Table-based UI

  • Allows defining conditions using a data grid with the following columns:
    • Variable: The value to check (e.g., message content, flow state, custom variables)
    • Operation: Comparison operation (e.g., Contains, Is Empty, Greater Than)
    • Value: The value to compare against
    • Output: The name of the output to trigger if the condition is met

Custom JavaScript

  • Allows writing a custom JavaScript function to evaluate conditions
  • Has access to flow state, messages, and custom variables
  • Must return a string value indicating the next step (e.g., “Agent” or “End”)

Outputs

  1. Next
    • Type: Condition
    • Description: Connection point for the next node if a condition is met
  2. End
    • Type: Condition
    • Description: Connection point to end the flow if no conditions are met

Functionality

  1. The node evaluates conditions based on the current flow state, including:
    • Message history
    • Custom variables
    • Flow configuration (sessionId, chatId, etc.)
  2. It determines the next step in the sequential flow based on the evaluation results
  3. Supports complex decision-making logic through custom JavaScript functions
  4. Allows for dynamic routing of the flow based on runtime conditions

Use Cases

  • Implementing decision trees in conversational flows
  • Routing conversations to different agents or tools based on user input
  • Ending conversations when certain conditions are met
  • Implementing loop logic or state-based transitions in sequential workflows

Implementation Details

  • Uses a sandbox environment to safely execute custom JavaScript code
  • Supports accessing and manipulating flow state and variables
  • Integrates with the broader Sequential Agents frameworks

Best Practices

  1. Use descriptive condition names for better readability
  2. Prefer the table-based UI for simple conditions
  3. Use custom JavaScript for complex logic or when accessing specific parts of the flow state
  4. Ensure custom functions always return a string value
  5. Handle potential errors in custom code to avoid breaking the flow