2222 Sequence ,
2323 TypeVar ,
2424)
25+ from uuid import uuid4
2526
2627from pydantic import (
2728 AfterValidator ,
4849 UserID ,
4950)
5051from ai .backend .common .types import (
52+ AgentId ,
5153 BinarySize ,
5254 BinarySizeField ,
5355 ResourceGroupType ,
@@ -438,6 +440,20 @@ class CommonAgentConfig(BaseConfigSchema):
438440 validation_alias = AliasChoices ("rpc-auth-agent-keypair" , "rpc_auth_agent_keypair" ),
439441 serialization_alias = "rpc-auth-agent-keypair" ,
440442 )
443+ ipc_base_path : AutoDirectoryPath = Field (
444+ default = AutoDirectoryPath ("/tmp/backend.ai/ipc" ),
445+ description = "Base path for IPC" ,
446+ examples = ["/tmp/backend.ai/ipc" ],
447+ validation_alias = AliasChoices ("ipc-base-path" , "ipc_base_path" ),
448+ serialization_alias = "ipc-base-path" ,
449+ )
450+ var_base_path : AutoDirectoryPath = Field (
451+ default = AutoDirectoryPath ("./var/lib/backend.ai" ),
452+ description = "Base path for variable data" ,
453+ examples = ["./var/lib/backend.ai" ],
454+ validation_alias = AliasChoices ("var-base-path" , "var_base_path" ),
455+ serialization_alias = "var-base-path" ,
456+ )
441457 mount_path : Optional [AutoDirectoryPath ] = Field (
442458 default = None ,
443459 description = "Mount path for containers" ,
@@ -528,6 +544,20 @@ class CommonAgentConfig(BaseConfigSchema):
528544 validation_alias = AliasChoices ("metadata-server-port" , "metadata_server_port" ),
529545 serialization_alias = "metadata-server-port" ,
530546 )
547+ image_commit_path : AutoDirectoryPath = Field (
548+ default = AutoDirectoryPath ("./tmp/backend.ai/commit" ),
549+ description = "Path for image commit" ,
550+ examples = ["./tmp/backend.ai/commit" ],
551+ validation_alias = AliasChoices ("image-commit-path" , "image_commit_path" ),
552+ serialization_alias = "image-commit-path" ,
553+ )
554+ abuse_report_path : Optional [Path ] = Field (
555+ default = None ,
556+ description = "Path for abuse reports" ,
557+ examples = ["/var/log/backend.ai/abuse" ],
558+ validation_alias = AliasChoices ("abuse-report-path" , "abuse_report_path" ),
559+ serialization_alias = "abuse-report-path" ,
560+ )
531561 use_experimental_redis_event_dispatcher : bool = Field (
532562 default = False ,
533563 description = "Whether to use experimental Redis event dispatcher" ,
@@ -574,8 +604,8 @@ def _validate_rpc_listen_addr(cls, rpc_listen_addr: HostPortPair) -> HostPortPai
574604
575605
576606class OverridableAgentConfig (BaseConfigSchema ):
577- id : Optional [ str ] = Field (
578- default = None ,
607+ id : str = Field (
608+ default_factory = lambda : f"agent- { uuid4 () } " ,
579609 description = "Agent ID" ,
580610 examples = ["agent-001" ],
581611 )
@@ -588,20 +618,6 @@ class OverridableAgentConfig(BaseConfigSchema):
588618 validation_alias = AliasChoices ("agent-sock-port" , "agent_sock_port" ),
589619 serialization_alias = "agent-sock-port" ,
590620 )
591- ipc_base_path : AutoDirectoryPath = Field (
592- default = AutoDirectoryPath ("/tmp/backend.ai/ipc" ),
593- description = "Base path for IPC" ,
594- examples = ["/tmp/backend.ai/ipc" ],
595- validation_alias = AliasChoices ("ipc-base-path" , "ipc_base_path" ),
596- serialization_alias = "ipc-base-path" ,
597- )
598- var_base_path : AutoDirectoryPath = Field (
599- default = AutoDirectoryPath ("./var/lib/backend.ai" ),
600- description = "Base path for variable data" ,
601- examples = ["./var/lib/backend.ai" ],
602- validation_alias = AliasChoices ("var-base-path" , "var_base_path" ),
603- serialization_alias = "var-base-path" ,
604- )
605621 scaling_group : str = Field (
606622 default = "default" ,
607623 description = "Scaling group name" ,
@@ -644,20 +660,6 @@ class OverridableAgentConfig(BaseConfigSchema):
644660 validation_alias = AliasChoices ("block-network-plugins" , "block_network_plugins" ),
645661 serialization_alias = "block-network-plugins" ,
646662 )
647- image_commit_path : AutoDirectoryPath = Field (
648- default = AutoDirectoryPath ("./tmp/backend.ai/commit" ),
649- description = "Path for image commit" ,
650- examples = ["./tmp/backend.ai/commit" ],
651- validation_alias = AliasChoices ("image-commit-path" , "image_commit_path" ),
652- serialization_alias = "image-commit-path" ,
653- )
654- abuse_report_path : Optional [Path ] = Field (
655- default = None ,
656- description = "Path for abuse reports" ,
657- examples = ["/var/log/backend.ai/abuse" ],
658- validation_alias = AliasChoices ("abuse-report-path" , "abuse_report_path" ),
659- serialization_alias = "abuse-report-path" ,
660- )
661663 force_terminate_abusing_containers : bool = Field (
662664 default = False ,
663665 description = "Whether to force terminate abusing containers" ,
@@ -1138,7 +1140,12 @@ class AgentOverrideConfig(BaseConfigSchema):
11381140 description = "Resource config overrides for the individual agent" ,
11391141 )
11401142
1141- def construct_unified_config (self , * , default : AgentUnifiedConfig ) -> AgentUnifiedConfig :
1143+ def construct_unified_config (
1144+ self ,
1145+ * ,
1146+ default : AgentUnifiedConfig ,
1147+ agent_idx : int ,
1148+ ) -> AgentUnifiedConfig :
11421149 agent_updates : dict [str , Any ] = {}
11431150 if self .agent is not None :
11441151 agent_override_fields = self .agent .model_dump (include = self .agent .model_fields_set )
@@ -1177,9 +1184,24 @@ class AgentUnifiedConfig(AgentGlobalConfig, AgentSpecificConfig):
11771184 extra = "allow" ,
11781185 )
11791186
1187+ @property
1188+ def agent_common (self ) -> CommonAgentConfig :
1189+ return self .agent
1190+
1191+ @property
1192+ def agent_default (self ) -> OverridableAgentConfig :
1193+ return self .agent
1194+
11801195 @property
11811196 def agent_configs (self ) -> Sequence [AgentUnifiedConfig ]:
1182- return self ._for_each_agent (lambda x : x )
1197+ agent_configs = self ._for_each_agent (lambda x : x )
1198+ if not agent_configs :
1199+ raise ValueError ("There must be at least one agent config" )
1200+ return agent_configs
1201+
1202+ @property
1203+ def agent_ids (self ) -> Sequence [AgentId ]:
1204+ return [AgentId (agent_config .agent .id ) for agent_config in self .agent_configs ]
11831205
11841206 def with_updates (
11851207 self ,
@@ -1265,7 +1287,10 @@ def validate(config: AgentSpecificConfig) -> None:
12651287 return self
12661288
12671289 def _for_each_agent (self , func : Callable [[AgentUnifiedConfig ], R ]) -> list [R ]:
1268- agents = [agent .construct_unified_config (default = self ) for agent in self .agents ]
1290+ agents = [
1291+ agent .construct_unified_config (default = self , agent_idx = i )
1292+ for i , agent in enumerate (self .agents )
1293+ ]
12691294 if not agents :
12701295 agents .append (self )
12711296
0 commit comments