Merge branch 'main' of github.com:NousResearch/hermes-agent into bb/gui
# Conflicts: # tui_gateway/server.py
This commit is contained in:
+35
-2
@@ -2243,6 +2243,19 @@ def _make_agent(sid: str, key: str, session_id: str | None = None):
|
||||
from run_agent import AIAgent
|
||||
from hermes_cli.runtime_provider import resolve_runtime_provider
|
||||
|
||||
# MCP tool discovery runs in a background daemon thread at startup so a
|
||||
# dead server can't freeze the shell (see tui_gateway/entry.py). The agent
|
||||
# snapshots its tool list once here and never re-reads it, so briefly wait
|
||||
# for in-flight discovery to land before building — bounded, so a slow/dead
|
||||
# server still can't block. No-op once discovery has finished (every build
|
||||
# after the first during a slow startup).
|
||||
try:
|
||||
from tui_gateway.entry import wait_for_mcp_discovery
|
||||
|
||||
wait_for_mcp_discovery()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
cfg = _load_cfg()
|
||||
agent_cfg = cfg.get("agent") or {}
|
||||
system_prompt = _prompt_text(agent_cfg.get("system_prompt", ""))
|
||||
@@ -5379,8 +5392,28 @@ def _(rid, params: dict) -> dict:
|
||||
discover_mcp_tools()
|
||||
if session:
|
||||
agent = session["agent"]
|
||||
if hasattr(agent, "refresh_tools"):
|
||||
agent.refresh_tools()
|
||||
# Rebuild the cached agent's tool snapshot so the current session
|
||||
# picks up added/removed MCP tools without `/new` (which discards
|
||||
# history). The agent snapshots tools once at build and never
|
||||
# re-reads the registry, so an explicit rebuild is required here.
|
||||
# The user already consented to the prompt-cache invalidation via
|
||||
# the confirm gate above. Mirrors gateway/run.py::_execute_mcp_reload.
|
||||
try:
|
||||
from model_tools import get_tool_definitions
|
||||
|
||||
new_defs = get_tool_definitions(
|
||||
enabled_toolsets=_load_enabled_toolsets(),
|
||||
quiet_mode=True,
|
||||
)
|
||||
agent.tools = new_defs
|
||||
agent.valid_tool_names = (
|
||||
{t["function"]["name"] for t in new_defs} if new_defs else set()
|
||||
)
|
||||
except Exception as _exc:
|
||||
logger.warning(
|
||||
"Failed to refresh cached agent tools after /reload-mcp: %s",
|
||||
_exc,
|
||||
)
|
||||
_emit(
|
||||
"session.info",
|
||||
params.get("session_id", ""),
|
||||
|
||||
Reference in New Issue
Block a user