From 996d5413da85dade692ddc75675e4a24d0f966e9 Mon Sep 17 00:00:00 2001 From: QihuAI Design Date: Wed, 15 Jul 2026 12:23:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8DAI=E8=81=8A=E5=A4=A9/I?= =?UTF-8?q?M=E5=A4=9A=E9=A1=B9=E9=97=AE=E9=A2=98(=E5=AA=92=E4=BD=93?= =?UTF-8?q?=E7=9B=B4=E8=BF=9E+=E6=8A=80=E8=83=BD=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8F=91=E7=8E=B0+agent/mcp=E4=B8=8A=E4=B8=8B=E6=96=87)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Issue4/7: 图像/视频生成对AGNES国内域名强制直连(trust_env=False),修复Server disconnected(代理172.18.0.1:7890返回502) - Issue8: 修复_parse_skill_content缺失def导致的NameError;新增_discover_installed_skills默认技能自动发现 - Issue2/3: system prompt注入agent资料与mcp描述/endpoint - Issue7: IM Bot制作图片走Auto路由媒体模型 --- backend/python/app/api/chat.py | 131 +++++++++++++++++++++++++++---- backend/python/app/api/im_llm.py | 130 ++++++++++++++++++++++++++---- 2 files changed, 232 insertions(+), 29 deletions(-) diff --git a/backend/python/app/api/chat.py b/backend/python/app/api/chat.py index cf29f07..a962cb8 100644 --- a/backend/python/app/api/chat.py +++ b/backend/python/app/api/chat.py @@ -125,13 +125,30 @@ def _html_escape(s: str) -> str: def _outbound_proxy() -> str: - """出网代理地址。容器内直连 apihub.agnes-ai.com 会被对端重置 - (httpx RemoteProtocolError: Server disconnected without sending a response), - 必须经 172.18.0.1:7890 智能路由代理(其对国内 AGNES 域名走直连)。""" + """出网代理地址(兜底)。默认经 172.18.0.1:7890 智能路由代理; + 运行时若未注入代理环境变量则回退到该地址。""" import os return os.environ.get("HTTPS_PROXY") or os.environ.get("HTTP_PROXY") or "http://172.18.0.1:7890" +def _proxy_for_url(url: str) -> str | None: + """按目标域名选择是否走代理。 + + 实测(2026-07-15):apihub.agnes-ai.com / platform-outputs.agnes-ai.space 为国内域名, + 容器内直连稳定返回 200;而经智能路由代理 172.18.0.1:7890 当前返回 502,导致 + httpx 报 "Server disconnected without sending a response"。 + 因此对 AGNES 等国内域名返回 None(直连),其余域名才走 _outbound_proxy()。 + + 注意:httpx 默认 trust_env=True 会忽略 proxy=None 而改用环境变量 HTTP_PROXY, + 故调用方必须同时传 trust_env=False 才能真正直连。 + """ + from urllib.parse import urlparse + host = (urlparse(url).hostname or "").lower() + if "agnes-ai.com" in host or "agnes-ai.space" in host: + return None + return _outbound_proxy() + + async def _generate_media(db, ai_model, prompt: str, user_id: str = None) -> str: """图像/视频生成模型统一入口:按 capabilities 调用 AGNES 等媒体生成 API。 返回可直接在 AI 聊天中渲染的富文本(含 /