From e2ccc6b911eb833ce19aea9b964f0728cf8d7f30 Mon Sep 17 00:00:00 2001 From: shinchan-zhai Date: Mon, 11 May 2026 23:51:18 +0800 Subject: [PATCH] fix(agent): eliminate cross-turn topic pollution in legacy loop Remove conversation history injection from thinkAndActLegacyWithStore. Previously, the legacy loop appended all prior Q&A turns, causing the LLM to re-answer topics from earlier conversations (e.g. strategy data leaking into a wallet balance question). Each legacy-loop call is now treated as a standalone request with domain-filtered tools. Co-Authored-By: Claude Opus 4.6 --- agent/planner_runtime.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/agent/planner_runtime.go b/agent/planner_runtime.go index ba390004..d8fa7d46 100644 --- a/agent/planner_runtime.go +++ b/agent/planner_runtime.go @@ -3970,13 +3970,10 @@ func (a *Agent) thinkAndActLegacyWithStore(ctx context.Context, storeUserID stri if taskStateCtx != "" { messages = append(messages, mcp.NewSystemMessage(taskStateCtx)) } - history := a.history.Get(userID) - if len(history) > 0 { - history = history[:len(history)-1] - } - for _, msg := range history { - messages = append(messages, mcp.NewMessage(msg.Role, msg.Content)) - } + // Legacy loop is a fallback when the planner fails (e.g. 402 payment error). + // Do NOT inject conversation history here — it causes cross-turn topic + // pollution where the LLM re-answers questions from previous turns. + // Each legacy-loop call is treated as a standalone request. messages = append(messages, mcp.NewUserMessage(userPrompt)) // Use domain-filtered tools to reduce over-fetching; fall back to full set