Fix: Replace SystemExit with LLMContextLengthExceededError in handle_context_length

- Changed handle_context_length to raise LLMContextLengthExceededError instead of SystemExit when respect_context_window=False
- This allows proper exception handling and prevents the entire application from terminating
- Added comprehensive unit tests to verify the fix
- Updated test imports to include LLMContextLengthExceededError

Fixes #3774

Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
Devin AI
2025-10-22 04:53:24 +00:00
parent 4371cf5690
commit 6dcc7ac725
4 changed files with 4098 additions and 3972 deletions

View File

@@ -18,6 +18,9 @@ from crewai.process import Process
from crewai.tools.tool_calling import InstructorToolCalling
from crewai.tools.tool_usage import ToolUsage
from crewai.utilities.errors import AgentRepositoryError
from crewai.utilities.exceptions.context_window_exceeding_exception import (
LLMContextLengthExceededError,
)
import pytest
from crewai import Agent, Crew, Task