1515from __future__ import annotations
1616
1717from collections import defaultdict
18- from collections .abc import Mapping
18+ from collections .abc import Mapping , MutableMapping
1919import importlib
2020import shutil
2121import sys
3535from dimos .utils .safe_thread_map import safe_thread_map
3636
3737if TYPE_CHECKING :
38- from dimos .core .coordination .blueprints import Blueprint , _BlueprintAtom
38+ from dimos .core .coordination .blueprints import Blueprint , BlueprintAtom
3939 from dimos .core .rpc_client import ModuleProxy , ModuleProxyProtocol
4040
4141logger = setup_logger ()
@@ -56,7 +56,7 @@ def __init__(
5656 cls .deployment_identifier : cls (g = g ) for cls in manager_types
5757 }
5858 self ._deployed_modules = {}
59- self ._deployed_atoms : dict [type [ModuleBase ], _BlueprintAtom ] = {}
59+ self ._deployed_atoms : dict [type [ModuleBase ], BlueprintAtom ] = {}
6060 self ._resolved_module_refs : dict [tuple [type [ModuleBase ], str ], type [ModuleBase ]] = {}
6161 self ._transport_registry : dict [tuple [str , type ], PubSubTransport [Any ]] = {}
6262 self ._class_aliases : dict [type [ModuleBase ], type [ModuleBase ]] = {}
@@ -114,7 +114,9 @@ def deploy(
114114 self ._deployed_modules [module_class ] = deployed_module
115115 return deployed_module # type: ignore[return-value]
116116
117- def deploy_parallel (self , module_specs : list [ModuleSpec ]) -> list [ModuleProxy ]:
117+ def deploy_parallel (
118+ self , module_specs : list [ModuleSpec ], blueprint_args : Mapping [str , Mapping [str , Any ]]
119+ ) -> list [ModuleProxy ]:
118120 if not self ._managers :
119121 raise ValueError ("Not started" )
120122
@@ -130,7 +132,7 @@ def deploy_parallel(self, module_specs: list[ModuleSpec]) -> list[ModuleProxy]:
130132 results : list [Any ] = [None ] * len (module_specs )
131133
132134 def _deploy_group (dep : str ) -> None :
133- deployed = self ._managers [dep ].deploy_parallel (specs_by_deployment [dep ])
135+ deployed = self ._managers [dep ].deploy_parallel (specs_by_deployment [dep ], blueprint_args )
134136 for index , module in zip (indices_by_deployment [dep ], deployed , strict = True ):
135137 results [index ] = module
136138
@@ -221,12 +223,13 @@ def _connect_streams(self, blueprint: Blueprint) -> None:
221223 def build (
222224 cls ,
223225 blueprint : Blueprint ,
224- cli_config_overrides : Mapping [str , Any ] | None = None ,
226+ blueprint_args : MutableMapping [str , Any ] | None = None ,
225227 ) -> ModuleCoordinator :
226228 logger .info ("Building the blueprint" )
227229 global_config .update (** dict (blueprint .global_config_overrides ))
228- if cli_config_overrides :
229- global_config .update (** dict (cli_config_overrides ))
230+ blueprint_args = blueprint_args or {}
231+ if "g" in blueprint_args :
232+ global_config .update (** blueprint_args .pop ("g" ))
230233
231234 _run_configurators (blueprint )
232235 _check_requirements (blueprint )
@@ -236,7 +239,7 @@ def build(
236239 coordinator = cls (g = global_config )
237240 coordinator .start ()
238241
239- _deploy_all_modules (blueprint , coordinator , global_config )
242+ _deploy_all_modules (blueprint , coordinator , global_config , blueprint_args )
240243 coordinator ._connect_streams (blueprint )
241244 _connect_module_refs (blueprint , coordinator )
242245
@@ -250,7 +253,7 @@ def build(
250253 def load_blueprint (
251254 self ,
252255 blueprint : Blueprint ,
253- cli_config_overrides : Mapping [str , Any ] | None = None ,
256+ blueprint_args : MutableMapping [ str , Mapping [str , Any ] ] | None = None ,
254257 ) -> None :
255258 """Load a blueprint into an already-running coordinator.
256259
@@ -263,8 +266,9 @@ def load_blueprint(
263266
264267 # Apply config overrides.
265268 self ._global_config .update (** dict (blueprint .global_config_overrides ))
266- if cli_config_overrides :
267- self ._global_config .update (** dict (cli_config_overrides ))
269+ blueprint_args = blueprint_args or {}
270+ if "g" in blueprint_args :
271+ self ._global_config .update (** blueprint_args .pop ("g" ))
268272
269273 # Scale worker pool.
270274 n_extra = int (blueprint .global_config_overrides .get ("n_workers" , 0 ))
@@ -288,7 +292,7 @@ def load_blueprint(
288292
289293 before = set (self ._deployed_modules )
290294
291- _deploy_all_modules (blueprint , self , self ._global_config )
295+ _deploy_all_modules (blueprint , self , self ._global_config , blueprint_args )
292296 self ._connect_streams (blueprint )
293297 _connect_module_refs (blueprint , self , existing_modules = before )
294298
@@ -300,8 +304,12 @@ def load_blueprint(
300304
301305 self ._send_on_system_modules ()
302306
303- def load_module (self , module_class : type [ModuleBase ], ** kwargs : Any ) -> None :
304- self .load_blueprint (module_class .blueprint (** kwargs ))
307+ def load_module (
308+ self ,
309+ module_class : type [ModuleBase ],
310+ blueprint_args : MutableMapping [str , Mapping [str , Any ]] | None = None ,
311+ ) -> None :
312+ self .load_blueprint (module_class .blueprint (** blueprint_args or {}))
305313
306314 def unload_module (self , module_class : type [ModuleBase ]) -> None :
307315 """Stop and tear down a single deployed module.
@@ -576,13 +584,16 @@ def _check_requirements(blueprint: Blueprint) -> None:
576584
577585
578586def _deploy_all_modules (
579- blueprint : Blueprint , module_coordinator : ModuleCoordinator , gc : GlobalConfig
587+ blueprint : Blueprint ,
588+ module_coordinator : ModuleCoordinator ,
589+ gc : GlobalConfig ,
590+ blueprint_args : Mapping [str , Mapping [str , Any ]],
580591) -> None :
581592 module_specs : list [ModuleSpec ] = []
582593 for bp in blueprint .active_blueprints :
583- module_specs .append ((bp .module , gc , bp .kwargs ))
594+ module_specs .append ((bp .module , gc , bp .kwargs . copy () ))
584595
585- module_coordinator .deploy_parallel (module_specs )
596+ module_coordinator .deploy_parallel (module_specs , blueprint_args )
586597
587598 for bp in blueprint .active_blueprints :
588599 module_coordinator ._deployed_atoms [bp .module ] = bp
0 commit comments