fix: cleanup responses also when not picking any tool (#102)

* fix: process response also when no action is picked

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

* chore: rename method to be more meaningful

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>

---------

Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
This commit is contained in:
Ettore Di Giacinto
2025-04-30 22:15:34 +02:00
committed by GitHub
parent 8abf5512a4
commit 67cb5937e7

View File

@@ -595,7 +595,7 @@ func (a *Agent) consumeJob(job *types.Job, role string, retries int) {
if reasoning != "" { if reasoning != "" {
conv = append(conv, openai.ChatCompletionMessage{ conv = append(conv, openai.ChatCompletionMessage{
Role: "assistant", Role: "assistant",
Content: reasoning, Content: a.cleanupLLMResponse(reasoning),
}) })
} else { } else {
xlog.Info("No reasoning, just reply", "agent", a.Character.Name) xlog.Info("No reasoning, just reply", "agent", a.Character.Name)
@@ -604,6 +604,7 @@ func (a *Agent) consumeJob(job *types.Job, role string, retries int) {
job.Result.Finish(fmt.Errorf("error asking LLM for a reply: %w", err)) job.Result.Finish(fmt.Errorf("error asking LLM for a reply: %w", err))
return return
} }
msg.Content = a.cleanupLLMResponse(msg.Content)
conv = append(conv, msg) conv = append(conv, msg)
reasoning = msg.Content reasoning = msg.Content
} }
@@ -803,7 +804,7 @@ func stripThinkingTags(content string) string {
return content return content
} }
func (a *Agent) processPrompt(content string) string { func (a *Agent) cleanupLLMResponse(content string) string {
if a.options.stripThinkingTags { if a.options.stripThinkingTags {
content = stripThinkingTags(content) content = stripThinkingTags(content)
} }
@@ -877,7 +878,7 @@ func (a *Agent) reply(job *types.Job, role string, conv Messages, actionParams t
msg := openai.ChatCompletionMessage{ msg := openai.ChatCompletionMessage{
Role: "assistant", Role: "assistant",
Content: a.processPrompt(replyResponse.Message), Content: a.cleanupLLMResponse(replyResponse.Message),
} }
conv = append(conv, msg) conv = append(conv, msg)
@@ -906,10 +907,10 @@ func (a *Agent) reply(job *types.Job, role string, conv Messages, actionParams t
msg = openai.ChatCompletionMessage{ msg = openai.ChatCompletionMessage{
Role: "assistant", Role: "assistant",
Content: a.processPrompt(replyResponse.Message), Content: a.cleanupLLMResponse(replyResponse.Message),
} }
} else { } else {
msg.Content = a.processPrompt(msg.Content) msg.Content = a.cleanupLLMResponse(msg.Content)
} }
conv = append(conv, msg) conv = append(conv, msg)