- config/sub_agent.py: 新增 resolve_sub_agent_models_config() 和 SUB_AGENT_MODELS_CONFIG_FILE,回退链:外置 → 源码种子 → easyagent/ 旧位置 → .example 兜底 - modules/sub_agent_manager.py: 子进程启动时传递 --config-file 参数 - easyagent/src/config.js: ensureConfig() 支持可选 customPath 参数 - easyagent/src/batch/index.js: 新增 --config-file CLI 参数 - config/sub_agent_models.json.example: 新增种子模板 - easyagent/models.json: 更新默认模型
64 lines
2.7 KiB
Python
64 lines
2.7 KiB
Python
"""子智能体相关配置。"""
|
||
|
||
import os
|
||
from pathlib import Path
|
||
|
||
from .paths import (
|
||
_resolve_repo_path,
|
||
_REPO_ROOT,
|
||
DATA_DIR,
|
||
DEFAULT_PROJECT_PATH,
|
||
resolve_deploy_config,
|
||
)
|
||
|
||
# 子智能体服务
|
||
SUB_AGENT_SERVICE_BASE_URL = os.environ.get("SUB_AGENT_SERVICE_URL", "http://127.0.0.1:8092")
|
||
SUB_AGENT_DEFAULT_TIMEOUT = int(os.environ.get("SUB_AGENT_DEFAULT_TIMEOUT", "180")) # 秒
|
||
SUB_AGENT_STATUS_POLL_INTERVAL = float(os.environ.get("SUB_AGENT_STATUS_POLL_INTERVAL", "2.0"))
|
||
|
||
# 存储与并发限制
|
||
# 子智能体任务目录与状态文件属于运行态数据,跟随 DATA_DIR(默认 ~/.agents/<mode>/data)。
|
||
SUB_AGENT_TASKS_BASE_DIR = _resolve_repo_path(os.environ.get("SUB_AGENT_TASKS_BASE_DIR", ""), f"{DATA_DIR}/sub_agent_tasks")
|
||
SUB_AGENT_STATE_FILE = _resolve_repo_path(os.environ.get("SUB_AGENT_STATE_FILE", ""), f"{DATA_DIR}/sub_agents.json")
|
||
# 子智能体产出结果有意落在工作区内,跟随 DEFAULT_PROJECT_PATH,不迁入运行态根目录。
|
||
SUB_AGENT_PROJECT_RESULTS_DIR = _resolve_repo_path(os.environ.get("SUB_AGENT_PROJECT_RESULTS_DIR", ""), f"{DEFAULT_PROJECT_PATH}/sub_agent_results")
|
||
SUB_AGENT_MAX_ACTIVE = int(os.environ.get("SUB_AGENT_MAX_ACTIVE", "5"))
|
||
|
||
|
||
def resolve_sub_agent_models_config() -> str:
|
||
"""解析子智能体模型配置文件路径,回退链(高→低):
|
||
|
||
1. ``~/.agents/<mode>/config/sub_agent_models.json``(部署者真实配置)
|
||
2. 源码树 ``config/sub_agent_models.json``(仓库内种子)
|
||
3. 源码树 ``easyagent/models.json``(旧版 easyagent 配置位置)
|
||
4. 源码树 ``config/sub_agent_models.json.example``(示例兜底)
|
||
|
||
都不存在时返回部署目录下的目标路径,由调用方处理不存在。
|
||
"""
|
||
# 先走标准回退链:部署 → config/种子 → config/.example
|
||
standard = resolve_deploy_config("sub_agent_models.json")
|
||
standard_path = Path(standard)
|
||
if standard_path.exists():
|
||
return str(standard_path)
|
||
# 最后回退到旧 easyagent/models.json
|
||
legacy = _REPO_ROOT / "easyagent" / "models.json"
|
||
if legacy.exists():
|
||
return str(legacy)
|
||
return standard # 返回部署目录路径,由调用方处理不存在
|
||
|
||
|
||
# 子智能体模型配置文件(可通过环境变量覆盖,否则走回退链解析)
|
||
SUB_AGENT_MODELS_CONFIG_FILE = os.environ.get("SUB_AGENT_MODELS_CONFIG_FILE", "") or resolve_sub_agent_models_config()
|
||
|
||
__all__ = [
|
||
"SUB_AGENT_SERVICE_BASE_URL",
|
||
"SUB_AGENT_DEFAULT_TIMEOUT",
|
||
"SUB_AGENT_STATUS_POLL_INTERVAL",
|
||
"SUB_AGENT_TASKS_BASE_DIR",
|
||
"SUB_AGENT_PROJECT_RESULTS_DIR",
|
||
"SUB_AGENT_STATE_FILE",
|
||
"SUB_AGENT_MAX_ACTIVE",
|
||
"SUB_AGENT_MODELS_CONFIG_FILE",
|
||
"resolve_sub_agent_models_config",
|
||
]
|