fix: enhance count argument handling in WebSearchTool to support string input

This commit is contained in:
Anish Biswas 2026-02-22 18:55:21 +05:30
parent ec6da7a530
commit 52a137f771

View file

@ -6,9 +6,11 @@ import (
"encoding/json"
"fmt"
"io"
"math"
"net/http"
"net/url"
"regexp"
"strconv"
"strings"
"time"
)
@ -473,9 +475,22 @@ func (t *WebSearchTool) Execute(ctx context.Context, args map[string]any) *ToolR
}
count := t.maxResults
if c, ok := args["count"].(float64); ok {
if int(c) > 0 && int(c) <= 10 {
count = int(c)
switch v := args["count"].(type) {
case float64:
rounded := int(math.Round(v))
if math.Abs(v-float64(rounded)) > 1e-9 {
return ErrorResult(fmt.Sprintf("count must be an integer, got %v", v))
}
if rounded > 0 && rounded <= 10 {
count = rounded
}
case int:
if v > 0 && v <= 10 {
count = v
}
case string:
if n, err := strconv.Atoi(v); err == nil && n > 0 && n <= 10 {
count = n
}
}