mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-16 10:52:27 +03:00
8300964930
A call such as search_files without `pattern` ran anyway and returned matches, and a typo'd or invented argument was dropped with no signal, so the model assumed an option had taken effect. One check now sits in front of every tool Hermes ships (registry dispatch and the agent's inline executors; model_tools.py is untouched): - a missing `required` argument is refused before the handler runs, naming the field (with its allowed values when the schema enumerates them) and the valid parameters; - an argument the schema does not declare still reaches the handler exactly as sent; the result gains a `_warning` naming it. Nothing is stripped. Slim redo of #142503. What differs from it, and why: - scope is built-in tools only. MCP and plugin tools, and schemas that are open or union-shaped at the root, pass through untouched: a third-party `properties` list is not a promise about what the handler accepts. - nothing is stripped, so handlers that read an undeclared key and execution middleware that rewrites arguments keep main's contract. - legacy call shapes and tool-owned guidance are declared by each tool at registration (`compat_args`, `self_checked_args`) instead of a central table: skill_manage and memory flat shapes, delegate_task's single-task shape, patch's V4A mode, terminal(code=...), video_generate(video_url=...), and the handlers whose own missing-argument message says more than a generic refusal can. - the dynamic schema is only built when the registered one reports a finding. Co-authored-by: Elisa Martinez Abad <elisam@nvidia.com> Co-authored-by: James Nolan <jnolan@nvidia.com>
81 lines
3.2 KiB
Python
81 lines
3.2 KiB
Python
"""Point at something in the Hermes desktop GUI and say one line about it — the quiet
|
|
sibling of ``tour`` (same ``data-tour`` handles) with no scrim/spotlight/paging.
|
|
Fire-and-forget: a tip is not a question, so blocking on a round-trip would stall the
|
|
reply. Lives in ``desktop_ui`` and withdraws itself when the user turns tips off."""
|
|
|
|
import json
|
|
|
|
from tools import desktop_ui
|
|
from tools.registry import registry, tool_error
|
|
|
|
SIDES = ("top", "right", "bottom", "left")
|
|
|
|
|
|
def tip_tool(text: str, selector: str, title: str = "", side: str = "") -> str:
|
|
"""Show one tip bubble anchored to ``selector``."""
|
|
text = (text or "").strip()
|
|
selector = (selector or "").strip()
|
|
if not text:
|
|
return tool_error("tip needs text — the one line the bubble says.")
|
|
if not selector:
|
|
return tool_error("tip needs a selector to point at. Call tour(action='targets') to see "
|
|
"what's on screen and prefer a target reporting stable: true.")
|
|
if side and side not in SIDES:
|
|
return tool_error(f"side must be one of: {', '.join(SIDES)}.")
|
|
payload = {"selector": selector, "text": text,
|
|
**{k: v for k, v in (("title", title), ("side", side)) if v}}
|
|
try:
|
|
ok = desktop_ui.emit("tip.show", payload)
|
|
except Exception as exc:
|
|
return tool_error(f"Failed to show the tip: {exc}")
|
|
if not ok:
|
|
return tool_error("tip is only available in the Hermes desktop app.")
|
|
return json.dumps({"success": True, "selector": selector}, ensure_ascii=False)
|
|
|
|
|
|
TIP_SCHEMA = {
|
|
"name": "show_tip",
|
|
"description": (
|
|
"Point at one desktop UI element with a small arrow bubble (no dimming or tour). "
|
|
"For when a sentence is clearer with a finger on its subject. Get selectors from tour(action='targets'), "
|
|
"prefer stable:true, never guess. One tip at a time (new replaces "
|
|
"last); say the same thing in chat too — the bubble is a pointer, "
|
|
"not the message. Sparingly: a bubble every turn stops being read."
|
|
),
|
|
"parameters": {
|
|
"type": "object",
|
|
"properties": {
|
|
"text": {
|
|
"type": "string",
|
|
"description": "The one-sentence bubble text.",
|
|
},
|
|
"selector": {
|
|
"type": "string",
|
|
"description": "Selector from tour targets.",
|
|
},
|
|
"title": {
|
|
"type": "string",
|
|
"description": "Optional heading.",
|
|
},
|
|
"side": {
|
|
"type": "string",
|
|
"enum": list(SIDES),
|
|
"description": "Omit for 'top'; flips at screen edges.",
|
|
},
|
|
},
|
|
"required": ["text", "selector"],
|
|
},
|
|
}
|
|
|
|
|
|
def check_tips_enabled() -> bool:
|
|
"""The user's Settings → Appearance switch. On unless they turned it off."""
|
|
return desktop_ui.user_enabled("in_app_tips", default=True)
|
|
|
|
|
|
registry.register(
|
|
name="show_tip", toolset="desktop_ui", schema=TIP_SCHEMA, check_fn=check_tips_enabled,
|
|
handler=lambda args, **kw: tip_tool(
|
|
**{k: args.get(k, "") for k in ("text", "selector", "title", "side")}),
|
|
emoji="💡", self_checked_args=("text", "selector"))
|