Validate required input in agent tool execution

The agentTool.Execute method accepted {} despite the schema
marking input as required. Unlike functionTool, it skipped
required-field validation, silently sending an empty message
to the sub-agent.

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2026-03-13 18:31:22 +01:00
parent 9f92a27b51
commit def8f417ca
2 changed files with 20 additions and 10 deletions

View File

@@ -195,19 +195,13 @@ func TestAgentTool_Execute(t *testing.T) {
)
t.Run(
"empty JSON object returns tool error",
"empty JSON object returns tool error for missing input",
func(t *testing.T) {
t.Parallel()
provider := &mockProvider{
responses: []*llm.ChatCompletionResponse{
stopResponse("ok"),
},
}
ag := agent.New(
"sub",
newTestClient(provider),
newTestClient(&mockProvider{}),
agent.WithModel("test-model"),
)
@@ -215,7 +209,9 @@ func TestAgentTool_Execute(t *testing.T) {
result, err := tool.Execute(context.Background(), `{}`)
require.NoError(t, err)
assert.False(t, result.IsError)
assert.True(t, result.IsError)
assert.Contains(t, result.Content, "Missing required parameters")
assert.Contains(t, result.Content, "input")
},
)