Reject null input in agent tool parameter validation
JSON null unmarshals into an empty string, so the presence-only
key check let {"input":null} through, running the nested agent
with a blank user message.
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -83,7 +83,8 @@ func (t *agentTool) Execute(ctx context.Context, arguments string) (ToolResult,
|
||||
}, nil
|
||||
}
|
||||
|
||||
if _, ok := fields["input"]; !ok {
|
||||
raw, ok := fields["input"]
|
||||
if !ok || string(raw) == "null" {
|
||||
return ToolResult{
|
||||
Content: "Missing required parameters: input",
|
||||
IsError: true,
|
||||
|
||||
@@ -215,6 +215,27 @@ func TestAgentTool_Execute(t *testing.T) {
|
||||
},
|
||||
)
|
||||
|
||||
t.Run(
|
||||
"null input returns tool error for missing input",
|
||||
func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
ag := agent.New(
|
||||
"sub",
|
||||
newTestClient(&mockProvider{}),
|
||||
agent.WithModel("test-model"),
|
||||
)
|
||||
|
||||
tool := ag.AsTool("sub_tool", "A sub-agent tool.")
|
||||
result, err := tool.Execute(context.Background(), `{"input":null}`)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.True(t, result.IsError)
|
||||
assert.Contains(t, result.Content, "Missing required parameters")
|
||||
assert.Contains(t, result.Content, "input")
|
||||
},
|
||||
)
|
||||
|
||||
t.Run(
|
||||
"sub-agent error propagates as Go error",
|
||||
func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user