Skip tool-use nudge when page context provides data
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 <noreply@anthropic.com>
This commit is contained in:
@@ -251,10 +251,10 @@ public class ChatService : IChatService
|
|||||||
var rawContent = response?.Message?.Content ?? "I'm sorry, I couldn't process that request.";
|
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
|
// If the model responded without calling any tools on the first attempt
|
||||||
// AND there are no prior tool results in the conversation, it likely
|
// AND there are no prior tool results AND no page context data, it
|
||||||
// fabricated data. Nudge it to use tools. Skip the nudge when prior
|
// likely fabricated data. Nudge it to use tools. Skip when prior tool
|
||||||
// tool results exist — the model may be referencing earlier data.
|
// results or page context exist — the model has real data to reference.
|
||||||
if (toolResults.Count == 0 && i == 0 && !hasExistingToolResults)
|
if (toolResults.Count == 0 && i == 0 && !hasExistingToolResults && string.IsNullOrEmpty(request.PageContext))
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Model responded without calling tools on first attempt, retrying with nudge");
|
_logger.LogWarning("Model responded without calling tools on first attempt, retrying with nudge");
|
||||||
ollamaMessages.Add(new OllamaToolMessage
|
ollamaMessages.Add(new OllamaToolMessage
|
||||||
|
|||||||
Reference in New Issue
Block a user