pydantic_graph.nodes
GraphRunContext
dataclass
Context for a graph.
Source code in pydantic_graph/pydantic_graph/nodes.py
27 28 29 30 31 32 33 34 |
|
BaseNode
Bases: ABC
, Generic[StateT, DepsT, NodeRunEndT]
Base class for a node.
Source code in pydantic_graph/pydantic_graph/nodes.py
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 116 117 118 119 120 121 122 123 124 125 126 |
|
docstring_notes
class-attribute
docstring_notes: bool = False
Set to True
to generate mermaid diagram notes from the class's docstring.
While this can add valuable information to the diagram, it can make diagrams harder to view, hence
it is disabled by default. You can also customise notes overriding the
get_note
method.
run
abstractmethod
async
run(
ctx: GraphRunContext[StateT, DepsT]
) -> BaseNode[StateT, DepsT, Any] | End[NodeRunEndT]
Run the node.
This is an abstract method that must be implemented by subclasses.
Return types used at runtime
The return type of this method are read by pydantic_graph
at runtime and used to define which
nodes can be called next in the graph. This is displayed in mermaid diagrams
and enforced when running the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ctx
|
GraphRunContext[StateT, DepsT]
|
The graph context. |
required |
Returns:
Type | Description |
---|---|
BaseNode[StateT, DepsT, Any] | End[NodeRunEndT]
|
The next node to run or |
Source code in pydantic_graph/pydantic_graph/nodes.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
get_id
cached
classmethod
get_id() -> str
Get the ID of the node.
Source code in pydantic_graph/pydantic_graph/nodes.py
67 68 69 70 71 |
|
get_note
classmethod
get_note() -> str | None
Get a note about the node to render on mermaid charts.
By default, this returns a note only if docstring_notes
is True
. You can override this method to customise the node notes.
Source code in pydantic_graph/pydantic_graph/nodes.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
|
get_node_def
classmethod
Get the node definition.
Source code in pydantic_graph/pydantic_graph/nodes.py
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 |
|
End
dataclass
Type to return from a node to signal the end of the graph.
Source code in pydantic_graph/pydantic_graph/nodes.py
129 130 131 132 133 134 |
|
Edge
dataclass
Annotation to apply a label to an edge in a graph.
Source code in pydantic_graph/pydantic_graph/nodes.py
137 138 139 140 141 142 |
|
DepsT
module-attribute
DepsT = TypeVar('DepsT', default=None)
Type variable for the dependencies of a graph and node.
RunEndT
module-attribute
RunEndT = TypeVar('RunEndT', default=None)
Type variable for the return type of a graph run
.