@@ -687,6 +687,46 @@ class OverridableAgentConfig(BaseConfigSchema):
687687 extra = "allow" ,
688688 )
689689
690+ def with_derived_fields (
691+ self ,
692+ default_agent : AgentConfig ,
693+ agent_idx : int ,
694+ ) -> OverridableAgentConfig :
695+ if self .id is None and default_agent .id is None :
696+ return self
697+
698+ agent_id = self .id if self .id is not None else f"{ default_agent .id } -{ agent_idx } "
699+
700+ if "ipc_base_path" in self .model_fields_set :
701+ ipc_base_path = self .ipc_base_path
702+ else :
703+ ipc_base_path = default_agent .ipc_base_path / agent_id
704+
705+ if "var_base_path" in self .model_fields_set :
706+ var_base_path = self .var_base_path
707+ else :
708+ var_base_path = default_agent .var_base_path / agent_id
709+
710+ if "image_commit_path" in self .model_fields_set :
711+ image_commit_path = self .image_commit_path
712+ else :
713+ image_commit_path = default_agent .image_commit_path / agent_id
714+
715+ if default_agent .abuse_report_path is None or "abuse_report_path" in self .model_fields_set :
716+ abuse_report_path = self .abuse_report_path
717+ else :
718+ abuse_report_path = default_agent .abuse_report_path / agent_id
719+
720+ return self .model_copy (
721+ update = {
722+ "id" : agent_id ,
723+ "ipc_base_path" : ipc_base_path ,
724+ "var_base_path" : var_base_path ,
725+ "image_commit_path" : image_commit_path ,
726+ "abuse_report_path" : abuse_report_path ,
727+ }
728+ )
729+
690730
691731class AgentConfig (CommonAgentConfig , OverridableAgentConfig ):
692732 pass
@@ -1130,10 +1170,16 @@ class AgentOverrideConfig(BaseConfigSchema):
11301170 description = "Resource config overrides for the individual agent" ,
11311171 )
11321172
1133- def construct_unified_config (self , * , default : AgentUnifiedConfig ) -> AgentUnifiedConfig :
1173+ def construct_unified_config (
1174+ self ,
1175+ * ,
1176+ default : AgentUnifiedConfig ,
1177+ agent_idx : int ,
1178+ ) -> AgentUnifiedConfig :
11341179 agent_updates : dict [str , Any ] = {}
11351180 if self .agent is not None :
1136- agent_override_fields = self .agent .model_dump (include = self .agent .model_fields_set )
1181+ agent = self .agent .with_derived_fields (default .agent , agent_idx )
1182+ agent_override_fields = agent .model_dump (include = agent .model_fields_set )
11371183 agent_updates ["agent" ] = default .agent .model_copy (update = agent_override_fields )
11381184 if self .container is not None :
11391185 container_override_fields = self .container .model_dump (
@@ -1169,9 +1215,20 @@ class AgentUnifiedConfig(AgentGlobalConfig, AgentSpecificConfig):
11691215 extra = "allow" ,
11701216 )
11711217
1218+ @property
1219+ def agent_common (self ) -> CommonAgentConfig :
1220+ return self .agent
1221+
1222+ @property
1223+ def agent_default (self ) -> OverridableAgentConfig :
1224+ return self .agent
1225+
11721226 @property
11731227 def agent_configs (self ) -> Sequence [AgentUnifiedConfig ]:
1174- return self ._for_each_agent (lambda x : x )
1228+ agent_configs = self ._for_each_agent (lambda x : x )
1229+ if not agent_configs :
1230+ raise ValueError ("There must be at least one agent config" )
1231+ return agent_configs
11751232
11761233 def with_updates (
11771234 self ,
@@ -1257,7 +1314,10 @@ def validate(config: AgentSpecificConfig) -> None:
12571314 return self
12581315
12591316 def _for_each_agent (self , func : Callable [[AgentUnifiedConfig ], R ]) -> list [R ]:
1260- agents = [agent .construct_unified_config (default = self ) for agent in self .agents ]
1317+ agents = [
1318+ agent .construct_unified_config (default = self , agent_idx = i )
1319+ for i , agent in enumerate (self .agents )
1320+ ]
12611321 if not agents :
12621322 agents .append (self )
12631323
0 commit comments