pydantic_graph.beta
The next version of the pydantic-graph framework with enhanced graph execution capabilities.
This module provides a parallel control flow graph execution framework with support for: - 'Step' nodes for task execution - 'Decision' nodes for conditional branching - 'Fork' nodes for parallel execution coordination - 'Join' nodes and 'Reducer's for re-joining parallel executions - Mermaid diagram generation for graph visualization
Graph
dataclass
Bases: Generic[StateT, DepsT, InputT, OutputT]
A complete graph definition ready for execution.
The Graph class represents a complete workflow graph with typed inputs, outputs, state, and dependencies. It contains all nodes, edges, and metadata needed for execution.
Type Parameters
StateT: The type of the graph state DepsT: The type of the dependencies InputT: The type of the input data OutputT: The type of the output data
Source code in pydantic_graph/pydantic_graph/beta/graph.py
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 | |
name
instance-attribute
name: str | None
Optional name for the graph, if not provided the name will be inferred from the calling frame on the first call to a graph method.
auto_instrument
instance-attribute
auto_instrument: bool
Whether to automatically create instrumentation spans.
edges_by_source
instance-attribute
Outgoing paths from each source node.
parent_forks
instance-attribute
parent_forks: dict[JoinID, ParentFork[NodeID]]
Parent fork information for each join node.
get_parent_fork
get_parent_fork(join_id: JoinID) -> ParentFork[NodeID]
Get the parent fork information for a join node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
join_id
|
JoinID
|
The ID of the join node |
required |
Returns:
| Type | Description |
|---|---|
ParentFork[NodeID]
|
The parent fork information for the join |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the join ID is not found or has no parent fork |
Source code in pydantic_graph/pydantic_graph/beta/graph.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | |
run
async
run(
*,
state: StateT = None,
deps: DepsT = None,
inputs: InputT = None,
span: (
AbstractContextManager[AbstractSpan] | None
) = None,
infer_name: bool = True
) -> OutputT
Execute the graph and return the final output.
This is the main entry point for graph execution. It runs the graph to completion and returns the final output value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
StateT
|
The graph state instance |
None
|
deps
|
DepsT
|
The dependencies instance |
None
|
inputs
|
InputT
|
The input data for the graph |
None
|
span
|
AbstractContextManager[AbstractSpan] | None
|
Optional span for tracing/instrumentation |
None
|
infer_name
|
bool
|
Whether to infer the graph name from the calling frame. |
True
|
Returns:
| Type | Description |
|---|---|
OutputT
|
The final output from the graph execution |
Source code in pydantic_graph/pydantic_graph/beta/graph.py
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 | |
iter
async
iter(
*,
state: StateT = None,
deps: DepsT = None,
inputs: InputT = None,
span: (
AbstractContextManager[AbstractSpan] | None
) = None,
infer_name: bool = True
) -> AsyncIterator[GraphRun[StateT, DepsT, OutputT]]
Create an iterator for step-by-step graph execution.
This method allows for more fine-grained control over graph execution, enabling inspection of intermediate states and results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
StateT
|
The graph state instance |
None
|
deps
|
DepsT
|
The dependencies instance |
None
|
inputs
|
InputT
|
The input data for the graph |
None
|
span
|
AbstractContextManager[AbstractSpan] | None
|
Optional span for tracing/instrumentation |
None
|
infer_name
|
bool
|
Whether to infer the graph name from the calling frame. |
True
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[GraphRun[StateT, DepsT, OutputT]]
|
A GraphRun instance that can be iterated for step-by-step execution |
Source code in pydantic_graph/pydantic_graph/beta/graph.py
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 | |
render
Render the graph as a Mermaid diagram string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
title
|
str | None
|
Optional title for the diagram |
None
|
direction
|
StateDiagramDirection | None
|
Optional direction for the diagram layout |
None
|
Returns:
| Type | Description |
|---|---|
str
|
A string containing the Mermaid diagram representation |
Source code in pydantic_graph/pydantic_graph/beta/graph.py
251 252 253 254 255 256 257 258 259 260 261 262 263 | |
__str__
__str__() -> str
Return a Mermaid diagram representation of the graph.
Returns:
| Type | Description |
|---|---|
str
|
A string containing the Mermaid diagram of the graph |
Source code in pydantic_graph/pydantic_graph/beta/graph.py
270 271 272 273 274 275 276 | |
GraphBuilder
dataclass
Bases: Generic[StateT, DepsT, GraphInputT, GraphOutputT]
A builder for constructing executable graph definitions.
GraphBuilder provides a fluent interface for defining nodes, edges, and routing in a graph workflow. It supports typed state, dependencies, and input/output validation.
Type Parameters
StateT: The type of the graph state DepsT: The type of the dependencies GraphInputT: The type of the graph input data GraphOutputT: The type of the graph output data
Source code in pydantic_graph/pydantic_graph/beta/graph_builder.py
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 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 | |
name
instance-attribute
name: str | None = name
Optional name for the graph, if not provided the name will be inferred from the calling frame on the first call to a graph method.
state_type
instance-attribute
state_type: TypeOrTypeExpression[StateT] = state_type
The type of the graph state.
deps_type
instance-attribute
deps_type: TypeOrTypeExpression[DepsT] = deps_type
The type of the dependencies.
input_type
instance-attribute
input_type: TypeOrTypeExpression[GraphInputT] = input_type
The type of the graph input data.
output_type
instance-attribute
output_type: TypeOrTypeExpression[GraphOutputT] = (
output_type
)
The type of the graph output data.
auto_instrument
instance-attribute
auto_instrument: bool = auto_instrument
Whether to automatically create instrumentation spans.
__init__
__init__(
*,
name: str | None = None,
state_type: TypeOrTypeExpression[StateT] = NoneType,
deps_type: TypeOrTypeExpression[DepsT] = NoneType,
input_type: TypeOrTypeExpression[
GraphInputT
] = NoneType,
output_type: TypeOrTypeExpression[
GraphOutputT
] = NoneType,
auto_instrument: bool = True
)
Initialize a graph builder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Optional name for the graph, if not provided the name will be inferred from the calling frame on the first call to a graph method. |
None
|
state_type
|
TypeOrTypeExpression[StateT]
|
The type of the graph state |
NoneType
|
deps_type
|
TypeOrTypeExpression[DepsT]
|
The type of the dependencies |
NoneType
|
input_type
|
TypeOrTypeExpression[GraphInputT]
|
The type of the graph input data |
NoneType
|
output_type
|
TypeOrTypeExpression[GraphOutputT]
|
The type of the graph output data |
NoneType
|
auto_instrument
|
bool
|
Whether to automatically create instrumentation spans |
True
|
Source code in pydantic_graph/pydantic_graph/beta/graph_builder.py
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 | |
start_node
property
start_node: StartNode[GraphInputT]
Get the start node for the graph.
Returns:
| Type | Description |
|---|---|
StartNode[GraphInputT]
|
The start node that receives the initial graph input |
end_node
property
end_node: EndNode[GraphOutputT]
Get the end node for the graph.
Returns:
| Type | Description |
|---|---|
EndNode[GraphOutputT]
|
The end node that produces the final graph output |
step
step(
*, node_id: str | None = None, label: str | None = None
) -> Callable[
[StepFunction[StateT, DepsT, InputT, OutputT]],
Step[StateT, DepsT, InputT, OutputT],
]
step(
call: StepFunction[StateT, DepsT, InputT, OutputT],
*,
node_id: str | None = None,
label: str | None = None
) -> Step[StateT, DepsT, InputT, OutputT]
step(
call: (
StepFunction[StateT, DepsT, InputT, OutputT] | None
) = None,
*,
node_id: str | None = None,
label: str | None = None
) -> (
Step[StateT, DepsT, InputT, OutputT]
| Callable[
[StepFunction[StateT, DepsT, InputT, OutputT]],
Step[StateT, DepsT, InputT, OutputT],
]
)
Create a step from a step function.
This method can be used as a decorator or called directly to create a step node from an async function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
call
|
StepFunction[StateT, DepsT, InputT, OutputT] | None
|
The step function to wrap |
None
|
node_id
|
str | None
|
Optional ID for the node |
None
|
label
|
str | None
|
Optional human-readable label |
None
|
Returns:
| Type | Description |
|---|---|
Step[StateT, DepsT, InputT, OutputT] | Callable[[StepFunction[StateT, DepsT, InputT, OutputT]], Step[StateT, DepsT, InputT, OutputT]]
|
Either a Step instance or a decorator function |
Source code in pydantic_graph/pydantic_graph/beta/graph_builder.py
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 | |
stream
stream(
*, node_id: str | None = None, label: str | None = None
) -> Callable[
[StreamFunction[StateT, DepsT, InputT, OutputT]],
Step[StateT, DepsT, InputT, AsyncIterable[OutputT]],
]
stream(
call: StreamFunction[StateT, DepsT, InputT, OutputT],
*,
node_id: str | None = None,
label: str | None = None
) -> Step[StateT, DepsT, InputT, AsyncIterable[OutputT]]
stream(
call: (
StreamFunction[StateT, DepsT, InputT, OutputT]
| None
) = None,
*,
node_id: str | None = None,
label: str | None = None
) -> (
Step[StateT, DepsT, InputT, AsyncIterable[OutputT]]
| Callable[
[StreamFunction[StateT, DepsT, InputT, OutputT]],
Step[StateT, DepsT, InputT, AsyncIterable[OutputT]],
]
)
stream(
call: (
StreamFunction[StateT, DepsT, InputT, OutputT]
| None
) = None,
*,
node_id: str | None = None,
label: str | None = None
) -> (
Step[StateT, DepsT, InputT, AsyncIterable[OutputT]]
| Callable[
[StreamFunction[StateT, DepsT, InputT, OutputT]],
Step[StateT, DepsT, InputT, AsyncIterable[OutputT]],
]
)
Create a step from an async iterator (which functions like a "stream").
This method can be used as a decorator or called directly to create a step node from an async function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
call
|
StreamFunction[StateT, DepsT, InputT, OutputT] | None
|
The step function to wrap |
None
|
node_id
|
str | None
|
Optional ID for the node |
None
|
label
|
str | None
|
Optional human-readable label |
None
|
Returns:
| Type | Description |
|---|---|
Step[StateT, DepsT, InputT, AsyncIterable[OutputT]] | Callable[[StreamFunction[StateT, DepsT, InputT, OutputT]], Step[StateT, DepsT, InputT, AsyncIterable[OutputT]]]
|
Either a Step instance or a decorator function |
Source code in pydantic_graph/pydantic_graph/beta/graph_builder.py
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 | |
add
add(*edges: EdgePath[StateT, DepsT]) -> None
Add one or more edge paths to the graph.
This method processes edge paths and automatically creates any necessary fork nodes for broadcasts and maps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*edges
|
EdgePath[StateT, DepsT]
|
The edge paths to add to the graph |
()
|
Source code in pydantic_graph/pydantic_graph/beta/graph_builder.py
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 393 394 395 396 | |
add_edge
add_edge(
source: Source[T],
destination: Destination[T],
*,
label: str | None = None
) -> None
Add a simple edge between two nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Source[T]
|
The source node |
required |
destination
|
Destination[T]
|
The destination node |
required |
label
|
str | None
|
Optional label for the edge |
None
|
Source code in pydantic_graph/pydantic_graph/beta/graph_builder.py
398 399 400 401 402 403 404 405 406 407 408 409 | |
add_mapping_edge
add_mapping_edge(
source: Source[Iterable[T]],
map_to: Destination[T],
*,
pre_map_label: str | None = None,
post_map_label: str | None = None,
fork_id: ForkID | None = None,
downstream_join_id: JoinID | None = None
) -> None
Add an edge that maps iterable data across parallel paths.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
Source[Iterable[T]]
|
The source node that produces iterable data |
required |
map_to
|
Destination[T]
|
The destination node that receives individual items |
required |
pre_map_label
|
str | None
|
Optional label before the map operation |
None
|
post_map_label
|
str | None
|
Optional label after the map operation |
None
|
fork_id
|
ForkID | None
|
Optional ID for the fork node produced for this map operation |
None
|
downstream_join_id
|
JoinID | None
|
Optional ID of a join node that will always be downstream of this map. Specifying this ensures correct handling if you try to map an empty iterable. |
None
|
Source code in pydantic_graph/pydantic_graph/beta/graph_builder.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 | |
edge_from
edge_from(
*sources: Source[SourceOutputT],
) -> EdgePathBuilder[StateT, DepsT, SourceOutputT]
Create an edge path builder starting from the given source nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*sources
|
Source[SourceOutputT]
|
The source nodes to start the edge path from |
()
|
Returns:
| Type | Description |
|---|---|
EdgePathBuilder[StateT, DepsT, SourceOutputT]
|
An EdgePathBuilder for constructing the complete edge path |
Source code in pydantic_graph/pydantic_graph/beta/graph_builder.py
442 443 444 445 446 447 448 449 450 451 452 453 | |
decision
decision(
*, note: str | None = None, node_id: str | None = None
) -> Decision[StateT, DepsT, Never]
Create a new decision node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
note
|
str | None
|
Optional note to describe the decision logic |
None
|
node_id
|
str | None
|
Optional ID for the node produced for this decision logic |
None
|
Returns:
| Type | Description |
|---|---|
Decision[StateT, DepsT, Never]
|
A new Decision node with no branches |
Source code in pydantic_graph/pydantic_graph/beta/graph_builder.py
455 456 457 458 459 460 461 462 463 464 465 | |
match
match(
source: TypeOrTypeExpression[SourceT],
*,
matches: Callable[[Any], bool] | None = None
) -> DecisionBranchBuilder[
StateT, DepsT, SourceT, SourceT, Never
]
Create a decision branch matcher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
TypeOrTypeExpression[SourceT]
|
The type or type expression to match against |
required |
matches
|
Callable[[Any], bool] | None
|
Optional custom matching function |
None
|
Returns:
| Type | Description |
|---|---|
DecisionBranchBuilder[StateT, DepsT, SourceT, SourceT, Never]
|
A DecisionBranchBuilder for constructing the branch |
Source code in pydantic_graph/pydantic_graph/beta/graph_builder.py
467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | |
match_node
match_node(
source: type[SourceNodeT],
*,
matches: Callable[[Any], bool] | None = None
) -> DecisionBranch[SourceNodeT]
Create a decision branch for BaseNode subclasses.
This is similar to match() but specifically designed for matching against BaseNode types from the v1 system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
type[SourceNodeT]
|
The BaseNode subclass to match against |
required |
matches
|
Callable[[Any], bool] | None
|
Optional custom matching function |
None
|
Returns:
| Type | Description |
|---|---|
DecisionBranch[SourceNodeT]
|
A DecisionBranch for the BaseNode type |
Source code in pydantic_graph/pydantic_graph/beta/graph_builder.py
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 | |
node
Create an edge path from a BaseNode class.
This method integrates v1-style BaseNode classes into the v2 graph system by analyzing their type hints and creating appropriate edges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_type
|
type[BaseNode[StateT, DepsT, GraphOutputT]]
|
The BaseNode subclass to integrate |
required |
Returns:
| Type | Description |
|---|---|
EdgePath[StateT, DepsT]
|
An EdgePath representing the node and its connections |
Raises:
| Type | Description |
|---|---|
GraphSetupError
|
If the node type is missing required type hints |
Source code in pydantic_graph/pydantic_graph/beta/graph_builder.py
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 | |
build
Build the final executable graph from the accumulated nodes and edges.
This method performs validation, normalization, and analysis of the graph structure to create a complete, executable graph instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
validate_graph_structure
|
bool
|
whether to perform validation of the graph structure See the docstring of _validate_graph_structure below for more details. |
True
|
Returns:
| Type | Description |
|---|---|
Graph[StateT, DepsT, GraphInputT, GraphOutputT]
|
A complete Graph instance ready for execution |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the graph structure is invalid (e.g., join without parent fork) |
Source code in pydantic_graph/pydantic_graph/beta/graph_builder.py
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 | |
EndNode
Terminal node representing the completion of graph execution.
The EndNode marks the successful completion of a graph execution flow and can collect the final output data.
Source code in pydantic_graph/pydantic_graph/beta/node.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
id
class-attribute
instance-attribute
id = NodeID('__end__')
Fixed identifier for the end node.
StartNode
Entry point node for graph execution.
The StartNode represents the beginning of a graph execution flow.
Source code in pydantic_graph/pydantic_graph/beta/node.py
26 27 28 29 30 31 32 33 | |
id
class-attribute
instance-attribute
id = NodeID('__start__')
Fixed identifier for the start node.
StepContext
dataclass
Bases: Generic[StateT, DepsT, InputT]
Context information passed to step functions during graph execution.
The step context provides access to the current graph state, dependencies, and input data for a step.
Type Parameters
StateT: The type of the graph state DepsT: The type of the dependencies InputT: The type of the input data
Source code in pydantic_graph/pydantic_graph/beta/step.py
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 | |
inputs
property
inputs: InputT
The input data for this step.
This must be a property to ensure correct variance behavior
StepNode
dataclass
Bases: BaseNode[StateT, DepsT, Any]
A base node that represents a step with bound inputs.
StepNode bridges between the v1 and v2 graph execution systems by wrapping
a Step with bound inputs in a BaseNode interface.
It is not meant to be run directly but rather used to indicate transitions
to v2-style steps.
Source code in pydantic_graph/pydantic_graph/beta/step.py
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 | |
run
async
run(
ctx: GraphRunContext[StateT, DepsT],
) -> BaseNode[StateT, DepsT, Any] | End[Any]
Attempt to run the step node.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
GraphRunContext[StateT, DepsT]
|
The graph execution context |
required |
Returns:
| Type | Description |
|---|---|
BaseNode[StateT, DepsT, Any] | End[Any]
|
The result of step execution |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always raised as StepNode is not meant to be run directly |
Source code in pydantic_graph/pydantic_graph/beta/step.py
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
TypeExpression
Bases: Generic[T]
A workaround for type checker limitations when using complex type expressions.
This class serves as a wrapper for types that cannot normally be used in positions
requiring type[T], such as Any, Union[...], or Literal[...]. It provides a
way to pass these complex type expressions to functions expecting concrete types.
Example
Instead of output_type=Union[str, int] (which may cause type errors),
use output_type=TypeExpression[Union[str, int]].
Note
This is a workaround for the lack of TypeForm in the Python type system.
Source code in pydantic_graph/pydantic_graph/beta/util.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |