1212
1313class NodeType (str , Enum ):
1414 """Types of nodes in orchestration graphs."""
15+
1516 AGENT = "agent"
1617 TOOL = "tool"
1718 FUNCTION = "function"
@@ -23,6 +24,7 @@ class NodeType(str, Enum):
2324@dataclass
2425class GraphNode :
2526 """Represents a node in the graph."""
27+
2628 id : str
2729 type : NodeType
2830 name : str
@@ -33,13 +35,14 @@ def to_dict(self) -> dict[str, Any]:
3335 "id" : self .id ,
3436 "type" : self .type .value ,
3537 "name" : self .name ,
36- "properties" : self .properties
38+ "properties" : self .properties ,
3739 }
3840
3941
4042@dataclass
4143class GraphEdge :
4244 """Represents an edge in the graph."""
45+
4346 source : str
4447 target : str
4548 condition : Optional [str ] = None
@@ -50,7 +53,7 @@ def to_dict(self) -> dict[str, Any]:
5053 "source" : self .source ,
5154 "target" : self .target ,
5255 "condition" : self .condition ,
53- "weight" : self .weight
56+ "weight" : self .weight ,
5457 }
5558
5659
@@ -77,7 +80,9 @@ def __init__(self) -> None:
7780 self ._edges : list [GraphEdge ] = []
7881 self ._adj : dict [str , list [str ]] = {}
7982
80- def node (self , node_id : str , node_type : NodeType = NodeType .AGENT , name : str = "" , ** properties : Any ) -> "GraphQuery" :
83+ def node (
84+ self , node_id : str , node_type : NodeType = NodeType .AGENT , name : str = "" , ** properties : Any
85+ ) -> "GraphQuery" :
8186 """Add a node to the graph."""
8287 if node_id in self ._nodes :
8388 return self
@@ -86,7 +91,9 @@ def node(self, node_id: str, node_type: NodeType = NodeType.AGENT, name: str = "
8691 self ._adj [node_id ] = []
8792 return self
8893
89- def edge (self , source : str , target : str , condition : Optional [str ] = None , weight : float = 1.0 ) -> "GraphQuery" :
94+ def edge (
95+ self , source : str , target : str , condition : Optional [str ] = None , weight : float = 1.0
96+ ) -> "GraphQuery" :
9097 """Add an edge between two nodes."""
9198 if source not in self ._nodes or target not in self ._nodes :
9299 raise ValueError (f"Node not found: { source if source not in self ._nodes else target } " )
@@ -221,7 +228,7 @@ def to_dict(self) -> dict[str, Any]:
221228 """Export graph as a dictionary."""
222229 return {
223230 "nodes" : [n .to_dict () for n in self ._nodes .values ()],
224- "edges" : [e .to_dict () for e in self ._edges ]
231+ "edges" : [e .to_dict () for e in self ._edges ],
225232 }
226233
227234 def __len__ (self ) -> int :
0 commit comments