From 5eb0eb7781f8ff2396ef6fa1feb16ced7a3d08cc Mon Sep 17 00:00:00 2001 From: theomonnom Date: Mon, 18 May 2026 03:39:08 +0000 Subject: [PATCH] feat(inference): add LLM updateOptions --- .changeset/live-model-swaps.md | 5 +++++ agents/src/inference/llm.ts | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 .changeset/live-model-swaps.md diff --git a/.changeset/live-model-swaps.md b/.changeset/live-model-swaps.md new file mode 100644 index 000000000..ff2b2e665 --- /dev/null +++ b/.changeset/live-model-swaps.md @@ -0,0 +1,5 @@ +--- +'@livekit/agents': patch +--- + +Add `updateOptions` support to inference LLM for live model swaps. diff --git a/agents/src/inference/llm.ts b/agents/src/inference/llm.ts index 3434e496c..01b9573a8 100644 --- a/agents/src/inference/llm.ts +++ b/agents/src/inference/llm.ts @@ -247,6 +247,27 @@ export class LLM extends llm.LLM { return new LLM({ model: modelString }); } + /** + * Update LLM configuration options used by the next chat call. + * + * `modelOptions` replaces the persistent options object instead of merging; + * pass `{}` to clear it. + */ + updateOptions({ + model, + modelOptions, + }: { + model?: LLMModels; + modelOptions?: ChatCompletionOptions; + }): void { + if (model !== undefined) { + this.opts.model = model; + } + if (modelOptions !== undefined) { + this.opts.modelOptions = { ...modelOptions }; + } + } + chat({ chatCtx, toolCtx,