From 9eb45950e4e5b3e50024ec3d7cf47122e91c09e3 Mon Sep 17 00:00:00 2001 From: Greyson LaLonde Date: Sun, 12 Apr 2026 04:34:23 +0800 Subject: [PATCH] fix: avoid forcing lazy client construction in lightweight accessors Two sites that were mechanically rewritten by the lazy-getter regex shouldn't actually go through the lazy getter: - `BedrockCompletion._ensure_async_client` manages its own client lifecycle through `aiobotocore` inside an exit stack. Its trailing `return self._get_async_client()` was a redundant indirection through a stub method that doesn't even attempt to build a client. Return the cached attribute directly. - `GeminiCompletion._get_client_params` is a lightweight config accessor used at `to_config_dict()` time. Calling `_get_sync_client()` here forced client construction (and would raise `ValueError` when credentials aren't set) just to check the `vertexai` attribute. Read `self._client` directly and null-guard before the `hasattr` check. --- lib/crewai/src/crewai/llms/providers/bedrock/completion.py | 2 +- lib/crewai/src/crewai/llms/providers/gemini/completion.py | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/crewai/src/crewai/llms/providers/bedrock/completion.py b/lib/crewai/src/crewai/llms/providers/bedrock/completion.py index 56072968f..c7676c778 100644 --- a/lib/crewai/src/crewai/llms/providers/bedrock/completion.py +++ b/lib/crewai/src/crewai/llms/providers/bedrock/completion.py @@ -1198,7 +1198,7 @@ class BedrockCompletion(BaseLLM): ) self._async_client = client self._async_client_initialized = True - return self._get_async_client() + return self._async_client async def _ahandle_converse( self, diff --git a/lib/crewai/src/crewai/llms/providers/gemini/completion.py b/lib/crewai/src/crewai/llms/providers/gemini/completion.py index d9b8da7c4..c092f539d 100644 --- a/lib/crewai/src/crewai/llms/providers/gemini/completion.py +++ b/lib/crewai/src/crewai/llms/providers/gemini/completion.py @@ -244,8 +244,9 @@ class GeminiCompletion(BaseLLM): if ( hasattr(self, "client") - and hasattr(self._get_sync_client(), "vertexai") - and self._get_sync_client().vertexai + and self._client is not None + and hasattr(self._client, "vertexai") + and self._client.vertexai ): # Vertex AI configuration params.update(