feat(console): console CLI runner + AgentsConsole session wiring (text mode)#1706
feat(console): console CLI runner + AgentsConsole session wiring (text mode)#1706toubatbrian wants to merge 1 commit into
Conversation
Add the `console` CLI subcommand and an in-process console runner that lets a local broker (e.g. the LiveKit CLI `lk session` daemon) drive a Node agent over TCP. `runConsole` loads the agent, opens a `TcpSessionTransport` to `--connect-addr`, sets up the `AgentsConsole` singleton, and runs the agent entrypoint in-process (mirroring python's `_run_tcp_console` / `JobExecutorType.THREAD`). `AgentSession._startImpl` now wires its `SessionHost` from the `AgentsConsole` singleton when console mode is active, and `JobContext` gained fake-job support (`isFakeJob`, no-op connect/deleteRoom/recording) so a console job without a backing LiveKit room behaves correctly. Ships text-mode console; audio-mode session wiring is a follow-up. Co-authored-by: Cursor <cursoragent@cursor.com>
🦋 Changeset detectedLatest commit: 80f07b4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 34 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 80f07b4e63
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| const consoleInst = AgentsConsole.getInstance(); | ||
| consoleInst.enabled = true; | ||
| consoleInst.record = record; |
There was a problem hiding this comment.
Wire the console record flag into session reporting
When running agents console --record, this assignment is the only place the flag is propagated, but AgentsConsole.record is never read elsewhere and the fake Job still leaves enableRecording at its default false. Since AgentSession.start() defaults record from ctx.job.enableRecording, the option advertised as saving a local session report has no effect for users who rely on the CLI flag.
Useful? React with 👍 / 👎.
| await transport.close(); | ||
| await room.disconnect(); |
There was a problem hiding this comment.
Run job shutdown callbacks in console mode
The console runner mirrors the job lifecycle but exits the finally block without awaiting ctx.shutdownCallbacks. Normal jobs execute these callbacks after _onSessionEnd() in ipc/job_proc_lazy_main.ts; console agents or SDK helpers that call JobContext.addShutdownCallback() will therefore leak resources or leave background work running on SIGINT/SIGTERM instead of being closed.
Useful? React with 👍 / 👎.
| } | ||
|
|
||
| async function loadAgent(agentPath: string): Promise<Agent> { | ||
| const module = await import(pathToFileURL(agentPath).pathname); |
There was a problem hiding this comment.
🟡 Dynamic import uses URL-encoded pathname instead of full file URL, breaking paths with spaces
loadAgent at agents/src/console.ts:31 uses pathToFileURL(agentPath).pathname which yields a URL-encoded path like /home/user/my%20agent/file.ts. Node.js import() treats bare absolute paths as literal file paths (no percent-decoding), so it would look for a file with %20 in the name rather than a space. The correct approach is pathToFileURL(agentPath).href which gives file:///home/user/my%20agent/file.ts — Node.js recognizes the file:// protocol and correctly decodes percent-encoded characters. Note that agents/src/download.ts:148 correctly uses .href, while agents/src/ipc/job_proc_lazy_main.ts:207 has the same pre-existing bug.
| const module = await import(pathToFileURL(agentPath).pathname); | |
| const module = await import(pathToFileURL(agentPath).href); |
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
Third and final PR in the series that ports the TCP console/session machinery from python
livekit-agentsso a local broker (e.g. the LiveKit CLIlk sessiondaemon) can drive a Node agent over TCP. Stacked on #1694 (console audio IO).This PR adds the glue that actually runs an agent in console mode:
agents/src/console.ts(runConsole) — an in-process runner that bypasses the websocket worker and ProcPool entirely. It loads the agent, opens aTcpSessionTransportto--connect-addr, sets up theAgentsConsolesingleton, fabricates afakeJobRunningJobInfo/JobContext, and runs the agent entrypoint on the current event loop. This mirrors python's_run_tcp_console, which relies onJobExecutorType.THREADto keep the job in-process so theAgentsConsolesingleton is shared with the agent'sAgentSession. (JS has no in-process/THREAD executor andAgentServerrequires WS credentials, so a self-contained runner is the clean equivalent.)AgentsConsolesingleton (voice/console_io.ts) — carries the console transport + audio bridges from the runner into theAgentSession.AgentSession._startImplnow acquires console IO and builds itsSessionHostfrom the singleton when console mode is active, instead of the RoomIO path.JobContextfake-job support —isFakeJob, plus no-opconnect/deleteRoom/initRecordingand a guarded_onSessionEnd(no cloud upload / URL parse) so a console job without a backing LiveKit room behaves correctly.consoleCLI subcommand —console --connect-addr <host:port> [--record].Ships text mode (the agent is driven over the session transport: text in via
runInput, events out). Audio-mode session wiring is intentionally a follow-up — the PR #1694 audio bridges are constructed and routed at the transport level, but not attached to the session pipeline yet.Test plan
pnpm build:agentsgreenAgentsConsole.acquireIo(text-mode IO unset, double-acquire guard, singleton);JobContextfake-job guards (isFakeJob, no-op connect/deleteRoom/initRecording)agent_session/agent_activity/remote_session/console_io/jobsuites (23 + 10 passing)Made with Cursor