Skip to content

Commit fe9e70f

Browse files
authored
fix: #2823 AnyLLM reasoning extraction for iterable vLLM/any-llm Reasoning objects (#2822)
1 parent f75a40e commit fe9e70f

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/agents/extensions/models/any_llm_model.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,15 @@ def _flatten_any_llm_reasoning_value(value: Any) -> str:
163163
if flattened:
164164
return flattened
165165
return ""
166-
if isinstance(value, Iterable) and not isinstance(value, (str, bytes)):
167-
parts = [_flatten_any_llm_reasoning_value(item) for item in value]
168-
return "".join(part for part in parts if part)
169166

170167
for attr in ("content", "text", "thinking"):
171168
flattened = _flatten_any_llm_reasoning_value(getattr(value, attr, None))
172169
if flattened:
173170
return flattened
171+
172+
if isinstance(value, Iterable) and not isinstance(value, (str, bytes)):
173+
parts = [_flatten_any_llm_reasoning_value(item) for item in value]
174+
return "".join(part for part in parts if part)
174175
return ""
175176

176177

@@ -829,6 +830,7 @@ async def _fetch_responses_response(
829830
handoffs=handoffs,
830831
model=self._provider_model,
831832
)
833+
832834
converted_tools = OpenAIResponsesConverter.convert_tools(
833835
tools,
834836
handoffs,

tests/models/test_any_llm_model.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,3 +739,17 @@ def test_any_llm_provider_passes_api_override() -> None:
739739

740740
assert isinstance(model, AnyLLMModel)
741741
assert model.api == "chat_completions"
742+
743+
744+
def test_any_llm_reasoning_objects_prefer_content_attributes_over_iterable_pairs() -> None:
745+
pytest.importorskip(
746+
"any_llm",
747+
reason="`any-llm-sdk` is only available when the optional dependency is installed.",
748+
)
749+
from any_llm.types.completion import Reasoning
750+
751+
from agents.extensions.models.any_llm_model import _extract_any_llm_reasoning_text
752+
753+
delta = pytypes.SimpleNamespace(reasoning=Reasoning(content="用户"))
754+
755+
assert _extract_any_llm_reasoning_text(delta) == "用户"

0 commit comments

Comments
 (0)