Edges
Edges are the routing logic that connects nodes in your MindedJS flows. They determine how your agent moves through the workflow, making intelligent decisions about which path to take based on different conditions and contexts.
What are Edges?
Edges define the transitions between nodes in your flow. Each edge specifies:
Source - The starting node
Target - The destination node
Type - The routing logic type
Condition - The criteria for taking this path
Prompt - The prompt for the LLM to make a decision
Edge Types
MindedJS provides three types of edges for different routing scenarios:
Step Forward Edges
Step forward edges create unconditional transitions between nodes. They're useful for sequential processing where you always want to move to the next step.
Use Cases: Data transformation pipelines, required validation steps, guaranteed notifications, logging and audit trails.
Prompt Condition Edges
Prompt condition edges use language models to make intelligent routing decisions based on conversation context, memory state, and complex reasoning.
Context-Aware Routing
Multi-Path Routing
Logical Condition Edges
Logical condition edges use JavaScript expressions to make deterministic routing decisions based on memory state, providing precise control over flow logic. Prefer using prompt condition edges, unless you need an exact match of an ouput of a previous node.
How Condition Expressions Work
The condition field accepts a JavaScript expression that will be evaluated to determine if the edge should be taken. The expression has access to the current agent state through the state variable and the previous node's result through the lastNodeResult variable.
The condition is automatically wrapped in a function that provides the state and lastNodeResult result context:
Supported Expression Types
Simple Comparisons
Complex Expressions
Advanced JavaScript Operations
Available Context
Your condition expressions have access to:
state: The full agent state object (access as
state.memory,state.messages, etc.)lastNodeResult: The result from the previous node in the flow
Standard JavaScript globals:
Math,Date,JSON,consoleString/Array/Object methods: All standard JavaScript methods
Accessing State Properties
Accessing Previous Node Results
The lastNodeResult object provides access to the result of the last executed node in the flow. This is particularly useful when you need to route based on what the previous operator or tool returned.
How lastNodeResult Works
MindedJS automatically extracts and normalizes results from different node types:
Operator (Browser Task) nodes: Extracts from
outputSchemafieldsTool nodes: Extracts the
resultproperty returned by the toolRPA nodes: Extracts collected data from RPA steps
App Tool nodes: Extracts the tool execution result
Example with Operator:
Example with Tool:
Safety Checks:
Always check if lastNodeResult exists before accessing its properties:
Example: Using lastNodeResult After a Tool
When a tool executes and returns a result, you can route based on that result using logical conditions. Here's a complete example with the refundOrder tool:
Tool Implementation:
Flow Configuration with Logical Conditions:
In this example, the tool returns a result object with a status property. The edges then route to different nodes based on whether the refund was successful or failed.

Example: Using lastNodeResult After an Operator
For Operator (Browser Task) nodes, you need to define the output schema first, then you can route based on the operator's result.
Step 1: Configure Operator Output Schema
In your operator node, add an output schema field to capture the result:
Field name:
resultField type:
NumberDescription:
0 = failure, 1 = success

Step 2: Configure Edges with Logical Conditions
The operator will extract the result value according to the prompt and output schema, and the edges will route based on whether the result is 1 (success) or 0 (failure).

Note: For security, the following are NOT available:
process,require,global,BufferFile system or network operations
Module imports
Memory-Based Routing
Complex Logic Conditions
Debugging Logical Conditions
For comprehensive debugging of logical conditions, see the Debugging Guide.
Edge Evaluation Order
When multiple edges exist from the same source node, MindedJS evaluates them by edge type priority, not declaration order:
Priority System
1st
stepForward
Always executes first (max 1 per source)
2nd
logicalCondition
Executes if no step forward edge
3rd
promptCondition
Executes if no step forward and logical conditions fail
Logical Condition Order
Within logical condition edges from the same source, evaluation follows declaration order:
Mixed Edge Example
Advanced Patterns
Fallback Chains
When you have multiple logicalCondition edges from the same source, you can define a final fallback edge by using condition: "else". This fallback edge is taken only if none of the previous conditions evaluate to true.
Error Handling
Next Steps
Tools - Build powerful functions that your edges can route to
Memory Types - Design state that supports effective routing
Implementation Examples - See complete edge examples
Master edges to create intelligent, responsive flows that adapt to any situation! 🔄
Last updated