Conditional Node
The Conditional Node enables dynamic branching logic within graph skills, allowing you to selectively trigger downstream nodes based on custom conditions.
Overview
The Conditional Node evaluates a user-defined function to determine which connected nodes should execute next. It operates based on the graph's order of execution (__max_connection__
edges).
Implementation
Function Signature
def run_next(skill_globals, graph_state) -> list[str]:
"""
Determine which child nodes should execute next.
Returns a list of node names to execute.
"""
pass
Available Context
The function has access to two key objects:
skill_globals
: Contains skill-level variablesgraph_state
: Provides a snapshot of the graph's execution state up to the current point- Structure: Nested dictionary using node names and output names as keys
- Example:
graph_state["node_name"]["output_name"]
Execution Rules
- Only immediate child nodes can be included in the return list
- Child nodes not included in the return list will be skipped
- Any downstream nodes that depend solely on skipped nodes will also be skipped
Example Usage
def run_next(skill_globals, graph_state) -> list[str]:
# Check if previous node's confidence score is above threshold
if graph_state["classification_node"]["confidence"] > 0.8:
return ["high_confidence_path"]
else:
return ["low_confidence_path", "retry_path"]
In this example:
- If the confidence score from a previous classification is high, only the "high_confidence_path" node will execute
- Otherwise, both the "low_confidence_path" and "retry_path" nodes will execute
- Any other connected nodes will be skipped
Updated 8 days ago