dag
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| DAGNode llmling_agent.utils.dag A node in a Directed Acyclic Graph. |
🛈 DocStrings¶
Minimal DAG (Directed Acyclic Graph) implementation.
This module provides a lightweight DAG node class for tracking message flows and generating mermaid diagrams. It replaces the bigtree dependency with only the functionality actually used.
DAGNode
dataclass
¶
A node in a Directed Acyclic Graph.
Nodes can have multiple parents and multiple children, representing a DAG structure suitable for tracking message flows between agents.
Example
a = DAGNode("a") b = DAGNode("b") c = DAGNode("c") c.add_parent(a) c.add_parent(b) a.children [DAGNode(name='c')]
Source code in src/llmling_agent/utils/dag.py
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
__lshift__
¶
__lshift__(other: Self) -> Self
Set parent using << operator: child << parent.
Source code in src/llmling_agent/utils/dag.py
112 113 114 115 | |
__rshift__
¶
__rshift__(other: Self) -> Self
Set child using >> operator: parent >> child.
Source code in src/llmling_agent/utils/dag.py
107 108 109 110 | |
add_child
¶
add_child(child: Self) -> None
Add a child node, also adding self as parent of child.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
child
|
Self
|
Node to add as child |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If adding would create a cycle |
Source code in src/llmling_agent/utils/dag.py
82 83 84 85 86 87 88 89 90 91 | |
add_parent
¶
add_parent(parent: Self) -> None
Add a parent node, also adding self as child of parent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent
|
Self
|
Node to add as parent |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If adding would create a cycle |
Source code in src/llmling_agent/utils/dag.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
dag_iterator
¶
Iterate through all edges in a DAG starting from a node.
Traverses both upward (to parents) and downward (to children) to discover all edges reachable from the starting node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
DAGNode
|
Starting node for iteration |
required |
Yields:
| Type | Description |
|---|---|
Iterable[tuple[DAGNode, DAGNode]]
|
Tuples of (parent, child) for each edge in the DAG |
Source code in src/llmling_agent/utils/dag.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
dag_to_list
¶
Export DAG edges as list of (parent_name, child_name) tuples.
Example
a = DAGNode("a") b = DAGNode("b") c = DAGNode("c") c.add_parent(a) c.add_parent(b) d = DAGNode("d") d.add_parent(c) sorted(dag_to_list(a)) [('a', 'c'), ('b', 'c'), ('c', 'd')]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dag
|
DAGNode
|
Any node in the DAG (will traverse to find all edges) |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[str, str]]
|
List of (parent_name, child_name) tuples for all edges |
Source code in src/llmling_agent/utils/dag.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |