Skip to content

CubeLoop — a Pythonic, async-native agent harness core designed for high performance, readability, and production-grade persistence.

fix(agent): reject positional-only reserved params in @tool too

Claude6863dbed4a2a
diff --git a/cubepi/agent/tool_decorator.py b/cubepi/agent/tool_decorator.py
index e671eb6..4c04c1b 100644
--- a/cubepi/agent/tool_decorator.py
+++ b/cubepi/agent/tool_decorator.py
@@ -61,15 +61,6 @@ def _build_params_model(
f"@tool function {fn.__name__!r} cannot use *args/**kwargs; "
"declare explicit parameters so an input schema can be generated."
)
- if p.kind is inspect.Parameter.POSITIONAL_ONLY:
- # Tool-call arguments arrive as named JSON fields and the generated
- # executor invokes the function with fn(**kwargs), which can't fill
- # a positional-only parameter.
- raise TypeError(
- f"@tool parameter {p.name!r} of {fn.__name__!r} is "
- "positional-only; tool-call arguments arrive by name, so "
- "declare it as a normal parameter (remove the '/')."
- )
if p.name not in hints and p.annotation is inspect.Parameter.empty:
raise TypeError(
f"@tool parameter {p.name!r} of {fn.__name__!r} needs a type "
@@ -113,6 +104,18 @@ def _make_agent_tool(
)
sig = inspect.signature(fn)
+
+ # The generated executor always calls the function with keyword arguments
+ # (schema fields plus any injected reserved args), so a positional-only
+ # parameter — reserved or not — would fail at call time. Reject it up front.
+ for p in sig.parameters.values():
+ if p.kind is inspect.Parameter.POSITIONAL_ONLY:
+ raise TypeError(
+ f"@tool parameter {p.name!r} of {fn.__name__!r} is "
+ "positional-only; @tool calls the function with keyword "
+ "arguments, so declare it as a normal parameter (remove the '/')."
+ )
+
try:
hints = get_type_hints(fn, include_extras=True)
except Exception as exc: # pragma: no cover — unresolved annotations
diff --git a/tests/agent/test_tool_decorator.py b/tests/agent/test_tool_decorator.py
index d6f65b9..72d27fc 100644
--- a/tests/agent/test_tool_decorator.py
+++ b/tests/agent/test_tool_decorator.py
@@ -160,6 +160,16 @@ class TestErrors:
"Positional-only is not callable with **kwargs."
return id
+ def test_positional_only_reserved_param_rejected(self):
+ # A reserved arg declared positional-only is filtered out of the schema
+ # params, so it must be caught by the full-signature check.
+ with pytest.raises(TypeError, match="positional-only"):
+
+ @tool
+ async def bad(tool_call_id, /, value: str) -> str:
+ "Reserved positional-only would fail fn(**kwargs) at call time."
+ return value
+
async def test_bad_return_type_rejected(self):
@tool
async def bad(value: str) -> int: # type: ignore[return-value]