From df1f9fa3675f9124f2ded08fb50e5d56ad9a16d3 Mon Sep 17 00:00:00 2001 From: Yassin Kortam Date: Sat, 25 Jul 2026 14:20:35 -0700 Subject: [PATCH] fix(proxy): stop litellm/proxy from shadowing installed packages on sys.path (#34656) Running the proxy as a script (python litellm/proxy/proxy_cli.py) puts litellm/proxy at sys.path[0], so `import a2a` resolved to the internal litellm/proxy/a2a package instead of the a2a SDK. The optional-import guard in litellm/a2a_protocol/card_resolver.py swallowed the resulting ModuleNotFoundError and left its None fallback in place, so the module-level class statement raised TypeError: NoneType takes no arguments and every proxied A2A agent call failed with JSON-RPC -32603. Move the script directory to the end of sys.path instead of removing it; the sibling-import fallbacks in proxy_cli (from proxy_server import ...) still need the entry to resolve. Co-authored-by: Yassin Kortam --- litellm/proxy/proxy_cli.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/litellm/proxy/proxy_cli.py b/litellm/proxy/proxy_cli.py index dc5bde8cb0b..8dc4a7b40c7 100644 --- a/litellm/proxy/proxy_cli.py +++ b/litellm/proxy/proxy_cli.py @@ -23,6 +23,22 @@ if TYPE_CHECKING: else: FastAPI = Any + +def _deprioritize_script_dir_in_sys_path() -> None: + """Stop ``litellm/proxy`` modules from shadowing installed packages. + + Running this file as a script puts its own directory at ``sys.path[0]``, so + ``import a2a`` resolves to ``litellm/proxy/a2a`` instead of the ``a2a`` SDK + and A2A agent calls fail. The entry is moved to the end rather than dropped, + because the sibling-import fallbacks in this module (``from proxy_server + import ...``) still need it. No-op under the ``litellm`` console script. + """ + script_dir = os.path.dirname(os.path.abspath(__file__)) + if sys.path and os.path.abspath(sys.path[0]) == script_dir: + sys.path.append(sys.path.pop(0)) + + +_deprioritize_script_dir_in_sys_path() sys.path.append(os.getcwd()) config_filename = "litellm.secrets"