Skip to content

Commit 23c96e1

Browse files
fix(session): launch Python agents via python -m livekit.agents
The session daemon spawned Python agents with `python <entry> console --connect-addr <addr>`, which routes through the legacy cli.run_app() click CLI. That CLI has no --connect-addr option, so the agent exited with status 2 before connecting and the Session E2E test failed ("agent exited before connecting: exit status 2"). The merge of main into this branch kept #868's direct-entry buildAgentCommand and dropped main's `python -m livekit.agents SUBCOMMAND ENTRYPOINT FLAGS` invocation, where --connect-addr actually lives. Restore the module invocation for the Python branch (Node keeps direct-entry, which is its only console entrypoint). Verified end to end against livekit-agents 1.6.4 with the echo-agent fixture. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent d15ec7c commit 23c96e1

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

cmd/lk/simulate_subprocess.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,13 @@ type AgentStartConfig struct {
221221
}
222222

223223
// buildAgentCommand resolves the interpreter and argv for an agent subprocess,
224-
// branching on project type. Python: `<python> <runtime-args> <entry> <args>`
225-
// (uv prefixes `run python`). Node: `node [--experimental-strip-types]
224+
// branching on project type. Node: `node [--experimental-strip-types]
226225
// <runtime-args> <entry> <args>`, where the type-stripping flag lets a `.ts`
227-
// entrypoint run without a build.
226+
// entrypoint run without a build. Python: `<python> <runtime-args> -m
227+
// livekit.agents <subcommand> <entry> <flags>` — the framework discovers the
228+
// AgentServer from the entrypoint and drives the thin CLI. The legacy
229+
// cli.run_app() console exposes no --connect-addr; only the module entrypoint
230+
// does, so the daemon's console launch must go through `-m livekit.agents`.
228231
func buildAgentCommand(cfg AgentStartConfig) (string, []string, error) {
229232
if cfg.ProjectType.IsNode() {
230233
nodeBin, err := findNodeBinary()
@@ -248,11 +251,20 @@ func buildAgentCommand(cfg AgentStartConfig) (string, []string, error) {
248251
if err != nil {
249252
return "", nil, err
250253
}
251-
args := make([]string, 0, len(prefixArgs)+len(cfg.RuntimeArgs)+len(cfg.CLIArgs)+1)
254+
// python [runtime-args] -m livekit.agents SUBCOMMAND ENTRYPOINT FLAGS: the
255+
// framework discovers the AgentServer from the entrypoint and drives the
256+
// thin CLI.
257+
args := make([]string, 0, len(prefixArgs)+len(cfg.RuntimeArgs)+len(cfg.CLIArgs)+3)
252258
args = append(args, prefixArgs...)
253259
args = append(args, cfg.RuntimeArgs...)
254-
args = append(args, cfg.Entrypoint)
255-
args = append(args, cfg.CLIArgs...)
260+
args = append(args, "-m", "livekit.agents")
261+
if len(cfg.CLIArgs) > 0 {
262+
args = append(args, cfg.CLIArgs[0]) // subcommand: start | console
263+
args = append(args, cfg.Entrypoint) // entrypoint positional (server discovery)
264+
args = append(args, cfg.CLIArgs[1:]...)
265+
} else {
266+
args = append(args, cfg.Entrypoint)
267+
}
256268
return pythonBin, args, nil
257269
}
258270

0 commit comments

Comments
 (0)