Skip to content

Commit 9c09814

Browse files
committed
enhance: elevate stop_event to ChatAgent.__init__()
1 parent 8d8fab2 commit 9c09814

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

camel/agents/chat_agent.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import json
1717
import logging
1818
import textwrap
19+
import threading
1920
import uuid
2021
from collections import defaultdict
2122
from datetime import datetime
@@ -151,6 +152,9 @@ class ChatAgent(BaseAgent):
151152
model calling at each step. (default: :obj:`False`)
152153
agent_id (str, optional): The ID of the agent. If not provided, a
153154
random UUID will be generated. (default: :obj:`None`)
155+
stop_event (Optional[threading.Event], optional): Event to signal
156+
termination of the agent's operation. When set, the agent will
157+
terminate its execution. (default: :obj:`None`)
154158
"""
155159

156160
def __init__(
@@ -182,6 +186,7 @@ def __init__(
182186
scheduling_strategy: str = "round_robin",
183187
single_iteration: bool = False,
184188
agent_id: Optional[str] = None,
189+
stop_event: Optional[threading.Event] = None,
185190
) -> None:
186191
# Resolve model backends and set up model manager
187192
resolved_models = self._resolve_models(model)
@@ -252,6 +257,7 @@ def __init__(
252257
self.terminated = False
253258
self.response_terminators = response_terminators or []
254259
self.single_iteration = single_iteration
260+
self.stop_event = stop_event
255261

256262
def reset(self):
257263
r"""Resets the :obj:`ChatAgent` to its initial state."""

0 commit comments

Comments
 (0)