Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

Agent operations: say in the schema that unknown arguments are refused

Petr Bauch169ddf0618d8
diff --git a/core/switch_core/bridges/agent/operations/registry.py b/core/switch_core/bridges/agent/operations/registry.py
index a4257f2c6..f6f39bd1a 100644
--- a/core/switch_core/bridges/agent/operations/registry.py
+++ b/core/switch_core/bridges/agent/operations/registry.py
@@ -36,6 +36,10 @@ def _input_schema(fn: OperationFn) -> dict[str, Any]:
Built here rather than taken from a transport library, so the schema a
client sees is the same whichever door it came through — and so the
operations layer stays free of transport dependencies.
+
+ Closed to other arguments (`additionalProperties: false`), as the call
+ path is: an argument the operation does not take is refused, so the
+ schema says so rather than inviting the guess.
"""
fields: dict[str, Any] = {}
for name, param in inspect.signature(fn).parameters.items():
@@ -46,11 +50,12 @@ def _input_schema(fn: OperationFn) -> dict[str, Any]:
fields[name] = (annotation, default)
if not fields:
- return {"type": "object", "properties": {}}
+ return {"type": "object", "properties": {}, "additionalProperties": False}
model = create_model(f"{fn.__name__}_arguments", **fields) # type: ignore[call-overload]
schema = model.model_json_schema()
schema.pop("title", None)
+ schema["additionalProperties"] = False
return schema
diff --git a/core/tests/switch_core/bridges/agent/api/test_operations.py b/core/tests/switch_core/bridges/agent/api/test_operations.py
index bb23bac4c..8245168a1 100644
--- a/core/tests/switch_core/bridges/agent/api/test_operations.py
+++ b/core/tests/switch_core/bridges/agent/api/test_operations.py
@@ -76,10 +76,21 @@ def test_operations_advertise_a_json_schema_for_their_arguments() -> None:
assert schema["properties"]["include_general_instructions"]["default"] is True
# Transport details are not arguments an agent supplies.
assert "ctx" not in schema["properties"]
+ # An argument the operation does not take is refused, and the schema says so.
+ assert schema["additionalProperties"] is False
# The full docstring is the tool description an agent reads.
assert "Connect this session to a room" in op["description"]
+def test_every_operation_refuses_arguments_it_does_not_take_in_its_schema() -> None:
+ open_schemas = [
+ name
+ for name, op in list_operations().items()
+ if op["input_schema"].get("additionalProperties") is not False
+ ]
+ assert open_schemas == []
+
+
async def test_unknown_operation_names_what_is_available() -> None:
with pytest.raises(UnknownOperationError) as excinfo:
await call_operation(