fix: restrict tool-heavy/swe-bench tagging to software development or agent-related tasks

This commit is contained in:
2026-07-17 17:25:17 +00:00
parent eb90f949a0
commit 293cf057b9
2 changed files with 104 additions and 2 deletions
+34 -1
View File
@@ -574,6 +574,31 @@ func (s *Server) handleChatCompletions(c *gin.Context) {
return
}
// Prune message history to sliding window if configured
if s.cfg.Server.MaxHistoryMessages > 0 && len(req.Messages) > s.cfg.Server.MaxHistoryMessages {
var systemMsgs []models.ChatMessage
var otherMsgs []models.ChatMessage
for _, msg := range req.Messages {
if msg.Role == "system" {
systemMsgs = append(systemMsgs, msg)
} else {
otherMsgs = append(otherMsgs, msg)
}
}
keepCount := s.cfg.Server.MaxHistoryMessages - len(systemMsgs)
if keepCount < 1 {
keepCount = 1
}
if len(otherMsgs) > keepCount {
startIndex := len(otherMsgs) - keepCount
otherMsgs = otherMsgs[startIndex:]
log.Printf("[DEBUG] Pruned message history: kept %d system messages and last %d messages (total %d out of %d)",
len(systemMsgs), len(otherMsgs), len(systemMsgs)+len(otherMsgs), len(req.Messages))
req.Messages = append(systemMsgs, otherMsgs...)
}
}
// Strip common prefixes and prepare model ID
modelID := req.Model
prefixes := []string{"gemini/", "google/", "openai/", "deepseek/", "moonshot/", "grok/", "ollama/", "xiaomi/"}
@@ -1119,7 +1144,15 @@ func (s *Server) getRouteCtxTags(routeCtx *router.RouteContext) []string {
}
}
if routeCtx.RequiresToolCalling {
hasHeavyLogic := false
for _, tag := range tags {
if tag == "heavy-logic" {
hasHeavyLogic = true
break
}
}
if routeCtx.RequiresToolCalling && (routeCtx.IsSoftwareDevelopment || hasHeavyLogic) {
tags = append(tags, "tool-heavy", "multi-step-agent", "swe-bench")
}