Graph Engine Debug Mode

Contents

Graph Engine Debug Mode#

EvoFabric allows users to debug graphs as they would debug Python, with the currently supported debugging operations including:

  • Set breakpoint, Cancel breakpoint: The program will stop running at the node corresponding to the breakpoint

  • Resume: Run to end/next breakpoint

  • Single-step debugging: Step over current node / all nodes currently reached

  • Return to Previous Step: Return to the previous step in the run from the current breakpoint

  • Modify the output result from node A -> node B

How to Use#

  1. Construct graph:

from typing import Annotated, List, TypedDict

from evofabric.core.graph import GraphBuilder
from evofabric.core.typing import AssistantMessage, GraphMode


class State(TypedDict):
    messages: Annotated[List, "append_messages"]
    node_output: Annotated[str, "overwrite"]


def node_a(state):
    return {"messages": [AssistantMessage(content="node a output")], 'node_output': 'a'}


def node_b(state):
    return {"messages": [AssistantMessage(content="node b output")], 'node_output': 'b'}


def node_c(state):
    return {"messages": [AssistantMessage(content="node c output")], 'node_output': 'c'}


def node_d(state):
    return {"messages": [AssistantMessage(content="node d output")], 'node_output': 'd'}


graph_builder = GraphBuilder(state_schema=State)
graph_builder.add_node("a", node_a)
graph_builder.add_node("b", node_b)
graph_builder.add_node("c", node_c)
graph_builder.add_node("d", node_d)

graph_builder.add_edge("a", "b")
graph_builder.add_edge("b", "c")
graph_builder.add_edge("c", "d")
graph_builder.set_entry_point("a")
  1. Use graph_mode=GraphMode.DEBUG in the build graph phase to enable graph Debug mode

graph = graph_builder.build(graph_mode=GraphMode.DEBUG)
  1. Set breakpoint

graph.set_breakpoint(node_name_bp="b")
  1. Start executing in debug mode

await graph.debug({"messages": [UserMessage(content='hello')]})
  1. At this point, the graph will stop executing at node b, and you can use single-step debugging step_over to execute node b.

await graph.step_over(node_uuid=graph._trace_tree.get_leaf_node_uuid_by_node_name(node_name="b"))
  1. Node b has already been executed. If you want to restore to the state before executing node b, you can use restore_step.

graph.restore_step()
  1. At this point, the node’s execution status returns to the initial state of node b, you can use clear_breakpoint to clear the breakpoint, and then continue executing until the program ends

graph.clear_breakpoint(node_name_bp="b")
result = await graph.resume()
  1. After the program execution ends, the execution result result can be obtained, which is consistent with the conventional execution result.