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.

fix: refactor use_stop_words to property, add check for stop words

Greyson LaLonde2e9eb8c32dc7
diff --git a/lib/crewai/src/crewai/agents/crew_agent_executor.py b/lib/crewai/src/crewai/agents/crew_agent_executor.py
index 07db1de0a..d2ae7fd00 100644
--- a/lib/crewai/src/crewai/agents/crew_agent_executor.py
+++ b/lib/crewai/src/crewai/agents/crew_agent_executor.py
@@ -119,7 +119,6 @@ class CrewAgentExecutor(CrewAgentExecutorMixin):
self.tools_handler = tools_handler
self.original_tools = original_tools or []
self.step_callback = step_callback
- self.use_stop_words = self.llm.supports_stop_words()
self.tools_description = tools_description
self.function_calling_llm = function_calling_llm
self.respect_context_window = respect_context_window
@@ -128,14 +127,25 @@ class CrewAgentExecutor(CrewAgentExecutorMixin):
self.messages: list[LLMMessage] = []
self.iterations = 0
self.log_error_after = 3
- existing_stop = getattr(self.llm, "stop", [])
- self.llm.stop = list(
- set(
- existing_stop + self.stop
- if isinstance(existing_stop, list)
- else self.stop
+ if self.llm:
+ # This may be mutating the shared llm object and needs further evaluation
+ existing_stop = getattr(self.llm, "stop", [])
+ self.llm.stop = list(
+ set(
+ existing_stop + self.stop
+ if isinstance(existing_stop, list)
+ else self.stop
+ )
)
- )
+
+ @property
+ def use_stop_words(self) -> bool:
+ """Check to determine if stop words are being used.
+
+ Returns:
+ bool: True if tool should be used or not.
+ """
+ return self.llm.supports_stop_words() if self.llm else False
def invoke(self, inputs: dict[str, Any]) -> dict[str, Any]:
"""Execute the agent with given inputs.