From 8e342045ebd395b8c3c6a9a17b41e88b7a3a5932 Mon Sep 17 00:00:00 2001 From: Catherine Renelle <32781029+catrenelle@users.noreply.github.com> Date: Wed, 11 Feb 2026 20:23:10 -0500 Subject: [PATCH] Skip tool-use nudge when page context provides data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The nudge forced the AI to call a tool even when the answer was already in the page context (e.g. Sarku transactions visible on the Transactions page). This caused the model to pick an unrelated tool. Now the nudge also checks for page context — if the current page has data attached, the model is allowed to answer from it directly. Co-Authored-By: Claude Opus 4.6 --- src/Purrse.Api/Services/ChatService.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Purrse.Api/Services/ChatService.cs b/src/Purrse.Api/Services/ChatService.cs index 3d3d685..0a94c0c 100644 --- a/src/Purrse.Api/Services/ChatService.cs +++ b/src/Purrse.Api/Services/ChatService.cs @@ -251,10 +251,10 @@ public class ChatService : IChatService var rawContent = response?.Message?.Content ?? "I'm sorry, I couldn't process that request."; // If the model responded without calling any tools on the first attempt - // AND there are no prior tool results in the conversation, it likely - // fabricated data. Nudge it to use tools. Skip the nudge when prior - // tool results exist — the model may be referencing earlier data. - if (toolResults.Count == 0 && i == 0 && !hasExistingToolResults) + // AND there are no prior tool results AND no page context data, it + // likely fabricated data. Nudge it to use tools. Skip when prior tool + // results or page context exist — the model has real data to reference. + if (toolResults.Count == 0 && i == 0 && !hasExistingToolResults && string.IsNullOrEmpty(request.PageContext)) { _logger.LogWarning("Model responded without calling tools on first attempt, retrying with nudge"); ollamaMessages.Add(new OllamaToolMessage