@@ -22,6 +22,7 @@ import (
2222 "strings"
2323 "sync"
2424 "time"
25+ "net/url"
2526
2627 openai "github.com/sashabaranov/go-openai"
2728 uuid "github.com/satori/go.uuid"
@@ -778,8 +779,9 @@ END OUTPUT FORMATTING
778779---
779780ERROR HANDLING
780781
782+ - Use common knowledge and the error response to identify the single most likely cause of the HTTP request failure.
781783- Fix the request based on the API context and the existing content in the path, body and queries
782- - You SHOULD add relevant fields to the body that are missing
784+ - You SHOULD add relevant fields to the body ONLY if the HTTP method allows a body and the error explicitly indicates missing required fields.
783785- Modify the "path" field according to what seems wrong with the API URL. Do NOT remove this field.
784786- Do NOT error-handle authentication issues unless it seems possible
785787
@@ -950,9 +952,81 @@ Input JSON Payload (ensure VALID JSON):
950952 return action , additionalInfo , errors .New (getBadOutputString (action , appname , inputdata , outputBody , status ))
951953 }
952954
955+ // De-duplicate url/path/queries to prevent duplication errors
956+ urlValue := ""
957+ pathValue := ""
958+ queriesValue := ""
959+
960+ // Collect current values from action parameters
961+ for _ , param := range action .Parameters {
962+ if param .Name == "url" {
963+ urlValue = param .Value
964+ } else if param .Name == "path" {
965+ pathValue = param .Value
966+ } else if param .Name == "queries" {
967+ queriesValue = param .Value
968+ }
969+ }
970+
971+ if strings .Contains (pathValue , "://" ) {
972+ if u , err := url .Parse (pathValue ); err == nil {
973+ pathValue = u .Path
974+ if queriesValue == "" {
975+ queriesValue = u .RawQuery
976+ }
977+ }
978+ }
979+
980+ urlValue , pathValue , queriesValue = normalize (urlValue , pathValue , queriesValue )
981+
982+ for i := range action .Parameters {
983+ switch action .Parameters [i ].Name {
984+ case "url" :
985+ action .Parameters [i ].Value = urlValue
986+ case "path" :
987+ action .Parameters [i ].Value = pathValue
988+ case "queries" :
989+ action .Parameters [i ].Value = queriesValue
990+ }
991+ }
992+
993+ if debug {
994+ log .Printf ("[DEBUG] De-duplicated URL components: url=%s, path=%s, queries=%s" , urlValue , pathValue , queriesValue )
995+ }
996+
953997 return action , additionalInfo , nil
954998}
955999
1000+ func normalize (urlValue , pathValue , queriesValue string ) (string , string , string ) {
1001+ parsed , err := url .Parse (urlValue )
1002+ if err != nil {
1003+ return urlValue , pathValue , queriesValue
1004+ }
1005+
1006+ // If BOTH path and queries are empty, keep the full URL as-is
1007+ // This means LLM didn't fill them, so we shouldn't split
1008+ if pathValue == "" && queriesValue == "" {
1009+ return urlValue , pathValue , queriesValue
1010+ }
1011+
1012+ baseURL := ""
1013+ if parsed .Scheme != "" && parsed .Host != "" {
1014+ baseURL = parsed .Scheme + "://" + parsed .Host
1015+ }
1016+
1017+ // Extract path from URL if path is still empty
1018+ if pathValue == "" {
1019+ pathValue = parsed .Path
1020+ }
1021+
1022+ // Extract queries from URL if queries is still empty
1023+ if queriesValue == "" {
1024+ queriesValue = parsed .RawQuery
1025+ }
1026+
1027+ return baseURL , pathValue , queriesValue
1028+ }
1029+
9561030func getBadOutputString (action Action , appname , inputdata , outputBody string , status int ) string {
9571031 outputParams := ""
9581032 for _ , param := range action .Parameters {
0 commit comments