From 6b6c0e9ef3958f8d8f89fff8a97e8f5561959b6a Mon Sep 17 00:00:00 2001 From: DBT Date: Thu, 26 Feb 2026 01:55:12 +0000 Subject: [PATCH] system message: recover orphan tool-call 400 by retrying with fresh context --- pkg/agent/loop.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index 6cce901..8a144b5 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -903,6 +903,20 @@ func (al *AgentLoop) processSystemMessage(ctx context.Context, msg bus.InboundMe }) if err != nil { + errMsg := strings.ToLower(err.Error()) + if strings.Contains(errMsg, "no tool call found for function call output") { + logger.WarnCF("agent", "System message hit orphan tool-call chain, retry with fresh context", map[string]interface{}{"iteration": iteration, "session": sessionKey}) + messages = al.contextBuilder.BuildMessages( + nil, + "", + msg.Content, + nil, + originChannel, + originChatID, + responseLang, + ) + continue + } logger.ErrorCF("agent", "LLM call failed in system message", map[string]interface{}{ "iteration": iteration,