From b69e3287523b46c3de6b2ce88d79dbc68d75e5dd Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Mon, 5 May 2025 22:49:01 +0000 Subject: [PATCH] Add input validation and improve documentation for max_age_days parameter Co-Authored-By: Joe Moura --- .../storage/llm_response_cache_storage.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/crewai/memory/storage/llm_response_cache_storage.py b/src/crewai/memory/storage/llm_response_cache_storage.py index 1af7fab62..20110b6e3 100644 --- a/src/crewai/memory/storage/llm_response_cache_storage.py +++ b/src/crewai/memory/storage/llm_response_cache_storage.py @@ -214,10 +214,27 @@ class LLMResponseCacheStorage: """ Removes cache entries older than the specified number of days. + This method helps maintain the cache size and ensures that only recent + responses are kept, which is important for keeping the cache relevant + and preventing it from growing too large over time. + Args: max_age_days: Maximum age of cache entries in days. Defaults to 7. If set to 0, all entries will be deleted. + Must be a non-negative integer. + + Raises: + ValueError: If max_age_days is not a non-negative integer. """ + if not isinstance(max_age_days, int) or max_age_days < 0: + error_msg = "max_age_days must be a non-negative integer" + self._printer.print( + content=f"LLM RESPONSE CACHE ERROR: {error_msg}", + color="red", + ) + logger.error(error_msg) + raise ValueError(error_msg) + try: conn = self._get_connection() cursor = conn.cursor()