From 78c0a5d44cedb3cb26597cc029d9899fcd2bb0fd Mon Sep 17 00:00:00 2001 From: Alex McGraw Date: Tue, 13 Jan 2026 16:52:26 -0600 Subject: [PATCH] Updating ask sage models to support tool calling. Plan and Agent mode now work correctly. --- core/llm/llms/Asksage.ts | 55 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/core/llm/llms/Asksage.ts b/core/llm/llms/Asksage.ts index 93d2016c3..d00222e54 100644 --- a/core/llm/llms/Asksage.ts +++ b/core/llm/llms/Asksage.ts @@ -4,6 +4,8 @@ import { CompletionOptions, LLMOptions, TextMessagePart, + Tool, + ToolCallDelta, } from "../../index.js"; import { BaseLLM } from "../index.js"; @@ -61,15 +63,26 @@ interface AskSageRequestArgs { file?: unknown; } +interface AskSageToolCall { + id: string; + type: "function"; + function: { + name: string; + arguments: string; + }; +} + interface AskSageResponse { text?: string; answer?: string; message?: string; status?: number | string; response?: unknown; + tool_calls?: AskSageToolCall[]; choices?: Array<{ message?: { content?: string; + tool_calls?: AskSageToolCall[]; }; }>; } @@ -185,6 +198,17 @@ class Asksage extends BaseLLM { }; } + protected _convertToolToAskSageTool(tool: Tool): AskSageTool { + return { + type: tool.type, + function: { + name: tool.function.name, + description: tool.function.description, + parameters: tool.function.parameters, + }, + }; + } + protected _convertArgs( options: AskSageCompletionOptions, messages: ChatMessage[], @@ -196,6 +220,14 @@ class Asksage extends BaseLLM { formattedMessage = messages.map(this._convertMessage); } + // Convert standard tools to AskSage format, or use askSageTools if provided + const tools = + options.tools?.map((tool) => this._convertToolToAskSageTool(tool)) ?? + options.askSageTools; + + // Map standard toolChoice to AskSage format, or use askSageToolChoice if provided + const toolChoice = options.toolChoice ?? options.askSageToolChoice; + const args: AskSageRequestArgs = { message: formattedMessage, model: options.model, @@ -207,10 +239,8 @@ class Asksage extends BaseLLM { options.systemPrompt ?? process.env.ASKSAGE_SYSTEM_PROMPT ?? "You are an expert software developer. You give helpful and concise responses.", - tools: options.askSageTools, - // enabled_mcp_tools: options.enabledMcpTools as string[] | undefined, - // tools_to_execute: options.toolsToExecute as string[] | undefined, - tool_choice: options.askSageToolChoice, + tools, + tool_choice: toolChoice, reasoning_effort: options.reasoningEffort as | "low" | "medium" @@ -391,6 +421,22 @@ class Asksage extends BaseLLM { const data = (await response.json()) as AskSageResponse; + // Extract tool calls from response (check both top-level and choices format) + const rawToolCalls = + data.tool_calls || data.choices?.[0]?.message?.tool_calls; + + // Convert to ToolCallDelta format if present + const toolCalls: ToolCallDelta[] | undefined = rawToolCalls?.map( + (tc) => ({ + id: tc.id, + type: tc.type, + function: { + name: tc.function.name, + arguments: tc.function.arguments, + }, + }), + ); + const assistantMessage: ChatMessage = { role: "assistant", content: @@ -399,6 +445,7 @@ class Asksage extends BaseLLM { data.message || data.choices?.[0]?.message?.content || "", + ...(toolCalls && toolCalls.length > 0 ? { toolCalls } : {}), }; yield assistantMessage;