Skip to content

Interactive debug

InteractiveDebugHook

Bases: GraphHook[T, S]

A hook that prints the state and shared data at each step of the graph execution and pauses for user input. Useful for interactive debugging.

Source code in src/edgygraph/graph_hooks/interactive_debug.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class InteractiveDebugHook[T: State, S: Shared](GraphHook[T, S]):
    """
    A hook that prints the state and shared data at each step of the graph
    execution and pauses for user input. Useful for interactive debugging.
    """

    def __init__(self) -> None:
        self._renderer = GraphRenderer[T, S]()

    def _pause(self) -> None:
        self._renderer.render_rule(style="dim")
        input("Press Enter to continue...")

    async def on_graph_start(self, state: T, shared: S) -> None:
        self._renderer.render_graph_start(state, shared)
        self._pause()

    async def on_step_start(self, state: T, shared: S, nodes: list[NextNode[T, S]]) -> None:
        self._renderer.render_step_start(nodes)
        self._pause()

    async def on_merge_conflict(
        self,
        state: T,
        changes: list[dict[tuple[Hashable, ...], Change]],
        conflicts: dict[tuple[Hashable, ...], list[Change]],
    ) -> None:
        self._renderer.render_merge_conflict(conflicts)
        self._pause()

    async def on_merge_end(
        self,
        state: T,
        result_states: list[T],
        changes: list[dict[tuple[Hashable, ...], Change]],
        merged_state: T,
    ) -> None:
        self._renderer.render_merge_end(changes)
        self._pause()

    async def on_step_end(self, state: T, shared: S, nodes: list[NextNode[T, S]]) -> None:
        self._renderer.render_step_end(state, shared, nodes)
        self._pause()

    async def on_graph_end(self, state: T, shared: S) -> None:
        self._renderer.render_graph_end(state, shared)
        self._pause()