| 352 | } |
| 353 | |
| 354 | func NormalizeMessages(messages []map[string]any, modelFamily string, recentErrors []string) []map[string]any { |
| 355 | normalized := ReorderAttachments(messages) |
| 356 | normalized = FilterVirtualMessages(normalized) |
| 357 | errorBlockMap := BuildErrorBlockMap(recentErrors) |
| 358 | normalized = StripInternalElementsWithErrors(normalized, errorBlockMap) |
| 359 | normalized = HandleThinkingBlocks(normalized, modelFamily, recentErrors) |
| 360 | normalized = MergeSplitMessages(normalized) |
| 361 | normalized = FixToolPairings(normalized) |
| 362 | normalized = EnforceImmediateToolResults(normalized) |
| 363 | return normalized |
| 364 | } |
| 365 | |
| 366 | func modelSupportsThinking(modelFamily string) bool { |
| 367 | low := strings.ToLower(modelFamily) |