From 6945b78c5541a9dacd88bb1d6acf5be2ac9bb6a9 Mon Sep 17 00:00:00 2001 From: chiguyong Date: Sat, 13 Jun 2026 11:40:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(server):=20=E8=87=AA=E5=8A=A8=E5=8F=91?= =?UTF-8?q?=E7=8E=B0=20CWD=20=E4=B8=8B=E7=9A=84=20agentkit.yaml=20?= =?UTF-8?q?=E5=92=8C=20.env?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 之前 create_app 只在 AGENTKIT_CONFIG_PATH 环境变量设置时才加载配置和 .env, 导致 uvicorn 直接启动时 LLM provider 未注册(No provider registered)。 现在当 AGENTKIT_CONFIG_PATH 未设置时,自动查找 CWD 下的 agentkit.yaml, 并加载同目录的 .env 文件注入环境变量。 --- src/agentkit/server/app.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/agentkit/server/app.py b/src/agentkit/server/app.py index 511dd0a..541e89c 100644 --- a/src/agentkit/server/app.py +++ b/src/agentkit/server/app.py @@ -351,10 +351,17 @@ def create_app( """ # Auto-load config from env var if not provided (uvicorn factory mode) if server_config is None: + from pathlib import Path as _P + config_path = os.environ.get("AGENTKIT_CONFIG_PATH") + if not config_path or not os.path.exists(config_path): + # Auto-discover agentkit.yaml in CWD + _cwd_yaml = _P.cwd() / "agentkit.yaml" + if _cwd_yaml.exists(): + config_path = str(_cwd_yaml) + if config_path and os.path.exists(config_path): # Load .env before parsing config (so ${ENV_VAR} substitutions work) - from pathlib import Path as _P _dotenv = _P(config_path).parent / ".env" if _dotenv.exists(): with open(_dotenv, encoding="utf-8") as _f: