diff --git a/lib/crewai/src/crewai/llm.py b/lib/crewai/src/crewai/llm.py index 105bc8988..8007a451e 100644 --- a/lib/crewai/src/crewai/llm.py +++ b/lib/crewai/src/crewai/llm.py @@ -1596,7 +1596,7 @@ class LLM(BaseLLM): messages=params.get("messages"), usage=usage_dict, finish_reason=finish_reason, - response_id=response_id_last or response_id, + response_id=response_id_last, ) return full_response @@ -1622,7 +1622,7 @@ class LLM(BaseLLM): messages=params.get("messages"), usage=self._usage_to_dict(usage_info), finish_reason=finish_reason, - response_id=response_id_last or response_id, + response_id=response_id_last, ) return full_response raise diff --git a/lib/crewai/src/crewai/llms/providers/gemini/completion.py b/lib/crewai/src/crewai/llms/providers/gemini/completion.py index e91800610..da75fbcdc 100644 --- a/lib/crewai/src/crewai/llms/providers/gemini/completion.py +++ b/lib/crewai/src/crewai/llms/providers/gemini/completion.py @@ -1385,7 +1385,9 @@ class GeminiCompletion(BaseLLM): ``.name`` attribute (e.g. ``"STOP"``, ``"MAX_TOKENS"``); we forward it raw and let downstream telemetry map to the OTel GenAI enum. """ - response_id = getattr(response, "response_id", None) + raw_response_id = getattr(response, "response_id", None) + response_id = raw_response_id if isinstance(raw_response_id, str) else None + finish_reason: str | None = None candidates = getattr(response, "candidates", None) if candidates: @@ -1394,9 +1396,8 @@ class GeminiCompletion(BaseLLM): except (IndexError, TypeError, KeyError): candidate_finish = None if candidate_finish is not None: - finish_reason = getattr(candidate_finish, "name", None) or str( - candidate_finish - ) + name = getattr(candidate_finish, "name", None) + finish_reason = name if isinstance(name, str) else None return finish_reason, response_id @staticmethod