Skip to content

Commit 23e2f7a

Browse files
committed
fix minor bugs & improve stabilities
1 parent 9f3febb commit 23e2f7a

4 files changed

Lines changed: 41 additions & 39 deletions

File tree

agents/src/cli.ts

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,16 @@ const runServer = async (args: CliArgs) => {
7777
* ```
7878
*/
7979
export const runApp = (opts: ServerOptions) => {
80+
const logLevelOption = (defaultLevel: string) =>
81+
new Option('--log-level <level>', 'Set the logging level')
82+
.choices(['trace', 'debug', 'info', 'warn', 'error', 'fatal'])
83+
.default(defaultLevel)
84+
.env('LOG_LEVEL');
85+
8086
const program = new Command()
8187
.name('agents')
8288
.description('LiveKit Agents CLI')
8389
.version(version)
84-
.addOption(
85-
new Option('--log-level <level>', 'Set the logging level')
86-
.choices(['trace', 'debug', 'info', 'warn', 'error', 'fatal'])
87-
.default('info')
88-
.env('LOG_LEVEL'),
89-
)
9090
.addOption(
9191
new Option('--url <string>', 'LiveKit server or Cloud project websocket URL').env(
9292
'LIVEKIT_URL',
@@ -120,13 +120,15 @@ export const runApp = (opts: ServerOptions) => {
120120
program
121121
.command('start')
122122
.description('Start the worker in production mode')
123-
.action(() => {
124-
const options = program.optsWithGlobals();
125-
opts.wsURL = options.url || opts.wsURL;
126-
opts.apiKey = options.apiKey || opts.apiKey;
127-
opts.apiSecret = options.apiSecret || opts.apiSecret;
128-
opts.logLevel = options.logLevel || opts.logLevel;
129-
opts.workerToken = options.workerToken || opts.workerToken;
123+
.addOption(logLevelOption('info'))
124+
.action((...[, command]) => {
125+
const globalOptions = program.optsWithGlobals();
126+
const commandOptions = command.opts();
127+
opts.wsURL = globalOptions.url || opts.wsURL;
128+
opts.apiKey = globalOptions.apiKey || opts.apiKey;
129+
opts.apiSecret = globalOptions.apiSecret || opts.apiSecret;
130+
opts.logLevel = commandOptions.logLevel;
131+
opts.workerToken = globalOptions.workerToken || opts.workerToken;
130132
runServer({
131133
opts,
132134
production: true,
@@ -137,19 +139,14 @@ export const runApp = (opts: ServerOptions) => {
137139
program
138140
.command('dev')
139141
.description('Start the worker in development mode')
140-
.addOption(
141-
new Option('--log-level <level>', 'Set the logging level')
142-
.choices(['trace', 'debug', 'info', 'warn', 'error', 'fatal'])
143-
.default('debug')
144-
.env('LOG_LEVEL'),
145-
)
142+
.addOption(logLevelOption('debug'))
146143
.action((...[, command]) => {
147144
const globalOptions = program.optsWithGlobals();
148145
const commandOptions = command.opts();
149146
opts.wsURL = globalOptions.url || opts.wsURL;
150147
opts.apiKey = globalOptions.apiKey || opts.apiKey;
151148
opts.apiSecret = globalOptions.apiSecret || opts.apiSecret;
152-
opts.logLevel = commandOptions.logLevel || globalOptions.logLevel || opts.logLevel;
149+
opts.logLevel = commandOptions.logLevel;
153150
opts.workerToken = globalOptions.workerToken || opts.workerToken;
154151
runServer({
155152
opts,
@@ -163,19 +160,14 @@ export const runApp = (opts: ServerOptions) => {
163160
.description('Connect to a specific room')
164161
.requiredOption('--room <string>', 'Room name to connect to')
165162
.option('--participant-identity <string>', 'Identity of user to listen to')
166-
.addOption(
167-
new Option('--log-level <level>', 'Set the logging level')
168-
.choices(['trace', 'debug', 'info', 'warn', 'error', 'fatal'])
169-
.default('debug')
170-
.env('LOG_LEVEL'),
171-
)
163+
.addOption(logLevelOption('info'))
172164
.action((...[, command]) => {
173165
const globalOptions = program.optsWithGlobals();
174166
const commandOptions = command.opts();
175167
opts.wsURL = globalOptions.url || opts.wsURL;
176168
opts.apiKey = globalOptions.apiKey || opts.apiKey;
177169
opts.apiSecret = globalOptions.apiSecret || opts.apiSecret;
178-
opts.logLevel = commandOptions.logLevel || globalOptions.logLevel || opts.logLevel;
170+
opts.logLevel = commandOptions.logLevel;
179171
opts.workerToken = globalOptions.workerToken || opts.workerToken;
180172
runServer({
181173
opts,
@@ -189,12 +181,7 @@ export const runApp = (opts: ServerOptions) => {
189181
program
190182
.command('download-files')
191183
.description('Download plugin dependency files')
192-
.addOption(
193-
new Option('--log-level <level>', 'Set the logging level')
194-
.choices(['trace', 'debug', 'info', 'warn', 'error', 'fatal'])
195-
.default('debug')
196-
.env('LOG_LEVEL'),
197-
)
184+
.addOption(logLevelOption('debug'))
198185
.action((...[, command]) => {
199186
const commandOptions = command.opts();
200187
initializeLogger({ pretty: true, level: commandOptions.logLevel });

agents/src/ipc/job_proc_lazy_main.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ import type { IPCMessage } from './message.js';
1515

1616
const ORPHANED_TIMEOUT = 15 * 1000;
1717

18+
const safeSend = (msg: IPCMessage): boolean => {
19+
if (process.connected && process.send) {
20+
process.send(msg);
21+
return true;
22+
}
23+
return false;
24+
};
25+
1826
type JobTask = {
1927
ctx: JobContext;
2028
task: Promise<void>;
@@ -50,7 +58,10 @@ class InfClient implements InferenceExecutor {
5058

5159
async doInference(method: string, data: unknown): Promise<unknown> {
5260
const requestId = shortuuid('inference_job_');
53-
process.send!({ case: 'inferenceRequest', value: { requestId, method, data } });
61+
if (!safeSend({ case: 'inferenceRequest', value: { requestId, method, data } })) {
62+
throw new Error('IPC channel closed');
63+
}
64+
5465
this.#requests[requestId] = new PendingInference();
5566
const resp = await this.#requests[requestId]!.promise;
5667
if (resp.error) {
@@ -117,7 +128,7 @@ const startJob = (
117128
await once(closeEvent, 'close').then((close) => {
118129
logger.debug('shutting down');
119130
shutdown = true;
120-
process.send!({ case: 'exiting', value: { reason: close[1] } });
131+
safeSend({ case: 'exiting', value: { reason: close[1] } });
121132
});
122133

123134
// Close the primary agent session if it exists
@@ -139,7 +150,7 @@ const startJob = (
139150
logger.error({ error }, 'error while shutting down the job'),
140151
);
141152

142-
process.send!({ case: 'done' });
153+
safeSend({ case: 'done', value: undefined });
143154
joinFuture.resolve();
144155
})();
145156

@@ -199,7 +210,7 @@ const startJob = (
199210
logger.debug('initializing job runner');
200211
await agent.prewarm(proc);
201212
logger.debug('job runner initialized');
202-
process.send({ case: 'initializeResponse' });
213+
safeSend({ case: 'initializeResponse', value: undefined });
203214

204215
let job: JobTask | undefined = undefined;
205216
const closeEvent = new EventEmitter();
@@ -213,7 +224,7 @@ const startJob = (
213224
switch (msg.case) {
214225
case 'pingRequest': {
215226
orphanedTimeout.refresh();
216-
process.send!({
227+
safeSend({
217228
case: 'pongResponse',
218229
value: { lastTimestamp: msg.value.timestamp, timestamp: Date.now() },
219230
});

agents/src/voice/agent_activity.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ export class AgentActivity implements RecognitionHooks {
342342
minEndpointingDelay: this.agentSession.options.minEndpointingDelay,
343343
maxEndpointingDelay: this.agentSession.options.maxEndpointingDelay,
344344
rootSpanContext: this.agentSession.rootSpanContext,
345+
sttModel: this.stt?.label,
346+
sttProvider: this.getSttProvider(),
347+
getLinkedParticipant: () => this.agentSession._roomIO?.linkedParticipant,
345348
});
346349
this.audioRecognition.start();
347350
this.started = true;

examples/src/basic_agent_task.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
llm,
1212
voice,
1313
} from '@livekit/agents';
14+
import * as openai from '@livekit/agents-plugin-openai';
1415
import * as silero from '@livekit/agents-plugin-silero';
1516
import { fileURLToPath } from 'node:url';
1617
import { z } from 'zod';
@@ -116,7 +117,7 @@ export default defineAgent({
116117
const session = new voice.AgentSession({
117118
vad: ctx.proc.userData.vad as silero.VAD,
118119
stt: new inference.STT({ model: 'deepgram/nova-3' }),
119-
llm: new inference.LLM({ model: 'openai/gpt-5.2' }),
120+
llm: new openai.responses.LLM(),
120121
tts: new inference.TTS({
121122
model: 'cartesia/sonic-3',
122123
voice: '9626c31c-bec5-4cca-baa8-f8ba9e84c8bc',

0 commit comments

Comments
 (0)