Files
hermes-agent/tools/thread_context.py
alt-glitch 9c5fe135c6 refactor(tools): interrupt, hosted policy, thread context and the async bridge become tools/context.py
tools/context.py holds what a running tool call reads from its thread or
context. It takes tools/interrupt.py, tools/hosted_tool_policy.py,
tools/thread_context.py and agent/tool_progress_relay.py whole, and from
model_tools.py the sync-to-async bridge and the call ids. Function bodies are
unchanged. Three names other modules import lose their underscore: run_async,
CallIds and prompt_callback_accessors.

The file imports no other tool-core file, so the registry and every tool
module can import it at module top. tools/registry.py does, and no longer
imports the bridge from model_tools inside dispatch.

Old names. tools.interrupt and tools.thread_context keep importing through
MOVES keys, for pinned catalog plugins. tools/hosted_tool_policy.py and
tools/thread_context.py are generated files: a TUI, CLI or ACP process that
started on a release up to v0.23.5 and built no agent before the update imports
them when it builds a system prompt or compresses. agent.tool_progress_relay
gets nothing; in such a process the TUI row for MCP progress fails until it
restarts. model_tools keeps _run_async and _CallIds as second names for
run_async and CallIds until v0.27.0: the registry and the inline executors of a
release import them from model_tools inside functions, and without the first a
TUI or ACP process that outlives the update fails every tool with an async
handler.

Log lines follow their module to the logger tools.context. The interrupt trace
(HERMES_DEBUG_INTERRUPT) logs under tools.context.interrupt, so the level it
forces applies to the trace alone. The one line of the progress relay moves
from the agent log component to tools.
2026-11-30 23:20:42 +05:30

35 lines
1.6 KiB
Python
Generated

try: # Generated by scripts/move/generate_shims.py; do not edit.
"""``tools.thread_context`` moved to ``tools.context``."""
import importlib
import importlib.util
import runpy
import sys
from pathlib import Path
def _forward():
if __name__ == "__main__" or sys.argv[:1] == ["-m"] or importlib.util.find_spec("hermes_agent") is None:
if __name__ == "__main__" and Path(sys.path[0]).resolve() == Path(__file__).resolve().parent:
del sys.path[0] # run as a path: a folder here named like an installed package would be imported in its place
sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
from hermes_agent.compat import install
install()
return None if __name__ == "__main__" else importlib.import_module("tools.context")
try:
_module = _forward()
except Exception:
if sys.argv[:1] != ["-m"] and __name__ != "__main__": # an entry launch; a plain import stays light
raise
import hermes_bootstrap # repairs a killed update and relaunches when it restored something
_module = _forward()
if __name__ == "__main__":
runpy.run_module("tools.context", run_name="__main__", alter_sys=True)
else:
if getattr(sys.modules.get(__name__), "__dict__", None) is globals():
sys.modules[__name__] = _module
_identity = ('__name__', '__file__', '__spec__', '__loader__', '__package__', '__path__', '__cached__', '__builtins__')
globals().update({k: v for k, v in vars(_module).items() if k not in _identity})
finally:
pass