|
16 | 16 | import json |
17 | 17 | import logging |
18 | 18 | import textwrap |
| 19 | +import threading |
19 | 20 | import uuid |
20 | 21 | from collections import defaultdict |
21 | 22 | from datetime import datetime |
@@ -151,6 +152,9 @@ class ChatAgent(BaseAgent): |
151 | 152 | model calling at each step. (default: :obj:`False`) |
152 | 153 | agent_id (str, optional): The ID of the agent. If not provided, a |
153 | 154 | 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`) |
154 | 158 | """ |
155 | 159 |
|
156 | 160 | def __init__( |
@@ -182,6 +186,7 @@ def __init__( |
182 | 186 | scheduling_strategy: str = "round_robin", |
183 | 187 | single_iteration: bool = False, |
184 | 188 | agent_id: Optional[str] = None, |
| 189 | + stop_event: Optional[threading.Event] = None, |
185 | 190 | ) -> None: |
186 | 191 | # Resolve model backends and set up model manager |
187 | 192 | resolved_models = self._resolve_models(model) |
@@ -252,6 +257,7 @@ def __init__( |
252 | 257 | self.terminated = False |
253 | 258 | self.response_terminators = response_terminators or [] |
254 | 259 | self.single_iteration = single_iteration |
| 260 | + self.stop_event = stop_event |
255 | 261 |
|
256 | 262 | def reset(self): |
257 | 263 | r"""Resets the :obj:`ChatAgent` to its initial state.""" |
|
0 commit comments