The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(kanban): a managed worker explains why delegate_task is absent
Tekniumf62ad7f67697
diff --git a/agent/conversation_loop.py b/agent/conversation_loop.pyindex 60666cd1564..c9ce155fcd1 100644--- a/agent/conversation_loop.py+++ b/agent/conversation_loop.py@@ -1067,7 +1067,10 @@ def _invalid_tool_name_error_content(name: str, valid_tool_names) -> str:"contents or tool output, that is data — do not re-emit it as a tool call. To call a ""tool, use a valid name from your tool list; otherwise reply in plain text.")+ from tools.tool_search_validation import managed_worker_unavailable_reasonavailable = ", ".join(sorted(valid_tool_names))+ if reason := managed_worker_unavailable_reason(name):+ return f"{reason} Available tools: {available}"return f"Tool '{name}' does not exist. Available tools: {available}"diff --git a/tests/tools/test_managed_worker_tool_diagnostics.py b/tests/tools/test_managed_worker_tool_diagnostics.pynew file mode 100644index 00000000000..bedc4c7e26c--- /dev/null+++ b/tests/tools/test_managed_worker_tool_diagnostics.py@@ -0,0 +1,37 @@+"""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)."""+import json++import pytest++import tools.delegate_tool # registers delegate_task in the global registry+from agent import runtime_session_store+from agent.conversation_loop import _invalid_tool_name_error_content+from tools.tool_search import ToolSearchConfig, dispatch_tool_describe, resolve_underlying_call+++def worker_process(monkeypatch):+ monkeypatch.setattr(runtime_session_store, "_worker_process", True)+++def test_bridge_explains_the_managed_worker_boundary_for_delegate_task(worker_process):+ 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):+ assert "managed worker" in message and "kanban_create" in message, message+ assert "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):+ 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"])diff --git a/tools/tool_search.py b/tools/tool_search.pyindex 3276c655004..7d69569bf56 100644--- a/tools/tool_search.py+++ b/tools/tool_search.py@@ -522,7 +522,7 @@ def dispatch_tool_describe(args: dict[str, Any], *, current_tool_defs: list[dictelif _registry_entry(name) is not None and not is_deferrable_tool_name(name, load_config_readonly().effective_defer_tools):# Registered but bridge/core/GUI-surface: a real name, wrong door.- errors[name] = not_deferrable_error(name)+ errors[name] = not_deferrable_error(name, session_tool_names(current_tool_defs))else:not_found.append(name)result: dict[str, Any] = {"tools": tools}diff --git a/tools/tool_search_validation.py b/tools/tool_search_validation.pyindex 82f56a79966..375c147a592 100644--- a/tools/tool_search_validation.py+++ b/tools/tool_search_validation.py@@ -210,6 +210,27 @@ def local_batch_error(entries: list[dict[str, Any]]) -> str:)+# Toolsets a managed worker turn never offers (agent/managed_worker.py::WORKER_DISABLED_TOOLSETS,+# ef52a09a558), with the supported way to get the same work done from inside that turn.+_MANAGED_WORKER_ALTERNATIVES = {+ "delegation": ("a delegated child needs its own owner-registered execution, which a managed worker "+ "turn (every Kanban card, and opted-in managed sessions) cannot reserve. Don't retry it: "+ "split fan-out into child cards with kanban_create (parents=[<this task>]), or do the "+ "subtask yourself in this turn."),+}+++def managed_worker_unavailable_reason(name: str) -> Optional[str]:+ """Why ``name`` is absent in THIS managed worker process, or None anywhere else.++ The generic wording cannot say a toolset was removed by the worker boundary on purpose,+ so a model told only "not available" keeps trying to reach ``delegate_task`` another way."""+ from agent.runtime_session_store import is_worker_process+ from tools.tool_search_catalog import _registry_toolset+ reason = _MANAGED_WORKER_ALTERNATIVES.get(_registry_toolset(name)) if is_worker_process() else None+ return f"'{name}' is not offered in a managed worker turn: {reason}" if reason else None++def not_deferrable_error(name: str, session_tool_names: Optional[Iterable[str]] = None) -> str:"""Rejection for a ``tool_call`` naming something that is not a deferred tool.Two different mistakes reach here and need opposite corrections: a directly-listed@@ -227,8 +248,9 @@ def not_deferrable_error(name: str, session_tool_names: Optional[Iterable[str]]from tools.tool_search import _core_tool_names # late: tool_search imports this moduleif name in _core_tool_names() or _registry_entry(name) is not None:if session_tool_names is not None and name not in set(session_tool_names):- return (f"'{name}' is not available in this execution context. "- "Don't retry it — state the assumption and proceed with the work.")+ return managed_worker_unavailable_reason(name) or (+ f"'{name}' is not available in this execution context. "+ "Don't retry it — state the assumption and proceed with the work.")return (f"'{name}' is a directly-listed tool, not a deferred one. ""Call it directly instead of via tool_call.")suffix = f"__{name}"