7575 Required : false ,
7676 }
7777
78+ regionFlag = & cli.StringSliceFlag {
79+ Name : "regions" ,
80+ Usage : "Region(s) to deploy the agent to. If unset, will deploy to the nearest region." ,
81+ Required : false ,
82+ }
83+
7884 AgentCommands = []* cli.Command {
7985 {
8086 Name : "agent" ,
9096 secretsFlag ,
9197 secretsFileFlag ,
9298 silentFlag ,
99+ regionFlag ,
93100 },
94101 ArgsUsage : "[working-dir]" ,
95102 },
@@ -324,6 +331,11 @@ func createAgent(ctx context.Context, cmd *cli.Command) error {
324331 fmt .Printf ("Creating new agent\n " )
325332 }
326333
334+ regions := cmd .StringSlice ("regions" )
335+ if len (regions ) != 0 {
336+ lkConfig .Agent .Regions = regions
337+ }
338+
327339 secrets , err := requireSecrets (ctx , cmd , false , false )
328340 if err != nil {
329341 return err
@@ -335,6 +347,7 @@ func createAgent(ctx context.Context, cmd *cli.Command) error {
335347
336348 req := & lkproto.CreateAgentRequest {
337349 Secrets : secrets ,
350+ Regions : lkConfig .Agent .Regions ,
338351 }
339352
340353 resp , err := agentsClient .CreateAgent (ctx , req )
@@ -440,10 +453,16 @@ func createAgentConfig(ctx context.Context, cmd *cli.Command) error {
440453 return fmt .Errorf ("invalid project URL: %s" , project .URL )
441454 }
442455
456+ var regions []string
457+ for _ , regionalAgent := range response .Agents [0 ].AgentDeployments {
458+ regions = append (regions , regionalAgent .Region )
459+ }
460+
443461 agent := response .Agents [0 ]
444462 lkConfig := config .NewLiveKitTOML (matches [1 ])
445463 lkConfig .Agent = & config.LiveKitTOMLAgentConfig {
446- ID : agent .AgentId ,
464+ ID : agent .AgentId ,
465+ Regions : regions ,
447466 }
448467
449468 if err := lkConfig .SaveTOMLFile ("" , tomlFilename ); err != nil {
@@ -577,8 +596,14 @@ func updateAgent(ctx context.Context, cmd *cli.Command) error {
577596 return fmt .Errorf ("no agent config found in [%s]" , tomlFilename )
578597 }
579598
599+ regions := cmd .StringSlice ("regions" )
600+ if len (regions ) != 0 {
601+ lkConfig .Agent .Regions = regions
602+ }
603+
580604 req := & lkproto.UpdateAgentRequest {
581605 AgentId : lkConfig .Agent .ID ,
606+ Regions : lkConfig .Agent .Regions ,
582607 }
583608
584609 secrets , err := requireSecrets (ctx , cmd , false , true )
@@ -601,7 +626,8 @@ func updateAgent(ctx context.Context, cmd *cli.Command) error {
601626
602627 if resp .Success {
603628 fmt .Printf ("Updated agent [%s]\n " , util .Accented (lkConfig .Agent .ID ))
604- return nil
629+ err = lkConfig .SaveTOMLFile ("" , tomlFilename )
630+ return err
605631 }
606632
607633 return fmt .Errorf ("failed to update agent: %s" , resp .Message )
0 commit comments