From 93977bf348b6d8b9760a38215e425aeef785f40e Mon Sep 17 00:00:00 2001 From: SiYue-ZO <2835601846@qq.com> Date: Tue, 14 Apr 2026 22:58:07 +0800 Subject: [PATCH 1/7] Add configurable Sogou-backed web search --- config/config.example.json | 7 +- pkg/agent/loop.go | 3 + pkg/config/config.go | 7 + pkg/config/defaults.go | 7 +- pkg/tools/web.go | 263 +++++++++++++--- pkg/tools/web_test.go | 60 ++++ web/backend/api/tools.go | 254 +++++++++++++++ web/backend/api/tools_test.go | 98 ++++++ web/frontend/src/api/tools.ts | 39 +++ .../src/components/agent/tools/tools-page.tsx | 290 +++++++++++++++++- web/frontend/src/i18n/locales/en.json | 22 +- web/frontend/src/i18n/locales/zh.json | 22 +- 12 files changed, 1027 insertions(+), 45 deletions(-) diff --git a/config/config.example.json b/config/config.example.json index 2d2d38496..d56b1cff7 100644 --- a/config/config.example.json +++ b/config/config.example.json @@ -269,10 +269,15 @@ "base_url": "", "max_results": 0 }, - "duckduckgo": { + "provider": "sogou", + "sogou": { "enabled": true, "max_results": 5 }, + "duckduckgo": { + "enabled": false, + "max_results": 5 + }, "perplexity": { "enabled": false, "api_key": "pplx-xxx", diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index bc71fa088..507d1c96f 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -194,6 +194,7 @@ func registerSharedTools( if cfg.Tools.IsToolEnabled("web") { searchTool, err := tools.NewWebSearchTool(tools.WebSearchToolOptions{ + Provider: cfg.Tools.Web.Provider, BraveAPIKeys: cfg.Tools.Web.Brave.APIKeys.Values(), BraveMaxResults: cfg.Tools.Web.Brave.MaxResults, BraveEnabled: cfg.Tools.Web.Brave.Enabled, @@ -201,6 +202,8 @@ func registerSharedTools( TavilyBaseURL: cfg.Tools.Web.Tavily.BaseURL, TavilyMaxResults: cfg.Tools.Web.Tavily.MaxResults, TavilyEnabled: cfg.Tools.Web.Tavily.Enabled, + SogouMaxResults: cfg.Tools.Web.Sogou.MaxResults, + SogouEnabled: cfg.Tools.Web.Sogou.Enabled, DuckDuckGoMaxResults: cfg.Tools.Web.DuckDuckGo.MaxResults, DuckDuckGoEnabled: cfg.Tools.Web.DuckDuckGo.Enabled, PerplexityAPIKeys: cfg.Tools.Web.Perplexity.APIKeys.Values(), diff --git a/pkg/config/config.go b/pkg/config/config.go index 683f68951..ae6a5cdb0 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -664,6 +664,11 @@ type DuckDuckGoConfig struct { MaxResults int `json:"max_results" env:"PICOCLAW_TOOLS_WEB_DUCKDUCKGO_MAX_RESULTS"` } +type SogouConfig struct { + Enabled bool `json:"enabled" env:"PICOCLAW_TOOLS_WEB_SOGOU_ENABLED"` + MaxResults int `json:"max_results" env:"PICOCLAW_TOOLS_WEB_SOGOU_MAX_RESULTS"` +} + type PerplexityConfig struct { Enabled bool `json:"enabled" yaml:"-" env:"PICOCLAW_TOOLS_WEB_PERPLEXITY_ENABLED"` APIKeys SecureStrings `json:"api_keys,omitzero" yaml:"api_keys,omitempty" env:"PICOCLAW_TOOLS_WEB_PERPLEXITY_API_KEYS"` @@ -710,11 +715,13 @@ type WebToolsConfig struct { ToolConfig ` yaml:"-" envPrefix:"PICOCLAW_TOOLS_WEB_"` Brave BraveConfig `yaml:"brave,omitempty" json:"brave"` Tavily TavilyConfig `yaml:"tavily,omitempty" json:"tavily"` + Sogou SogouConfig `yaml:"-" json:"sogou"` DuckDuckGo DuckDuckGoConfig `yaml:"-" json:"duckduckgo"` Perplexity PerplexityConfig `yaml:"perplexity,omitempty" json:"perplexity"` SearXNG SearXNGConfig `yaml:"-" json:"searxng"` GLMSearch GLMSearchConfig `yaml:"glm_search,omitempty" json:"glm_search"` BaiduSearch BaiduSearchConfig `yaml:"baidu_search,omitempty" json:"baidu_search"` + Provider string `yaml:"-" json:"provider,omitempty" env:"PICOCLAW_TOOLS_WEB_PROVIDER"` // PreferNative controls whether to use provider-native web search when // the active LLM supports it (e.g. OpenAI web_search_preview). When true, // the client-side web_search tool is hidden to avoid duplicate search surfaces, diff --git a/pkg/config/defaults.go b/pkg/config/defaults.go index d67b7a668..5f5e3d0b3 100644 --- a/pkg/config/defaults.go +++ b/pkg/config/defaults.go @@ -278,6 +278,7 @@ func DefaultConfig() *Config { ToolConfig: ToolConfig{ Enabled: true, }, + Provider: "sogou", PreferNative: true, Proxy: "", FetchLimitBytes: 10 * 1024 * 1024, // 10MB by default @@ -290,10 +291,14 @@ func DefaultConfig() *Config { Enabled: false, MaxResults: 5, }, - DuckDuckGo: DuckDuckGoConfig{ + Sogou: SogouConfig{ Enabled: true, MaxResults: 5, }, + DuckDuckGo: DuckDuckGoConfig{ + Enabled: false, + MaxResults: 5, + }, Perplexity: PerplexityConfig{ Enabled: false, MaxResults: 5, diff --git a/pkg/tools/web.go b/pkg/tools/web.go index 342f7458b..e98770b3f 100644 --- a/pkg/tools/web.go +++ b/pkg/tools/web.go @@ -46,7 +46,10 @@ var ( reDDGLink = regexp.MustCompile( `]*class="[^"]*result__a[^"]*"[^>]*href="([^"]+)"[^>]*>([\s\S]*?)`, ) - reDDGSnippet = regexp.MustCompile(`([\s\S]*?)`) + reDDGSnippet = regexp.MustCompile(`([\s\S]*?)`) + reSogouTitle = regexp.MustCompile(`]*id="sogou_vr_\d+_\d+"[^>]*>\s*(.*?)\s*`) + reSogouSnippet = regexp.MustCompile(`