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

@@ -75,8 +75,22 @@ func (t *agentTool) Execute(ctx context.Context, arguments string) (ToolResult,
return ToolResult{}, &MaxToolDepthExceededError{MaxDepth: t.agent.maxToolDepth}
}
var params agentToolParams
var fields map[string]json.RawMessage
if err := json.Unmarshal([]byte(arguments), &fields); err != nil {
return ToolResult{
Content: fmt.Sprintf("Invalid parameters: %s", err.Error()),
IsError: true,
}, nil
}
if _, ok := fields["input"]; !ok {
return ToolResult{
Content: "Missing required parameters: input",
IsError: true,
}, nil
}
var params agentToolParams
if err := json.Unmarshal([]byte(arguments), &params); err != nil {
return ToolResult{
Content: fmt.Sprintf("Invalid parameters: %s", err.Error()),