From 0b9af25ae0d7ca261362cb4a5935026fa14f33c3 Mon Sep 17 00:00:00 2001 From: Stanley Shen Date: Wed, 7 Oct 2026 16:26:13 -0700 Subject: [PATCH] fix(agents): leave anyOf unions with repeated types untouched Merging two branches of the same type applied one branch's limits to both, so the rewritten schema rejected values the original accepted. Co-Authored-By: Claude Opus 5.5 --- strix/agents/factory.py | 6 ++++-- tests/test_agent_tool_registration.py | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) 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: