Skip to content

Conversation

@OiPunk
Copy link
Contributor

@OiPunk OiPunk commented Feb 10, 2026

Summary

This defers litellm import in litellm_model.py so importing agents.extensions.models.litellm_model does not eagerly import LiteLLM.

This targets issue #610, where Windows users hit UnicodeDecodeError at module import time.

What changed

  • Replaced top-level import litellm with a lazy loader (_import_litellm) and a module proxy.
  • Kept the existing dependency error message, but now raised at first actual LiteLLM usage.
  • Added regression tests for both paths:
    • deferred import + import failure path (including cached failure)
    • successful import + cached module reuse path

Why this helps

  • Importing litellm_model no longer fails immediately due to LiteLLM import-time issues.
  • The failure is deferred to actual LiteLLM usage, which avoids breaking unrelated imports and startup paths.

Testing

  • uv run --with ruff ruff check src/agents/extensions/models/litellm_model.py tests/models/test_litellm_deferred_import.py tests/models/test_litellm_user_agent.py tests/models/test_map.py
  • uv run --with pytest pytest -q tests/models/test_litellm_deferred_import.py tests/models/test_litellm_user_agent.py tests/models/test_map.py
  • uv run --with litellm --with pytest pytest -q tests/models/test_kwargs_functionality.py tests/models/test_litellm_extra_body.py
  • uv run --with pytest python -m trace --count --coverdir /tmp/openai_agents_610_trace_1770722012 --module pytest tests/models/test_litellm_deferred_import.py -q

Trace output confirms all newly added lazy-import branches were executed.

@OiPunk
Copy link
Contributor Author

OiPunk commented Feb 10, 2026

Follow-up fix pushed for CI typecheck failure (new commit: e386968).

Root cause:

  • mypy flagged dynamic ModuleType test attributes in test_litellm_deferred_import.py.

What I changed:

  • Kept the same test behavior, but switched to explicit Any casts for dynamic module attributes so both ruff and mypy pass.

Local re-validation:

  • uv run --with ruff ruff check tests/models/test_litellm_deferred_import.py
  • uv run --with pytest pytest -q tests/models/test_litellm_deferred_import.py tests/models/test_litellm_user_agent.py tests/models/test_map.py
  • uv run --with litellm --with pytest pytest -q tests/models/test_kwargs_functionality.py tests/models/test_litellm_extra_body.py
  • uv run --with litellm --with mypy mypy --follow-imports=silent tests/models/test_litellm_deferred_import.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant