添加四则运算工具

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-06-17 12:22:02 +08:00
co-authored by Claude
parent 2c4d4af070
commit 249227ef0a
5 changed files with 335 additions and 8 deletions
+9 -8
View File
@@ -46,7 +46,7 @@ func TestNormalizeToolRouterConfigDefaults(t *testing.T) {
if strings.TrimSpace(cfg.ToolRouter.SystemPrompt) == "" {
t.Fatal("system prompt should be defaulted")
}
if len(cfg.ToolRouter.Tools) != 3 || cfg.ToolRouter.Tools[0].Name != "time" || cfg.ToolRouter.Tools[1].Name != "search" || cfg.ToolRouter.Tools[2].Name != "sql" || !cfg.ToolRouter.Tools[0].Enabled || !cfg.ToolRouter.Tools[1].Enabled || !cfg.ToolRouter.Tools[2].Enabled {
if len(cfg.ToolRouter.Tools) != 4 || cfg.ToolRouter.Tools[0].Name != "calculator" || cfg.ToolRouter.Tools[1].Name != "time" || cfg.ToolRouter.Tools[2].Name != "search" || cfg.ToolRouter.Tools[3].Name != "sql" || !cfg.ToolRouter.Tools[0].Enabled || !cfg.ToolRouter.Tools[1].Enabled || !cfg.ToolRouter.Tools[2].Enabled || !cfg.ToolRouter.Tools[3].Enabled {
t.Fatalf("unexpected tools: %#v", cfg.ToolRouter.Tools)
}
}
@@ -66,7 +66,7 @@ func TestNormalizeOpenAIConfigDefaultsContextWindow(t *testing.T) {
}
}
func TestNormalizeToolRouterConfigAddsTimeBeforeSQL(t *testing.T) {
func TestNormalizeToolRouterConfigAddsCalculatorAndTimeBeforeSQL(t *testing.T) {
cfg := &config.Config{ToolRouter: config.ToolRouterConfig{
Enabled: true,
Timeout: 1,
@@ -82,9 +82,9 @@ func TestNormalizeToolRouterConfigAddsTimeBeforeSQL(t *testing.T) {
t.Fatal(err)
}
if !changed {
t.Fatal("expected time tool to be added")
t.Fatal("expected calculator and time tools to be added")
}
if len(cfg.ToolRouter.Tools) < 3 || cfg.ToolRouter.Tools[0].Name != "time" || cfg.ToolRouter.Tools[2].Name != "sql" {
if len(cfg.ToolRouter.Tools) < 4 || cfg.ToolRouter.Tools[0].Name != "calculator" || cfg.ToolRouter.Tools[1].Name != "time" || cfg.ToolRouter.Tools[3].Name != "sql" {
t.Fatalf("unexpected tool order: %#v", cfg.ToolRouter.Tools)
}
}
@@ -112,6 +112,7 @@ func TestAvailableAgentToolsUsesConfigOrderAndEnabled(t *testing.T) {
Enabled: true,
Tools: []config.ToolRouteConfig{
{Name: "search", Enabled: true},
{Name: "calculator", Enabled: true, Description: "custom calculator"},
{Name: "time", Enabled: true, Description: "custom time"},
{Name: "sql", Enabled: false},
},
@@ -121,14 +122,14 @@ func TestAvailableAgentToolsUsesConfigOrderAndEnabled(t *testing.T) {
}
tools := toolrouter.AvailableAgentTools(router, ai.ActiveProfile(), nil, nil, nil)
if len(tools) != 1 {
if len(tools) != 2 {
t.Fatalf("tools length = %d", len(tools))
}
if tools[0].Name() != "time" {
t.Fatalf("tool name = %s", tools[0].Name())
if tools[0].Name() != "calculator" || tools[1].Name() != "time" {
t.Fatalf("unexpected tools: %#v", tools)
}
definition := tools[0].Definition()
if definition.Function == nil || definition.Function.Description != "custom time" {
if definition.Function == nil || definition.Function.Description != "custom calculator" {
t.Fatalf("unexpected definition: %#v", definition)
}
}