The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(clarify): route multi_select through current dispatch paths and harden callback detection
teknium10b670f053967
diff --git a/agent/agent_runtime_helpers.py b/agent/agent_runtime_helpers.pyindex 6458ad88fbe..323c7487d75 100644--- a/agent/agent_runtime_helpers.py+++ b/agent/agent_runtime_helpers.py@@ -2614,6 +2614,7 @@ def invoke_tool(agent, function_name: str, function_args: dict, effective_task_i_clarify_tool(question=next_args.get("question", ""),choices=next_args.get("choices"),+ multi_select=next_args.get("multi_select", False),callback=agent.clarify_callback,),next_args,diff --git a/agent/tool_executor.py b/agent/tool_executor.pyindex a5729a2e8f5..c6751ac6c94 100644--- a/agent/tool_executor.py+++ b/agent/tool_executor.py@@ -1360,6 +1360,7 @@ def execute_tool_calls_sequential(agent, assistant_message, messages: list, effereturn _clarify_tool(question=next_args.get("question", ""),choices=next_args.get("choices"),+ multi_select=next_args.get("multi_select", False),callback=agent.clarify_callback,)function_result, function_args = _run_agent_tool_execution_middleware(diff --git a/tests/tools/test_clarify_tool.py b/tests/tools/test_clarify_tool.pyindex 7ad24eefc88..aaf1d878453 100644--- a/tests/tools/test_clarify_tool.py+++ b/tests/tools/test_clarify_tool.py@@ -443,3 +443,81 @@ class TestClarifyToolMultiSelect:callback=mock_callback,)assert len(choices_passed) == MAX_CHOICES+++class TestInvokeCallbackDispatch:+ """_invoke_callback uses signature inspection, never a TypeError retry."""++ def test_internal_typeerror_not_swallowed_or_retried(self):+ """A compatible callback that raises TypeError internally must be+ invoked exactly once and its error surfaced — not retried with the+ legacy 2-arg form (which would prompt the user twice)."""+ from tools.clarify_tool import _invoke_callback+ calls = []++ def bad_callback(question, choices, multi_select=False):+ calls.append(1)+ raise TypeError("internal bug")++ import pytest+ with pytest.raises(TypeError, match="internal bug"):+ _invoke_callback(bad_callback, "Q?", ["a"], True)+ assert len(calls) == 1++ def test_legacy_two_arg_callback_supported(self):+ from tools.clarify_tool import _invoke_callback+ seen = {}++ def legacy(question, choices):+ seen["args"] = (question, choices)+ return "ok"++ assert _invoke_callback(legacy, "Q?", ["a"], True) == "ok"+ assert seen["args"] == ("Q?", ["a"])++ def test_var_keyword_callback_receives_flag(self):+ from tools.clarify_tool import _invoke_callback+ seen = {}++ def kw_cb(question, choices, **kwargs):+ seen.update(kwargs)+ return "ok"++ _invoke_callback(kw_cb, "Q?", ["a"], True)+ assert seen.get("multi_select") is True+++class TestRegistryMultiSelectPassThrough:+ """The registered tool handler must forward multi_select from tool args."""++ def test_handler_passes_multi_select(self):+ from tools.registry import registry+ entry = registry.get_entry("clarify")+ seen = {}++ def cb(question, choices, multi_select=False):+ seen["multi"] = multi_select+ return "a, b"++ result = json.loads(entry.handler(+ {"question": "Pick", "choices": ["a", "b"], "multi_select": True},+ callback=cb,+ ))+ assert seen["multi"] is True+ assert result["user_response"] == ["a", "b"]++ def test_handler_default_single_select(self):+ from tools.registry import registry+ entry = registry.get_entry("clarify")+ seen = {}++ def cb(question, choices, multi_select=False):+ seen["multi"] = multi_select+ return "a"++ result = json.loads(entry.handler(+ {"question": "Pick", "choices": ["a", "b"]},+ callback=cb,+ ))+ assert seen["multi"] is False+ assert result["user_response"] == "a"diff --git a/tools/clarify_tool.py b/tools/clarify_tool.pyindex ebacdcb94d4..88e9762ca78 100644--- a/tools/clarify_tool.py+++ b/tools/clarify_tool.py@@ -57,12 +57,30 @@ def _flatten_choice(c) -> str:def _invoke_callback(callback, question, choices, multi_select):- """Invoke the platform callback, passing multi_select if supported."""+ """Invoke the platform callback, passing multi_select if supported.++ Uses signature inspection (not a ``TypeError`` retry) to decide whether+ the callback accepts the ``multi_select`` keyword — a retry-on-TypeError+ approach would re-invoke a *compatible* callback that raised TypeError+ internally, potentially prompting the user twice.+ """+ import inspect++ accepts_multi = Falsetry:+ sig = inspect.signature(callback)+ params = sig.parameters+ accepts_multi = "multi_select" in params or any(+ p.kind == inspect.Parameter.VAR_KEYWORD for p in params.values()+ )+ except (TypeError, ValueError):+ # Builtins / C callables without introspectable signatures:+ # be conservative and use the legacy 2-arg form.+ accepts_multi = False++ if accepts_multi:return callback(question, choices, multi_select=multi_select)- except TypeError:- # Callback does not accept the multi_select keyword; fall back- return callback(question, choices)+ return callback(question, choices)def _parse_multi_select_response(raw_response) -> List[str]: