{"record":{"id":"2c9de6bdbf0fd259","repo":"mastra-ai/mastra","slug":"mastra-livekit-set-exactly-one-reply-generator","errorCode":null,"errorMessage":"@mastra/livekit: set exactly one reply generator — `generate`, `agent`, or `workflow` — not a combination.","messagePattern":"@mastra/livekit: set exactly one reply generator — `generate`, `agent`, or `workflow` — not a combination\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"integrations/livekit/src/worker.ts","lineNumber":783,"sourceCode":" * import { fileURLToPath } from 'node:url';\n * import { createLiveKitWorker, runLiveKitWorker } from '@mastra/livekit/worker';\n * import { mastra } from './index';\n *\n * export default createLiveKitWorker({\n *   mastra,\n *   stt: 'deepgram/nova-3',\n *   tts: 'cartesia/sonic-3',\n *   turnDetection: 'multilingual',\n * });\n *\n * if (process.argv[1] === fileURLToPath(import.meta.url)) {\n *   runLiveKitWorker({ entry: import.meta.url, agentName: 'mastra-voice' });\n * }\n * ```\n */\nexport function createLiveKitWorker(options: CreateLiveKitWorkerOptions) {\n  if (options.generate && (options.agent || options.workflow)) {\n    throw new Error(\n      '@mastra/livekit: set exactly one reply generator — `generate`, `agent`, or `workflow` — not a combination.',\n    );\n  }\n  if (options.agent && options.workflow) {\n    throw new Error(\n      '@mastra/livekit: set `agent` or `workflow`, not both — they are mutually exclusive reply generators.',\n    );\n  }\n  if (options.workflow && !options.workflowInput) {\n    throw new Error(\n      '@mastra/livekit: `workflowInput` is required when `workflow` is set. Map the turn into the ' +\n        'workflow inputData, e.g. workflowInput: ({ chatCtx }) => ({ history: chatContextToMessages(chatCtx) }).',\n    );\n  }\n  if (options.generate && options.configuration?.endCall) {\n    throw new Error(\n      '@mastra/livekit: `configuration.endCall` has no effect with `generate` — the worker cannot observe ' +\n        'tool calls from a custom reply generator. Detect the end-call tool inside your generator and call ' +","sourceCodeStart":765,"sourceCodeEnd":801,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/integrations/livekit/src/worker.ts#L765-L801","documentation":"createLiveKitWorker accepts three mutually exclusive ways to produce a voice reply: `generate` (custom generator), `agent` (Mastra agent), or `workflow` (Mastra workflow). The library throws this when `generate` is set together with `agent` and/or `workflow`, because it cannot decide which generator to run. Exactly one reply generator must be configured.","triggerScenarios":"Calling createLiveKitWorker({ generate: ..., agent: someAgent }) or createLiveKitWorker({ generate: ..., workflow: someWorkflow }) — any combination where options.generate && (options.agent || options.workflow).","commonSituations":"Migrating from the `generate` callback to a higher-level `agent` option but forgetting to delete `generate`; copying a sample config that sets both; spreading two partial option objects into one worker config.","solutions":["Keep only one reply generator: delete `generate` if you now use `agent` or `workflow` (or vice versa).","If you need custom logic plus an agent/workflow, move that logic into the `generate` function itself or into the workflow steps, keeping a single option."],"exampleFix":"// before\ncreateLiveKitWorker({ generate: myGenerate, agent: myAgent });\n// after\ncreateLiveKitWorker({ agent: myAgent });","handlingStrategy":"validation","validationCode":"const generatorCount = [!!options.generate, !!options.agent, !!options.workflow].filter(Boolean).length;\nif (generatorCount !== 1) throw new Error('configure exactly one of generate/agent/workflow before creating the worker');","typeGuard":"function hasSingleGenerator(o: { generate?: unknown; agent?: unknown; workflow?: unknown }): boolean {\n  return [o.generate, o.agent, o.workflow].filter(v => v != null).length === 1;\n}","tryCatchPattern":"try {\n  const worker = createLiveKitWorker(options);\n} catch (e) {\n  if ((e as Error).message.includes('exactly one reply generator')) {\n    console.error('Fix worker config: keep only one of generate/agent/workflow');\n  } else throw e;\n}","preventionTips":["Build the worker options from a discriminated union so only one generator can be set at the type level","Never spread multiple partial config objects into createLiveKitWorker","Remove the old generator option when migrating between generate/agent/workflow"],"tags":["configuration","validation","livekit","worker"],"backgroundTag":"mutually-exclusive-options","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}