NodeProtocol Objects

class NodeProtocol(Protocol)
Protocol defining the interface of a decorated node.

Graph Objects

class Graph()

get_state

def get_state() -> dict[str, Any]
Get the current graph state.

set_state

def set_state(state: dict[str, Any]) -> Graph
Set the graph state.

update_state

def update_state(values: dict[str, Any]) -> Graph
Update the graph state with new values.

reset_state

def reset_state() -> Graph
Reset the graph state to an empty dict.

add_edge

def add_edge(source: NodeProtocol | str,
             destination: NodeProtocol | str) -> Graph
Adds an edge between two nodes that already exist in the graph. Arguments:
  • source - The source node or its name.
  • destination - The destination node or its name.

compile

def compile(*, strict: bool = False) -> Graph
Validate the graph:
  • exactly one start node present (or Graph.start_node set)
  • at least one end node present
  • all edges reference known nodes
  • all nodes reachable from the start (optional) no cycles when strict=True Returns self on success; raises GraphCompileError otherwise.

get_callback

def get_callback()
Get a new instance of the callback class. Returns: Callback: A new instance of the callback class.

set_callback

def set_callback(callback_class: type[Callback]) -> "Graph"
Set the callback class that is returned by the get_callback method and used as the default callback when no callback is passed to the execute method. Arguments:
  • callback_class (type[Callback]): The callback class to use as the default callback.

visualize

def visualize(*, save_path: str | None = None)
Render the current graph. If matplotlib is not installed, raise a helpful error telling users to install the viz extra. Optionally save to a file via save_path.