Skip to content

Commit 4564efe

Browse files
fix(skills): fix integer parameter parsing through agent skills (#2847)
This PR fixes an issue where integer parameters were incorrectly parsed as float64 when invoking tools via the CLI. Co-authored-by: Pavan Krishna Rampalli <pavanrampalli@google.com> --------- Co-authored-by: Pavan Krishna Rampalli <pavanrampalli@google.com>
1 parent 7a070da commit 4564efe

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

cmd/internal/invoke/command.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ import (
1818
"context"
1919
"encoding/json"
2020
"fmt"
21+
"strings"
2122

2223
"github.com/googleapis/genai-toolbox/cmd/internal"
2324
"github.com/googleapis/genai-toolbox/internal/server"
2425
"github.com/googleapis/genai-toolbox/internal/server/resources"
26+
"github.com/googleapis/genai-toolbox/internal/util"
2527
"github.com/googleapis/genai-toolbox/internal/util/parameters"
2628
"github.com/spf13/cobra"
2729
)
@@ -87,7 +89,7 @@ func runInvoke(cmd *cobra.Command, args []string, opts *internal.ToolboxOptions)
8789

8890
params := make(map[string]any)
8991
if paramsInput != "" {
90-
if err := json.Unmarshal([]byte(paramsInput), &params); err != nil {
92+
if err := util.DecodeJSON(strings.NewReader(paramsInput), &params); err != nil {
9193
errMsg := fmt.Errorf("params must be a valid JSON string: %w", err)
9294
opts.Logger.ErrorContext(ctx, errMsg.Error())
9395
return errMsg

cmd/internal/invoke/command_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ tools:
6868
- name: message
6969
type: string
7070
description: message to echo
71+
int-tool:
72+
kind: sqlite-sql
73+
source: my-sqlite
74+
description: "int tool"
75+
statement: "SELECT ? as val"
76+
parameters:
77+
- name: value
78+
type: integer
79+
description: int value
7180
`
7281

7382
toolsFilePath := filepath.Join(tmpDir, "tools.yaml")
@@ -92,6 +101,11 @@ tools:
92101
args: []string{"invoke", "echo-tool", `{"message": "world"}`, "--config", toolsFilePath},
93102
want: `"msg": "world"`,
94103
},
104+
{
105+
desc: "success - tool call with integer parameters",
106+
args: []string{"invoke", "int-tool", `{"value": 42}`, "--tools-file", toolsFilePath},
107+
want: `"val": 42`,
108+
},
95109
{
96110
desc: "error - tool not found",
97111
args: []string{"invoke", "non-existent", "--config", toolsFilePath},

0 commit comments

Comments
 (0)