@@ -119,7 +119,6 @@ def __init__(
119119 self .tools_handler = tools_handler
120120 self .original_tools = original_tools or []
121121 self .step_callback = step_callback
122- self .use_stop_words = self .llm .supports_stop_words ()
123122 self .tools_description = tools_description
124123 self .function_calling_llm = function_calling_llm
125124 self .respect_context_window = respect_context_window
@@ -128,14 +127,25 @@ def __init__(
128127 self .messages : list [LLMMessage ] = []
129128 self .iterations = 0
130129 self .log_error_after = 3
131- existing_stop = getattr (self .llm , "stop" , [])
132- self .llm .stop = list (
133- set (
134- existing_stop + self .stop
135- if isinstance (existing_stop , list )
136- else self .stop
130+ if self .llm :
131+ # This may be mutating the shared llm object and needs further evaluation
132+ existing_stop = getattr (self .llm , "stop" , [])
133+ self .llm .stop = list (
134+ set (
135+ existing_stop + self .stop
136+ if isinstance (existing_stop , list )
137+ else self .stop
138+ )
137139 )
138- )
140+
141+ @property
142+ def use_stop_words (self ) -> bool :
143+ """Check to determine if stop words are being used.
144+
145+ Returns:
146+ bool: True if tool should be used or not.
147+ """
148+ return self .llm .supports_stop_words () if self .llm else False
139149
140150 def invoke (self , inputs : dict [str , Any ]) -> dict [str , Any ]:
141151 """Execute the agent with given inputs.
0 commit comments