The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(tools): a one-shot resume keeps the session's pinned tool bytes
Teknium3a1a58899219
diff --git a/tests/agent/test_oneshot_interactive_surface.py b/tests/agent/test_oneshot_interactive_surface.pyindex 8cca489502c..59b9aadc1a6 100644--- a/tests/agent/test_oneshot_interactive_surface.py+++ b/tests/agent/test_oneshot_interactive_surface.py@@ -51,6 +51,18 @@ def test_oneshot_tool_build_drops_clarify_and_delegate_live_control(monkeypatch)assert "steer" not in delegate["description"] and "BETWEEN your turns" not in delegate["description"]+def test_oneshot_resume_keeps_the_pinned_interactive_tool_bytes(monkeypatch):+ # `hermes -z --resume <interactive session>`: the same-code pin's bytes head every request (prompt cache), so+ # neither the one-shot delegate_task variant nor the one-shot clarify gate may rewrite or drop a pinned tool.+ from tools.mcp_tool_agent import restore_agent_tool_prefix, tool_pin_version++ interactive = _built_agent(monkeypatch, oneshot=False)+ oneshot = _built_agent(monkeypatch, oneshot=True)+ restore_agent_tool_prefix(oneshot, {"version": tool_pin_version(), "tools": interactive.tools})++ assert oneshot.tools == interactive.tools++def test_gateway_oneshot_inventory_drops_clarify(tmp_path, monkeypatch):from gateway.session_local_inventory import _policy_toolsfrom gateway.session_policy import build_policy, policy_scopediff --git a/tools/mcp_tool_agent.py b/tools/mcp_tool_agent.pyindex 1106b6f1fef..cfd8a936c18 100644--- a/tools/mcp_tool_agent.py+++ b/tools/mcp_tool_agent.py@@ -57,8 +57,13 @@ def _tool_defs_content_changed(agent, new_defs: list) -> bool:def _drop_session_tools(agent, new_defs: list, new_names: set) -> tuple:- from toolsets import agent_tool_drops, agent_tool_surface- return agent_tool_surface(agent, new_defs), new_names - agent_tool_drops(agent)+ # Drops only: runs after a merge, where a carried or pinned entry keeps the bytes already sent. The one-shot+ # schema variants (``toolsets.agent_tool_surface``) shape fresh definitions, before any merge.+ from toolsets import agent_tool_drops+ drops = agent_tool_drops(agent)+ if not drops:+ return new_defs, new_names+ return [entry for entry in new_defs if _def_name(entry) not in drops], new_names - dropsdef _publish_tool_snapshot(@@ -124,7 +129,9 @@ def refresh_agent_mcp_tools(snapshot_generation = registry._generationfrom agent.delegation_backends import adopt_built_backend, saved_backendbuilt_backend = saved_backend()- new_defs = list(get_tool_definitions(enabled_toolsets=enabled, disabled_toolsets=disabled, quiet_mode=quiet_mode) or [])+ from toolsets import agent_tool_surface+ new_defs = agent_tool_surface(agent, list(+ get_tool_definitions(enabled_toolsets=enabled, disabled_toolsets=disabled, quiet_mode=quiet_mode) or []))new_names = {_def_name(t) for t in new_defs}# Post-build families re-appended on LOCALS only; live attributes untouched until publish.staged_engine_names = _reinject_post_build_tools(agent, new_defs, new_names)@@ -196,12 +203,16 @@ def _config_permitted_names(agent) -> set:"""Tool names this agent's toolset selection allows before ``check_fn``: all a pin may carryforward. A client-surface toolset counts as allowed (only its client can add it, so its absencehere is no config choice); ``disabled_toolsets`` still strips it."""+ from agent.oneshot_footprint import ONESHOT_DISABLED_TOOLSETS, agent_is_oneshotfrom model_tools import _select_tool_namesfrom toolsets import CLIENT_SURFACE_TOOLSETSenabled = getattr(agent, "enabled_toolsets", None)if enabled is not None:enabled = [*enabled, *CLIENT_SURFACE_TOOLSETS]- return _select_tool_names(enabled, getattr(agent, "disabled_toolsets", None), True)+ disabled = getattr(agent, "disabled_toolsets", None)+ if disabled and agent_is_oneshot(agent): # the one-shot gate is no config choice either: a pinned clarify stays+ disabled = [name for name in disabled if name not in ONESHOT_DISABLED_TOOLSETS]+ return _select_tool_names(enabled, disabled, True)def _drop_gated_carried_tools(merged: list, carried: set) -> list:diff --git a/toolsets.py b/toolsets.pyindex d81b0352ab9..a4f73e29c05 100644--- a/toolsets.py+++ b/toolsets.py@@ -475,7 +475,8 @@ def agent_tool_drops(agent: Any) -> frozenset:def agent_tool_surface(agent: Any, tools: list[dict[str, Any]]) -> list[dict[str, Any]]:"""*tools* as *agent* carries them: :func:`agent_tool_drops` removed and, in a one-shot session, the- one-shot schema variants (``agent.oneshot_footprint.oneshot_tool_schemas``). Applied at load and MCP refresh."""+ one-shot schema variants (``agent.oneshot_footprint.oneshot_tool_schemas``). Applied to FRESH definitions (load,+ MCP refresh) before any merge: a pinned or carried entry keeps the bytes already sent."""from agent.oneshot_footprint import agent_is_oneshot, oneshot_tool_schemasdrops = agent_tool_drops(agent)tools = [tool for tool in tools if (tool.get("function") or {}).get("name") not in drops] if drops else list(tools)