Skip to content

The agent that grows with you

Inline agent tools get the shared argument repair (clarify, todo, memory, session_search) (#127781)

Siddharth Balyana2840f954be8
diff --git a/agent/inline_tool_executors.py b/agent/inline_tool_executors.py
index cdc4c4c1b54..c995fe6387e 100644
--- a/agent/inline_tool_executors.py
+++ b/agent/inline_tool_executors.py
@@ -14,6 +14,8 @@ from dataclasses import dataclass
from importlib import import_module
from typing import Any, Callable, Dict, Optional, Tuple
+from tools.arg_coercion import coerce_tool_args
+
def tool_hook_ids(agent, effective_task_id: str, tool_call_id: Optional[str]) -> Dict[str, str]:
"""Identity kwargs every tool hook/middleware call carries (all coerced to ``""``)."""
@@ -232,7 +234,7 @@ def _setup_mcp_shim(agent, args: dict, ctx: InlineToolContext) -> Any:
# Order is the historical if/elif order of ``execute_tool_calls_sequential``.
-INLINE_TOOL_EXECUTORS: Dict[str, InlineToolExecutor] = {
+_RAW_INLINE_TOOL_EXECUTORS: Dict[str, InlineToolExecutor] = {
"todo_list": _tool(
"tools.todo_tool", "todo_tool", ("todos", "todos"), ("merge", "merge", False),
store=lambda agent, ctx: agent._todo_store,
@@ -277,6 +279,17 @@ INLINE_TOOL_EXECUTORS: Dict[str, InlineToolExecutor] = {
"delegate_task": lambda agent, args, ctx: agent._dispatch_delegate_task(args),
}
+
+def _coerced(name: str, executor: InlineToolExecutor) -> InlineToolExecutor:
+ def _exec(agent, args: dict, ctx: InlineToolContext) -> Any:
+ return executor(agent, coerce_tool_args(name, args), ctx)
+ return _exec
+
+
+INLINE_TOOL_EXECUTORS: Dict[str, InlineToolExecutor] = {
+ name: _coerced(name, executor) for name, executor in _RAW_INLINE_TOOL_EXECUTORS.items()
+}
+
# ``invoke_tool`` (concurrent path) consults the memory manager right after these three
# names and before the remaining inline tools; ``message_agent`` falls through to the
# registry there (Bot Mode DM is only injected into the sequential path's schema).
diff --git a/tests/tools/test_todo_tool_type_coercion.py b/tests/tools/test_todo_tool_type_coercion.py
index 84d03a6781f..20d003663c1 100644
--- a/tests/tools/test_todo_tool_type_coercion.py
+++ b/tests/tools/test_todo_tool_type_coercion.py
@@ -7,12 +7,14 @@ Covers three crash patterns:
"""
import json
+from types import SimpleNamespace
+from agent.inline_tool_executors import INLINE_TOOL_EXECUTORS, InlineToolContext
from tools.todo_tool import TodoStore, todo_tool
class TestJsonStringCoercion:
- """Guard 1: todo_tool() recovers when LLM sends todos as a JSON string."""
+ """Guard 1: the inline todo_list dispatch recovers when LLM sends todos as a JSON string."""
def test_json_string_is_parsed_into_list(self):
store = TodoStore()
@@ -20,7 +22,9 @@ class TestJsonStringCoercion:
{"id": "t1", "content": "Do A", "status": "pending"},
{"id": "t2", "content": "Do B", "status": "in_progress"},
])
- result = json.loads(todo_tool(todos=todos_str, store=store))
+ agent = SimpleNamespace(_todo_store=store)
+ result = json.loads(INLINE_TOOL_EXECUTORS["todo_list"](
+ agent, {"todos": todos_str}, InlineToolContext(effective_task_id="t")))
assert "error" not in result
assert result["summary"]["total"] == 2
# Order-agnostic: TodoStore._normalize_order may lift the in_progress
diff --git a/tools/todo_tool.py b/tools/todo_tool.py
index 5deb184570f..b73b21e7f5e 100644
--- a/tools/todo_tool.py
+++ b/tools/todo_tool.py
@@ -196,11 +196,6 @@ def todo_tool(todos: Optional[List[Dict[str, Any]]] = None, merge: bool = False,
if todos is None:
items = store.read()
else:
- if isinstance(todos, str): # LLMs sometimes send a JSON string instead of a list
- try:
- todos = json.loads(todos)
- except (json.JSONDecodeError, TypeError):
- return tool_error("todos must be a list of objects, got unparseable string")
if not isinstance(todos, list):
return tool_error(f"todos must be a list, got {type(todos).__name__}")
items = store.write(todos, merge)