Skip to content

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.

Refresh the LiteLLM catalog after the version-bump PR merges. (#8103)

Vidit Ostwal13b7c3079ff6
diff --git a/lib/devtools/README.md b/lib/devtools/README.md
index 2faac201f..861af3298 100644
--- a/lib/devtools/README.md
+++ b/lib/devtools/README.md
@@ -35,7 +35,7 @@ devtools release 1.10.3 --skip-enterprise # skip enterprise release phase
3. Creates version bump PR against main, polls until merged
4. Generates release notes (OpenAI) from commits since last release
5. Updates Edge changelogs (`docs/edge/{en,pt-BR,ko,ar}/changelog.mdx`)
-6. Freezes `docs/edge/` into `docs/v<version>/`, registers the version in `docs.json`, and points the canonical `/<lang>/:slug*` redirects at the new default
+6. Downloads the LiteLLM model catalog into `lib/crewai/src/crewai/llms/litellm_catalog/model_prices_and_context_window.json`, freezes `docs/edge/` into `docs/v<version>/`, registers the version in `docs.json`, and points the canonical `/<lang>/:slug*` redirects at the new default
7. Opens a `[docs-freeze]` PR against main, polls until merged
8. Tags main and creates GitHub release
9. Triggers PyPI publish workflow
diff --git a/lib/devtools/src/crewai_devtools/cli.py b/lib/devtools/src/crewai_devtools/cli.py
index a3c003580..39a7e8b04 100644
--- a/lib/devtools/src/crewai_devtools/cli.py
+++ b/lib/devtools/src/crewai_devtools/cli.py
@@ -29,6 +29,7 @@ from crewai_devtools.docs_versioning import (
MissingEdgeSourcesError,
freeze as freeze_docs,
)
+from crewai_devtools.litellm_catalog_update import CATALOG_RELATIVE, update_catalog
from crewai_devtools.prompts import RELEASE_NOTES_PROMPT, TRANSLATE_RELEASE_NOTES_PROMPT
@@ -1096,16 +1097,18 @@ def _update_docs_and_create_pr(
) -> str | None:
"""Update Edge changelogs, freeze a snapshot, and open the docs PR.
- For a stable release this freezes ``docs/edge/`` into ``docs/v<version>/``
- (after the Edge changelogs have been updated so the snapshot contains the
- new entry), updates ``docs/docs.json`` to register the new version and
- canonical-URL redirects, and opens a ``[docs-freeze]`` PR. The
- ``docs-snapshots`` CI guard recognises that title prefix and allows the
- snapshot directory to land.
+ Runs after the version-bump PR has merged. Refreshes the checked-in
+ LiteLLM catalog, then for a stable release freezes ``docs/edge/`` into
+ ``docs/v<version>/`` (after the Edge changelogs have been updated so the
+ snapshot contains the new entry), updates ``docs/docs.json`` to register
+ the new version and canonical-URL redirects, and opens a ``[docs-freeze]``
+ PR. The ``docs-snapshots`` CI guard recognises that title prefix and
+ allows the snapshot directory to land. The catalog file is included in
+ that same PR.
- For a pre-release, only the Edge changelogs are touched (pre-releases don't
- get a frozen snapshot — they ride Edge), and the PR title omits the
- ``[docs-freeze]`` prefix.
+ For a pre-release, the catalog is still refreshed and the Edge changelogs
+ are updated. Pre-releases don't get a frozen snapshot — they ride Edge —
+ and the PR title omits the ``[docs-freeze]`` prefix.
Returns:
The docs branch name if a PR was created, None otherwise.
@@ -1116,6 +1119,9 @@ def _update_docs_and_create_pr(
changelog_langs: list[ChangelogLang] = ["en", "pt-BR", "ko", "ar"]
if dry_run:
+ console.print(
+ f"[dim][DRY RUN][/dim] Would download the LiteLLM catalog into {CATALOG_RELATIVE}"
+ )
for lang in changelog_langs:
cl_path = edge_root / lang / "changelog.mdx"
translated = " (translated)" if lang != "en" else ""
@@ -1142,6 +1148,14 @@ def _update_docs_and_create_pr(
docs_paths_staged: list[str] = []
+ # The bump PR has already merged. Refresh the catalog before the docs
+ # snapshot so this PR carries the model data that ships with the release.
+ catalog_path = update_catalog(cwd)
+ console.print(
+ f"[green]✓[/green] Updated LiteLLM catalog {catalog_path.relative_to(cwd)}"
+ )
+ docs_paths_staged.append(str(catalog_path))
+
# Step 1: update Edge changelogs first so the snapshot we freeze afterwards
# contains the new release's entry.
for lang in changelog_langs:
diff --git a/lib/devtools/src/crewai_devtools/litellm_catalog_update.py b/lib/devtools/src/crewai_devtools/litellm_catalog_update.py
new file mode 100644
index 000000000..b2a7c89be
--- /dev/null
+++ b/lib/devtools/src/crewai_devtools/litellm_catalog_update.py
@@ -0,0 +1,87 @@
+# ruff: noqa: T201
+"""Refresh the checked-in LiteLLM model catalog.
+
+``devtools release`` calls :func:`update_catalog` after the version-bump PR
+merges, while it is preparing the docs PR. The standalone script
+``scripts/update_litellm_catalog.py`` is the manual wrapper.
+"""
+
+from __future__ import annotations
+
+import json
+from pathlib import Path
+import shutil
+import subprocess
+import tempfile
+from typing import Final
+
+
+CATALOG_URL: Final[str] = (
+ "https://raw.githubusercontent.com/BerriAI/litellm/main/"
+ "model_prices_and_context_window.json"
+)
+CATALOG_RELATIVE: Final[Path] = Path(
+ "lib/crewai/src/crewai/llms/litellm_catalog/model_prices_and_context_window.json"
+)
+
+
+def update_catalog(repo_root: Path) -> Path:
+ """Download the LiteLLM catalog with curl and write it into the checkout.
+
+ Args:
+ repo_root: Checkout root that contains ``lib/crewai``.
+
+ Returns:
+ Path of the catalog file that was written.
+
+ Raises:
+ RuntimeError: curl is missing or the download fails.
+ ValueError: the response is not a LiteLLM catalog object.
+ json.JSONDecodeError: the response is not valid JSON.
+ """
+ destination = repo_root / CATALOG_RELATIVE
+ curl = shutil.which("curl")
+ if curl is None:
+ raise RuntimeError("curl is not installed or not on PATH")
+
+ destination.parent.mkdir(parents=True, exist_ok=True)
+ with tempfile.NamedTemporaryFile(
+ dir=destination.parent,
+ prefix=".model_prices_and_context_window.",
+ suffix=".json",
+ delete=False,
+ ) as handle:
+ temp_path = Path(handle.name)
+
+ try:
+ print(f"Downloading {CATALOG_URL}")
+ completed = subprocess.run( # noqa: S603 - fixed curl binary and catalog URL
+ [
+ curl,
+ "--fail",
+ "--silent",
+ "--show-error",
+ "--location",
+ "--output",
+ str(temp_path),
+ CATALOG_URL,
+ ],
+ check=False,
+ capture_output=True,
+ text=True,
+ )
+ if completed.returncode != 0:
+ detail = completed.stderr.strip() or f"curl exited {completed.returncode}"
+ raise RuntimeError(detail)
+
+ payload = json.loads(temp_path.read_bytes())
+ if not isinstance(payload, dict) or "sample_spec" not in payload:
+ raise ValueError("Downloaded catalog is not a LiteLLM model prices object")
+
+ print(f"Updating {CATALOG_RELATIVE}")
+ temp_path.replace(destination)
+ except Exception:
+ temp_path.unlink(missing_ok=True)
+ raise
+
+ return destination
diff --git a/lib/devtools/tests/test_litellm_catalog_update.py b/lib/devtools/tests/test_litellm_catalog_update.py
new file mode 100644
index 000000000..f19e378fa
--- /dev/null
+++ b/lib/devtools/tests/test_litellm_catalog_update.py
@@ -0,0 +1,79 @@
+"""The release catalog refresh downloads LiteLLM's snapshot with curl."""
+
+from __future__ import annotations
+
+import json
+from pathlib import Path
+import subprocess
+
+from crewai_devtools.litellm_catalog_update import CATALOG_URL, update_catalog
+import pytest
+
+
+def _destination(repo_root: Path) -> Path:
+ return (
+ repo_root
+ / "lib/crewai/src/crewai/llms/litellm_catalog/model_prices_and_context_window.json"
+ )
+
+
+def test_update_catalog_replaces_the_snapshot_after_a_valid_download(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ destination = _destination(tmp_path)
+ destination.parent.mkdir(parents=True)
+ destination.write_text('{"old": true}\n', encoding="utf-8")
+ seen: list[list[str]] = []
+
+ def fake_run(
+ args: list[str], **_kwargs: object
+ ) -> subprocess.CompletedProcess[str]:
+ seen.append(args)
+ output = Path(args[args.index("--output") + 1])
+ output.write_bytes(b'{"sample_spec": {"max_input_tokens": 1}}')
+ return subprocess.CompletedProcess(args, 0, stdout="", stderr="")
+
+ monkeypatch.setattr(
+ "crewai_devtools.litellm_catalog_update.shutil.which",
+ lambda _name: "/usr/bin/curl",
+ )
+ monkeypatch.setattr(
+ "crewai_devtools.litellm_catalog_update.subprocess.run", fake_run
+ )
+
+ written = update_catalog(tmp_path)
+
+ assert written == destination
+ assert json.loads(destination.read_text(encoding="utf-8")) == {
+ "sample_spec": {"max_input_tokens": 1}
+ }
+ assert seen[0][0] == "/usr/bin/curl"
+ assert CATALOG_URL in seen[0]
+ assert not list(destination.parent.glob(".model_prices_and_context_window.*.json"))
+
+
+def test_update_catalog_keeps_the_existing_snapshot_when_the_download_fails(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ destination = _destination(tmp_path)
+ destination.parent.mkdir(parents=True)
+ destination.write_text('{"old": true}\n', encoding="utf-8")
+
+ def fake_run(
+ args: list[str], **_kwargs: object
+ ) -> subprocess.CompletedProcess[str]:
+ return subprocess.CompletedProcess(args, 22, stdout="", stderr="curl: (22) 404")
+
+ monkeypatch.setattr(
+ "crewai_devtools.litellm_catalog_update.shutil.which",
+ lambda _name: "/usr/bin/curl",
+ )
+ monkeypatch.setattr(
+ "crewai_devtools.litellm_catalog_update.subprocess.run", fake_run
+ )
+
+ with pytest.raises(RuntimeError, match="404"):
+ update_catalog(tmp_path)
+
+ assert destination.read_text(encoding="utf-8") == '{"old": true}\n'
+ assert not list(destination.parent.glob(".model_prices_and_context_window.*.json"))
diff --git a/scripts/update_litellm_catalog.py b/scripts/update_litellm_catalog.py
new file mode 100644
index 000000000..c3487a5d3
--- /dev/null
+++ b/scripts/update_litellm_catalog.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+# ruff: noqa: T201
+"""Refresh the checked-in LiteLLM model catalog.
+
+Manual wrapper around :func:`crewai_devtools.litellm_catalog_update.update_catalog`.
+``devtools release`` calls that function after the version-bump PR merges.
+
+Usage::
+
+ python scripts/update_litellm_catalog.py
+"""
+
+from __future__ import annotations
+
+from pathlib import Path
+import sys
+
+from crewai_devtools.litellm_catalog_update import update_catalog
+
+
+def _repo_root() -> Path:
+ return Path(__file__).resolve().parents[1]
+
+
+def main() -> int:
+ """Download the catalog and print the path that was updated."""
+ repo_root = _repo_root()
+ try:
+ path = update_catalog(repo_root)
+ except (OSError, RuntimeError, ValueError) as exc:
+ print(f"ERROR: {exc}", file=sys.stderr)
+ return 1
+
+ print(f"Updated {path.relative_to(repo_root)}")
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())