fix(server): 自动发现 CWD 下的 agentkit.yaml 和 .env
之前 create_app 只在 AGENTKIT_CONFIG_PATH 环境变量设置时才加载配置和 .env, 导致 uvicorn 直接启动时 LLM provider 未注册(No provider registered)。 现在当 AGENTKIT_CONFIG_PATH 未设置时,自动查找 CWD 下的 agentkit.yaml, 并加载同目录的 .env 文件注入环境变量。
This commit is contained in:
parent
905c1f6b18
commit
6945b78c55
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue