agent system-message: rebuild context and retry after purging orphan tool outputs on provider pairing 400

This commit is contained in:
DBT
2026-03-01 15:06:46 +00:00
parent 8a94600b1e
commit ed47e2dfe0

View File

@@ -1184,6 +1184,21 @@ func (al *AgentLoop) processSystemMessage(ctx context.Context, msg bus.InboundMe
if strings.Contains(errText, "no tool call found for function call output") {
removed := al.sessions.PurgeOrphanToolOutputs(sessionKey)
logger.WarnCF("agent", "Purged orphan tool outputs after provider pairing error (system)", map[string]interface{}{"session_key": sessionKey, "removed": removed})
if removed > 0 {
// Rebuild context from cleaned history and retry current iteration.
history = al.sessions.GetHistory(sessionKey)
summary = al.sessions.GetSummary(sessionKey)
messages = al.contextBuilder.BuildMessages(
history,
summary,
msg.Content,
nil,
originChannel,
originChatID,
responseLang,
)
continue
}
}
logger.ErrorCF("agent", "LLM call failed in system message",
map[string]interface{}{