diff --git a/pkg/agent/context.go b/pkg/agent/context.go index e737fbd..e32e456 100644 --- a/pkg/agent/context.go +++ b/pkg/agent/context.go @@ -189,6 +189,17 @@ func (cb *ContextBuilder) BuildMessages(history []providers.Message, summary str systemPrompt += "\n\n## Summary of Previous Conversation\n\n" + summary } + //This fix prevents the session memory from LLM failure due to elimination of toolu_IDs required from LLM + // --- INICIO DEL FIX --- + //Diegox-17 + for len(history) > 0 && (history[0].Role == "tool") { + logger.DebugCF("agent", "Removing orphaned tool message from history to prevent LLM error", + map[string]interface{}{"role": history[0].Role}) + history = history[1:] + } + //Diegox-17 + // --- FIN DEL FIX --- + messages = append(messages, providers.Message{ Role: "system", Content: systemPrompt,