diff --git a/strix/agents/factory.py b/strix/agents/factory.py index c6e48fd9..5de2cbcb 100644 --- a/strix/agents/factory.py +++ b/strix/agents/factory.py @@ -287,13 +287,15 @@ def _with_strictness(tool: FunctionTool, strict_schemas: bool) -> FunctionTool: def _merged_variants(variants: list[dict[str, Any]]) -> dict[str, Any] | None: merged: dict[str, Any] = {} + types: list[str] = [] for variant in variants: - if not isinstance(variant.get("type"), str): + if not isinstance(variant.get("type"), str) or variant["type"] in types: return None if merged.keys() & (variant.keys() - {"type"}) or variant.keys() & {"enum", "const"}: return None merged |= variant - merged["type"] = [variant["type"] for variant in variants] + types.append(variant["type"]) + merged["type"] = types return merged diff --git a/tests/test_agent_tool_registration.py b/tests/test_agent_tool_registration.py index b9f6474a..069f8c57 100644 --- a/tests/test_agent_tool_registration.py +++ b/tests/test_agent_tool_registration.py @@ -184,6 +184,7 @@ def test_nullable_parameter_keeps_its_variant_schema() -> None: {"anyOf": [{"type": "string", "const": "a"}, {"type": "null"}]}, {"anyOf": [{"type": "string", "format": "uri"}, {"type": "array", "format": "x"}]}, {"anyOf": [{"$ref": "#/$defs/Mode"}, {"type": "null"}]}, + {"anyOf": [{"type": "string", "minLength": 2}, {"type": "string"}]}, ], ) def test_unmergeable_unions_are_left_untouched(spec: dict[str, Any]) -> None: