diff --git a/src/lib/server/textGeneration/index.ts b/src/lib/server/textGeneration/index.ts index 37538ef74d4..86753c99e05 100644 --- a/src/lib/server/textGeneration/index.ts +++ b/src/lib/server/textGeneration/index.ts @@ -19,6 +19,8 @@ import { generate } from "./generate"; import { mergeAsyncGenerators } from "$lib/utils/mergeAsyncGenerators"; import type { TextGenerationContext } from "./types"; import type { ToolResult } from "$lib/types/Tool"; +import { toolHasName } from "../tools/utils"; +import directlyAnswer from "../tools/directlyAnswer"; export async function* textGeneration(ctx: TextGenerationContext) { yield* mergeAsyncGenerators([ @@ -61,7 +63,8 @@ async function* textGenerationWithoutTitle( if (model.tools && !conv.assistantId) { const tools = pickTools(toolsPreference, Boolean(assistant)); - toolResults = yield* runTools(ctx, tools, preprompt); + const toolCallsRequired = tools.some((tool) => !toolHasName(directlyAnswer.name, tool)); + if (toolCallsRequired) toolResults = yield* runTools(ctx, tools, preprompt); } const processedMessages = await preprocessMessages(messages, webSearchResult, convId);