|
|
@@ -22,8 +22,20 @@ from agent.trace.websocket import broadcast_sub_trace_started, broadcast_sub_tra
|
|
|
# ===== 远端路由常量 =====
|
|
|
|
|
|
REMOTE_PREFIX = "remote_"
|
|
|
-KNOWHUB_API = os.getenv("KNOWHUB_API", "http://localhost:9999").rstrip("/")
|
|
|
-REMOTE_AGENT_TIMEOUT = float(os.getenv("REMOTE_AGENT_TIMEOUT", "600")) # 秒
|
|
|
+
|
|
|
+
|
|
|
+def _knowhub_api() -> str:
|
|
|
+ """运行时读取 KNOWHUB_API,避免 module-load 时 .env 尚未加载的情况"""
|
|
|
+ return os.getenv("KNOWHUB_API", "http://localhost:9999").rstrip("/")
|
|
|
+
|
|
|
+
|
|
|
+def _remote_agent_timeout() -> float:
|
|
|
+ return float(os.getenv("REMOTE_AGENT_TIMEOUT", "600"))
|
|
|
+
|
|
|
+
|
|
|
+# 兼容旧代码对 module-level 常量的引用(运行时值 = 首次 import 时的快照)
|
|
|
+KNOWHUB_API = _knowhub_api()
|
|
|
+REMOTE_AGENT_TIMEOUT = _remote_agent_timeout()
|
|
|
|
|
|
|
|
|
# ===== prompts =====
|
|
|
@@ -643,9 +655,11 @@ async def _run_remote_agent(
|
|
|
"skills": skills,
|
|
|
}
|
|
|
|
|
|
+ api_base = _knowhub_api()
|
|
|
+ timeout = _remote_agent_timeout()
|
|
|
try:
|
|
|
- async with httpx.AsyncClient(timeout=REMOTE_AGENT_TIMEOUT) as client:
|
|
|
- response = await client.post(f"{KNOWHUB_API}/api/agent", json=payload)
|
|
|
+ async with httpx.AsyncClient(timeout=timeout) as client:
|
|
|
+ response = await client.post(f"{api_base}/api/agent", json=payload)
|
|
|
response.raise_for_status()
|
|
|
result = response.json()
|
|
|
|