task_graph
Task graph model and construction surface.
This package exposes the class-based task-graph API used by orchestration code:
an immutable TaskGraph plus TaskGraphBuilder for loading and validating
graph definitions. Internal indexing/validation helpers live in private submodules
(_indexing, _validation).
TaskGraphBuilder
Builder for constructing :class:TaskGraph from validated input specs.
Source code in src/agentrelay/task_graph/builder.py
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 116 117 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 | |
from_yaml(path)
classmethod
Parse YAML and build a validated :class:TaskGraph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to a graph YAML file. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If YAML cannot be parsed or schema validation fails. |
Returns:
| Name | Type | Description |
|---|---|---|
TaskGraph |
TaskGraph
|
Validated immutable task graph. |
Source code in src/agentrelay/task_graph/builder.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
from_dict(data)
classmethod
Build a validated :class:TaskGraph from mapping data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Mapping[str, Any] | Any
|
Parsed graph data mapping. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the graph schema is invalid. |
Returns:
| Name | Type | Description |
|---|---|---|
TaskGraph |
TaskGraph
|
Validated immutable task graph. |
Source code in src/agentrelay/task_graph/builder.py
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 116 117 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 | |
TaskGraph
dataclass
Immutable DAG of :class:Task specifications keyed by task ID.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
Optional[str]
|
Optional human-readable graph name. |
max_workstream_depth |
int
|
Maximum allowed parent-depth for workstream
hierarchies. |
_tasks_by_id |
Mapping[str, Task]
|
Canonical task objects keyed by task ID. |
_dependency_ids |
Mapping[str, tuple[str, ...]]
|
Dependency IDs for each task ID. |
_dependent_ids |
Mapping[str, tuple[str, ...]]
|
Reverse dependency IDs for each task ID. |
_topological_order |
tuple[str, ...]
|
Dependency-first stable task ordering. |
_workstreams_by_id |
Mapping[str, WorkstreamSpec]
|
Workstream specs keyed by workstream ID. |
_task_ids_by_workstream |
Mapping[str, tuple[str, ...]]
|
Task IDs grouped by workstream ID. |
_child_workstream_ids |
Mapping[str, tuple[str, ...]]
|
Child workstream IDs grouped by parent workstream ID. |
Source code in src/agentrelay/task_graph/graph.py
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 116 117 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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 | |
__init__(tasks_by_id, name=None, workstreams_by_id=None, max_workstream_depth=1)
Initialize and validate an immutable task graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tasks_by_id
|
Mapping[str, Task]
|
Mapping of task IDs to canonical :class: |
required |
name
|
Optional[str]
|
Optional human-readable name for this graph. |
None
|
workstreams_by_id
|
Optional[Mapping[str, WorkstreamSpec]]
|
Optional mapping of workstream IDs to
:class: |
None
|
max_workstream_depth
|
int
|
Maximum parent-depth allowed for workstream
hierarchies. |
1
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the graph is empty, contains mismatched key/ID pairs, contains conflicting task definitions for a shared task ID, contains invalid dependency declarations, contains dependency cycles, or contains invalid workstream declarations. |
Source code in src/agentrelay/task_graph/graph.py
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 116 117 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 | |
from_tasks(tasks, name=None, workstreams=None, max_workstream_depth=1)
classmethod
Build a :class:TaskGraph from an iterable of tasks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tasks
|
Iterable[Task]
|
Iterable of canonical graph tasks. |
required |
name
|
Optional[str]
|
Optional human-readable name for this graph. |
None
|
workstreams
|
Optional[Iterable[WorkstreamSpec]]
|
Optional iterable of workstream specifications. |
None
|
max_workstream_depth
|
int
|
Maximum parent-depth allowed for workstream
hierarchies. |
1
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If duplicate task IDs or duplicate workstream IDs are provided in input iterables. |
Returns:
| Name | Type | Description |
|---|---|---|
TaskGraph |
'TaskGraph'
|
A validated immutable task graph. |
Source code in src/agentrelay/task_graph/graph.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
task(task_id)
Return the task specification for a task ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_id
|
str
|
Task identifier to retrieve. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Returns:
| Name | Type | Description |
|---|---|---|
Task |
Task
|
The immutable task specification. |
Source code in src/agentrelay/task_graph/graph.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
task_ids()
Return all task IDs in dependency-first topological order.
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
tuple[str, ...]: All task IDs in stable topological order. |
Source code in src/agentrelay/task_graph/graph.py
209 210 211 212 213 214 215 | |
dependency_ids(task_id)
Return dependency IDs for a task in declared order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_id
|
str
|
Task identifier to inspect. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
tuple[str, ...]: Dependency task IDs for |
Source code in src/agentrelay/task_graph/graph.py
217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
dependent_ids(task_id)
Return task IDs that depend on a task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_id
|
str
|
Task identifier to inspect. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
tuple[str, ...]: Dependent task IDs in stable sorted order. |
Source code in src/agentrelay/task_graph/graph.py
232 233 234 235 236 237 238 239 240 241 242 243 244 245 | |
roots()
Return IDs of tasks with no dependencies.
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
tuple[str, ...]: Root task IDs in stable topological order. |
Source code in src/agentrelay/task_graph/graph.py
247 248 249 250 251 252 253 254 255 256 257 | |
leaves()
Return IDs of tasks with no dependents.
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
tuple[str, ...]: Leaf task IDs in stable topological order. |
Source code in src/agentrelay/task_graph/graph.py
259 260 261 262 263 264 265 266 267 268 269 | |
topological_order()
Return dependency-first stable ordering of task IDs.
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
tuple[str, ...]: Task IDs in stable topological order. |
Source code in src/agentrelay/task_graph/graph.py
271 272 273 274 275 276 277 | |
ready_ids(completed_ids, running_ids=())
Return runnable task IDs from pure set inputs.
A task is ready when:
- it is not in completed_ids
- it is not in running_ids
- every dependency ID is in completed_ids
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
completed_ids
|
Iterable[str]
|
IDs currently considered completed by the caller. |
required |
running_ids
|
Iterable[str]
|
IDs currently considered in progress by the caller. |
()
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
tuple[str, ...]: Runnable task IDs in stable topological order. |
Source code in src/agentrelay/task_graph/graph.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
workstream_ids()
Return all workstream IDs in stable sorted order.
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
tuple[str, ...]: All workstream IDs in sorted order. |
Source code in src/agentrelay/task_graph/graph.py
317 318 319 320 321 322 323 | |
workstream(workstream_id)
Return workstream specification for a workstream ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workstream_id
|
str
|
Workstream identifier to retrieve. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Returns:
| Name | Type | Description |
|---|---|---|
WorkstreamSpec |
WorkstreamSpec
|
Immutable workstream specification. |
Source code in src/agentrelay/task_graph/graph.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 | |
tasks_in_workstream(workstream_id)
Return task IDs in a workstream in graph topological order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workstream_id
|
str
|
Workstream identifier to inspect. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
tuple[str, ...]: Task IDs in the given workstream. |
Source code in src/agentrelay/task_graph/graph.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 | |
child_workstream_ids(workstream_id)
Return child workstream IDs for a parent workstream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workstream_id
|
str
|
Parent workstream identifier. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
tuple[str, ...]: Child workstream IDs in stable sorted order. |
Source code in src/agentrelay/task_graph/graph.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 | |
agentrelay.task_graph._indexing
Index-building and ordering helpers for TaskGraph.
This module contains pure functions that build task/workstream indexes and
compute topological order for agentrelay.task_graph.TaskGraph.
build_dependency_ids(tasks_by_id)
Build dependency ID index and validate per-task dependency declarations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tasks_by_id
|
Mapping[str, Task]
|
Canonical mapping of graph task IDs to tasks. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a task depends on itself or repeats dependency IDs. |
Returns:
| Type | Description |
|---|---|
dict[str, tuple[str, ...]]
|
dict[str, tuple[str, ...]]: Dependency IDs keyed by task ID. |
Source code in src/agentrelay/task_graph/_indexing.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
build_dependent_ids(tasks_by_id, dependency_ids)
Build reverse dependency index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tasks_by_id
|
Mapping[str, Task]
|
Canonical mapping of graph task IDs to tasks. |
required |
dependency_ids
|
Mapping[str, tuple[str, ...]]
|
Dependency ID index keyed by task ID. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, tuple[str, ...]]
|
dict[str, tuple[str, ...]]: Dependent IDs keyed by task ID. |
Source code in src/agentrelay/task_graph/_indexing.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
topological_order_or_raise(dependency_ids, dependent_ids)
Compute stable topological order or raise on cyclic graphs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dependency_ids
|
Mapping[str, tuple[str, ...]]
|
Dependency ID index keyed by task ID. |
required |
dependent_ids
|
Mapping[str, tuple[str, ...]]
|
Reverse dependency ID index keyed by task ID. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the graph contains one or more cycles. |
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
tuple[str, ...]: Stable dependency-first topological order. |
Source code in src/agentrelay/task_graph/_indexing.py
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 | |
build_task_ids_by_workstream(tasks_by_id, topological_order, workstreams_by_id)
Build a topological-order task ID index for each workstream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tasks_by_id
|
Mapping[str, Task]
|
Canonical mapping of graph task IDs to tasks. |
required |
topological_order
|
tuple[str, ...]
|
Graph topological task ID order. |
required |
workstreams_by_id
|
Mapping[str, WorkstreamSpec]
|
Canonical mapping of workstream IDs to specs. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, tuple[str, ...]]
|
dict[str, tuple[str, ...]]: Task IDs keyed by workstream ID. |
Source code in src/agentrelay/task_graph/_indexing.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
build_child_workstream_ids(workstreams_by_id)
Build an index of child workstream IDs for each workstream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workstreams_by_id
|
Mapping[str, WorkstreamSpec]
|
Canonical mapping of workstream IDs to specs. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, tuple[str, ...]]
|
dict[str, tuple[str, ...]]: Child IDs keyed by parent workstream ID. |
Source code in src/agentrelay/task_graph/_indexing.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
agentrelay.task_graph._validation
Validation helpers for TaskGraph construction and query inputs.
This module contains pure validation and normalization functions used by
agentrelay.task_graph.TaskGraph. Keeping these helpers separate allows the
TaskGraph type to stay focused on immutable graph state and query APIs.
normalize_workstreams(workstreams_by_id)
Normalize input workstream mapping with compatibility defaults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workstreams_by_id
|
Optional[Mapping[str, WorkstreamSpec]]
|
Optional input mapping of workstreams. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If workstream mapping keys mismatch |
Returns:
| Type | Description |
|---|---|
dict[str, WorkstreamSpec]
|
dict[str, WorkstreamSpec]: Canonical workstream mapping. |
Source code in src/agentrelay/task_graph/_validation.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
validate_task_workstream_ids(tasks_by_id, workstreams_by_id)
Validate that every task references a known workstream ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tasks_by_id
|
Mapping[str, Task]
|
Canonical mapping of graph task IDs to tasks. |
required |
workstreams_by_id
|
Mapping[str, WorkstreamSpec]
|
Canonical mapping of workstream IDs to specs. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If one or more task workstream IDs are unknown. |
Source code in src/agentrelay/task_graph/_validation.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
validate_workstream_parent_ids_exist(workstreams_by_id)
Validate that each parent workstream reference exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workstreams_by_id
|
Mapping[str, WorkstreamSpec]
|
Canonical mapping of workstream IDs to specs. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any |
Source code in src/agentrelay/task_graph/_validation.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
validate_workstream_hierarchy_acyclic(workstreams_by_id)
Validate that the workstream parent hierarchy has no cycles.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workstreams_by_id
|
Mapping[str, WorkstreamSpec]
|
Canonical mapping of workstream IDs to specs. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a parent cycle exists. |
Source code in src/agentrelay/task_graph/_validation.py
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 116 117 118 119 120 121 122 123 | |
validate_workstream_max_depth(workstreams_by_id, max_depth)
Validate that workstream hierarchy depth does not exceed max_depth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workstreams_by_id
|
Mapping[str, WorkstreamSpec]
|
Canonical mapping of workstream IDs to specs. |
required |
max_depth
|
int
|
Maximum allowed ancestry depth. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any workstream has ancestry depth greater than |
Source code in src/agentrelay/task_graph/_validation.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
validate_dependencies_exist(tasks_by_id, dependency_ids)
Validate that every dependency ID exists as a graph task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tasks_by_id
|
Mapping[str, Task]
|
Canonical mapping of graph task IDs to tasks. |
required |
dependency_ids
|
Mapping[str, tuple[str, ...]]
|
Dependency ID index keyed by task ID. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any dependency ID is unknown. |
Source code in src/agentrelay/task_graph/_validation.py
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
validate_known_ids(ids, tasks_by_id, source_name)
Validate that an input ID set only references known graph tasks.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ids
|
set[str]
|
Input task IDs to validate. |
required |
tasks_by_id
|
Mapping[str, Task]
|
Canonical mapping of graph task IDs to tasks. |
required |
source_name
|
str
|
Human-readable source label for error reporting. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/agentrelay/task_graph/_validation.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |