refactor(agent): improve legacy loop comment and extract domain variable

Clarify the rationale for not injecting conversation history in the
legacy loop comment, and extract plannerToolDomainForText result into
a named variable for readability.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
shinchan-zhai
2026-05-12 00:16:20 +08:00
parent d80bb31c0a
commit ab5873e2de

View File

@@ -3970,19 +3970,21 @@ func (a *Agent) thinkAndActLegacyWithStore(ctx context.Context, storeUserID stri
if taskStateCtx != "" { if taskStateCtx != "" {
messages = append(messages, mcp.NewSystemMessage(taskStateCtx)) messages = append(messages, mcp.NewSystemMessage(taskStateCtx))
} }
// Legacy loop is a fallback when the planner fails (e.g. 402 payment error). // NOTE: We intentionally do NOT inject conversation history into the legacy
// Do NOT inject conversation history here — it causes cross-turn topic // loop. Even a single prior round causes DeepSeek to hallucinate data from
// pollution where the LLM re-answers questions from previous turns. // earlier topics (e.g. outputting strategy details when asked about a wallet).
// Each legacy-loop call is treated as a standalone request. // The planner path handles multi-turn context properly; the legacy loop is
// a single-turn fallback. References like "那binance的钱包呢" still work
// because the text itself contains enough keywords for domain routing.
messages = append(messages, mcp.NewUserMessage(userPrompt)) messages = append(messages, mcp.NewUserMessage(userPrompt))
// Use domain-filtered tools to reduce over-fetching; fall back to full set // Use domain-filtered tools to reduce over-fetching; fall back to full set
// for "general" domain to preserve full functionality. // for "general" domain to preserve full functionality.
domain := plannerToolDomainForText(text)
tools := plannerToolsForText(text) tools := plannerToolsForText(text)
if plannerToolDomainForText(text) == "general" { if domain == "general" {
tools = agentTools() tools = agentTools()
} }
const maxToolRounds = 5 const maxToolRounds = 5
for round := 0; round < maxToolRounds; round++ { for round := 0; round < maxToolRounds; round++ {
req := &mcp.Request{ req := &mcp.Request{