swarms 7.7.6__py3-none-any.whl → 7.7.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
swarms/agents/__init__.py CHANGED
@@ -25,7 +25,6 @@ from swarms.structs.stopping_conditions import (
25
25
  )
26
26
 
27
27
  __all__ = [
28
- # "ToolAgent",
29
28
  "check_done",
30
29
  "check_finished",
31
30
  "check_complete",
swarms/structs/agent.py CHANGED
@@ -562,7 +562,7 @@ class Agent:
562
562
  if self.react_on is True:
563
563
  self.system_prompt += REACT_SYS_PROMPT
564
564
 
565
- if len(self.max_loops) > 1:
565
+ if self.max_loops >= 2:
566
566
  self.system_prompt += generate_reasoning_prompt(
567
567
  self.max_loops
568
568
  )
@@ -1044,14 +1044,14 @@ class Agent:
1044
1044
  ):
1045
1045
  loop_count += 1
1046
1046
 
1047
- if len(self.max_loops) > 1:
1047
+ if self.max_loops >= 2:
1048
1048
  self.short_memory.add(
1049
1049
  role=self.agent_name,
1050
1050
  content=f"Current Internal Reasoning Loop: {loop_count}/{self.max_loops}",
1051
1051
  )
1052
1052
 
1053
1053
  # If it is the final loop, then add the final loop message
1054
- if loop_count == self.max_loops:
1054
+ if loop_count >= 2 and loop_count == self.max_loops:
1055
1055
  self.short_memory.add(
1056
1056
  role=self.agent_name,
1057
1057
  content=f"🎉 Final Internal Reasoning Loop: {loop_count}/{self.max_loops} Prepare your comprehensive response.",
@@ -4,8 +4,6 @@ from concurrent.futures import ThreadPoolExecutor
4
4
  from functools import lru_cache
5
5
  from typing import Any, Callable, Dict, List, Optional, Union
6
6
 
7
- from tqdm import tqdm
8
-
9
7
  from swarms.structs.agent import Agent
10
8
  from swarms.structs.base_swarm import BaseSwarm
11
9
  from swarms.structs.conversation import Conversation
@@ -22,9 +20,7 @@ class ConcurrentWorkflow(BaseSwarm):
22
20
  """
23
21
  Represents a concurrent workflow that executes multiple agents concurrently in a production-grade manner.
24
22
  Features include:
25
- - Interactive model support
26
23
  - Caching for repeated prompts
27
- - Optional progress tracking
28
24
  - Enhanced error handling and retries
29
25
  - Input validation
30
26
 
@@ -39,11 +35,9 @@ class ConcurrentWorkflow(BaseSwarm):
39
35
  return_str_on (bool): Flag indicating whether to return the output as a string. Defaults to False.
40
36
  auto_generate_prompts (bool): Flag indicating whether to auto-generate prompts for agents. Defaults to False.
41
37
  return_entire_history (bool): Flag indicating whether to return the entire conversation history. Defaults to False.
42
- interactive (bool): Flag indicating whether to enable interactive mode. Defaults to False.
43
38
  cache_size (int): The size of the cache. Defaults to 100.
44
39
  max_retries (int): The maximum number of retry attempts. Defaults to 3.
45
40
  retry_delay (float): The delay between retry attempts in seconds. Defaults to 1.0.
46
- show_progress (bool): Flag indicating whether to show progress. Defaults to False.
47
41
 
48
42
  Raises:
49
43
  ValueError: If the list of agents is empty or if the description is empty.
@@ -59,13 +53,10 @@ class ConcurrentWorkflow(BaseSwarm):
59
53
  return_str_on (bool): Flag indicating whether to return the output as a string.
60
54
  auto_generate_prompts (bool): Flag indicating whether to auto-generate prompts for agents.
61
55
  return_entire_history (bool): Flag indicating whether to return the entire conversation history.
62
- interactive (bool): Flag indicating whether to enable interactive mode.
63
56
  cache_size (int): The size of the cache.
64
57
  max_retries (int): The maximum number of retry attempts.
65
58
  retry_delay (float): The delay between retry attempts in seconds.
66
- show_progress (bool): Flag indicating whether to show progress.
67
59
  _cache (dict): The cache for storing agent outputs.
68
- _progress_bar (tqdm): The progress bar for tracking execution.
69
60
  """
70
61
 
71
62
  def __init__(
@@ -80,11 +71,9 @@ class ConcurrentWorkflow(BaseSwarm):
80
71
  return_str_on: bool = False,
81
72
  auto_generate_prompts: bool = False,
82
73
  return_entire_history: bool = False,
83
- interactive: bool = False,
84
74
  cache_size: int = 100,
85
75
  max_retries: int = 3,
86
76
  retry_delay: float = 1.0,
87
- show_progress: bool = False,
88
77
  *args,
89
78
  **kwargs,
90
79
  ):
@@ -107,21 +96,14 @@ class ConcurrentWorkflow(BaseSwarm):
107
96
  self.output_type = output_type
108
97
  self.return_entire_history = return_entire_history
109
98
  self.tasks = [] # Initialize tasks list
110
- self.interactive = interactive
111
99
  self.cache_size = cache_size
112
100
  self.max_retries = max_retries
113
101
  self.retry_delay = retry_delay
114
- self.show_progress = show_progress
115
102
  self._cache = {}
116
- self._progress_bar = None
117
103
 
118
104
  self.reliability_check()
119
105
  self.conversation = Conversation()
120
106
 
121
- def disable_agent_prints(self):
122
- for agent in self.agents:
123
- agent.no_print = False
124
-
125
107
  def reliability_check(self):
126
108
  try:
127
109
  formatter.print_panel(
@@ -186,44 +168,6 @@ class ConcurrentWorkflow(BaseSwarm):
186
168
  """Cached version of agent execution to avoid redundant computations"""
187
169
  return self.agents[agent_id].run(task=task)
188
170
 
189
- def enable_progress_bar(self):
190
- """Enable progress bar display"""
191
- self.show_progress = True
192
-
193
- def disable_progress_bar(self):
194
- """Disable progress bar display"""
195
- if self._progress_bar:
196
- self._progress_bar.close()
197
- self._progress_bar = None
198
- self.show_progress = False
199
-
200
- def _create_progress_bar(self, total: int):
201
- """Create a progress bar for tracking execution"""
202
- if self.show_progress:
203
- try:
204
- self._progress_bar = tqdm(
205
- total=total,
206
- desc="Processing tasks",
207
- unit="task",
208
- disable=not self.show_progress,
209
- ncols=100,
210
- bar_format="{l_bar}{bar}| {n_fmt}/{total_fmt} [{elapsed}<{remaining}]",
211
- )
212
- except Exception as e:
213
- logger.warning(f"Failed to create progress bar: {e}")
214
- self.show_progress = False
215
- self._progress_bar = None
216
- return self._progress_bar
217
-
218
- def _update_progress(self, increment: int = 1):
219
- """Update the progress bar"""
220
- if self._progress_bar and self.show_progress:
221
- try:
222
- self._progress_bar.update(increment)
223
- except Exception as e:
224
- logger.warning(f"Failed to update progress bar: {e}")
225
- self.disable_progress_bar()
226
-
227
171
  def _validate_input(self, task: str) -> bool:
228
172
  """Validate input task"""
229
173
  if not isinstance(task, str):
@@ -232,38 +176,6 @@ class ConcurrentWorkflow(BaseSwarm):
232
176
  raise ValueError("Task cannot be empty")
233
177
  return True
234
178
 
235
- def _handle_interactive(self, task: str) -> str:
236
- """Handle interactive mode for task input"""
237
- if self.interactive:
238
- from swarms.utils.formatter import formatter
239
-
240
- # Display current task in a panel
241
- formatter.print_panel(
242
- content=f"Current task: {task}",
243
- title="Task Status",
244
- style="bold blue",
245
- )
246
-
247
- # Get user input with formatted prompt
248
- formatter.print_panel(
249
- content="Do you want to modify this task? (y/n/q to quit): ",
250
- title="User Input",
251
- style="bold green",
252
- )
253
- response = input().lower()
254
-
255
- if response == "q":
256
- return None
257
- elif response == "y":
258
- formatter.print_panel(
259
- content="Enter new task: ",
260
- title="New Task Input",
261
- style="bold yellow",
262
- )
263
- new_task = input()
264
- return new_task
265
- return task
266
-
267
179
  def _run_with_retry(
268
180
  self, agent: Agent, task: str, img: str = None
269
181
  ) -> Any:
@@ -286,68 +198,69 @@ class ConcurrentWorkflow(BaseSwarm):
286
198
  self.retry_delay * (attempt + 1)
287
199
  ) # Exponential backoff
288
200
 
201
+ def _process_agent(
202
+ self, agent: Agent, task: str, img: str = None
203
+ ) -> Any:
204
+ """
205
+ Process a single agent with caching and error handling.
206
+
207
+ Args:
208
+ agent: The agent to process
209
+ task: Task to execute
210
+ img: Optional image input
211
+
212
+ Returns:
213
+ The agent's output
214
+ """
215
+ try:
216
+ # Fast path - check cache first
217
+ cache_key = f"{task}_{agent.agent_name}"
218
+ if cache_key in self._cache:
219
+ output = self._cache[cache_key]
220
+ else:
221
+ # Slow path - run agent and update cache
222
+ output = self._run_with_retry(agent, task, img)
223
+
224
+ if len(self._cache) >= self.cache_size:
225
+ self._cache.pop(next(iter(self._cache)))
226
+
227
+ self._cache[cache_key] = output
228
+
229
+ return output
230
+ except Exception as e:
231
+ logger.error(
232
+ f"Error running agent {agent.agent_name}: {e}"
233
+ )
234
+ raise
235
+
289
236
  def _run(
290
237
  self, task: str, img: str = None, *args, **kwargs
291
238
  ) -> Union[Dict[str, Any], str]:
292
239
  """
293
- Enhanced run method with caching, progress tracking, and better error handling
240
+ Enhanced run method with parallel execution.
294
241
  """
295
-
296
- # Validate and potentially modify task
242
+ # Fast validation
297
243
  self._validate_input(task)
298
- task = self._handle_interactive(task)
299
-
300
- # Add task to conversation
301
244
  self.conversation.add("User", task)
302
245
 
303
- # Create progress bar if enabled
304
- if self.show_progress:
305
- self._create_progress_bar(len(self.agents))
306
-
307
- def run_agent(
308
- agent: Agent, task: str, img: str = None
309
- ) -> Any:
310
- try:
311
- # Check cache first
312
- cache_key = f"{task}_{agent.agent_name}"
313
- if cache_key in self._cache:
314
- output = self._cache[cache_key]
315
- else:
316
- output = self._run_with_retry(agent, task, img)
317
- # Update cache
318
- if len(self._cache) >= self.cache_size:
319
- self._cache.pop(next(iter(self._cache)))
320
- self._cache[cache_key] = output
321
-
322
- self._update_progress()
323
- return output
324
- except Exception as e:
325
- logger.error(
326
- f"Error running agent {agent.agent_name}: {e}"
327
- )
328
- self._update_progress()
329
- raise
330
-
331
246
  try:
247
+ # Parallel execution with optimized thread pool
332
248
  with ThreadPoolExecutor(
333
249
  max_workers=self.max_workers
334
250
  ) as executor:
335
- list(
336
- executor.map(
337
- lambda agent: run_agent(agent, task),
338
- self.agents,
251
+ futures = [
252
+ executor.submit(
253
+ self._process_agent, agent, task, img
339
254
  )
340
- )
341
- finally:
342
- if self._progress_bar and self.show_progress:
343
- try:
344
- self._progress_bar.close()
345
- except Exception as e:
346
- logger.warning(
347
- f"Failed to close progress bar: {e}"
348
- )
349
- finally:
350
- self._progress_bar = None
255
+ for agent in self.agents
256
+ ]
257
+ # Wait for all futures to complete
258
+ for future in futures:
259
+ future.result()
260
+
261
+ except Exception as e:
262
+ logger.error(f"An error occurred during execution: {e}")
263
+ raise e
351
264
 
352
265
  return history_output_formatter(
353
266
  self.conversation,
@@ -362,20 +275,11 @@ class ConcurrentWorkflow(BaseSwarm):
362
275
  **kwargs,
363
276
  ) -> Any:
364
277
  """
365
- Executes the agent's run method on a specified device with optional interactive mode.
366
-
367
- This method attempts to execute the agent's run method on a specified device, either CPU or GPU.
368
- It supports both standard execution and interactive mode where users can modify tasks and continue
369
- the workflow interactively.
278
+ Executes the agent's run method with parallel execution.
370
279
 
371
280
  Args:
372
281
  task (Optional[str], optional): The task to be executed. Defaults to None.
373
282
  img (Optional[str], optional): The image to be processed. Defaults to None.
374
- is_last (bool, optional): Indicates if this is the last task. Defaults to False.
375
- device (str, optional): The device to use for execution. Defaults to "cpu".
376
- device_id (int, optional): The ID of the GPU to use if device is set to "gpu". Defaults to 0.
377
- all_cores (bool, optional): If True, uses all available CPU cores. Defaults to True.
378
- all_gpus (bool, optional): If True, uses all available GPUS. Defaults to True.
379
283
  *args: Additional positional arguments to be passed to the execution method.
380
284
  **kwargs: Additional keyword arguments to be passed to the execution method.
381
285
 
@@ -383,117 +287,27 @@ class ConcurrentWorkflow(BaseSwarm):
383
287
  Any: The result of the execution.
384
288
 
385
289
  Raises:
386
- ValueError: If an invalid device is specified.
290
+ ValueError: If task validation fails.
387
291
  Exception: If any other error occurs during execution.
388
292
  """
389
293
  if task is not None:
390
294
  self.tasks.append(task)
391
295
 
392
296
  try:
393
- # Handle interactive mode
394
- if self.interactive:
395
- current_task = task
396
- loop_count = 0
397
-
398
- while loop_count < self.max_loops:
399
- if (
400
- self.max_loops is not None
401
- and loop_count >= self.max_loops
402
- ):
403
- formatter.print_panel(
404
- content=f"Maximum number of loops ({self.max_loops}) reached.",
405
- title="Session Complete",
406
- style="bold red",
407
- )
408
- break
409
-
410
- if current_task is None:
411
- formatter.print_panel(
412
- content="Enter your task (or 'q' to quit): ",
413
- title="Task Input",
414
- style="bold blue",
415
- )
416
- current_task = input()
417
- if current_task.lower() == "q":
418
- break
419
-
420
- # Run the workflow with the current task
421
- try:
422
- outputs = self._run(
423
- current_task, img, *args, **kwargs
424
- )
425
- formatter.print_panel(
426
- content=str(outputs),
427
- title="Workflow Result",
428
- style="bold green",
429
- )
430
- except Exception as e:
431
- formatter.print_panel(
432
- content=f"Error: {str(e)}",
433
- title="Error",
434
- style="bold red",
435
- )
436
-
437
- # Ask if user wants to continue
438
- formatter.print_panel(
439
- content="Do you want to continue with a new task? (y/n): ",
440
- title="Continue Session",
441
- style="bold yellow",
442
- )
443
- if input().lower() != "y":
444
- break
445
-
446
- current_task = None
447
- loop_count += 1
448
-
449
- formatter.print_panel(
450
- content="Interactive session ended.",
451
- title="Session Complete",
452
- style="bold blue",
453
- )
454
- return outputs
455
- else:
456
- # Standard non-interactive execution
457
- outputs = self._run(task, img, *args, **kwargs)
458
- return outputs
459
-
460
- except ValueError as e:
461
- logger.error(f"Invalid device specified: {e}")
462
- raise e
297
+ outputs = self._run(task, img, *args, **kwargs)
298
+ return outputs
463
299
  except Exception as e:
464
300
  logger.error(f"An error occurred during execution: {e}")
465
301
  raise e
466
302
 
467
303
  def run_batched(self, tasks: List[str]) -> Any:
468
304
  """
469
- Enhanced batched execution with progress tracking
305
+ Enhanced batched execution
470
306
  """
471
307
  if not tasks:
472
308
  raise ValueError("Tasks list cannot be empty")
473
309
 
474
- results = []
475
-
476
- # Create progress bar if enabled
477
- if self.show_progress:
478
- self._create_progress_bar(len(tasks))
479
-
480
- try:
481
- for task in tasks:
482
- result = self.run(task)
483
- results.append(result)
484
- self._update_progress()
485
- finally:
486
- if self._progress_bar and self.show_progress:
487
- try:
488
- self._progress_bar.close()
489
- except Exception as e:
490
- logger.warning(
491
- f"Failed to close progress bar: {e}"
492
- )
493
- finally:
494
- self._progress_bar = None
495
-
496
- return results
310
+ return [self.run(task) for task in tasks]
497
311
 
498
312
  def clear_cache(self):
499
313
  """Clear the task cache"""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: swarms
3
- Version: 7.7.6
3
+ Version: 7.7.8
4
4
  Summary: Swarms - TGSC
5
5
  Home-page: https://github.com/kyegomez/swarms
6
6
  License: MIT
@@ -1,5 +1,5 @@
1
1
  swarms/__init__.py,sha256=YxGdUrWHekSiNneyQUM7Yrdf6pCIy2-xgIzhocZY0Ek,561
2
- swarms/agents/__init__.py,sha256=ebUrX9rMccQokq5XthgnzGDMISn8EyQyOIOwVAlLs1E,1190
2
+ swarms/agents/__init__.py,sha256=hEp16SuPhlcLX84HAlaK_9RNf6JB0JQ27YTrTnvak04,1171
3
3
  swarms/agents/agent_judge.py,sha256=xT242CX5mV64cq2B-3RGkuEHiV5aD04P_Zq8_s64iMQ,3967
4
4
  swarms/agents/agent_print.py,sha256=SXqWA2ZzXwRFdv8hkuYwOPMTasvaGTG6U29413qRCAA,918
5
5
  swarms/agents/ape_agent.py,sha256=1kz_65LJgjLlY1yv2WLBeVMs7sP9BgEVWk0w1f67YLc,1563
@@ -87,7 +87,7 @@ swarms/schemas/__init__.py,sha256=AZ7BZE3bLabA5_m83jbELB6SaOMHx1MhMy9EeUODBqs,10
87
87
  swarms/schemas/agent_step_schemas.py,sha256=a14gb58vR0xOwB_fwSJQbN6yb9HddEaT30E6hUrzEQA,2573
88
88
  swarms/schemas/base_schemas.py,sha256=UvBLVWg2qRen4tK5GJz50v42SiX95EQ5qK7hfyAHTEU,3267
89
89
  swarms/structs/__init__.py,sha256=jfvyqtA5WMpjYgvmngBqijwOhjLhRkjWAucPGe91THU,4051
90
- swarms/structs/agent.py,sha256=aWl6te6MaoJsucrFlqOs9ihGnNS4tHpHhCdMoBpzFxg,98387
90
+ swarms/structs/agent.py,sha256=rOwES2GjAtP_ItT0yzTWEOJxngBK2URV4atlhBC1My4,98399
91
91
  swarms/structs/agent_builder.py,sha256=tYNpfO4_8cgfMHfgA5DAOWffHnt70p6CLt59esqfVCY,12133
92
92
  swarms/structs/agent_registry.py,sha256=il507cO1NF-d4ChyANVLuWrN8bXsEAi8_7bLJ_sTU6A,12112
93
93
  swarms/structs/agent_roles.py,sha256=8XEw6RjOOZelaZaWt4gXaYQm5WMLEhSO7W6Z8sQjmFg,582
@@ -98,7 +98,7 @@ swarms/structs/base_structure.py,sha256=GDu4QJQQmhU7IyuFJHIh9UVThACCva-L7uoMbVD9
98
98
  swarms/structs/base_swarm.py,sha256=LSGJDPJdyUCcK6698mNtjxoC1OU3s_J2NxC2k_ccGUs,23779
99
99
  swarms/structs/base_workflow.py,sha256=DTfFwX3AdFYxACDYwUDqhsbcDZnITlg5TeEYyxmJBCc,11414
100
100
  swarms/structs/concat.py,sha256=utezSxNyh1mIwXgdf8-dJ803NDPyEy79WE8zJHuooGk,732
101
- swarms/structs/concurrent_workflow.py,sha256=IANeOnzHcHZfrmNG6HA1RXaZLRQv6q89DiOxUg2q0Hw,20490
101
+ swarms/structs/concurrent_workflow.py,sha256=OqXI-X-9a0hG2a7aLzobwd7CVF2ez0rgLj3ZHqri5bg,12952
102
102
  swarms/structs/conversation.py,sha256=_b9YddnIi8uhTjDQMGQSW-oSUfMG5tcwIm0Yi6yMF_o,21899
103
103
  swarms/structs/csv_to_agent.py,sha256=ug9JqQFPguXeU9JQpSUXuVtOpHYdJhlpKJUJBovo694,9443
104
104
  swarms/structs/de_hallucination_swarm.py,sha256=9cC0rSSXGwYu6SRDwpeMbCcQ40C1WI1RE9SNapKRLOQ,10309
@@ -181,8 +181,8 @@ swarms/utils/try_except_wrapper.py,sha256=appEGu9Afy3TmdkNNXUgQ9yU9lj2j0uNkIoW0J
181
181
  swarms/utils/visualizer.py,sha256=0ylohEk62MAS6iPRaDOV03m9qo2k5J56tWlKJk_46p4,16927
182
182
  swarms/utils/vllm_wrapper.py,sha256=OIGnU9Vf81vE_hul1FK-xEhChFK8fxqZX6-fhQeW22c,4987
183
183
  swarms/utils/wrapper_clusterop.py,sha256=PMSCVM7ZT1vgj1D_MYAe835RR3SMLYxA-si2JS02yNQ,4220
184
- swarms-7.7.6.dist-info/LICENSE,sha256=jwRtEmTWjLrEsvFB6QFdYs2cEeZPRMdj-UMOFkPF8_0,11363
185
- swarms-7.7.6.dist-info/METADATA,sha256=Bb_y8yPpStFUTExRM33G5WX-HiKTM2pT4Axv7YmTb1I,94905
186
- swarms-7.7.6.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
187
- swarms-7.7.6.dist-info/entry_points.txt,sha256=2K0rTtfO1X1WaO-waJlXIKw5Voa_EpAL_yU0HXE2Jgc,47
188
- swarms-7.7.6.dist-info/RECORD,,
184
+ swarms-7.7.8.dist-info/LICENSE,sha256=jwRtEmTWjLrEsvFB6QFdYs2cEeZPRMdj-UMOFkPF8_0,11363
185
+ swarms-7.7.8.dist-info/METADATA,sha256=gc02YQD9nv-etWEFaZ6aac_8gjtzpoE7x0Kq7xvBQO4,94905
186
+ swarms-7.7.8.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
187
+ swarms-7.7.8.dist-info/entry_points.txt,sha256=2K0rTtfO1X1WaO-waJlXIKw5Voa_EpAL_yU0HXE2Jgc,47
188
+ swarms-7.7.8.dist-info/RECORD,,
File without changes