fix(agent): 修复流式推理与工具参数重试

This commit is contained in:
ddCat
2026-09-15 05:22:07 +08:00
parent 06794aea95
commit 201f3aac65
13 changed files with 231 additions and 46 deletions

View File

@@ -1,6 +1,7 @@
package app
import (
"crypto/sha256"
"encoding/json"
"fmt"
"sort"
@@ -103,7 +104,9 @@ func cloudAgentCanonical(system string, history []providerTextMessage, prompt st
messages = append(messages, map[string]any{"role": m.Role, "content": m.Content})
}
messages = append(messages, map[string]any{"role": "user", "content": prompt})
return canonicalAgentRequest{SystemPrompt: system, Messages: messages, Tools: cloudAgentTools(req), ToolChoice: "auto"}
// Keep routing stable across tool turns, without exposing canvas identifiers.
cacheHash := sha256.Sum256([]byte(req.CanvasID + "\x00" + system))
return canonicalAgentRequest{SystemPrompt: system, Messages: messages, Tools: cloudAgentTools(req), ToolChoice: "auto", PromptCacheKey: fmt.Sprintf("cloud-agent:%x", cacheHash[:24])}
}
func cloudAgentTools(req CloudAgentRequest) []map[string]any {
tools := []map[string]any{}