From af88310f313da36a3fb0a02844460a3eb32d9657 Mon Sep 17 00:00:00 2001 From: lawrence3699 Date: Fri, 17 Apr 2026 14:47:11 +1000 Subject: [PATCH] fix(agents): error on failed tts tool synthesis --- src/agents/tools/tts-tool.test.ts | 13 +++++++++++++ src/agents/tools/tts-tool.ts | 10 +--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/agents/tools/tts-tool.test.ts b/src/agents/tools/tts-tool.test.ts index f559166d7bb..7faa0790950 100644 --- a/src/agents/tools/tts-tool.test.ts +++ b/src/agents/tools/tts-tool.test.ts @@ -41,4 +41,17 @@ describe("createTtsTool", () => { }); expect(JSON.stringify(result.content)).not.toContain("MEDIA:"); }); + + it("throws when synthesis fails so the agent records a tool error", async () => { + textToSpeechSpy.mockResolvedValue({ + success: false, + error: "TTS conversion failed: openai: not configured", + }); + + const tool = createTtsTool(); + + await expect(tool.execute("call-1", { text: "hello" })).rejects.toThrow( + "TTS conversion failed: openai: not configured", + ); + }); }); diff --git a/src/agents/tools/tts-tool.ts b/src/agents/tools/tts-tool.ts index 38ac7b4e65f..ba37c73e0c4 100644 --- a/src/agents/tools/tts-tool.ts +++ b/src/agents/tools/tts-tool.ts @@ -49,15 +49,7 @@ export function createTtsTool(opts?: { }; } - return { - content: [ - { - type: "text", - text: result.error ?? "TTS conversion failed", - }, - ], - details: { error: result.error }, - }; + throw new Error(result.error ?? "TTS conversion failed"); }, }; }