mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-12 08:42:18 +00:00
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 <yassin.kortam@gmail.com>
This commit is contained in:
parent
998a372417
commit
df1f9fa367
1 changed files with 16 additions and 0 deletions
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue