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 <noreply@anthropic.com>
This commit is contained in:
shinchan-zhai
2026-05-11 23:51:18 +08:00
parent bf289e8eb3
commit e2ccc6b911

View File

@@ -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