@@ -2065,7 +2065,6 @@ def __init__(self):
2065
2065
self .loaded_from_fork : bool = False
2066
2066
self .tracker = None
2067
2067
self .graph_builder = None
2068
- self .prebuilt_graph = None
2069
2068
self .typing_system = None
2070
2069
self .parallel_executor_factory = None
2071
2070
self .state_persister = None
@@ -2143,9 +2142,21 @@ def with_state(
2143
2142
self .state = State (kwargs )
2144
2143
return self
2145
2144
2145
+ def with_graphs (self , * graphs ) -> "ApplicationBuilder[StateType]" :
2146
+ """Adds multiple prebuilt graphs -- this just calls :py:meth:`with_graph <burr.core.application.ApplicationBuilder.with_graph>`
2147
+ in a loop! See caveats in :py:meth:`with_graph <burr.core.application.ApplicationBuilder.with_graph>`.
2148
+
2149
+ :param graphs: Graphs to add to the application
2150
+ :return: The application builder for future chaining.
2151
+ """
2152
+ for graph in graphs :
2153
+ self .with_graph (graph )
2154
+ return self
2155
+
2146
2156
def with_graph (self , graph : Graph ) -> "ApplicationBuilder[StateType]" :
2147
- """Adds a prebuilt graph -- this is an alternative to using the with_actions and with_transitions methods.
2148
- While you will likely use with_actions and with_transitions, you may want this in a few cases:
2157
+ """Adds a prebuilt graph -- this can work in addition to using with_actions and with_transitions methods.
2158
+ This will add all nodes + edges from a prebuilt graph to the current graph. Note that if you add two
2159
+ graphs (or a combination of graphs/nodes/edges), you will need to ensure that there are no node name conflicts.
2149
2160
2150
2161
1. You want to reuse the same graph object for different applications
2151
2162
2. You want the logic that constructs the graph to be separate from that which constructs the application
@@ -2154,13 +2165,8 @@ def with_graph(self, graph: Graph) -> "ApplicationBuilder[StateType]":
2154
2165
:param graph: Graph object built with the :py:class:`GraphBuilder <burr.core.graph.GraphBuilder>`
2155
2166
:return: The application builder for future chaining.
2156
2167
"""
2157
- if self .graph_builder is not None :
2158
- raise ValueError (
2159
- BASE_ERROR_MESSAGE
2160
- + "You have already called `with_actions`, or `with_transitions` -- you currently "
2161
- "cannot use the with_graph method along with that. Use `with_graph` or the other methods, not both"
2162
- )
2163
- self .prebuilt_graph = graph
2168
+ self ._initialize_graph_builder ()
2169
+ self .graph_builder = self .graph_builder .with_graph (graph )
2164
2170
return self
2165
2171
2166
2172
def with_parallel_executor (self , executor_factory : lambda : Executor ):
@@ -2190,15 +2196,6 @@ def with_parallel_executor(self, executor_factory: lambda: Executor):
2190
2196
self .parallel_executor_factory = executor_factory
2191
2197
return self
2192
2198
2193
- def _ensure_no_prebuilt_graph (self ):
2194
- if self .prebuilt_graph is not None :
2195
- raise ValueError (
2196
- BASE_ERROR_MESSAGE + "You have already called `with_graph` -- you currently "
2197
- "cannot use the with_actions, or with_transitions method along with that. "
2198
- "Use `with_graph` or the other methods, not both."
2199
- )
2200
- return self
2201
-
2202
2199
def _initialize_graph_builder (self ):
2203
2200
if self .graph_builder is None :
2204
2201
self .graph_builder = GraphBuilder ()
@@ -2233,7 +2230,6 @@ def with_actions(
2233
2230
:param action_dict: Actions to add, keyed by name
2234
2231
:return: The application builder for future chaining.
2235
2232
"""
2236
- self ._ensure_no_prebuilt_graph ()
2237
2233
self ._initialize_graph_builder ()
2238
2234
self .graph_builder = self .graph_builder .with_actions (* action_list , ** action_dict )
2239
2235
return self
@@ -2256,7 +2252,6 @@ def with_transitions(
2256
2252
:param transitions: Transitions to add
2257
2253
:return: The application builder for future chaining.
2258
2254
"""
2259
- self ._ensure_no_prebuilt_graph ()
2260
2255
self ._initialize_graph_builder ()
2261
2256
self .graph_builder = self .graph_builder .with_transitions (* transitions )
2262
2257
return self
@@ -2583,15 +2578,13 @@ def reset_to_entrypoint(self):
2583
2578
self .state = self .state .wipe (delete = [PRIOR_STEP ])
2584
2579
2585
2580
def _get_built_graph (self ) -> Graph :
2586
- if self .graph_builder is None and self . prebuilt_graph is None :
2581
+ if self .graph_builder is None :
2587
2582
raise ValueError (
2588
2583
BASE_ERROR_MESSAGE
2589
- + "You must set the graph using with_graph, or use with_entrypoint, with_actions, and with_transitions "
2590
- " to build the graph. "
2584
+ + "No graph constructs exist. You must call some combination of with_graph, with_entrypoint, "
2585
+ "with_actions, and with_transitions "
2591
2586
)
2592
- if self .graph_builder is not None :
2593
- return self .graph_builder .build ()
2594
- return self .prebuilt_graph
2587
+ return self .graph_builder .build ()
2595
2588
2596
2589
def _build_common (self ) -> Application :
2597
2590
graph = self ._get_built_graph ()
0 commit comments