( toolResults []fantasy.ToolResultPart, toolNameByCallID map[string]string, )
| 1143 | } |
| 1144 | |
| 1145 | func syntheticToolUseMessage( |
| 1146 | toolResults []fantasy.ToolResultPart, |
| 1147 | toolNameByCallID map[string]string, |
| 1148 | ) fantasy.Message { |
| 1149 | parts := make([]fantasy.MessagePart, 0, len(toolResults)) |
| 1150 | seen := make(map[string]struct{}, len(toolResults)) |
| 1151 | |
| 1152 | for _, toolResult := range toolResults { |
| 1153 | toolCallID := sanitizeToolCallID(toolResult.ToolCallID) |
| 1154 | if toolCallID == "" { |
| 1155 | continue |
| 1156 | } |
| 1157 | if _, ok := seen[toolCallID]; ok { |
| 1158 | continue |
| 1159 | } |
| 1160 | |
| 1161 | toolName := strings.TrimSpace(toolNameByCallID[toolCallID]) |
| 1162 | if toolName == "" { |
| 1163 | continue |
| 1164 | } |
| 1165 | |
| 1166 | seen[toolCallID] = struct{}{} |
| 1167 | parts = append(parts, fantasy.ToolCallPart{ |
| 1168 | ToolCallID: toolCallID, |
| 1169 | ToolName: toolName, |
| 1170 | Input: "{}", |
| 1171 | }) |
| 1172 | } |
| 1173 | |
| 1174 | return fantasy.Message{ |
| 1175 | Role: fantasy.MessageRoleAssistant, |
| 1176 | Content: parts, |
| 1177 | } |
| 1178 | } |
| 1179 | |
| 1180 | func sanitizeToolCallID(id string) string { |
| 1181 | if id == "" { |
no test coverage detected