@@ -127,8 +127,8 @@ type AgentStartConfig struct {
127127 Dir string
128128 Entrypoint string
129129 ProjectType agentfs.ProjectType
130- CLIArgs []string // e.g. ["start", "--url", "..."] or ["console", "--connect-addr", addr]
131- Env []string // e.g. ["LIVEKIT_AGENT_NAME =x"] or nil
130+ CLIArgs []string // subcommand first, then flags: ["start", "--url", "..."] or ["console", "--connect-addr", addr]
131+ Env []string // e.g. ["LIVEKIT_AGENT_NAME_OVERRIDE =x"] or nil
132132 ReadySignal string // substring to scan for in output (e.g. "registered worker"), empty to skip
133133 ForwardOutput io.Writer // if set, forward each output line to this writer
134134}
@@ -140,8 +140,19 @@ func startAgent(cfg AgentStartConfig) (*AgentProcess, error) {
140140 return nil , err
141141 }
142142
143- args := append (prefixArgs , cfg .Entrypoint )
144- args = append (args , cfg .CLIArgs ... )
143+ // Launch via the framework CLI module rather than running the user's file
144+ // directly: python -m livekit.agents SUBCOMMAND ENTRYPOINT FLAGS. The framework
145+ // discovers the AgentServer from the entrypoint and drives the thin CLI. Requires a
146+ // livekit-agents that supports start/console under -m livekit.agents; older versions
147+ // only expose download-files there.
148+ args := append (prefixArgs , "-m" , "livekit.agents" )
149+ if len (cfg .CLIArgs ) > 0 {
150+ args = append (args , cfg .CLIArgs [0 ]) // subcommand: start | console
151+ args = append (args , cfg .Entrypoint ) // entrypoint positional (server discovery)
152+ args = append (args , cfg .CLIArgs [1 :]... )
153+ } else {
154+ args = append (args , cfg .Entrypoint )
155+ }
145156 cmd := exec .Command (pythonBin , args ... )
146157 setProcAttr (cmd )
147158 cmd .Dir = cfg .Dir
0 commit comments