Skip to content

Commit cb201e0

Browse files
authored
Merge pull request #2172 from dgageot/board/fix-https-github-com-docker-docker-agent-2c36a0a8
fix: use %v to format script tool args, fixing number type interpolation
2 parents 5579669 + f319faf commit cb201e0

2 files changed

Lines changed: 40 additions & 1 deletion

File tree

pkg/tools/builtin/script_shell.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func (t *ScriptShellTool) execute(ctx context.Context, toolConfig *latest.Script
144144
cmd.Env = t.env
145145
for key, value := range params {
146146
if value != nil {
147-
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", key, value))
147+
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%v", key, value))
148148
}
149149
}
150150

pkg/tools/builtin/script_shell_test.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package builtin
22

33
import (
44
"encoding/json"
5+
"os"
56
"testing"
67

78
"github.com/stretchr/testify/assert"
89
"github.com/stretchr/testify/require"
910

1011
"github.com/docker/docker-agent/pkg/config/latest"
12+
"github.com/docker/docker-agent/pkg/tools"
1113
)
1214

1315
func TestNewScriptShellTool_Empty(t *testing.T) {
@@ -116,6 +118,43 @@ func TestNewScriptShellTool_MissingRequired(t *testing.T) {
116118
require.ErrorContains(t, err, "tool 'docker_images' has required arg 'img' which is not defined in args")
117119
}
118120

121+
func TestNewScriptShellTool_NumberArg(t *testing.T) {
122+
shellTools := map[string]latest.ScriptShellToolConfig{
123+
"repeat": {
124+
Description: "Repeat a message N times",
125+
Cmd: "for i in $(seq 1 $count); do echo $message; done",
126+
Args: map[string]any{
127+
"message": map[string]any{
128+
"description": "Message to repeat",
129+
"type": "string",
130+
},
131+
"count": map[string]any{
132+
"description": "Number of repetitions",
133+
"type": "number",
134+
},
135+
},
136+
Required: []string{"message", "count"},
137+
},
138+
}
139+
140+
tool, err := NewScriptShellTool(shellTools, os.Environ())
141+
require.NoError(t, err)
142+
143+
allTools, err := tool.Tools(t.Context())
144+
require.NoError(t, err)
145+
require.Len(t, allTools, 1)
146+
147+
// Simulate LLM sending a number argument (JSON numbers are float64)
148+
result, err := allTools[0].Handler(t.Context(), tools.ToolCall{
149+
Function: tools.FunctionCall{
150+
Arguments: `{"message": "hello", "count": 3}`,
151+
},
152+
})
153+
require.NoError(t, err)
154+
assert.False(t, result.IsError, "unexpected error: %s", result.Output)
155+
assert.Equal(t, "hello\nhello\nhello\n", result.Output)
156+
}
157+
119158
func TestNewScriptShellTool_ArgWithoutType(t *testing.T) {
120159
shellTools := map[string]latest.ScriptShellToolConfig{
121160
"greet": {

0 commit comments

Comments
 (0)