MCPcopy Create free account
hub / github.com/GongShichen/LuminaCode / HandleThinkingBlocks

Function HandleThinkingBlocks

agent/normalize.go:123–149  ·  view source on GitHub ↗
(messages []map[string]any, modelFamily string, recentErrors []string)

Source from the content-addressed store, hash-verified

121}
122
123func HandleThinkingBlocks(messages []map[string]any, modelFamily string, recentErrors []string) []map[string]any {
124 supports := modelSupportsThinking(modelFamily)
125 out := make([]map[string]any, 0, len(messages))
126 for _, msg := range messages {
127 blocks := contentBlocks(msg["content"])
128 if blocks == nil {
129 out = append(out, msg)
130 continue
131 }
132 role := stringFromAny(msg["role"])
133 stripThinking := role == "user" || !supports
134 filtered := make([]map[string]any, 0, len(blocks))
135 for _, block := range blocks {
136 if _, ok := thinkingBlockTypes[stringFromAny(block["type"])]; ok && stripThinking {
137 continue
138 }
139 filtered = append(filtered, block)
140 }
141 if len(filtered) == 0 {
142 continue
143 }
144 cp := copyMap(msg)
145 cp["content"] = filtered
146 out = append(out, cp)
147 }
148 return out
149}
150
151func MergeSplitMessages(messages []map[string]any) []map[string]any {
152 if len(messages) == 0 {

Callers 1

NormalizeMessagesFunction · 0.85

Calls 4

modelSupportsThinkingFunction · 0.85
contentBlocksFunction · 0.70
stringFromAnyFunction · 0.70
copyMapFunction · 0.70

Tested by

no test coverage detected