You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[perf][imports][defer litellm and mcp so import swarms does no provider work]
import swarms eagerly imported litellm (~1.1s, and litellm's own __init__
fetches its model-cost map from raw.githubusercontent.com) and mcp, neither
of which is needed until the first LLM call or the first MCP use. Import
drops from ~2.2s to ~0.6s and no longer touches the network — verified by
importing with socket.connect monkeypatched to raise.
litellm deferral, per module:
- litellm_wrapper binds litellm/completion/supports_vision into module
globals on first LiteLLM construction. Module attributes rather than
function-local imports so existing tests that patch
litellm_wrapper.completion keep working; each name binds only while
None, so an active patch is never overwritten. context_compressor gets
the same treatment for its patched completion.
- agent.py's reasoning_effort annotation called get_reasoning_efforts() in
the class body, which introspects litellm.completion — forcing the
import at class-definition time. The Literal on a plain class is never
enforced at runtime, so it now uses the static REASONING_EFFORTS set the
same module already maintains for exactly this fallback.
- litellm_tokenizer, agent_loader, agent_router, tree_swarm, llm_manager
and agent.py move their litellm imports into the functions that use
them (count_tokens, model validation, embedding calls, capability
checks, reliability_check).
- The litellm exception names vanish from except tuples that already
contained Exception, which subsumed them; behaviour is identical and the
exceptions still propagate to callers.
mcp deferral: mcp_manager and aop gain `from __future__ import
annotations` so mcp types in signatures stop needing the real classes at
def time, TYPE_CHECKING imports keep the annotations meaningful, and the
two runtime uses (ClientSession construction, the MCPTool isinstance
check, FastMCP construction) import locally.
Two subprocess regression tests in tests/test___init__.py pin the
contract: import swarms leaves litellm/mcp/openai unloaded, and the first
LiteLLM construction still binds litellm.
Addresses kyegomez#1754 and the import-time side effects behind kyegomez#1739 and kyegomez#1738.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
# Bound on first use; see summarize(). Patched directly by tests.
17
+
completion=None
18
+
17
19
18
20
COMPRESSION_SYSTEM_PROMPT="""
19
21
You are a conversation compression expert. Your job is to produce a faithful, dense summary of an ongoing agent conversation so that the agent can continue its work without losing critical context.
0 commit comments