fix(cron): pass session_db to AIAgent so cron messages are persisted
Cron jobs create AIAgent without passing session_db, so messages from
cron runs (and their delegate_task subagents) are never written to the
SQLite session store. This means session_search cannot find any cron
conversation history — the same class of bug fixed for the gateway in
8aa531c (PR #105).
Initialize SessionDB in run_job() and pass it to AIAgent, following the
identical pattern used in gateway/run.py.
This commit is contained in:
parent
29176f302e
commit
9283877204
1 changed files with 11 additions and 1 deletions
|
|
@ -156,6 +156,15 @@ def run_job(job: dict) -> tuple[bool, str, str, Optional[str]]:
|
||||||
"""
|
"""
|
||||||
from run_agent import AIAgent
|
from run_agent import AIAgent
|
||||||
|
|
||||||
|
# Initialize SQLite session store so cron job messages are persisted
|
||||||
|
# and discoverable via session_search (same pattern as gateway/run.py).
|
||||||
|
_session_db = None
|
||||||
|
try:
|
||||||
|
from hermes_state import SessionDB
|
||||||
|
_session_db = SessionDB()
|
||||||
|
except Exception as e:
|
||||||
|
logger.debug("Job '%s': SQLite session store not available: %s", job.get("id", "?"), e)
|
||||||
|
|
||||||
job_id = job["id"]
|
job_id = job["id"]
|
||||||
job_name = job["name"]
|
job_name = job["name"]
|
||||||
prompt = job["prompt"]
|
prompt = job["prompt"]
|
||||||
|
|
@ -260,7 +269,8 @@ def run_job(job: dict) -> tuple[bool, str, str, Optional[str]]:
|
||||||
providers_order=pr.get("order"),
|
providers_order=pr.get("order"),
|
||||||
provider_sort=pr.get("sort"),
|
provider_sort=pr.get("sort"),
|
||||||
quiet_mode=True,
|
quiet_mode=True,
|
||||||
session_id=f"cron_{job_id}_{_hermes_now().strftime('%Y%m%d_%H%M%S')}"
|
session_id=f"cron_{job_id}_{_hermes_now().strftime('%Y%m%d_%H%M%S')}",
|
||||||
|
session_db=_session_db,
|
||||||
)
|
)
|
||||||
|
|
||||||
result = agent.run_conversation(prompt)
|
result = agent.run_conversation(prompt)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue