Skip to content

Commit 18485b4

Browse files
fix: include original error message in ImportError for LLM client dependencies
Improved import error handling across autogen-ext to include the original error message, making it easier for users to diagnose dependency issues. Previously, import errors would show a generic message like: 'Dependencies for X not found. Please install ...' Now they show: 'Dependencies for X not found. Original error: No module named vertexai Please install ...' This helps users distinguish between missing packages and other issues like version conflicts or missing transitive dependencies. Files updated: - models/llama_cpp/__init__.py - agents/azure/__init__.py - agents/magentic_one/__init__.py - runtimes/grpc/__init__.py and worker runtime files - memory/chromadb/_chromadb.py - memory/redis/_redis_memory.py - tools/azure/_ai_search.py Closes #4605
1 parent 8544314 commit 18485b4

File tree

10 files changed

+20
-15
lines changed

10 files changed

+20
-15
lines changed

python/packages/autogen-ext/src/autogen_ext/agents/azure/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from ._azure_ai_agent import AzureAIAgent
33
except ImportError as e:
44
raise ImportError(
5-
"Dependencies for AzureAIAgent not found. "
5+
f"Dependencies for AzureAIAgent not found. Original error: {e}\n"
66
'Please install autogen-ext with the "azure" extra: '
77
'pip install "autogen-ext[azure]"'
88
) from e

python/packages/autogen-ext/src/autogen_ext/agents/magentic_one/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from ._magentic_one_coder_agent import MagenticOneCoderAgent
33
except ImportError as e:
44
raise ImportError(
5-
"Dependencies for MagenticOneCoderAgent not found. "
5+
f"Dependencies for MagenticOneCoderAgent not found. Original error: {e}\n"
66
'Please install autogen-ext with the "magentic-one" extra: '
77
'pip install "autogen-ext[magentic-one]"'
88
) from e

python/packages/autogen-ext/src/autogen_ext/memory/chromadb/_chromadb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
from chromadb.api import ClientAPI
2929
except ImportError as e:
3030
raise ImportError(
31-
"To use the ChromaDBVectorMemory the chromadb extra must be installed. Run `pip install autogen-ext[chromadb]`"
31+
f"To use the ChromaDBVectorMemory the chromadb extra must be installed. Original error: {e}\n"
32+
"Run `pip install autogen-ext[chromadb]`"
3233
) from e
3334

3435

python/packages/autogen-ext/src/autogen_ext/memory/redis/_redis_memory.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
from redisvl.utils.utils import deserialize, serialize
1616
from redisvl.utils.vectorize import HFTextVectorizer
1717
except ImportError as e:
18-
raise ImportError("To use Redis Memory RedisVL must be installed. Run `pip install autogen-ext[redisvl]`") from e
18+
raise ImportError(
19+
f"To use Redis Memory RedisVL must be installed. Original error: {e}\n"
20+
"Run `pip install autogen-ext[redisvl]`"
21+
) from e
1922

2023

2124
class RedisMemoryConfig(BaseModel):

python/packages/autogen-ext/src/autogen_ext/models/llama_cpp/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from ._llama_cpp_completion_client import LlamaCppChatCompletionClient
33
except ImportError as e:
44
raise ImportError(
5-
"Dependencies for Llama Cpp not found. "
5+
f"Dependencies for Llama Cpp not found. Original error: {e}\n"
66
"Please install llama-cpp-python: "
77
"pip install autogen-ext[llama-cpp]"
88
) from e

python/packages/autogen-ext/src/autogen_ext/runtimes/grpc/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import grpc # type: ignore
77
except ImportError as e:
88
raise ImportError(
9-
"To use the GRPC runtime the grpc extra must be installed. Run `pip install autogen-ext[grpc]`"
9+
f"To use the GRPC runtime the grpc extra must be installed. Original error: {e}\n"
10+
"Run `pip install autogen-ext[grpc]`"
1011
) from e
1112

1213
__all__ = [

python/packages/autogen-ext/src/autogen_ext/runtimes/grpc/_worker_runtime.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
try:
6767
import grpc.aio
6868
except ImportError as e:
69-
raise ImportError(GRPC_IMPORT_ERROR_STR) from e
69+
raise ImportError(f"{GRPC_IMPORT_ERROR_STR} Original error: {e}") from e
7070

7171
if TYPE_CHECKING:
7272
from .protos.agent_worker_pb2_grpc import AgentRpcAsyncStub

python/packages/autogen-ext/src/autogen_ext/runtimes/grpc/_worker_runtime_host.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
try:
1111
import grpc
1212
except ImportError as e:
13-
raise ImportError(GRPC_IMPORT_ERROR_STR) from e
13+
raise ImportError(f"{GRPC_IMPORT_ERROR_STR} Original error: {e}") from e
1414
from .protos import agent_worker_pb2_grpc
1515

1616
logger = logging.getLogger("autogen_core")

python/packages/autogen-ext/src/autogen_ext/runtimes/grpc/_worker_runtime_host_servicer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
try:
1717
import grpc
1818
except ImportError as e:
19-
raise ImportError(GRPC_IMPORT_ERROR_STR) from e
19+
raise ImportError(f"{GRPC_IMPORT_ERROR_STR} Original error: {e}") from e
2020

2121
from .protos import agent_worker_pb2, agent_worker_pb2_grpc, cloudevent_pb2
2222

python/packages/autogen-ext/src/autogen_ext/tools/azure/_ai_search.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,11 @@ async def _get_embedding(self, query: str) -> List[float]:
154154
from openai import AsyncAzureOpenAI
155155

156156
from azure.identity import DefaultAzureCredential
157-
except ImportError:
157+
except ImportError as e:
158158
raise ImportError(
159-
"Azure OpenAI SDK is required for client-side embedding generation. "
159+
f"Azure OpenAI SDK is required for client-side embedding generation. Original error: {e}\n"
160160
"Please install it with: uv add openai azure-identity"
161-
) from None
161+
) from e
162162

163163
api_key = getattr(search_config, "openai_api_key", None)
164164
api_version = getattr(search_config, "openai_api_version", "2023-11-01")
@@ -193,11 +193,11 @@ def get_token() -> str:
193193
elif embedding_provider.lower() == "openai":
194194
try:
195195
from openai import AsyncOpenAI
196-
except ImportError:
196+
except ImportError as e:
197197
raise ImportError(
198-
"OpenAI SDK is required for client-side embedding generation. "
198+
f"OpenAI SDK is required for client-side embedding generation. Original error: {e}\n"
199199
"Please install it with: uv add openai"
200-
) from None
200+
) from e
201201

202202
api_key = getattr(search_config, "openai_api_key", None)
203203
openai_client = AsyncOpenAI(api_key=api_key)

0 commit comments

Comments
 (0)