fix: inject SessionDB into AIAgent for WebUI sessions — enables session_search (#356)
* fix: inject SessionDB into AIAgent for WebUI sessions session_search tool requires a SessionDB instance passed via the session_db parameter. The CLI and gateway paths already do this, but the WebUI streaming path was missing it, causing every session_search call to return 'Session database not available'. Initialize SessionDB before creating the AIAgent and pass it through. Failure is non-fatal — a warning is printed and session_search gracefully degrades. * fix: inject SessionDB into AIAgent for WebUI sessions (enables session_search) (#356) - api/streaming.py: initialize SessionDB() before AIAgent construction and pass session_db= kwarg so session_search works in WebUI sessions - tests/test_sprint42.py: 7 new tests covering SessionDB injection, try/except guard, WARNING log, ordering, and AST lock-safety check - CHANGELOG.md: v0.50.13 entry; 822 tests total (up from 815) --------- Co-authored-by: 王昌旭 <wangchangxu@xiaohongshu.com> Co-authored-by: Nathan Esquenazi <nesquena@gmail.com>
This commit is contained in:
@@ -186,6 +186,14 @@ def _run_agent_streaming(session_id, msg_text, model, workspace, stream_id, atta
|
||||
_AIAgent = _get_ai_agent()
|
||||
if _AIAgent is None:
|
||||
raise ImportError("AIAgent not available -- check that hermes-agent is on sys.path")
|
||||
|
||||
# Initialize SessionDB so session_search works in WebUI sessions
|
||||
_session_db = None
|
||||
try:
|
||||
from hermes_state import SessionDB
|
||||
_session_db = SessionDB()
|
||||
except Exception as _db_err:
|
||||
print(f"[webui] WARNING: SessionDB init failed — session_search will be unavailable: {_db_err}", flush=True)
|
||||
resolved_model, resolved_provider, resolved_base_url = resolve_model_provider(model)
|
||||
|
||||
# Resolve API key via Hermes runtime provider (matches gateway behaviour).
|
||||
@@ -235,6 +243,7 @@ def _run_agent_streaming(session_id, msg_text, model, workspace, stream_id, atta
|
||||
enabled_toolsets=_toolsets,
|
||||
fallback_model=_fallback_resolved,
|
||||
session_id=session_id,
|
||||
session_db=_session_db,
|
||||
stream_delta_callback=on_token,
|
||||
tool_progress_callback=on_tool,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user