Open nbsp opened 2 weeks ago
Hi @nbsp, I am having problem even when the type
already set to module
.
"@livekit/agents": "^0.4.3",
"@livekit/agents-plugin-openai": "^0.4.3",
Hi @nbsp, I am having problem even when the
type
already set tomodule
."@livekit/agents": "^0.4.3", "@livekit/agents-plugin-openai": "^0.4.3",
we're currently working on making agents-js into a dual package, which would allow you to integrate Agents directly with CJS code natively
@tanys123 if you encounter this error in an ESM exclusive environment (with type: module set), could you post the stack trace of the error?
@lukasIO
file:///.../node_modules/.pnpm/@livekit+agents@0.4.3/node_modules/@livekit/agents/dist/log.js:9
throw new TypeError('logger not initialized. did you forget to run initializeLogger()?');
^
TypeError: logger not initialized. did you forget to run initializeLogger()?
at log (file:///.../node_modules/.pnpm/@livekit+agents@0.4.3/node_modules/@livekit/agents/dist/log.js:9:15)
at <instance_members_initializer> (file:///.../node_modules/.pnpm/@livekit+agents-plugin-openai@0.4.3_zod@3.23.8/node_modules/@livekit/agents-plugin-openai/dist/realtime/realtime_model.js:285:15)
at new RealtimeSession (file:///.../node_modules/.pnpm/@livekit+agents-plugin-openai@0.4.3_zod@3.23.8/node_modules/@livekit/agents-plugin-openai/dist/realtime/realtime_model.js:290:9)
at RealtimeModel.session (file:///.../node_modules/.pnpm/@livekit+agents-plugin-openai@0.4.3_zod@3.23.8/node_modules/@livekit/agents-plugin-openai/dist/realtime/realtime_model.js:266:28)
at file:///.../node_modules/.pnpm/@livekit+agents@0.4.4/node_modules/@livekit/agents/dist/multimodal/multimodal_agent.js:139:40
is this still run using tsx, or directly with Node?
Directly with Node
My node.js multimodal realtime chat app works fine in dev, but I get this same error in production after I pushed it to AWS Elastic Container Service (ECS).
For some reason, the app works fine locally when I run both node dist/agent.js dev
and node dist/agent.js start
in the terminal. But in ECS, even though it starts up fine (I have some logs that shows it indeed calls node dist/agent.js start
), I get the following error when I try to connect:
logger not initialized. did you forget to run initializeLogger()?
I looked into the node_modules and saw that this error is in /node_modules/.pnpm/@livekit+agents@0.4.3/node_modules/@livekit/agents/dist/log.js
The type
is set to module
in package.json
. Here are my dependencies:
"@livekit/agents": "^0.4.1",
"@livekit/agents-plugin-openai": "^0.4.1",
I noticed a few of the initializeLogger()
calls within an async
function are without await
.
I'm fairly disappointed. I wanted to share this with a few early customers today. If there's a quick workaround, please let me know!
The issue is that the logger uses module level state as a kind-of singleton pattern. As the agent plugins are published as separate packages, the logger state crosses package boundaries which can easily break down if there's anything causing the individual packages to use your own copy of @livekit/agents
, particularly if you're using pnpm or yarn.
@creightontaylor if you're in that boat you could try setting noHoist
on each @livekit/agents* package that you're trying to use:
// package.json
...
"pnpm": {
"packageExtensions": {
"@livekit/agents": {
"nohoist": true
},
"@livekit/agents-plugin-openai": {
"nohoist": true
},
"@livekit/agents-plugin-silero": {
"nohoist": true
}
}
}
the issue directly with Node has been fixed in https://github.com/livekit/agents-js/pull/170 by using peerDependencies
. for tsx/CJS this still remains an issue
@nbsp I upgraded the packages:
"@livekit/agents": "^0.4.5",
"@livekit/agents-plugin-openai": "^0.6.0",
And it now works in production! It's alive. It's ALIIIIIIVE! 😄 😄 😄
we are aware of a bug affecting users of the tsx runner with Agents. specifically, it affects those who define their agent in files read as CommonJS.
if you don't use tsx/CJS and are running into this issue:
^0.4.5
(^0.6.0
for OpenAI)the fix
set
"type": "module"
in your package.json, or rename the file to explicitly use ESM (e.g.agent.ts
⇒agent.mts
).