JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
Python
fix(harness): improve search tool prompts and add huawei proxy config
m0568387002806a56e75ca
diff --git a/docs/en/Configuration.md b/docs/en/Configuration.mdindex 5b3c699e20..016d9bb0bc 100644--- a/docs/en/Configuration.md+++ b/docs/en/Configuration.md@@ -30,6 +30,7 @@ These can be changed in the web app; values are written back to `.env` or config| `serper_api_key` | `SERPER_API_KEY` | Serper search API key || `perplexity_api_key` | `PERPLEXITY_API_KEY` | Perplexity API key || `github_token` | `GITHUB_TOKEN` | GitHub PAT; SkillNet search/install uses the GitHub API |+| `free_search_proxy_url` | `FREE_SEARCH_PROXY_URL` | Optional HTTP/HTTPS proxy for free search and webpage fetch, for example `http://username:[email protected]:8080` || `evolution_auto_scan` | `EVOLUTION_AUTO_SCAN` | Auto-scan evolvable skills after each turn (`true`/`false`) |**Note**: After saving, the backend restarts to load new settings. Model fields (`api_base`, `api_key`, `model`, `model_provider`) are required.diff --git "a/docs/zh/\351\205\215\347\275\256\344\277\241\346\201\257.md" "b/docs/zh/\351\205\215\347\275\256\344\277\241\346\201\257.md"index 73ae663cde..55b41c93ea 100644--- "a/docs/zh/\351\205\215\347\275\256\344\277\241\346\201\257.md"+++ "b/docs/zh/\351\205\215\347\275\256\344\277\241\346\201\257.md"@@ -30,6 +30,7 @@ JiuwenClaw 的配置来源包括:`config/config.yaml`、`.env` 环境变量、| `serper_api_key` | `SERPER_API_KEY` | Serper 搜索 API 密钥 || `perplexity_api_key` | `PERPLEXITY_API_KEY` | Perplexity API 密钥 || `github_token` | `GITHUB_TOKEN` | GitHub Personal Access Token;SkillNet 搜索/安装走 GitHub API |+| `free_search_proxy_url` | `FREE_SEARCH_PROXY_URL` | 免费搜索和网页抓取使用的可选 HTTP/HTTPS 代理,例如 `http://username:[email protected]:8080` || `evolution_auto_scan` | `EVOLUTION_AUTO_SCAN` | 是否每轮对话后自动扫描可演进技能(`true`/`false`) |**说明**:保存后后端会重启以加载新配置。模型配置(`api_base`、`api_key`、`model`、`model_provider`)为必填项。diff --git a/jiuwenclaw/agentserver/deep_agent/rails/runtime_prompt_rail.py b/jiuwenclaw/agentserver/deep_agent/rails/runtime_prompt_rail.pyindex 330dc5c88e..a4337be8af 100644--- a/jiuwenclaw/agentserver/deep_agent/rails/runtime_prompt_rail.py+++ b/jiuwenclaw/agentserver/deep_agent/rails/runtime_prompt_rail.py@@ -87,13 +87,25 @@ class RuntimePromptRail(DeepAgentRail):returnnow = datetime.now(tz=self._tz)+ now_str = now.strftime("%Y-%m-%d %H:%M:%S")+ current_year = now.strftime("%Y")+if self._language == "cn":- weekday_str = _CN_WEEKDAYS[now.weekday()]- now_str = now.strftime("%Y-%m-%d") + f" {weekday_str} " + now.strftime("%H:%M:%S")- time_content = f"# 当前日期与时间\n\n{now_str}"+ time_content = (+ f"# 当前日期与时间\n\n"+ f"- 当前时间:{now_str}\n"+ f"- 当前年份:{current_year}\n"+ "- 当用户询问“最新、当前、今年、本年、实时、近期”等信息并需要搜索时,"+ "搜索 query 必须优先使用当前年份或日期"+ )else:- now_str = now.strftime("%Y-%m-%d %A %H:%M:%S")- time_content = f"# Current Date & Time\n\n{now_str}"+ time_content = (+ f"# Current Date & Time\n\n"+ f"- Current time: {now_str}\n"+ f"- Current year: {current_year}\n"+ "- When the user asks for latest/current/this-year/recent information and search is needed, "+ "search queries must prefer the current year or date."+ )self.system_prompt_builder.add_section(PromptSection(name="time",diff --git a/jiuwenclaw/agentserver/tools/search_tools.py b/jiuwenclaw/agentserver/tools/search_tools.pyindex c254da8d38..27371312df 100644--- a/jiuwenclaw/agentserver/tools/search_tools.py+++ b/jiuwenclaw/agentserver/tools/search_tools.py@@ -21,11 +21,50 @@ _USER_AGENT = ("Chrome/124.0.0.0 Safari/537.36")_REQUEST_HEADERS = {"User-Agent": _USER_AGENT}+_FREE_SEARCH_PROXY_URL_ENV = "FREE_SEARCH_PROXY_URL"+_FREE_SEARCH_DEFAULT_NO_PROXY = (+ "127.0.0.1,.huawei.com,localhost,local,.local,10.155.97.247,.myhuaweicloud.coms"+)+++def _get_free_search_proxy_url() -> str:+ return str(os.environ.get(_FREE_SEARCH_PROXY_URL_ENV, "") or "").strip()+++def _no_proxy_entries() -> list[str]:+ configured = os.environ.get("NO_PROXY") or os.environ.get("no_proxy") or _FREE_SEARCH_DEFAULT_NO_PROXY+ return [entry.strip().lower() for entry in configured.split(",") if entry.strip()]+++def _should_bypass_free_search_proxy(url: str) -> bool:+ proxy_url = _get_free_search_proxy_url()+ if not proxy_url:+ return True+ hostname = (urlparse(url).hostname or "").lower()+ if not hostname:+ return False+ for entry in _no_proxy_entries():+ if entry == "*":+ return True+ if entry.startswith(".") and (hostname == entry[1:] or hostname.endswith(entry)):+ return True+ if hostname == entry or hostname.endswith(f".{entry}"):+ return True+ return False+++def _apply_free_search_proxy(url: str, kwargs: dict[str, Any]) -> bool:+ proxy_url = _get_free_search_proxy_url()+ if not proxy_url or _should_bypass_free_search_proxy(url):+ return False+ kwargs.setdefault("proxies", {"http": proxy_url, "https": proxy_url})+ return Truedef _http_request(method: str, url: str, **kwargs) -> requests.Response:"""Try normal request first; retry without env proxies on ProxyError."""method_up = method.upper()+ explicit_proxy = _apply_free_search_proxy(url, kwargs)try:if method_up == "GET":return requests.get(url, **kwargs)@@ -33,6 +72,8 @@ def _http_request(method: str, url: str, **kwargs) -> requests.Response:return requests.post(url, **kwargs)return requests.request(method_up, url, **kwargs)except requests.exceptions.ProxyError:+ if explicit_proxy:+ raisewith requests.Session() as session:session.trust_env = Falsereturn session.request(method_up, url, **kwargs)diff --git a/jiuwenclaw/agentserver/tools/web_fetch_tools.py b/jiuwenclaw/agentserver/tools/web_fetch_tools.pyindex ca11422053..7a52521b1b 100644--- a/jiuwenclaw/agentserver/tools/web_fetch_tools.py+++ b/jiuwenclaw/agentserver/tools/web_fetch_tools.py@@ -19,6 +19,10 @@ _USER_AGENT = ("Chrome/124.0.0.0 Safari/537.36")_REQUEST_HEADERS = {"User-Agent": _USER_AGENT}+_FREE_SEARCH_PROXY_URL_ENV = "FREE_SEARCH_PROXY_URL"+_FREE_SEARCH_DEFAULT_NO_PROXY = (+ "127.0.0.1,.huawei.com,localhost,local,.local,10.155.97.247,.myhuaweicloud.coms"+)_CHARSET_HEADER_RE = re.compile(r"charset=([^\s;]+)", flags=re.IGNORECASE)_CHARSET_META_RE = re.compile(br"""<meta[^>]+charset=["']?\s*([A-Za-z0-9._-]+)""",@@ -42,6 +46,40 @@ def _extract_declared_charset(response: requests.Response) -> str:return ""+def _get_free_search_proxy_url() -> str:+ return str(os.environ.get(_FREE_SEARCH_PROXY_URL_ENV, "") or "").strip()+++def _no_proxy_entries() -> list[str]:+ configured = os.environ.get("NO_PROXY") or os.environ.get("no_proxy") or _FREE_SEARCH_DEFAULT_NO_PROXY+ return [entry.strip().lower() for entry in configured.split(",") if entry.strip()]+++def _should_bypass_free_search_proxy(url: str) -> bool:+ proxy_url = _get_free_search_proxy_url()+ if not proxy_url:+ return True+ hostname = (urlparse(url).hostname or "").lower()+ if not hostname:+ return False+ for entry in _no_proxy_entries():+ if entry == "*":+ return True+ if entry.startswith(".") and (hostname == entry[1:] or hostname.endswith(entry)):+ return True+ if hostname == entry or hostname.endswith(f".{entry}"):+ return True+ return False+++def _apply_free_search_proxy(url: str, kwargs: dict[str, object]) -> bool:+ proxy_url = _get_free_search_proxy_url()+ if not proxy_url or _should_bypass_free_search_proxy(url):+ return False+ kwargs.setdefault("proxies", {"http": proxy_url, "https": proxy_url})+ return True++def _decode_response_text(response: requests.Response) -> str:raw = response.content or b""if not raw:@@ -86,9 +124,12 @@ def _decode_response_text(response: requests.Response) -> str:def _http_get(url: str, **kwargs) -> requests.Response:"""Try normal requests first; retry without env proxies on ProxyError."""+ explicit_proxy = _apply_free_search_proxy(url, kwargs)try:return requests.get(url, **kwargs)except requests.exceptions.ProxyError:+ if explicit_proxy:+ raisewith requests.Session() as session:session.trust_env = Falsereturn session.get(url, **kwargs)diff --git a/jiuwenclaw/app_web_handlers.py b/jiuwenclaw/app_web_handlers.pyindex d23c45d0fd..511f5a8a88 100644--- a/jiuwenclaw/app_web_handlers.py+++ b/jiuwenclaw/app_web_handlers.py@@ -176,6 +176,7 @@ _CONFIG_SET_ENV_MAP = {"evolution_auto_scan": "EVOLUTION_AUTO_SCAN","free_search_ddg_enabled": "FREE_SEARCH_DDG_ENABLED","free_search_bing_enabled": "FREE_SEARCH_BING_ENABLED",+ "free_search_proxy_url": "FREE_SEARCH_PROXY_URL",}# 配置项键名列表,用于日志等说明CONFIG_KEYS = tuple(_CONFIG_SET_ENV_MAP.keys())diff --git a/jiuwenclaw/resources/.env.template b/jiuwenclaw/resources/.env.templateindex 1ad949cf32..dd59dd96cc 100644--- a/jiuwenclaw/resources/.env.template+++ b/jiuwenclaw/resources/.env.template@@ -31,6 +31,7 @@ JINA_API_KEY=SERPER_API_KEY=PERPLEXITY_API_KEY=GITHUB_TOKEN=+FREE_SEARCH_PROXY_URL=# Browser MCP runtime (optional)# 0: disabled, 1: enabled@@ -95,4 +96,4 @@ NO_PROXY=localhost,127.0.0.1,api.openai.rnd.huawei.comMEMORY_MODE=# Extension package search dirs, separated by ';'-EXTENSION_DIRS=""\ No newline at end of file+EXTENSION_DIRS=""diff --git a/jiuwenclaw/web/src/components/ConfigPanel/index.tsx b/jiuwenclaw/web/src/components/ConfigPanel/index.tsxindex 8bf5c68528..2073e8f79c 100644--- a/jiuwenclaw/web/src/components/ConfigPanel/index.tsx+++ b/jiuwenclaw/web/src/components/ConfigPanel/index.tsx@@ -40,7 +40,8 @@ const THIRD_PARTY_API_KEYS = new Set([const REQUIRED_MODEL_FIELDS = ["api_base", "api_key", "model", "model_provider"] as const;const REQUIRED_MODEL_FIELD_SET = new Set<string>(REQUIRED_MODEL_FIELDS);const EVOLUTION_KEYS = new Set(["evolution_auto_scan"]);-const FREE_SEARCH_KEYS = new Set(["free_search_ddg_enabled", "free_search_bing_enabled"]);+const FREE_SEARCH_BOOLEAN_KEYS = new Set(["free_search_ddg_enabled", "free_search_bing_enabled"]);+const FREE_SEARCH_KEYS = new Set([...FREE_SEARCH_BOOLEAN_KEYS, "free_search_proxy_url"]);const MEMORY_KEYS = new Set(["memory_forbidden_enabled", "memory_forbidden_description"]);function classifyKey(key: string): string {@@ -160,7 +161,7 @@ function getNestedModelStyle(tag: string): string {function isBooleanKey(key: string): boolean {return (EVOLUTION_KEYS.has(key) ||- FREE_SEARCH_KEYS.has(key) ||+ FREE_SEARCH_BOOLEAN_KEYS.has(key) ||key === "context_engine_enabled" ||key === "kv_cache_affinity_enabled" ||key === "permissions_enabled" ||@@ -191,7 +192,8 @@ function isSensitiveKey(key: string): boolean {lower.includes("key") ||lower.includes("secret") ||lower.includes("token") ||- lower.includes("password")+ lower.includes("password") ||+ lower.includes("proxy"));}@@ -236,15 +238,20 @@ function isProviderKey(key: string): boolean {/** 表格列显示用:video_api_base -> api_base,避免与分组标题重复 *//** i18n 键名映射:字段名 -> 翻译 key(显示名 / placeholder) */const KEY_DISPLAY_I18N: Record<string, string> = {+ free_search_proxy_url: "config.keys.freeSearchProxyUrl",memory_forbidden_enabled: "config.keys.memoryForbiddenEnabled",memory_forbidden_description: "config.keys.memoryForbiddenDescription",};const KEY_PLACEHOLDER_I18N: Record<string, string> = {+ free_search_proxy_url: "config.keys.freeSearchProxyUrlPlaceholder",memory_forbidden_description: "config.keys.memoryForbiddenDescriptionPlaceholder",};/** 组内字段排序优先级,数字越小越靠前 */const KEY_SORT_PRIORITY: Record<string, number> = {+ free_search_ddg_enabled: 0,+ free_search_bing_enabled: 1,+ free_search_proxy_url: 2,memory_forbidden_enabled: 0,memory_forbidden_description: 1,};diff --git a/jiuwenclaw/web/src/i18n/locales/en.json b/jiuwenclaw/web/src/i18n/locales/en.jsonindex c97f3ba216..296f638ac8 100644--- a/jiuwenclaw/web/src/i18n/locales/en.json+++ b/jiuwenclaw/web/src/i18n/locales/en.json@@ -381,6 +381,8 @@"selectModelProvider": "Select a model provider","enterValue": "Enter a configuration value","keys": {+ "freeSearchProxyUrl": "Huawei proxy URL",+ "freeSearchProxyUrlPlaceholder": "http://username:[email protected]:8080","memoryForbiddenEnabled": "Enable","memoryForbiddenDescription": "Forbidden memory content description","memoryForbiddenDescriptionPlaceholder": "e.g. passwords, API keys, secrets, tokens, credit card numbers, ID numbers, phone numbers"@@ -404,7 +406,7 @@"model": { "label": "Model Configuration", "hint": "Model service and authentication settings" },"embed": { "label": "Embed Configuration", "hint": "Embed service and authentication settings" },"thirdParty": { "label": "Third-Party Services", "hint": "API key settings" },- "freeSearch": { "label": "Free Search Engines", "hint": "Enable or disable free search engines" },+ "freeSearch": { "label": "Free Search Engines", "hint": "Enable engines and optional Huawei proxy for enterprise intranet" },"evolution": { "label": "Evolution Settings", "hint": "Online skill evolution settings" },"contextEngine": { "label": "Context Compression", "hint": "Enable or disable dialogue context compression" },"permissions": { "label": "Tool Safety Guardrail", "hint": "Enable or disable permission checks for tool calls" },diff --git a/jiuwenclaw/web/src/i18n/locales/zh.json b/jiuwenclaw/web/src/i18n/locales/zh.jsonindex 381562c76d..ce110823dc 100644--- a/jiuwenclaw/web/src/i18n/locales/zh.json+++ b/jiuwenclaw/web/src/i18n/locales/zh.json@@ -380,6 +380,8 @@"selectModelProvider": "请选择模型提供商","enterValue": "请输入配置值","keys": {+ "freeSearchProxyUrl": "\u534e\u4e3a\u4ee3\u7406\u5730\u5740",+ "freeSearchProxyUrlPlaceholder": "http://username:[email protected]:8080","memoryForbiddenEnabled": "启用","memoryForbiddenDescription": "禁止记忆内容描述","memoryForbiddenDescriptionPlaceholder": "例如:密码、API密钥、Secret、Token、信用卡号、身份证号、手机号等敏感信息"@@ -403,7 +405,7 @@"model": { "label": "模型配置", "hint": "模型服务与鉴权参数" },"embed": { "label": "Embed配置", "hint": "Embed 服务与鉴权参数" },"thirdParty": { "label": "第三方服务配置", "hint": "API Key 配置" },- "freeSearch": { "label": "免费搜索引擎配置", "hint": "控制免费搜索工具启用的搜索引擎" },+ "freeSearch": { "label": "免费搜索引擎配置", "hint": "控制搜索引擎启用和企业内网华为代理" },"evolution": { "label": "自演进配置", "hint": "Skills 在线自演进参数" },"contextEngine": { "label": "上下文压缩", "hint": "控制对话上下文是否启用压缩" },"permissions": { "label": "工具安全护栏", "hint": "控制工具调用时的权限检查" },