Add vendor assessment agent
Signed-off-by: Aurélien Sibiril <81782+aureliensibiril@users.noreply.github.com>
This commit is contained in:
@@ -30,14 +30,13 @@ func TestFunctionTool_Name(t *testing.T) {
|
||||
|
||||
type Params struct{}
|
||||
|
||||
tool, err := agent.FunctionTool(
|
||||
tool := agent.FunctionTool(
|
||||
"my_tool",
|
||||
"does things",
|
||||
func(_ context.Context, _ Params) (agent.ToolResult, error) {
|
||||
return agent.ToolResult{}, nil
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Equal(t, "my_tool", tool.Name())
|
||||
}
|
||||
@@ -54,14 +53,13 @@ func TestFunctionTool_Definition(t *testing.T) {
|
||||
Query string `json:"query"`
|
||||
}
|
||||
|
||||
tool, err := agent.FunctionTool(
|
||||
tool := agent.FunctionTool(
|
||||
"search",
|
||||
"Search for items",
|
||||
func(_ context.Context, _ Params) (agent.ToolResult, error) {
|
||||
return agent.ToolResult{}, nil
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
def := tool.Definition()
|
||||
assert.Equal(t, "search", def.Name)
|
||||
@@ -79,14 +77,13 @@ func TestFunctionTool_Definition(t *testing.T) {
|
||||
Count int `json:"count"`
|
||||
}
|
||||
|
||||
tool, err := agent.FunctionTool(
|
||||
tool := agent.FunctionTool(
|
||||
"create",
|
||||
"Create items",
|
||||
func(_ context.Context, _ Params) (agent.ToolResult, error) {
|
||||
return agent.ToolResult{}, nil
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
def := tool.Definition()
|
||||
require.NotNil(t, def.Parameters)
|
||||
@@ -116,14 +113,13 @@ func TestFunctionTool_Definition(t *testing.T) {
|
||||
|
||||
type Params struct{}
|
||||
|
||||
tool, err := agent.FunctionTool(
|
||||
tool := agent.FunctionTool(
|
||||
"noop",
|
||||
"No-op",
|
||||
func(_ context.Context, _ Params) (agent.ToolResult, error) {
|
||||
return agent.ToolResult{}, nil
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
var schema map[string]any
|
||||
require.NoError(t, json.Unmarshal(tool.Definition().Parameters, &schema))
|
||||
@@ -140,14 +136,13 @@ func TestFunctionTool_Definition(t *testing.T) {
|
||||
Title *string `json:"title,omitempty"`
|
||||
}
|
||||
|
||||
tool, err := agent.FunctionTool(
|
||||
tool := agent.FunctionTool(
|
||||
"update",
|
||||
"Update",
|
||||
func(_ context.Context, _ Params) (agent.ToolResult, error) {
|
||||
return agent.ToolResult{}, nil
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
var schema map[string]any
|
||||
require.NoError(t, json.Unmarshal(tool.Definition().Parameters, &schema))
|
||||
@@ -173,14 +168,13 @@ func TestFunctionTool_Execute(t *testing.T) {
|
||||
Y int `json:"y"`
|
||||
}
|
||||
|
||||
tool, err := agent.FunctionTool(
|
||||
tool := agent.FunctionTool(
|
||||
"add",
|
||||
"Add two numbers",
|
||||
func(_ context.Context, p Params) (agent.ToolResult, error) {
|
||||
return agent.ToolResult{Content: "42"}, nil
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
result, err := tool.Execute(context.Background(), `{"x": 1, "y": 2}`)
|
||||
require.NoError(t, err)
|
||||
@@ -199,7 +193,7 @@ func TestFunctionTool_Execute(t *testing.T) {
|
||||
}
|
||||
|
||||
var received string
|
||||
tool, err := agent.FunctionTool(
|
||||
tool := agent.FunctionTool(
|
||||
"weather",
|
||||
"Get weather",
|
||||
func(_ context.Context, p Params) (agent.ToolResult, error) {
|
||||
@@ -207,9 +201,8 @@ func TestFunctionTool_Execute(t *testing.T) {
|
||||
return agent.ToolResult{Content: "sunny"}, nil
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = tool.Execute(context.Background(), `{"city":"Paris"}`)
|
||||
_, err := tool.Execute(context.Background(), `{"city":"Paris"}`)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "Paris", received)
|
||||
},
|
||||
@@ -222,14 +215,13 @@ func TestFunctionTool_Execute(t *testing.T) {
|
||||
|
||||
type Params struct{}
|
||||
|
||||
tool, err := agent.FunctionTool(
|
||||
tool := agent.FunctionTool(
|
||||
"noop",
|
||||
"No-op",
|
||||
func(_ context.Context, _ Params) (agent.ToolResult, error) {
|
||||
return agent.ToolResult{Content: "ok"}, nil
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
result, err := tool.Execute(context.Background(), `{invalid`)
|
||||
require.NoError(t, err)
|
||||
@@ -245,16 +237,15 @@ func TestFunctionTool_Execute(t *testing.T) {
|
||||
|
||||
type Params struct{}
|
||||
|
||||
tool, err := agent.FunctionTool(
|
||||
tool := agent.FunctionTool(
|
||||
"fail",
|
||||
"Always fails",
|
||||
func(_ context.Context, _ Params) (agent.ToolResult, error) {
|
||||
return agent.ToolResult{}, errors.New("db down")
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = tool.Execute(context.Background(), `{}`)
|
||||
_, err := tool.Execute(context.Background(), `{}`)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "db down")
|
||||
},
|
||||
@@ -268,7 +259,7 @@ func TestFunctionTool_Execute(t *testing.T) {
|
||||
type ctxKey struct{}
|
||||
type Params struct{}
|
||||
|
||||
tool, err := agent.FunctionTool(
|
||||
tool := agent.FunctionTool(
|
||||
"ctx_check",
|
||||
"Check context",
|
||||
func(ctx context.Context, _ Params) (agent.ToolResult, error) {
|
||||
@@ -276,7 +267,6 @@ func TestFunctionTool_Execute(t *testing.T) {
|
||||
return agent.ToolResult{Content: val}, nil
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
ctx := context.WithValue(context.Background(), ctxKey{}, "hello")
|
||||
result, err := tool.Execute(ctx, `{}`)
|
||||
@@ -294,7 +284,7 @@ func TestFunctionTool_Execute(t *testing.T) {
|
||||
City string `json:"city"`
|
||||
}
|
||||
|
||||
tool, err := agent.FunctionTool(
|
||||
tool := agent.FunctionTool(
|
||||
"weather",
|
||||
"Get weather",
|
||||
func(_ context.Context, _ Params) (agent.ToolResult, error) {
|
||||
@@ -302,7 +292,6 @@ func TestFunctionTool_Execute(t *testing.T) {
|
||||
return agent.ToolResult{}, nil
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
result, err := tool.Execute(context.Background(), `{}`)
|
||||
require.NoError(t, err)
|
||||
@@ -321,7 +310,7 @@ func TestFunctionTool_Execute(t *testing.T) {
|
||||
Country string `json:"country"`
|
||||
}
|
||||
|
||||
tool, err := agent.FunctionTool(
|
||||
tool := agent.FunctionTool(
|
||||
"weather",
|
||||
"Get weather",
|
||||
func(_ context.Context, _ Params) (agent.ToolResult, error) {
|
||||
@@ -329,7 +318,6 @@ func TestFunctionTool_Execute(t *testing.T) {
|
||||
return agent.ToolResult{}, nil
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
result, err := tool.Execute(context.Background(), `{}`)
|
||||
require.NoError(t, err)
|
||||
@@ -349,7 +337,7 @@ func TestFunctionTool_Execute(t *testing.T) {
|
||||
Country string `json:"country"`
|
||||
}
|
||||
|
||||
tool, err := agent.FunctionTool(
|
||||
tool := agent.FunctionTool(
|
||||
"weather",
|
||||
"Get weather",
|
||||
func(_ context.Context, _ Params) (agent.ToolResult, error) {
|
||||
@@ -357,7 +345,6 @@ func TestFunctionTool_Execute(t *testing.T) {
|
||||
return agent.ToolResult{}, nil
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
result, err := tool.Execute(context.Background(), `{"city":"Paris"}`)
|
||||
require.NoError(t, err)
|
||||
@@ -376,14 +363,13 @@ func TestFunctionTool_Execute(t *testing.T) {
|
||||
Units *string `json:"units,omitempty"`
|
||||
}
|
||||
|
||||
tool, err := agent.FunctionTool(
|
||||
tool := agent.FunctionTool(
|
||||
"weather",
|
||||
"Get weather",
|
||||
func(_ context.Context, p Params) (agent.ToolResult, error) {
|
||||
return agent.ToolResult{Content: "sunny in " + p.City}, nil
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
result, err := tool.Execute(context.Background(), `{"city":"Paris"}`)
|
||||
require.NoError(t, err)
|
||||
@@ -401,14 +387,13 @@ func TestFunctionTool_Execute(t *testing.T) {
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
tool, err := agent.FunctionTool(
|
||||
tool := agent.FunctionTool(
|
||||
"greet",
|
||||
"Greet",
|
||||
func(_ context.Context, p Params) (agent.ToolResult, error) {
|
||||
return agent.ToolResult{Content: "hi " + p.Name}, nil
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
result, err := tool.Execute(context.Background(), `{"name":"Alice","extra":"ignored"}`)
|
||||
require.NoError(t, err)
|
||||
@@ -424,14 +409,13 @@ func TestFunctionTool_Execute(t *testing.T) {
|
||||
|
||||
type Params struct{}
|
||||
|
||||
tool, err := agent.FunctionTool(
|
||||
tool := agent.FunctionTool(
|
||||
"ping",
|
||||
"Ping",
|
||||
func(_ context.Context, _ Params) (agent.ToolResult, error) {
|
||||
return agent.ToolResult{Content: "pong"}, nil
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
result, err := tool.Execute(context.Background(), `{}`)
|
||||
require.NoError(t, err)
|
||||
@@ -446,14 +430,13 @@ func TestFunctionTool_Execute(t *testing.T) {
|
||||
|
||||
type Params struct{}
|
||||
|
||||
tool, err := agent.FunctionTool(
|
||||
tool := agent.FunctionTool(
|
||||
"validate",
|
||||
"Validate input",
|
||||
func(_ context.Context, _ Params) (agent.ToolResult, error) {
|
||||
return agent.ToolResult{Content: "validation failed", IsError: true}, nil
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
result, err := tool.Execute(context.Background(), `{}`)
|
||||
require.NoError(t, err)
|
||||
@@ -468,14 +451,13 @@ func TestFunctionTool_InterfaceSatisfaction(t *testing.T) {
|
||||
|
||||
type Params struct{}
|
||||
|
||||
tool, err := agent.FunctionTool(
|
||||
tool := agent.FunctionTool(
|
||||
"test",
|
||||
"test tool",
|
||||
func(_ context.Context, _ Params) (agent.ToolResult, error) {
|
||||
return agent.ToolResult{}, nil
|
||||
},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Implements(t, (*agent.Tool)(nil), tool)
|
||||
assert.Implements(t, (*agent.ToolDescriptor)(nil), tool)
|
||||
|
||||
Reference in New Issue
Block a user