Overview
BaseGraph manages the execution flow of a graph composed of interconnected nodes. It handles node traversal, state management, execution tracking, and supports both standard and Burr-based execution modes.
Class Signature
Constructor Parameters
A list of node instances that will be part of the graph. Each node should be an instance of a BaseNode subclass.
A list of tuples representing directed edges in the graph. Each tuple contains a pair
(from_node, to_node) defining the workflow connections.The node instance that represents the entry point of the graph execution.
Flag to enable Burr-based execution for enhanced workflow tracking and state management.
Configuration dictionary for Burr integration. Should include
app_instance_id and other Burr-specific settings.Name identifier for the graph, used in logging and telemetry.
Attributes
List of all node instances in the graph.
Dictionary mapping each node’s name to its successor node name.
The name of the entry point node from which graph execution begins.
Name of the graph for identification purposes.
The initial state passed to the graph during execution.
Manages callbacks for LLM interactions and tracks token usage.
Methods
execute()
Executes the graph by traversing nodes starting from the entry point.The initial state dictionary to pass to the entry point node. Typically contains
user_prompt and source data.Returns a tuple containing:
state(dict): The final state after graph executionexec_info(list): List of execution information for each node including tokens, costs, and execution time
append_node()
Adds a new node to the end of the graph and connects it to the last existing node.The node instance to add to the graph. Must have a unique
node_name that doesn’t already exist in the graph.ValueError: If a node with the same name already exists in the graph.
Usage Example
Burr Integration Example
Execution Information
Theexec_info list returned by execute() contains detailed metrics for each node:
Conditional Nodes
BaseGraph supports conditional branching with ConditionalNode:
Notes
- The entry point node should typically be the first node in the nodes list (a warning is issued otherwise)
- Node names must be unique within the graph
- The graph automatically handles state propagation between nodes
- Execution info includes token counts and costs for LLM-based nodes
- Telemetry data is automatically logged for monitoring and debugging
