pydantic_graph.basenode
StateT
module-attribute
StateT = TypeVar('StateT', default=object)
Type variable for the state in a graph.
GraphRunContext
dataclass
Context for a graph.
Source code in pydantic_graph/pydantic_graph/basenode.py
23 24 25 26 27 28 29 30 | |
BaseNode
Bases: ABC, Generic[StateT, DepsT, NodeRunEndT]
Base class for a node.
Source code in pydantic_graph/pydantic_graph/basenode.py
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 | |
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, 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/basenode.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
get_node_id
cached
classmethod
get_node_id() -> str
Get the ID of the node.
Source code in pydantic_graph/pydantic_graph/basenode.py
54 55 56 57 58 | |
End
dataclass
Type to return from a node to signal the end of the graph.
Source code in pydantic_graph/pydantic_graph/basenode.py
61 62 63 64 65 66 | |
Edge
dataclass
Annotation to apply a label to an edge in a graph.
Source code in pydantic_graph/pydantic_graph/basenode.py
69 70 71 72 73 74 | |
DepsT
module-attribute
DepsT = TypeVar("DepsT", default=object, contravariant=True)
Type variable for the dependencies of a graph and node.