From 67bf4aea56a4f82b1f9f6111ab05186826a7148e Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 24 Jan 2025 17:04:41 -0500 Subject: [PATCH] Add version check to crew_chat.py (#1966) * Add version check to crew_chat.py with min version 0.98.0 Co-Authored-By: brandon@crewai.com * Fix import sorting in crew_chat.py Co-Authored-By: brandon@crewai.com * Fix import sorting in crew_chat.py (attempt 3) Co-Authored-By: brandon@crewai.com * Update error message, add version check helper, fix import sorting Co-Authored-By: brandon@crewai.com * Fix import sorting with Ruff auto-fix Co-Authored-By: brandon@crewai.com * Remove poetry check and import comment headers in crew_chat.py Co-Authored-By: brandon@crewai.com --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: brandon@crewai.com --- src/crewai/cli/crew_chat.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/crewai/cli/crew_chat.py b/src/crewai/cli/crew_chat.py index a38315620..f1695f0a4 100644 --- a/src/crewai/cli/crew_chat.py +++ b/src/crewai/cli/crew_chat.py @@ -6,12 +6,42 @@ from typing import Any, Dict, List, Optional, Set, Tuple import click import tomli +from packaging import version +from crewai.cli.utils import read_toml +from crewai.cli.version import get_crewai_version from crewai.crew import Crew from crewai.llm import LLM from crewai.types.crew_chat import ChatInputField, ChatInputs from crewai.utilities.llm_utils import create_llm +MIN_REQUIRED_VERSION = "0.98.0" + + +def check_conversational_crews_version(crewai_version: str, pyproject_data: dict) -> bool: + """ + Check if the installed crewAI version supports conversational crews. + + Args: + crewai_version: The current version of crewAI + pyproject_data: Dictionary containing pyproject.toml data + + Returns: + bool: True if version check passes, False otherwise + """ + try: + if version.parse(crewai_version) < version.parse(MIN_REQUIRED_VERSION): + click.secho( + "You are using an older version of crewAI that doesn't support conversational crews. " + "Run 'uv upgrade crewai' to get the latest version.", + fg="red" + ) + return False + except version.InvalidVersion: + click.secho("Invalid crewAI version format detected", fg="red") + return False + return True + def run_chat(): """ @@ -19,6 +49,11 @@ def run_chat(): Incorporates crew_name, crew_description, and input fields to build a tool schema. Exits if crew_name or crew_description are missing. """ + crewai_version = get_crewai_version() + pyproject_data = read_toml() + + if not check_conversational_crews_version(crewai_version, pyproject_data): + return crew, crew_name = load_crew_and_name() chat_llm = initialize_chat_llm(crew) if not chat_llm: