diff --git a/lib/tasks/llm/llms/ultravox_s2s.js b/lib/tasks/llm/llms/ultravox_s2s.js index 1823c2ac..6d0d621d 100644 --- a/lib/tasks/llm/llms/ultravox_s2s.js +++ b/lib/tasks/llm/llms/ultravox_s2s.js @@ -32,12 +32,14 @@ class TaskLlmUltravox_S2S extends Task { this.auth = this.parent.auth; this.connectionOptions = this.parent.connectOptions; - const {apiKey} = this.auth || {}; + const {apiKey, agent_id} = this.auth || {}; if (!apiKey) throw new Error('auth.apiKey is required for Vendor: Ultravox'); this.apiKey = apiKey; + this.agentId = agent_id; this.actionHook = this.data.actionHook; this.eventHook = this.data.eventHook; this.toolHook = this.data.toolHook; + this.llmOptions = this.data.llmOptions || {}; this.results = { completionReason: 'normal conversation end' @@ -105,24 +107,29 @@ class TaskLlmUltravox_S2S extends Task { } ); // merge with any existing tools - this.data.llmOptions.selectedTools = [ + this.llmOptions.selectedTools = [ ...convertedTools, - ...(this.data.llmOptions.selectedTools || []) + ...(this.llmOptions.selectedTools || []) ]; } const payload = { - ...this.data.llmOptions, - model: this.model, + ...this.llmOptions, + ...(!this.agentId && { + model: this.model, + }), medium: { - ...(this.data.llmOptions.medium || {}), + ...(this.llmOptions.medium || {}), serverWebSocket: { inputSampleRate: 8000, outputSampleRate: 8000, } } }; - const {statusCode, body} = await request('https://api.ultravox.ai/api/calls', { + const baseUrl = 'https://api.ultravox.ai'; + const url = this.agentId ? + `${baseUrl}/api/agents/${this.agentId}/calls` : `${baseUrl}/api/calls`; + const {statusCode, body} = await request(url, { method: 'POST', headers: { 'Content-Type': 'application/json',