@@ -22,6 +22,8 @@ import (
2222 "syscall"
2323
2424 "github.com/urfave/cli/v3"
25+
26+ "github.com/livekit/livekit-cli/v2/pkg/agentfs"
2527)
2628
2729func init () {
@@ -38,15 +40,15 @@ var agentRunFlags = []cli.Flag{
3840var startCommand = & cli.Command {
3941 Name : "start" ,
4042 Usage : "Run an agent in production mode" ,
41- ArgsUsage : "[entrypoint]" ,
43+ ArgsUsage : "[entrypoint] [-- node/python-args...] " ,
4244 Flags : agentRunFlags ,
4345 Action : runAgentStart ,
4446}
4547
4648var devCommand = & cli.Command {
4749 Name : "dev" ,
4850 Usage : "Run an agent in development mode with auto-reload" ,
49- ArgsUsage : "[entrypoint]" ,
51+ ArgsUsage : "[entrypoint] [-- node/python-args...] " ,
5052 Flags : append (agentRunFlags , & cli.BoolFlag {
5153 Name : "no-reload" ,
5254 Usage : "Disable auto-reload on file changes" ,
@@ -57,6 +59,11 @@ var devCommand = &cli.Command{
5759// resolveCredentials returns CLI args (--url, --api-key, --api-secret) for the agent subprocess.
5860func resolveCredentials (cmd * cli.Command , loadOpts ... loadOption ) ([]string , error ) {
5961 url := cmd .String ("url" )
62+ if ! cmd .IsSet ("url" ) {
63+ // Ignore the global flag's default (http://localhost:7880) so the
64+ // project config can supply the URL.
65+ url = ""
66+ }
6067 apiKey := cmd .String ("api-key" )
6168 apiSecret := cmd .String ("api-secret" )
6269
@@ -93,10 +100,10 @@ func resolveCredentials(cmd *cli.Command, loadOpts ...loadOption) ([]string, err
93100 return args , nil
94101}
95102
96- func buildCLIArgs (subcmd string , cmd * cli.Command , loadOpts ... loadOption ) ([]string , error ) {
103+ func buildCLIArgs (projectType agentfs. ProjectType , subcmd string , cmd * cli.Command , loadOpts ... loadOption ) ([]string , error ) {
97104 args := []string {subcmd }
98105 if logLevel := cmd .String ("log-level" ); logLevel != "" {
99- args = append (args , "--log-level" , logLevel )
106+ args = append (args , "--log-level" , normalizeLogLevel ( projectType , logLevel ) )
100107 }
101108 creds , err := resolveCredentials (cmd , loadOpts ... )
102109 if err != nil {
@@ -113,7 +120,7 @@ func runAgentStart(ctx context.Context, cmd *cli.Command) error {
113120 }
114121 out .Statusf ("Detected %s agent (%s in %s)" , projectType .Lang (), entrypoint , projectDir )
115122
116- cliArgs , err := buildCLIArgs ("start" , cmd )
123+ cliArgs , err := buildCLIArgs (projectType , "start" , cmd )
117124 if err != nil {
118125 return err
119126 }
@@ -122,6 +129,7 @@ func runAgentStart(ctx context.Context, cmd *cli.Command) error {
122129 Dir : projectDir ,
123130 Entrypoint : entrypoint ,
124131 ProjectType : projectType ,
132+ RuntimeArgs : forwardedArgs (cmd ),
125133 CLIArgs : cliArgs ,
126134 ForwardOutput : os .Stdout ,
127135 })
@@ -134,7 +142,7 @@ func runAgentStart(ctx context.Context, cmd *cli.Command) error {
134142 sigCh := make (chan os.Signal , 1 )
135143 signal .Notify (sigCh , syscall .SIGINT , syscall .SIGTERM )
136144
137- // Forward every signal to the agent — Python decides
145+ // Forward every signal to the agent — the agent decides:
138146 // first = graceful shutdown, second = force exit.
139147 go func () {
140148 for range sigCh {
@@ -154,19 +162,28 @@ func runAgentDev(ctx context.Context, cmd *cli.Command) error {
154162 return err
155163 }
156164
157- cliArgs , err := buildCLIArgs ("start" , cmd )
165+ // Python has no dedicated dev subcommand: dev mode is `start --dev`.
166+ // agents-js has a `dev` subcommand that already defaults to debug logs.
167+ subcmd := "dev"
168+ if projectType .IsPython () {
169+ subcmd = "start"
170+ }
171+ cliArgs , err := buildCLIArgs (projectType , subcmd , cmd )
158172 if err != nil {
159173 return err
160174 }
161- cliArgs = append (cliArgs , "--dev" )
162- if cmd .String ("log-level" ) == "" {
163- cliArgs = append (cliArgs , "--log-level" , "DEBUG" )
175+ if projectType .IsPython () {
176+ cliArgs = append (cliArgs , "--dev" )
177+ if cmd .String ("log-level" ) == "" {
178+ cliArgs = append (cliArgs , "--log-level" , "DEBUG" )
179+ }
164180 }
165181
166182 cfg := AgentStartConfig {
167183 Dir : projectDir ,
168184 Entrypoint : entrypoint ,
169185 ProjectType : projectType ,
186+ RuntimeArgs : forwardedArgs (cmd ),
170187 CLIArgs : cliArgs ,
171188 ForwardOutput : os .Stdout ,
172189 }
0 commit comments