mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
refactor: update job execution configuration loading in scheduler
- Implemented dynamic loading of environment variables and configuration settings for job execution, allowing for real-time updates without restarting the gateway. - Enhanced model and API configuration retrieval from both environment variables and a YAML configuration file, improving flexibility and adaptability of the job execution process.
This commit is contained in:
parent
9ec4f7504b
commit
6d74d424d3
1 changed files with 27 additions and 1 deletions
|
|
@ -152,8 +152,34 @@ def run_job(job: dict) -> tuple[bool, str, str, Optional[str]]:
|
||||||
os.environ["HERMES_SESSION_CHAT_NAME"] = origin["chat_name"]
|
os.environ["HERMES_SESSION_CHAT_NAME"] = origin["chat_name"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
# Re-read .env and config.yaml fresh every run so provider/key
|
||||||
|
# changes take effect without a gateway restart.
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
load_dotenv(os.path.expanduser("~/.hermes/.env"), override=True)
|
||||||
|
|
||||||
|
model = os.getenv("HERMES_MODEL", "anthropic/claude-opus-4.6")
|
||||||
|
api_key = os.getenv("OPENROUTER_API_KEY", "")
|
||||||
|
base_url = os.getenv("OPENROUTER_BASE_URL", "https://openrouter.ai/api/v1")
|
||||||
|
|
||||||
|
try:
|
||||||
|
import yaml
|
||||||
|
_cfg_path = os.path.expanduser("~/.hermes/config.yaml")
|
||||||
|
if os.path.exists(_cfg_path):
|
||||||
|
with open(_cfg_path) as _f:
|
||||||
|
_cfg = yaml.safe_load(_f) or {}
|
||||||
|
_model_cfg = _cfg.get("model", {})
|
||||||
|
if isinstance(_model_cfg, str):
|
||||||
|
model = _model_cfg
|
||||||
|
elif isinstance(_model_cfg, dict):
|
||||||
|
model = _model_cfg.get("default", model)
|
||||||
|
base_url = _model_cfg.get("base_url", base_url)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
agent = AIAgent(
|
agent = AIAgent(
|
||||||
model=os.getenv("HERMES_MODEL", "anthropic/claude-opus-4.6"),
|
model=model,
|
||||||
|
api_key=api_key,
|
||||||
|
base_url=base_url,
|
||||||
quiet_mode=True,
|
quiet_mode=True,
|
||||||
session_id=f"cron_{job_id}_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
|
session_id=f"cron_{job_id}_{datetime.now().strftime('%Y%m%d_%H%M%S')}"
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue