Skip to content

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

fix(agent): validate full signature for *args/**kwargs in @tool

Claude5ac29831609d
diff --git a/cubepi/agent/tool_decorator.py b/cubepi/agent/tool_decorator.py
index 4c04c1b..4f0bf14 100644
--- a/cubepi/agent/tool_decorator.py
+++ b/cubepi/agent/tool_decorator.py
@@ -50,17 +50,14 @@ def _build_params_model(
schema_params: list[inspect.Parameter],
hints: dict[str, Any],
) -> type[BaseModel]:
- """Generate a Pydantic model from the tool function's schema parameters."""
+ """Generate a Pydantic model from the tool function's schema parameters.
+
+ Structural validation (no *args/**kwargs or positional-only parameters) is
+ done by the caller over the full signature; here we only need each schema
+ parameter to carry a type annotation.
+ """
fields: dict[str, Any] = {}
for p in schema_params:
- if p.kind in (
- inspect.Parameter.VAR_POSITIONAL,
- inspect.Parameter.VAR_KEYWORD,
- ):
- raise TypeError(
- f"@tool function {fn.__name__!r} cannot use *args/**kwargs; "
- "declare explicit parameters so an input schema can be generated."
- )
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 "
@@ -105,10 +102,21 @@ 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.
+ # Structural validation runs over the FULL signature, before reserved names
+ # are filtered out below. The generated executor always calls the function
+ # with keyword arguments (schema fields plus any injected reserved args), so
+ # a *args/**kwargs or positional-only parameter — even one using a reserved
+ # name like *signal — would fail at call time. Reject it at definition time.
for p in sig.parameters.values():
+ if p.kind in (
+ inspect.Parameter.VAR_POSITIONAL,
+ inspect.Parameter.VAR_KEYWORD,
+ ):
+ raise TypeError(
+ f"@tool function {fn.__name__!r} cannot use *args/**kwargs "
+ f"(parameter {p.name!r}); declare explicit parameters so an "
+ "input schema can be generated."
+ )
if p.kind is inspect.Parameter.POSITIONAL_ONLY:
raise TypeError(
f"@tool parameter {p.name!r} of {fn.__name__!r} is "
diff --git a/tests/agent/test_tool_decorator.py b/tests/agent/test_tool_decorator.py
index 72d27fc..649498f 100644
--- a/tests/agent/test_tool_decorator.py
+++ b/tests/agent/test_tool_decorator.py
@@ -152,6 +152,15 @@ class TestErrors:
async def bad(*args: str) -> str:
return ""
+ def test_reserved_named_varargs_rejected(self):
+ # A vararg using a reserved name is filtered out of schema params, so it
+ # must be caught by the full-signature validation, not silently allowed.
+ with pytest.raises(TypeError, match="cannot use"):
+
+ @tool
+ async def bad(*signal) -> str: # type: ignore[no-untyped-def]
+ return ""
+
def test_positional_only_param_rejected(self):
with pytest.raises(TypeError, match="positional-only"):