Skip to content

Commit 4cb94b3

Browse files
Add glm4.6 to FORCE_STRING_SERIALIZER (#994)
1 parent 21c4d27 commit 4cb94b3

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

openhands-sdk/openhands/sdk/llm/llm.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -848,10 +848,9 @@ def format_messages_for_llm(self, messages: list[Message]) -> list[dict]:
848848
message.cache_enabled = self.is_caching_prompt_active()
849849
message.vision_enabled = self.vision_is_active()
850850
message.function_calling_enabled = self.native_tool_calling
851-
if "deepseek" in self.model or (
852-
"kimi-k2-instruct" in self.model and "groq" in self.model
853-
):
854-
message.force_string_serializer = True
851+
message.force_string_serializer = get_features(
852+
self.model
853+
).force_string_serializer
855854

856855
formatted_messages = [message.to_chat_dict() for message in messages]
857856

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class ModelFeatures:
2222
supports_prompt_cache: bool
2323
supports_stop_words: bool
2424
supports_responses_api: bool
25+
force_string_serializer: bool
2526

2627

2728
# Pattern tables capturing current behavior. Keep patterns lowercase.
@@ -85,6 +86,18 @@ class ModelFeatures:
8586
"codex-mini-latest",
8687
]
8788

89+
# Models that require string serializer for tool messages
90+
# These models don't support structured content format [{"type":"text","text":"..."}]
91+
# and need plain strings instead
92+
FORCE_STRING_SERIALIZER_PATTERNS: list[str] = [
93+
"*deepseek*",
94+
"glm*",
95+
# kimi-k2-instruct on groq provider requires string serialization
96+
# Pattern contains '/' so it matches against full model string
97+
# (e.g., "groq/kimi-k2-instruct")
98+
"*groq*/kimi-k2-instruct*",
99+
]
100+
88101

89102
def get_features(model: str) -> ModelFeatures:
90103
"""Get model features."""
@@ -96,4 +109,5 @@ def get_features(model: str) -> ModelFeatures:
96109
model, SUPPORTS_STOP_WORDS_FALSE_PATTERNS
97110
),
98111
supports_responses_api=model_matches(model, RESPONSES_API_PATTERNS),
112+
force_string_serializer=model_matches(model, FORCE_STRING_SERIALIZER_PATTERNS),
99113
)

0 commit comments

Comments
 (0)