From 34e85112942014aad6287c4c1f8812e7808f0072 Mon Sep 17 00:00:00 2001 From: Lucas Gomide Date: Wed, 27 May 2026 11:11:17 -0300 Subject: [PATCH] chore(otel): drop dead last_chunk variable from async streaming MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The streaming-fix commit (49e5581b5) replaced the post-loop `_extract_finish_reason_and_response_id(last_chunk)` call with the incrementally-tracked `stream_finish_reason` / `stream_response_id`, which removed the only reader of `last_chunk` in `_ahandle_streaming_response`. The declaration and per-iteration assignment were left behind — harmless but confusing for future readers because the sync sibling still legitimately uses `last_chunk` (for usage and content fallbacks via `_handle_streaming_callbacks`). The async path inlines its usage extraction directly inside the loop (`chunk.model_extra.get("usage")`), so there's no fallback consumer. Drop both lines. Sync path untouched — `last_chunk` there is still load-bearing. --- lib/crewai/src/crewai/llm.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/crewai/src/crewai/llm.py b/lib/crewai/src/crewai/llm.py index 337d2bed8..add04cb1e 100644 --- a/lib/crewai/src/crewai/llm.py +++ b/lib/crewai/src/crewai/llm.py @@ -1452,7 +1452,6 @@ class LLM(BaseLLM): params["stream"] = True params["stream_options"] = {"include_usage": True} response_id = None - last_chunk: Any | None = None # See sync sibling: incrementally track finish_reason/response_id so the # usage-only final chunk doesn't wipe them. stream_finish_reason: str | None = None @@ -1462,7 +1461,6 @@ class LLM(BaseLLM): async for chunk in await litellm.acompletion(**params): chunk_count += 1 chunk_content = None - last_chunk = chunk response_id = chunk.id if isinstance(chunk, ModelResponseBase) else None chunk_finish, chunk_id = self._extract_finish_reason_and_response_id(