perf(cli): defer litellm import to cut cold start#147
Merged
Conversation
Every raven command imported litellm eagerly (via the CLI entry module and the deep_research_commands -> raven.agent chain), and litellm is ~85% of the ~2.35s cold start. Defer it: make raven.agent and raven.providers PEP 562 lazy re-exports, drop the eager import in the CLI entry, and route every litellm import through a shared helper that silences its terminal noise. raven --version now starts in ~0.4s. Co-authored-by: Claude (claude-opus-4-8) <noreply@anthropic.com>
arelchan
approved these changes
Jul 17, 2026
12 tasks
cyfyifanchen
added a commit
that referenced
this pull request
Jul 19, 2026
## Summary Bump Raven package metadata from 0.1.5 to 0.1.6 so the release tag can build a wheel from the current main branch. This release carries the changes merged after v0.1.5: - Version display now derives from installed package metadata (#139). - Tracing dashboard port reuse avoids taking over non-Raven viewers (#141). - CLI startup defers LiteLLM imports for faster cold start (#147). - Self-evolution stack and AppWorld benchmark entry points are included (#140). - TUI render delay is reduced by deferring provider and memory loading (#157). ## Type - [ ] Fix - [ ] Feature - [ ] Docs - [ ] CI / tooling - [ ] Refactor - [x] Other ## Verification - [x] Relevant tests pass locally - [x] Relevant lint / type checks pass locally - [ ] User-facing docs or screenshots are updated when needed Commands run: - `PYTHONPATH=. uv run pytest tests/test_cli_smoke.py::test_version_flag_matches_installed_metadata -q` - `make check-commits COMMIT_RANGE=origin/main..HEAD` - `PYTHONPATH=. uv run python scripts/check_commit_file.py /tmp/raven-commit-msg.txt` No user-facing docs or screenshots were needed for this version metadata bump; release notes will be published with the GitHub Release. ## Risk - [x] Security impact considered - [x] Backward compatibility considered - [x] Rollback path is clear for risky changes This changes package metadata only. Rollback is to delete the v0.1.6 tag/release if publication fails before users upgrade, or publish a follow-up patch release if a released package issue is found. ## Related Issues N/A
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Every
ravencommand imported litellm eagerly, and litellm was ~85% of the~2.35s cold start -- so even
raven --versionpaid the full tax. This deferslitellm to the code paths that actually need a model:
import litellmin the CLI entry module.raven.agentandraven.providersPEP 562 lazy re-exports, so importinga submodule no longer eagerly constructs
AgentLoop-> litellm (0 in-repocallers of the re-exports, so no behavior change).
import_litellm()helper thatsilences litellm's "Provider List" banner and suppresses its import-time DEBUG
from the terminal (litellm installs its own stderr handler and logs while
importing; the deferred import happens after raven's CLI logging setup, so the
helper keeps that noise off the terminal / Ink TUI).
Result:
raven --versionstarts in ~0.4s (from ~2.35s). Verified the everosmemory substrate was never on the startup path; it was not the bottleneck.
Type
Verification
raven --version: ~2.35s -> ~0.4s (direct.venv/bin/raven).python -X importtime -c "import raven.cli.commands": 0 litellm.Real logging path (
redirect_loguru_to_file+ provider import) and aninteractive
raven tui: 0LiteLLM:DEBUGlines leaked to the terminal.make test-python(now includestest_cli_smoke.py+test_litellm_setup.py).Affected suites (agent loop / providers / token_wise / tui logging isolation): pass.
Relevant tests pass locally
Relevant lint / type checks pass locally
User-facing docs or screenshots are updated when needed
Risk
Related Issues
Fixes #142