Skip to content

Commit ae419f2

Browse files
committed
enhance: elevate stop_event to OwlRolePlaying parent class (camel-ai/owl#450)
1 parent 1df5ebe commit ae419f2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

camel/societies/role_playing.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# limitations under the License.
1313
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
1414
import logging
15+
import threading
1516
from typing import Dict, List, Optional, Sequence, Tuple, Union
1617

1718
from camel.agents import (
@@ -77,6 +78,9 @@ class RolePlaying:
7778
task specify meta dict with. (default: :obj:`None`)
7879
output_language (str, optional): The language to be output by the
7980
agents. (default: :obj:`None`)
81+
stop_event (Optional[threading.Event], optional): Event to signal
82+
termination of the agent's operation. When set, the agent will
83+
terminate its execution. (default: :obj:`None`)
8084
"""
8185

8286
def __init__(
@@ -101,6 +105,7 @@ def __init__(
101105
extend_sys_msg_meta_dicts: Optional[List[Dict]] = None,
102106
extend_task_specify_meta_dict: Optional[Dict] = None,
103107
output_language: Optional[str] = None,
108+
stop_event: Optional[threading.Event] = None,
104109
) -> None:
105110
if model is not None:
106111
logger.warning(
@@ -156,6 +161,7 @@ def __init__(
156161
assistant_agent_kwargs=assistant_agent_kwargs,
157162
user_agent_kwargs=user_agent_kwargs,
158163
output_language=output_language,
164+
stop_event=stop_event,
159165
)
160166
self.critic: Optional[Union[CriticAgent, Human]] = None
161167
self.critic_sys_msg: Optional[BaseMessage] = None
@@ -316,6 +322,7 @@ def _init_agents(
316322
assistant_agent_kwargs: Optional[Dict] = None,
317323
user_agent_kwargs: Optional[Dict] = None,
318324
output_language: Optional[str] = None,
325+
stop_event: Optional[threading.Event] = None,
319326
) -> None:
320327
r"""Initialize assistant and user agents with their system messages.
321328
@@ -330,6 +337,9 @@ def _init_agents(
330337
pass to the user agent. (default: :obj:`None`)
331338
output_language (str, optional): The language to be output by the
332339
agents. (default: :obj:`None`)
340+
stop_event (Optional[threading.Event], optional): Event to signal
341+
termination of the agent's operation. When set, the agent will
342+
terminate its execution. (default: :obj:`None`)
333343
"""
334344
if self.model is not None:
335345
if assistant_agent_kwargs is None:
@@ -344,13 +354,15 @@ def _init_agents(
344354
self.assistant_agent = ChatAgent(
345355
init_assistant_sys_msg,
346356
output_language=output_language,
357+
stop_event=stop_event,
347358
**(assistant_agent_kwargs or {}),
348359
)
349360
self.assistant_sys_msg = self.assistant_agent.system_message
350361

351362
self.user_agent = ChatAgent(
352363
init_user_sys_msg,
353364
output_language=output_language,
365+
stop_event=stop_event,
354366
**(user_agent_kwargs or {}),
355367
)
356368
self.user_sys_msg = self.user_agent.system_message

0 commit comments

Comments
 (0)