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#
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")
Use
graph_mode=GraphMode.DEBUGin the build graph phase to enable graph Debug mode
graph = graph_builder.build(graph_mode=GraphMode.DEBUG)
Set breakpoint
graph.set_breakpoint(node_name_bp="b")
Start executing in debug mode
await graph.debug({"messages": [UserMessage(content='hello')]})
At this point, the graph will stop executing at node
b, and you can use single-step debuggingstep_overto execute nodeb.
await graph.step_over(node_uuid=graph._trace_tree.get_leaf_node_uuid_by_node_name(node_name="b"))
Node
bhas already been executed. If you want to restore to the state before executing nodeb, you can userestore_step.
graph.restore_step()
At this point, the node’s execution status returns to the initial state of node
b, you can useclear_breakpointto clear the breakpoint, and then continue executing until the program ends
graph.clear_breakpoint(node_name_bp="b")
result = await graph.resume()
After the program execution ends, the execution result
resultcan be obtained, which is consistent with the conventional execution result.