fix: retry with nudge when LLM returns empty response after tool use
This commit is contained in:
parent
9a3f3611c3
commit
2a962d4a96
1 changed files with 13 additions and 0 deletions
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue