orkes.graph.GraphRunner#
- class orkes.graph.GraphRunner(graph_name, graph_description, nodes_pool, graph_type, traces_dir='traces', auto_save_trace=False, traced=True)[source]#
Executes a compiled OrkesGraph, managing state and tracing the execution.
The GraphRunner takes a compiled graph and an initial state, then traverses the graph, executing the nodes and updating the state accordingly. It also records traces of the execution, which can be saved to a file and visualized.
- Parameters:
graph_name (str)
graph_description (str)
nodes_pool (Dict[str, NodePoolItem])
graph_type (Dict)
traces_dir (str)
auto_save_trace (bool)
traced (bool)
- state_def#
The TypedDict class that defines the shared state of the graph.
- Type:
type
- nodes_pool#
A dictionary of all nodes in the graph.
- Type:
Dict[str, NodePoolItem]
- graph_state#
The current state of the graph.
- Type:
Dict
- run_id#
A unique identifier for the current run.
- Type:
str
- graph_name#
The name of the graph being executed.
- Type:
str
- graph_description#
The description of the graph being executed.
- Type:
str
- trace#
The trace of the current run.
- Type:
- traces_dir#
The directory where traces are saved.
- Type:
str
- run_number#
The current step number in the execution.
- Type:
int
- auto_save_trace#
If True, the trace is automatically saved after execution.
- Type:
bool
- trace_inspector#
An object to generate a visualization of the trace.
- Type:
- __init__(graph_name, graph_description, nodes_pool, graph_type, traces_dir='traces', auto_save_trace=False, traced=True)[source]#
Initializes the GraphRunner.
- Parameters:
graph_name (str) – The name of the graph.
graph_description (str) – The description of the graph.
nodes_pool (Dict[str, NodePoolItem]) – The dictionary of nodes in the graph.
graph_type (Dict) – The TypedDict class that defines the shared state.
traces_dir (str, optional) – The directory to save traces. Defaults to “traces”.
auto_save_trace (bool, optional) – Whether to automatically save traces. Defaults to False.
traced (bool, optional) – Whether to enable tracing. Defaults to True.
Methods
__init__(graph_name, graph_description, ...)Initializes the GraphRunner.
run(invoke_state)Runs the graph with a given initial state.
save_run_trace()Saves the execution trace to a JSON file.
traverse_graph(current_edge, input_state[, ...])Traverses the graph, either with or without tracing.
visualize_trace()Generates an HTML visualization of the execution trace.