From ed47e2dfe0631c11b251ae9afaeb1a92cd4474ba Mon Sep 17 00:00:00 2001 From: DBT Date: Sun, 1 Mar 2026 15:06:46 +0000 Subject: [PATCH] agent system-message: rebuild context and retry after purging orphan tool outputs on provider pairing 400 --- pkg/agent/loop.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index fef27b1..8ad7070 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -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{}{