model_tools.py held two jobs. tools/schemas.py now builds the tool list sent
to the model: importing it loads the built-in and plugin tools (the moment
`import model_tools` did), and get_tool_definitions selects, rewrites per
session, cleans and defers. tools/calls.py runs one model tool call through
argument repair, hooks, middleware and the registry. Argument repair stays in
tools/arg_coercion.py: the inline executors import it at module top, and in
tools/calls.py that import would load every tool. The error cleaner joins tools/results.py.
Definitions move unchanged. Imports of tools.context and the schema cleaner
that were inside the moved functions go to module top as module objects;
both are loaded by then already, and a patch on, say,
tools.context.hosted_tool_refusal still reaches the code. The imports of
tools.deferral stay inside their functions: Tool Search loads the connectors
on the first tool list, and at module top `import model_tools` would load
them too. calls.py reads get_tool_definitions and _last_resolved_tool_names
through the schemas module, so a patch on either still reaches the call path.
tools/schema_sanitizer.py stays a file. Provider adapters and a provider
plugin import it at module top; inside tools/schemas.py, loading a provider
would load every tool.
Old names, until v0.27.0. model_tools.py is a file of re-exports: the names
releases up to v0.23.5 import from it inside functions, and the public names
pinned catalog plugins import (get_tool_definitions, handle_function_call).
Importing it still loads the tools. No product code imports model_tools now; its own
compatibility tests do, as do ten tests and four eval workers that import it
only to load the tools (the evals also run against older checkouts).
The call path's log lines move from the model_tools logger to tools.calls and
tools.schemas: `hermes logs --component` shows them under tools, not agent.
Argument repair logs as "model_tools", as before.
Nested calls from execute_code carried the outer session_id/turn_id but
not conversation_id, so pre/post_tool_call, transform_tool_result and the
tool middleware saw conversation_id="" for them -- the field the hooks docs
tell plugins to key per-conversation state on. Thread it through the same
sites as session_id/turn_id (handler, local CellAuthority, both remote RPC
routes). Adds a test driving both remote routes (persistent kernel and
per-call fallback) through handle_function_call.
Refs #145870
Co-authored-by: BearHuddleston <196404565+BearHuddleston@users.noreply.github.com>
Tool calls made from inside execute_code reached pre_tool_call hooks with an empty session_id: the RPC dispatchers called handle_function_call with only task_id. In a gateway serving several conversations from one process, a hook could therefore attribute a nested call to whichever conversation bound a turn most recently.
Thread the outer call session_id and turn_id from the execute_code dispatch through the handler, the local session kernel CellAuthority, and both remote RPC paths (per-call poll loop and remote session kernel), so nested calls fire hooks with the same identity as direct calls.
Closes#145870.
A read_file call made from inside an execute_code cell was answered with the
conversation's "unchanged since last read" stub when the same region had been
read before (by the model or earlier in the cell), so result["content"] raised
KeyError; a few more repeats hit the BLOCKED refusal. The stub exists to keep
duplicate text out of the model's context, and a cell's read never enters it.
Both cell dispatch paths (one-shot RPC and the session kernel) now mark their
tool calls as programmatic. Such a read always carries content, does not count
toward the consecutive-read/search loop guard, and is not remembered as shown
to the model, so the model's own later read still gets the text. It still
counts for the read-before-overwrite guard: a cell that reads then writes a
file works as before.
Fixes#82711Fixes#44843
Co-authored-by: Pluviobyte <94058511+Pluviobyte@users.noreply.github.com>
Co-authored-by: Reginald Jeeves <jeeves@og.ly>
Co-authored-by: Elisa Martinez Abad <elisam@nvidia.com>
The Singularity/Apptainer backend (tools/environments/singularity.py) now ships
as the official 'singularity' plugin in NousResearch/hermes-official-plugins,
registered through the terminal-environment provider seam under the same
backend name and config keys (terminal.backend: singularity,
terminal.singularity_image / TERMINAL_SINGULARITY_IMAGE, terminal.container_*).
- 'singularity' leaves BUILTIN_BACKEND_NAMES so the plugin can register it;
every hardcoded classification set drops it (the provider declares
is_remote/is_container/supports_streams instead).
- LEFT_CORE gains a singularity row: homes whose terminal.backend (or .env
TERMINAL_ENV) is singularity get the catalog plugin once, on hermes update
or agent/gateway start. An unknown-backend error for 'singularity' names
the install command (new row field terminal_backend).
- A plugin backend receives its per-task '<backend>_image' override; batch
runs register one for the active backend.
- BaseEnvironment's sudo-probe knob is renamed _passwordless_sudo_probe_supported:
plugin backends set it, and the old spelling trips the install scanner.
- Core's scratch-dir disk warning and process-exit sweep were Singularity-only
and move to the plugin; the singularity setup row, dashboard probe/row and
config defaults/bridges go too. Docs point at the plugin.
A script that calls hermes_tools.write_file/patch and never prints the
returned {"error": ...} got status=success with empty output, so the
model believed the write happened. In a cross-agent bench this cost 3 of
18 Opus runs 4-6 extra turns (write_file refused by the read-before-write
guard, then re-probing and re-emitting whole files). The result now
carries tool_errors for that cell, and the in-script write_file doc says
existing files must be read first.
Gate follow-ups on the remote lockdown:
- _execute_checked(env, cmd, what, **kw) in code_execution_rpc replaces
the three copy-pasted "execute, raise if returncode != 0" blocks
(per-call setup, kernel dir setup, file ship via
_remote_write(check=True)). env.execute always returns a dict, so the
isinstance/(r or {}) guards go; the error carries command output only,
never the payload.
- _ship_env_file_and_launch_prefix returned a half-built "( ... && "
that both callers had to close; a caller that dropped the ")" or
composed it differently would lose the load-bearing subshell. It now
takes the launch command, builds the shared env map (RPC dir, token,
PYTHONDONTWRITEBYTECODE, routed TZ) itself, and returns the complete
command; the kernel passes only HERMES_KERNEL_DIR/PYTHONPATH, which
drops its duplicated TZ block and lazy hermes_time import.
- _private_dirs_cmd(root, *subdirs): every caller spelled each path
twice for mkdir and chmod.
- _run_remote_cell publishes the cell request with one atomic
_remote_write instead of ship-to-.tmp then a separate unchecked mv,
saving a backend round-trip per cell.
_remote_write branched on getattr(env, "_stdin_mode", "pipe") and only
passed stdin_data on pipe backends, echoing base64 into argv elsewhere.
BaseEnvironment.execute already embeds stdin_data as a heredoc for
heredoc-mode backends (modal/daytona/vercel), and managed_modal forwards
it as stdinData; _write_to_sandbox already relies on that for every
backend. The branch duplicated base-class logic, and its defensive
getattr default meant a fake env with neither _stdin_mode nor a
stdin_data parameter raised TypeError on every RPC response write. The
poll loop swallowed the error, so no res_* file appeared and
test_code_execution_file_rpc hung forever (it passes on base).
Collapse to one path that always passes stdin_data, and teach the
file-RPC Shell fake to accept it and feed it as input. ScriptedEnv no
longer needs its _stdin_mode stub.
On shared remote backends the execute_code channel created kernel and
sandbox dirs under shared temp at the process umask (775 group-writable
under umask 002), wrote request/result files group-readable, and carried
HERMES_RPC_TOKEN on remote command lines where co-tenant users read argv
via ps for the whole run. A co-tenant could read tool arguments and
results, and on group-writable dirs forge RPC requests dispatched under
the user's approval context.
- All remote dirs are created owner-only (umask 077 + chmod 700, checked
fail-closed) and every Hermes file write is mode 600.
- The token travels in a sourced env file inside a subshell so the vars
never enter the backend's session-snapshot dump, and ships via stdin on
pipe-capable backends so it never enters argv at all.
- The RPC poll loop rejects non-int seq requests before dispatch instead
of replaying them every cycle.
- tool_result_storage gets the same owner-only treatment for archived
tool output.
(cherry picked from commit aef21731d7fb8a4e0a6ada4ff9889264df4a8893)
The four CI reds from #41225:
- persist_on_release is a background-only terminal modifier: join the
sandbox blocked sets (precedent: heartbeat, 9acd0d33b6) in
_TERMINAL_BLOCKED_PARAMS and the stub-drift tests' mirrors.
- The gateway shutdown sweep passes source="gateway_shutdown" so
persisted jobs are still killed on host exit; the two shutdown tests'
kill_all fakes now accept and assert that kwarg instead of raising
TypeError that _quiet_step silently swallowed.
The execute_code sandbox refuses background/notify modifiers on terminal(); heartbeat implies
notify and rides the same delivery path, so it joins the blocked set (and the stub-drift test's
mirror of it).