fix: fix message order is not user -> assistant -> user

This commit is contained in:
fatelei 2026-02-16 11:13:56 +08:00
parent 9a3f3611c3
commit 1d4fa2727c
No known key found for this signature in database
GPG key ID: 2F91DA05646F4EED

View file

@ -12,6 +12,7 @@ import (
"github.com/sipeed/picoclaw/pkg/providers" "github.com/sipeed/picoclaw/pkg/providers"
"github.com/sipeed/picoclaw/pkg/skills" "github.com/sipeed/picoclaw/pkg/skills"
"github.com/sipeed/picoclaw/pkg/tools" "github.com/sipeed/picoclaw/pkg/tools"
"github.com/sipeed/picoclaw/pkg/utils"
) )
type ContextBuilder struct { type ContextBuilder struct {
@ -200,6 +201,14 @@ func (cb *ContextBuilder) BuildMessages(history []providers.Message, summary str
// Diegox-17 // Diegox-17
// --- FIN DEL FIX --- // --- FIN DEL FIX ---
if len(history) > 0 && history[len(history)-1].Role == "user" {
logger.WarnCF("agent", "Removing trailing user message from history to prevent consecutive user messages",
map[string]interface{}{
"content_preview": utils.Truncate(history[len(history)-1].Content, 50),
})
history = history[:len(history)-1]
}
messages = append(messages, providers.Message{ messages = append(messages, providers.Message{
Role: "system", Role: "system",
Content: systemPrompt, Content: systemPrompt,