From 0df3c12699c0eab8d599841b2f802949a5b19fdb Mon Sep 17 00:00:00 2001 From: huangxudong663-sys Date: Tue, 30 Jun 2026 03:03:05 -0700 Subject: [PATCH] fix(agent): guard against non-dict model_extra in tool call normalization Some OpenAI-compatible providers (NVIDIA NIM + qwen3.5) return a string for model_extra instead of a dict. The falsy fallback (x or {}) treats a truthy non-empty string as the value and calls .get() on it, raising AttributeError and turning every tool call into [error]. Replace the falsy fallback with an explicit isinstance(.., dict) guard at both extra_content extraction sites (non-streaming normalize_response and the streaming delta accumulator). --- agent/chat_completion_helpers.py | 2 +- agent/transports/chat_completions.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/agent/chat_completion_helpers.py b/agent/chat_completion_helpers.py index 7a5e7534723..ace3b6439de 100644 --- a/agent/chat_completion_helpers.py +++ b/agent/chat_completion_helpers.py @@ -2086,7 +2086,7 @@ def interruptible_streaming_api_call(agent, api_kwargs: dict, *, on_first_delta= entry["function"]["arguments"] += tc_delta.function.arguments extra = getattr(tc_delta, "extra_content", None) if extra is None and hasattr(tc_delta, "model_extra"): - extra = (tc_delta.model_extra or {}).get("extra_content") + extra = (tc_delta.model_extra if isinstance(tc_delta.model_extra, dict) else {}).get("extra_content") if extra is not None: if hasattr(extra, "model_dump"): extra = extra.model_dump() diff --git a/agent/transports/chat_completions.py b/agent/transports/chat_completions.py index 42e81dc30e7..878045da66d 100644 --- a/agent/transports/chat_completions.py +++ b/agent/transports/chat_completions.py @@ -619,7 +619,7 @@ class ChatCompletionsTransport(ProviderTransport): tc_provider_data: dict[str, Any] = {} extra = getattr(tc, "extra_content", None) if extra is None and hasattr(tc, "model_extra"): - extra = (tc.model_extra or {}).get("extra_content") + extra = (tc.model_extra if isinstance(tc.model_extra, dict) else {}).get("extra_content") if extra is not None: if hasattr(extra, "model_dump"): try: