Skip to content

Commit 0b44206

Browse files
Add tests for string serializer (#996)
Co-authored-by: openhands <openhands@all-hands.dev>
1 parent 9ac99bd commit 0b44206

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

openhands-sdk/openhands/sdk/llm/utils/model_features.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,13 @@ class ModelFeatures:
8989
# Models that require string serializer for tool messages
9090
# These models don't support structured content format [{"type":"text","text":"..."}]
9191
# and need plain strings instead
92+
# NOTE: model_matches uses case-insensitive substring matching, not globbing.
93+
# Keep these entries as bare substrings without wildcards.
9294
FORCE_STRING_SERIALIZER_PATTERNS: list[str] = [
93-
"deepseek",
94-
"glm",
95-
"groq/kimi-k2-instruct",
95+
"deepseek", # e.g., DeepSeek-V3.2-Exp
96+
"glm", # e.g., GLM-4.5 / GLM-4.6
97+
# Kimi K2-Instruct requires string serialization only on Groq
98+
"groq/kimi-k2-instruct", # explicit provider-prefixed IDs
9699
]
97100

98101

tests/sdk/llm/test_model_features.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,17 @@ def test_supports_stop_words_false_models(model):
226226
def test_responses_api_support(model, expected_responses):
227227
features = get_features(model)
228228
assert features.supports_responses_api is expected_responses
229+
230+
231+
def test_force_string_serializer_full_model_names():
232+
"""Ensure full model names match substring patterns for string serializer.
233+
234+
Regression coverage for patterns like deepseek/glm without wildcards; Kimi
235+
should only match when provider-prefixed with groq/.
236+
"""
237+
assert get_features("DeepSeek-V3.2-Exp").force_string_serializer is True
238+
assert get_features("GLM-4.5").force_string_serializer is True
239+
# Provider-agnostic Kimi should not force string serializer
240+
assert get_features("Kimi K2-Instruct-0905").force_string_serializer is False
241+
# Groq-prefixed Kimi should force string serializer
242+
assert get_features("groq/kimi-k2-instruct-0905").force_string_serializer is True

0 commit comments

Comments
 (0)