Skip to content

support proxy in web tool#735

Closed
wgjtyu wants to merge 1 commit intosipeed:mainfrom
wgjtyu:main
Closed

support proxy in web tool#735
wgjtyu wants to merge 1 commit intosipeed:mainfrom
wgjtyu:main

Conversation

@wgjtyu
Copy link
Contributor

@wgjtyu wgjtyu commented Feb 24, 2026

📝 Description

add proxy support in web tool

🗣️ Type of Change

  • 🐞 Bug fix (non-breaking change which fixes an issue)
  • [*] ✨ New feature (non-breaking change which adds functionality)
  • 📖 Documentation update
  • ⚡ Code refactoring (no functional changes, no api changes)

🤖 AI Code Generation

  • 🤖 Fully AI-generated (100% AI, 0% Human)
  • [*] 🛠️ Mostly AI-generated (AI draft, Human verified/modified)
  • 👨‍💻 Mostly Human-written (Human lead, AI assisted or none)

🔗 Related Issue

📚 Technical Context (Skip for Docs)

  • Reference URL:
  • Reasoning:

🧪 Test Environment

  • Hardware:
  • OS:
  • Model/Provider:
  • Channels:

📸 Evidence (Optional)

Click to view Logs/Screenshots

☑️ Checklist

  • My code/docs follow the style of this project.
  • I have performed a self-review of my own changes.
  • I have updated the documentation accordingly.

Copilot AI review requested due to automatic review settings February 24, 2026 14:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds configurable proxy support for the web search toolchain by threading a proxy string from config/env into each search provider and creating HTTP clients/transports that honor SOCKS5 or HTTP(S) proxy settings.

Changes:

  • Add Proxy to WebToolsConfig (JSON + env var) and default it in DefaultConfig().
  • Pass the configured proxy into web search providers (Brave/Tavily/DuckDuckGo/Perplexity).
  • Introduce clientForProxy() helper to build an http.Client using either SOCKS5 or HTTP proxy.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
pkg/tools/web.go Adds per-provider proxy support and a shared clientForProxy() factory.
pkg/config/config.go Extends WebToolsConfig with Proxy (JSON/env).
pkg/config/defaults.go Sets default Tools.Web.Proxy to empty string.
pkg/agent/loop.go Wires cfg.Tools.Web.Proxy into WebSearchToolOptions.
Comments suppressed due to low confidence (1)

pkg/agent/loop.go:113

  • cfg.Tools.Web.Proxy is passed into NewWebSearchTool, but web_fetch is still registered with a fixed http.Client that does not use this proxy config. If the intent is to support proxies for all web tools, consider plumbing the proxy option into WebFetchTool as well (or clarify the config name/scope).
				Proxy:                cfg.Tools.Web.Proxy,
		}); searchTool != nil {
			agent.Tools.Register(searchTool)
		}
		agent.Tools.Register(tools.NewWebFetchTool(50000))

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +302 to +305
transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
return dialer.Dial(network, addr)
}
return &http.Client{Timeout: timeout, Transport: transport}, nil
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This DialContext implementation ignores the provided ctx and calls dialer.Dial directly. That prevents request cancellation/timeouts from aborting an in-progress SOCKS5 dial, which can cause hangs under network issues. Prefer using a dialer that supports context (e.g., if the returned dialer implements proxy.ContextDialer, use DialContext), or otherwise implement a ctx-aware cancellation wrapper.

Copilot uses AI. Check for mistakes.
Comment on lines +324 to +326
transport.DialContext = func(ctx context.Context, network, addr string) (net.Conn, error) {
return dialer.Dial(network, addr)
}
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue here: DialContext ignores ctx, so cancelling the request context may not stop the SOCKS5 connection attempt. Consider using proxy.ContextDialer when available or otherwise honoring ctx to avoid stuck dials.

Copilot uses AI. Check for mistakes.
Comment on lines +279 to +289
// clientForProxy returns an *http.Client honoring the provided proxy string.
// Supported formats:
// - "socks5://host:port" or plain "host:port" (treated as socks5)
// - any URL with scheme (http://, https://) will be used as an HTTP proxy via ProxyURL
func clientForProxy(proxyStr string, timeout time.Duration) (*http.Client, error) {
transport := &http.Transport{
TLSHandshakeTimeout: 15 * time.Second,
MaxIdleConns: 10,
IdleConnTimeout: 30 * time.Second,
DisableCompression: false,
}
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Proxy support is newly introduced here (via Proxy option and clientForProxy), but the existing pkg/tools/web_test.go suite doesn’t appear to cover any proxy behaviors (e.g., HTTP proxy URL parsing, SOCKS5 dialer selection, or error handling on invalid proxy strings). Adding focused unit tests for clientForProxy (and at least one provider using it) would help prevent regressions.

Copilot uses AI. Check for mistakes.
PerplexityAPIKey: cfg.Tools.Web.Perplexity.APIKey,
PerplexityMaxResults: cfg.Tools.Web.Perplexity.MaxResults,
PerplexityEnabled: cfg.Tools.Web.Perplexity.Enabled,
Proxy: cfg.Tools.Web.Proxy,
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Proxy: field in this struct literal is mis-indented compared to the other fields and will be reformatted by gofmt; if CI enforces formatting, this may fail. Please run gofmt (or fix indentation) so the struct literal field alignment is consistent.

Suggested change
Proxy: cfg.Tools.Web.Proxy,
Proxy: cfg.Tools.Web.Proxy,

Copilot uses AI. Check for mistakes.
@yinwm
Copy link
Collaborator

yinwm commented Feb 24, 2026

Same as #587

@yinwm yinwm closed this Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants