fix: fix message order is not user -> assistant -> user
This commit is contained in:
parent
9a3f3611c3
commit
1d4fa2727c
1 changed files with 12 additions and 3 deletions
|
|
@ -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,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue