fix: #2823 AnyLLM reasoning extraction for iterable vLLM/any-llm Reasoning objects (#2822)

This commit is contained in:
祝子祺
2026-04-02 13:50:28 +08:00
committed by GitHub
parent f75a40ebe2
commit fe9e70fd4d
2 changed files with 19 additions and 3 deletions
@@ -163,14 +163,15 @@ def _flatten_any_llm_reasoning_value(value: Any) -> str:
if flattened:
return flattened
return ""
if isinstance(value, Iterable) and not isinstance(value, (str, bytes)):
parts = [_flatten_any_llm_reasoning_value(item) for item in value]
return "".join(part for part in parts if part)
for attr in ("content", "text", "thinking"):
flattened = _flatten_any_llm_reasoning_value(getattr(value, attr, None))
if flattened:
return flattened
if isinstance(value, Iterable) and not isinstance(value, (str, bytes)):
parts = [_flatten_any_llm_reasoning_value(item) for item in value]
return "".join(part for part in parts if part)
return ""
@@ -829,6 +830,7 @@ class AnyLLMModel(Model):
handoffs=handoffs,
model=self._provider_model,
)
converted_tools = OpenAIResponsesConverter.convert_tools(
tools,
handoffs,
+14
View File
@@ -739,3 +739,17 @@ def test_any_llm_provider_passes_api_override() -> None:
assert isinstance(model, AnyLLMModel)
assert model.api == "chat_completions"
def test_any_llm_reasoning_objects_prefer_content_attributes_over_iterable_pairs() -> None:
pytest.importorskip(
"any_llm",
reason="`any-llm-sdk` is only available when the optional dependency is installed.",
)
from any_llm.types.completion import Reasoning
from agents.extensions.models.any_llm_model import _extract_any_llm_reasoning_text
delta = pytypes.SimpleNamespace(reasoning=Reasoning(content="用户"))
assert _extract_any_llm_reasoning_text(delta) == "用户"