fix(execute-code): teach the working helper import contract
Slim adaptation of #83772 to the current schema and failure-hint table. Generated helpers are module exports on every execution path, not globals. Correct schema, recovery hints and CLI tip rather than injecting names or changing the execution boundary. Two registry-driven invariants reproduce both misleading instructions on main and execute the corrected guidance. Additional tool fix discovered during campaign #104904. Original diagnosis and correction: @yuzilongleif-collab (#83772). Co-authored-by: yuzilongleif-collab <235949691+yuzilongleif-collab@users.noreply.github.com>
This commit is contained in:
@@ -144,8 +144,10 @@ _TOOL_STUBS = {
|
||||
def _missing_hermes_tools_import_hint(m, enabled_tools) -> str:
|
||||
missing = m.group(1)
|
||||
if missing in {"json_parse", "shell_quote", "retry"}:
|
||||
return (f"{missing} is a BUILT-IN helper in the sandbox — no import "
|
||||
f"needed. Remove it from the import line and call {missing}(...) directly.")
|
||||
return (f"Import helpers with `from hermes_tools import {missing}`. "
|
||||
"If that import failed, the generated module may be stale or another "
|
||||
"hermes_tools may be first on sys.path. Check hermes_tools.__file__ "
|
||||
"and retry with reset=true.")
|
||||
available = sorted(SANDBOX_ALLOWED_TOOLS & set(enabled_tools or SANDBOX_ALLOWED_TOOLS))
|
||||
return (f"'{missing}' is not available inside the execute_code sandbox. "
|
||||
f"Importable tools here: {', '.join(available)}. For anything "
|
||||
@@ -153,13 +155,13 @@ def _missing_hermes_tools_import_hint(m, enabled_tools) -> str:
|
||||
|
||||
|
||||
# (regex, formatter(match, enabled_tools)) — first match wins. Production mining (state.db) ranked
|
||||
# these as the top execute_code failure classes: hermes_tools import misuse, importing the built-in
|
||||
# helpers, treating tool results as strings, importing third-party packages absent from the sandbox.
|
||||
# these as the top execute_code failure classes: hermes_tools import misuse, missing helper
|
||||
# imports, treating tool results as strings, importing third-party packages absent from the sandbox.
|
||||
_FAILURE_HINT_RULES = (
|
||||
(r"cannot import name '(\w+)' from 'hermes_tools'", _missing_hermes_tools_import_hint),
|
||||
(r"NameError: name '(json_parse|shell_quote|retry)' is not defined",
|
||||
lambda m, _: f"{m.group(1)} is built into the generated sandbox module — "
|
||||
"call it directly at module scope without importing it."),
|
||||
lambda m, _: f"Import {m.group(1)} before calling it: "
|
||||
f"from hermes_tools import {m.group(1)}"),
|
||||
(r"ModuleNotFoundError: No module named '([\w.]+)'",
|
||||
lambda m, _: f"'{m.group(1)}' is not installed in the sandbox interpreter. "
|
||||
"Use Python stdlib inside execute_code, or run the code via "
|
||||
@@ -850,7 +852,8 @@ def build_execute_code_schema(enabled_sandbox_tools: set = None,
|
||||
"Limits: 5-minute timeout, max 50 tool calls per call. Stdout over "
|
||||
"50KB shows head/tail inline; the FULL text is auto-saved to a file whose path rides in the result.\n\n"
|
||||
f"{cwd_note}\n\n"
|
||||
"Built-in helpers (no import): json_parse(text) — tolerant "
|
||||
"Helpers require imports: `from hermes_tools import json_parse, shell_quote, retry`. "
|
||||
"json_parse(text) — tolerant "
|
||||
"json.loads for terminal() output; shell_quote(s) — shlex.quote for "
|
||||
"dynamic shell args; retry(fn, max_attempts=3, delay=2) — exponential backoff."
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user