The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test: pin the session-scoped tool_call error through the real model_tools bridge
Tekniumc970e46755ea
diff --git a/tests/tools/test_managed_worker_tool_diagnostics.py b/tests/tools/test_managed_worker_tool_diagnostics.pyindex bedc4c7e26c..de988ee0718 100644--- a/tests/tools/test_managed_worker_tool_diagnostics.py+++ b/tests/tools/test_managed_worker_tool_diagnostics.py@@ -1,37 +1,44 @@-"""A managed worker turn (every Kanban card) is never offered ``delegate_task`` on purpose-(ef52a09a558: a child needs an owner-registered execution the worker cannot reserve). Asking-for it must explain that boundary and name the supported alternative, never answer "call it-directly" for a tool this turn cannot see (#141793)."""+"""A tool this session cannot reach must never be answered with "call it directly".++``_HERMES_CORE_TOOLS`` is static, so ``tool_call`` matched any core tool by name, including+``clarify`` inside a subagent and ``delegate_task`` inside a managed worker turn (every Kanban+card, ef52a09a558), where no direct call can ever succeed and the model retries. Absence is+reported as unavailability, and a managed worker names the supported alternative (#141793).+Both tests drive the real ``tool_call`` bridge in ``model_tools``.+"""import jsonimport pytest+import model_toolsimport tools.delegate_tool # registers delegate_task in the global registryfrom agent import runtime_session_storefrom agent.conversation_loop import _invalid_tool_name_error_content-from tools.tool_search import ToolSearchConfig, dispatch_tool_describe, resolve_underlying_call+from tools.tool_search import ToolSearchConfig, dispatch_tool_describe-def worker_process(monkeypatch):- monkeypatch.setattr(runtime_session_store, "_worker_process", True)+def _bridge(name: str, toolsets: list[str]) -> str:+ result = model_tools.handle_function_call(+ "tool_call", {"calls": [{"name": name, "arguments": {}}]}, enabled_toolsets=toolsets)+ return json.loads(result).get("error", "")-def test_bridge_explains_the_managed_worker_boundary_for_delegate_task(worker_process):+def test_managed_worker_explains_the_boundary_for_delegate_task(monkeypatch):+ monkeypatch.setattr(runtime_session_store, "_worker_process", True)worker_tools = [{"type": "function", "function": {"name": "kanban_create", "parameters": {}}}]- _, _, call_err = resolve_underlying_call({"calls": [{"name": "delegate_task", "arguments": {}}]},- {"kanban_create"})described = json.loads(dispatch_tool_describe({"names": ["delegate_task"]}, current_tool_defs=worker_tools,config=ToolSearchConfig.from_raw({})))direct = _invalid_tool_name_error_content("delegate_task", ["kanban_create"])- for message in (call_err or "", described["errors"]["delegate_task"], direct):+ for message in (_bridge("delegate_task", ["file"]), described["errors"]["delegate_task"], direct):assert "managed worker" in message and "kanban_create" in message, messageassert "Call it directly" not in message and "does not exist" not in message, message-def test_outside_a_worker_delegate_task_keeps_the_ordinary_guidance(monkeypatch):[email protected]("toolsets, expected", [+ (["file"], "not available in this execution context"), # stripped here: never "call it directly"+ (["file", "clarify"], "Call it directly"), # reachable here: the door guidance holds+])+def test_outside_a_worker_core_tool_guidance_follows_the_session(monkeypatch, toolsets, expected):monkeypatch.setattr(runtime_session_store, "_worker_process", False)- _, _, err = resolve_underlying_call({"calls": [{"name": "delegate_task", "arguments": {}}]},- {"delegate_task"})- assert "Call it directly" in (err or "")- assert "managed worker" not in _invalid_tool_name_error_content("delegate_task", ["todo"])+ message = _bridge("clarify", toolsets)+ assert expected in message and "managed worker" not in message, message