Skip to content

Build and run agents you can see, understand and trust.

fix(model): support newer vllm reasoning field parsing (#1271)

Sibo Wei28cfb99a2190
diff --git a/src/agentscope/model/_openai_model.py b/src/agentscope/model/_openai_model.py
index 2ee9edcd3..61a224964 100644
--- a/src/agentscope/model/_openai_model.py
+++ b/src/agentscope/model/_openai_model.py
@@ -374,9 +374,17 @@ class OpenAIChatModel(ChatModelBase):
choice = chunk.choices[0]
- thinking += (
- getattr(choice.delta, "reasoning_content", None) or ""
+ delta_reasoning = getattr(
+ choice.delta,
+ "reasoning_content",
+ None,
)
+ if not isinstance(delta_reasoning, str):
+ delta_reasoning = getattr(choice.delta, "reasoning", None)
+ if not isinstance(delta_reasoning, str):
+ delta_reasoning = ""
+
+ thinking += delta_reasoning
text += getattr(choice.delta, "content", None) or ""
if (
@@ -538,14 +546,17 @@ class OpenAIChatModel(ChatModelBase):
if response.choices:
choice = response.choices[0]
- if (
- hasattr(choice.message, "reasoning_content")
- and choice.message.reasoning_content is not None
- ):
+ reasoning = getattr(choice.message, "reasoning_content", None)
+ if not isinstance(reasoning, str):
+ reasoning = getattr(choice.message, "reasoning", None)
+ if not isinstance(reasoning, str):
+ reasoning = None
+
+ if reasoning is not None:
content_blocks.append(
ThinkingBlock(
type="thinking",
- thinking=response.choices[0].message.reasoning_content,
+ thinking=reasoning,
),
)