Skip to content

Commit 60977eb

Browse files
committed
fix: stoppping of StateBaseAgent
1 parent eea1cda commit 60977eb

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/rai_core/rai/agents/langchain/agent.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ def _run_loop(self):
209209
self._run_agent()
210210

211211
def stop(self):
212+
"""Stop the agent's execution loop."""
212213
self._stop_event.set()
213214
self._interrupt_event.set()
214215
self._agent_ready_event.wait()
@@ -217,6 +218,7 @@ def stop(self):
217218
self._thread.join()
218219
self._thread = None
219220
self.logger.info("Agent stopped")
221+
self._stop_event.clear()
220222

221223
@staticmethod
222224
def _apply_reduction_behavior(

src/rai_core/rai/agents/langchain/state_based_agent.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,18 @@ def process_aggregator(
165165

166166
def stop(self):
167167
"""Stop the agent's execution loop."""
168-
self.logger.info("Stopping the agent. Please wait...")
169168
self._stop_event.set()
170-
if self.thread is not None:
171-
self.thread.join()
172-
self.thread = None
169+
self._interrupt_event.set()
170+
self._agent_ready_event.wait()
171+
if self._thread is not None:
172+
self.logger.info("Stopping the agent. Please wait...")
173+
self._thread.join()
174+
self._thread = None
173175
if self._aggregation_thread is not None:
174176
self._aggregation_thread.join()
175177
self._aggregation_thread = None
176-
self._stop_event.clear()
177178
for callback_id in self._registered_callbacks:
178179
self._connector.unregister_callback(callback_id)
180+
self._stop_event.clear()
179181
self._connector.shutdown()
180182
self.logger.info("Agent stopped")

0 commit comments

Comments
 (0)