Skip to content

The agent that grows with you

fix(agent): classify NVIDIA NIM serde rejection of list-type tool content

KeyArgo0968fa2631b9
diff --git a/agent/error_classifier.py b/agent/error_classifier.py
index b90a39daac4..1b071843a28 100644
--- a/agent/error_classifier.py
+++ b/agent/error_classifier.py
@@ -183,11 +183,16 @@ _IMAGE_CORRUPT_PATTERNS = (
# 400s rejecting list-type ``content`` in tool messages (Xiaomi MiMo "text is
# not set", Alibaba, OpenAI-compat long tail). Recovery: strip image parts from
# tool messages, remember (provider, model), retry. (#27344)
+# NVIDIA NIM's Rust gateway never names the field: its serde rejection says the
+# body "did not match any variant of untagged enum
+# ChatCompletionRequestToolMessageContent", which is the same list-type tool
+# content that every other wording here describes (#111231).
_MULTIMODAL_TOOL_CONTENT_PATTERNS = (
"text is not set", "tool message content must be a string", "tool content must be a string",
"tool message must be a string", "expected string, got list", "expected string, got array",
# Console Go / pydantic-v2 relays behind opencode-go (422, param ``messages.N.tool.content.str``, #104731).
"tool_call.content must be string", "tool.content.str", "input should be a valid string",
+ "chatcompletionrequesttoolmessagecontent",
)
# Local-inference memory/resource-ceiling rejections (oMLX/MLX memory guard,
diff --git a/tests/agent/test_multimodal_tool_content_recovery.py b/tests/agent/test_multimodal_tool_content_recovery.py
index 7119310e808..9d2fa95ad7e 100644
--- a/tests/agent/test_multimodal_tool_content_recovery.py
+++ b/tests/agent/test_multimodal_tool_content_recovery.py
@@ -211,6 +211,62 @@ class TestRecoveryEndToEndClassification:
assert result.reason == FailoverReason.multimodal_tool_content_unsupported
assert result.retryable is True
+ def test_nvidia_nim_serde_tool_content_classifies(self):
+ """Regression test for #111231 (bug 2): NVIDIA NIM's Rust gateway rejects
+ list-type tool content without naming the field — the serde text names the
+ *enum* instead. Verbatim provider wording from the report."""
+ err = _FakeApiError(
+ status_code=400,
+ message=(
+ "HTTP 400: Failed to deserialize the JSON body into the target type: "
+ "data did not match any variant of untagged enum "
+ "ChatCompletionRequestToolMessageContent at line 1 column 1974809"
+ ),
+ )
+ result = classify_api_error(err, provider="nvidia", model="moonshotai/kimi-k3")
+ assert result.reason == FailoverReason.multimodal_tool_content_unsupported
+ assert result.retryable is True
+
+ def test_nvidia_nim_serde_other_enum_not_misclassified(self):
+ """A NIM serde rejection naming a different enum must stay a format error —
+ only the tool-message-content enum means list-type tool content."""
+ err = _FakeApiError(
+ status_code=400,
+ message=(
+ "HTTP 400: Failed to deserialize the JSON body into the target type: "
+ "data did not match any variant of untagged enum ChatCompletionRequestMessage"
+ ),
+ )
+ result = classify_api_error(err, provider="nvidia", model="moonshotai/kimi-k3")
+ assert result.reason != FailoverReason.multimodal_tool_content_unsupported
+
+ def test_nvidia_nim_serde_reaches_strip_recovery(self):
+ """The classified reason must actually drive the strip helper: the NVIDIA
+ rejection becomes reachable by the same recovery the other wordings use."""
+ err = _FakeApiError(
+ status_code=400,
+ message=(
+ "HTTP 400: Failed to deserialize the JSON body into the target type: "
+ "data did not match any variant of untagged enum "
+ "ChatCompletionRequestToolMessageContent at line 1 column 1974809"
+ ),
+ )
+ result = classify_api_error(err, provider="nvidia", model="moonshotai/kimi-k3")
+ assert result.reason == FailoverReason.multimodal_tool_content_unsupported
+
+ agent = _make_agent(provider="nvidia", model="moonshotai/kimi-k3")
+ msgs = [
+ {"role": "tool", "tool_call_id": "computer_use:0", "content": [
+ {"type": "text", "text": "screenshot of the desktop"},
+ {"type": "image_url", "image_url": {"url": "data:image/png;base64,iVBORw0KGgoAAAA"}},
+ ]},
+ ]
+ assert agent._try_strip_image_parts_from_tool_messages(msgs) is True
+ assert isinstance(msgs[0]["content"], str)
+ assert "data:image" not in msgs[0]["content"]
+ assert "screenshot of the desktop" in msgs[0]["content"]
+ assert ("nvidia", "moonshotai/kimi-k3") in agent._no_list_tool_content_models
+
class TestOpenCodeGoProactiveToolResultDowngrade:
def _multimodal_result(self, png_b64: str = "iVBORw0KGgoAAAA"):