fix: enforce strict tool-call pairing across chat paths

This commit is contained in:
DBT
2026-02-26 05:47:35 +00:00
parent dea7f361f2
commit f8c662a468
4 changed files with 167 additions and 47 deletions

View File

@@ -442,7 +442,10 @@ func (al *AgentLoop) GetSessionHistory(sessionKey string) []providers.Message {
}
func (al *AgentLoop) processMessage(ctx context.Context, msg bus.InboundMessage) (string, error) {
msg.SessionKey = "main"
msg.SessionKey = strings.TrimSpace(msg.SessionKey)
if msg.SessionKey == "" {
msg.SessionKey = "main"
}
unlock := al.lockSessionRun(msg.SessionKey)
defer unlock()
// Add message preview to log
@@ -908,20 +911,6 @@ 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,