fix: retry with nudge when LLM returns empty response after tool use

This commit is contained in:
Buddha 2026-02-16 20:12:42 +05:30
parent 9a3f3611c3
commit 2a962d4a96
No known key found for this signature in database
GPG key ID: 8EF71C1D12278589

View file

@ -468,6 +468,19 @@ func (al *AgentLoop) runLLMIteration(ctx context.Context, messages []providers.M
"iteration": iteration, "iteration": iteration,
"content_chars": len(finalContent), "content_chars": len(finalContent),
}) })
// If content is empty and we just processed tool results (iteration > 1),
// retry once by adding a nudge message to prompt the model to respond.
if strings.TrimSpace(finalContent) == "" && iteration > 1 && iteration < al.maxIterations {
logger.InfoCF("agent", "Empty response after tool use, retrying with nudge",
map[string]interface{}{
"iteration": iteration,
})
messages = append(messages, providers.Message{
Role: "user",
Content: "Please provide your response based on the tool results above.",
})
continue
}
break break
} }