From afe220d3e88bddeb694ea8f0cd02e470dbfd72a6 Mon Sep 17 00:00:00 2001 From: Lorenze Jay Date: Wed, 12 Mar 2025 08:15:30 -0700 Subject: [PATCH] Improve stop words handling in CrewAgentExecutor - Add support for handling existing stop words in LLM configuration - Ensure stop words are correctly merged and deduplicated - Update type hints to support both LLM and BaseLLM types --- src/crewai/agents/crew_agent_executor.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/crewai/agents/crew_agent_executor.py b/src/crewai/agents/crew_agent_executor.py index d573561e2..0fe61888e 100644 --- a/src/crewai/agents/crew_agent_executor.py +++ b/src/crewai/agents/crew_agent_executor.py @@ -13,7 +13,7 @@ from crewai.agents.parser import ( OutputParserException, ) from crewai.agents.tools_handler import ToolsHandler -from crewai.llm import BaseLLM +from crewai.llm import LLM, BaseLLM from crewai.tools.base_tool import BaseTool from crewai.tools.tool_usage import ToolUsage, ToolUsageErrorException from crewai.utilities import I18N, Printer @@ -61,7 +61,7 @@ class CrewAgentExecutor(CrewAgentExecutorMixin): callbacks: List[Any] = [], ): self._i18n: I18N = I18N() - self.llm: BaseLLM = llm + self.llm: Union[LLM, BaseLLM] = llm self.task = task self.agent = agent self.crew = crew @@ -87,8 +87,14 @@ class CrewAgentExecutor(CrewAgentExecutorMixin): self.tool_name_to_tool_map: Dict[str, BaseTool] = { tool.name: tool for tool in self.tools } - self.stop = stop_words - self.llm.stop = list(set(self.llm.stop + self.stop)) + existing_stop = self.llm.stop or [] + self.llm.stop = list( + set( + existing_stop + self.stop + if isinstance(existing_stop, list) + else self.stop + ) + ) def invoke(self, inputs: Dict[str, str]) -> Dict[str, Any]: if "system" in self.prompt: