swarms 7.8.3__py3-none-any.whl → 7.8.7__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/ape_agent.py +5 -22
- swarms/agents/consistency_agent.py +1 -1
- swarms/agents/i_agent.py +1 -1
- swarms/agents/reasoning_agents.py +99 -3
- swarms/agents/reasoning_duo.py +1 -1
- swarms/cli/main.py +1 -1
- swarms/communication/__init__.py +1 -0
- swarms/communication/duckdb_wrap.py +32 -2
- swarms/communication/pulsar_struct.py +45 -19
- swarms/communication/redis_wrap.py +56 -11
- swarms/communication/supabase_wrap.py +1659 -0
- swarms/prompts/agent_conversation_aggregator.py +38 -0
- swarms/prompts/prompt.py +0 -3
- swarms/schemas/agent_completion_response.py +71 -0
- swarms/schemas/agent_rag_schema.py +7 -0
- swarms/schemas/conversation_schema.py +9 -0
- swarms/schemas/llm_agent_schema.py +99 -81
- swarms/schemas/swarms_api_schemas.py +164 -0
- swarms/structs/__init__.py +15 -9
- swarms/structs/agent.py +219 -199
- swarms/structs/agent_rag_handler.py +685 -0
- swarms/structs/base_swarm.py +2 -1
- swarms/structs/conversation.py +832 -264
- swarms/structs/csv_to_agent.py +153 -100
- swarms/structs/deep_research_swarm.py +197 -193
- swarms/structs/dynamic_conversational_swarm.py +18 -7
- swarms/structs/hiearchical_swarm.py +1 -1
- swarms/structs/hybrid_hiearchical_peer_swarm.py +2 -18
- swarms/structs/image_batch_processor.py +261 -0
- swarms/structs/interactive_groupchat.py +356 -0
- swarms/structs/ma_blocks.py +159 -0
- swarms/structs/majority_voting.py +1 -1
- swarms/structs/mixture_of_agents.py +1 -1
- swarms/structs/multi_agent_exec.py +25 -26
- swarms/structs/multi_agent_router.py +3 -2
- swarms/structs/rearrange.py +3 -3
- swarms/structs/sequential_workflow.py +3 -3
- swarms/structs/swarm_matcher.py +499 -408
- swarms/structs/swarm_router.py +15 -97
- swarms/structs/swarming_architectures.py +1 -1
- swarms/tools/mcp_client_call.py +3 -0
- swarms/utils/__init__.py +10 -2
- swarms/utils/check_all_model_max_tokens.py +43 -0
- swarms/utils/generate_keys.py +0 -27
- swarms/utils/history_output_formatter.py +5 -20
- swarms/utils/litellm_wrapper.py +208 -60
- swarms/utils/output_types.py +24 -0
- swarms/utils/vllm_wrapper.py +14 -13
- swarms/utils/xml_utils.py +37 -2
- {swarms-7.8.3.dist-info → swarms-7.8.7.dist-info}/METADATA +31 -55
- {swarms-7.8.3.dist-info → swarms-7.8.7.dist-info}/RECORD +55 -48
- swarms/structs/multi_agent_collab.py +0 -242
- swarms/structs/output_types.py +0 -6
- swarms/utils/markdown_message.py +0 -21
- swarms/utils/visualizer.py +0 -510
- swarms/utils/wrapper_clusterop.py +0 -127
- /swarms/{tools → schemas}/tool_schema_base_model.py +0 -0
- {swarms-7.8.3.dist-info → swarms-7.8.7.dist-info}/LICENSE +0 -0
- {swarms-7.8.3.dist-info → swarms-7.8.7.dist-info}/WHEEL +0 -0
- {swarms-7.8.3.dist-info → swarms-7.8.7.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,159 @@
|
|
1
|
+
from typing import Union
|
2
|
+
from swarms.structs.agent import Agent
|
3
|
+
from typing import List, Callable
|
4
|
+
from swarms.structs.conversation import Conversation
|
5
|
+
from swarms.structs.multi_agent_exec import run_agents_concurrently
|
6
|
+
from swarms.utils.history_output_formatter import (
|
7
|
+
history_output_formatter,
|
8
|
+
HistoryOutputType,
|
9
|
+
)
|
10
|
+
|
11
|
+
from swarms.prompts.agent_conversation_aggregator import (
|
12
|
+
AGGREGATOR_SYSTEM_PROMPT,
|
13
|
+
)
|
14
|
+
|
15
|
+
|
16
|
+
def aggregator_agent_task_prompt(
|
17
|
+
task: str, workers: List[Agent], conversation: Conversation
|
18
|
+
):
|
19
|
+
return f"""
|
20
|
+
Please analyze and summarize the following multi-agent conversation, following your guidelines for comprehensive synthesis:
|
21
|
+
|
22
|
+
Conversation Context:
|
23
|
+
Original Task: {task}
|
24
|
+
Number of Participating Agents: {len(workers)}
|
25
|
+
|
26
|
+
Conversation Content:
|
27
|
+
{conversation.get_str()}
|
28
|
+
|
29
|
+
Please provide a 3,000 word comprehensive summary report of the conversation.
|
30
|
+
"""
|
31
|
+
|
32
|
+
|
33
|
+
def aggregate(
|
34
|
+
workers: List[Callable],
|
35
|
+
task: str = None,
|
36
|
+
type: HistoryOutputType = "all",
|
37
|
+
aggregator_model_name: str = "anthropic/claude-3-sonnet-20240229",
|
38
|
+
):
|
39
|
+
"""
|
40
|
+
Aggregate a list of tasks into a single task.
|
41
|
+
"""
|
42
|
+
|
43
|
+
if task is None:
|
44
|
+
raise ValueError("Task is required in the aggregator block")
|
45
|
+
|
46
|
+
if workers is None:
|
47
|
+
raise ValueError(
|
48
|
+
"Workers is required in the aggregator block"
|
49
|
+
)
|
50
|
+
|
51
|
+
if not isinstance(workers, list):
|
52
|
+
raise ValueError("Workers must be a list of Callable")
|
53
|
+
|
54
|
+
if not all(isinstance(worker, Callable) for worker in workers):
|
55
|
+
raise ValueError("Workers must be a list of Callable")
|
56
|
+
|
57
|
+
conversation = Conversation()
|
58
|
+
|
59
|
+
aggregator_agent = Agent(
|
60
|
+
agent_name="Aggregator",
|
61
|
+
agent_description="Expert agent specializing in analyzing and synthesizing multi-agent conversations",
|
62
|
+
system_prompt=AGGREGATOR_SYSTEM_PROMPT,
|
63
|
+
max_loops=1,
|
64
|
+
model_name=aggregator_model_name,
|
65
|
+
output_type="final",
|
66
|
+
max_tokens=4000,
|
67
|
+
)
|
68
|
+
|
69
|
+
results = run_agents_concurrently(agents=workers, task=task)
|
70
|
+
|
71
|
+
# Zip the results with the agents
|
72
|
+
for result, agent in zip(results, workers):
|
73
|
+
conversation.add(content=result, role=agent.agent_name)
|
74
|
+
|
75
|
+
final_result = aggregator_agent.run(
|
76
|
+
task=aggregator_agent_task_prompt(task, workers, conversation)
|
77
|
+
)
|
78
|
+
|
79
|
+
conversation.add(
|
80
|
+
content=final_result, role=aggregator_agent.agent_name
|
81
|
+
)
|
82
|
+
|
83
|
+
return history_output_formatter(
|
84
|
+
conversation=conversation, type=type
|
85
|
+
)
|
86
|
+
|
87
|
+
|
88
|
+
def run_agent(
|
89
|
+
agent: Agent,
|
90
|
+
task: str,
|
91
|
+
type: HistoryOutputType = "all",
|
92
|
+
*args,
|
93
|
+
**kwargs,
|
94
|
+
):
|
95
|
+
"""
|
96
|
+
Run an agent on a task.
|
97
|
+
|
98
|
+
Args:
|
99
|
+
agent (Agent): The agent to run
|
100
|
+
task (str): The task to run the agent on
|
101
|
+
type (HistoryOutputType, optional): The type of history output. Defaults to "all".
|
102
|
+
*args: Variable length argument list
|
103
|
+
**kwargs: Arbitrary keyword arguments
|
104
|
+
|
105
|
+
Returns:
|
106
|
+
Any: The result of running the agent
|
107
|
+
|
108
|
+
Raises:
|
109
|
+
ValueError: If agent or task is None
|
110
|
+
TypeError: If agent is not an instance of Agent
|
111
|
+
"""
|
112
|
+
if agent is None:
|
113
|
+
raise ValueError("Agent cannot be None")
|
114
|
+
|
115
|
+
if task is None:
|
116
|
+
raise ValueError("Task cannot be None")
|
117
|
+
|
118
|
+
if not isinstance(agent, Agent):
|
119
|
+
raise TypeError("Agent must be an instance of Agent")
|
120
|
+
|
121
|
+
try:
|
122
|
+
return agent.run(task=task, *args, **kwargs)
|
123
|
+
except Exception as e:
|
124
|
+
raise RuntimeError(f"Error running agent: {str(e)}")
|
125
|
+
|
126
|
+
|
127
|
+
def find_agent_by_name(
|
128
|
+
agents: List[Union[Agent, Callable]], agent_name: str
|
129
|
+
) -> Agent:
|
130
|
+
"""
|
131
|
+
Find an agent by its name in a list of agents.
|
132
|
+
|
133
|
+
Args:
|
134
|
+
agents (List[Union[Agent, Callable]]): List of agents to search through
|
135
|
+
agent_name (str): Name of the agent to find
|
136
|
+
|
137
|
+
Returns:
|
138
|
+
Agent: The found agent
|
139
|
+
|
140
|
+
Raises:
|
141
|
+
ValueError: If agents list is empty or agent not found
|
142
|
+
TypeError: If agent_name is not a string
|
143
|
+
"""
|
144
|
+
if not agents:
|
145
|
+
raise ValueError("Agents list cannot be empty")
|
146
|
+
|
147
|
+
if not isinstance(agent_name, str):
|
148
|
+
raise TypeError("Agent name must be a string")
|
149
|
+
|
150
|
+
if not agent_name.strip():
|
151
|
+
raise ValueError("Agent name cannot be empty or whitespace")
|
152
|
+
|
153
|
+
try:
|
154
|
+
for agent in agents:
|
155
|
+
if hasattr(agent, "name") and agent.name == agent_name:
|
156
|
+
return agent
|
157
|
+
raise ValueError(f"Agent with name '{agent_name}' not found")
|
158
|
+
except Exception as e:
|
159
|
+
raise RuntimeError(f"Error finding agent: {str(e)}")
|
@@ -9,7 +9,7 @@ from typing import Any, Callable, List, Optional
|
|
9
9
|
from swarms.structs.agent import Agent
|
10
10
|
from swarms.structs.conversation import Conversation
|
11
11
|
from swarms.structs.multi_agent_exec import run_agents_concurrently
|
12
|
-
from swarms.
|
12
|
+
from swarms.utils.output_types import OutputType
|
13
13
|
from swarms.utils.formatter import formatter
|
14
14
|
from swarms.utils.loguru_logger import initialize_logger
|
15
15
|
|
@@ -7,7 +7,7 @@ from swarms.structs.agent import Agent
|
|
7
7
|
from swarms.prompts.ag_prompt import aggregator_system_prompt_main
|
8
8
|
from swarms.utils.loguru_logger import initialize_logger
|
9
9
|
import concurrent.futures
|
10
|
-
from swarms.
|
10
|
+
from swarms.utils.output_types import OutputType
|
11
11
|
from swarms.structs.conversation import Conversation
|
12
12
|
from swarms.utils.history_output_formatter import (
|
13
13
|
history_output_formatter,
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import concurrent.futures
|
1
2
|
import asyncio
|
2
3
|
import os
|
3
4
|
import threading
|
@@ -5,7 +6,7 @@ from concurrent.futures import (
|
|
5
6
|
ThreadPoolExecutor,
|
6
7
|
)
|
7
8
|
from dataclasses import dataclass
|
8
|
-
from typing import Any, Callable, List, Union
|
9
|
+
from typing import Any, Callable, List, Optional, Union
|
9
10
|
|
10
11
|
import psutil
|
11
12
|
|
@@ -68,44 +69,42 @@ async def run_agents_concurrently_async(
|
|
68
69
|
def run_agents_concurrently(
|
69
70
|
agents: List[AgentType],
|
70
71
|
task: str,
|
71
|
-
|
72
|
-
max_workers: int = None,
|
72
|
+
max_workers: Optional[int] = None,
|
73
73
|
) -> List[Any]:
|
74
74
|
"""
|
75
|
-
Optimized concurrent agent runner using
|
75
|
+
Optimized concurrent agent runner using ThreadPoolExecutor.
|
76
76
|
|
77
77
|
Args:
|
78
78
|
agents: List of Agent instances to run concurrently
|
79
79
|
task: Task string to execute
|
80
|
-
|
81
|
-
max_workers: Maximum number of threads in the executor (defaults to CPU count * 2)
|
80
|
+
max_workers: Maximum number of threads in the executor (defaults to 95% of CPU cores)
|
82
81
|
|
83
82
|
Returns:
|
84
83
|
List of outputs from each agent
|
85
84
|
"""
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
85
|
+
if max_workers is None:
|
86
|
+
# 95% of the available CPU cores
|
87
|
+
num_cores = os.cpu_count()
|
88
|
+
max_workers = int(num_cores * 0.95) if num_cores else 1
|
90
89
|
|
91
90
|
results = []
|
92
91
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
92
|
+
with concurrent.futures.ThreadPoolExecutor(
|
93
|
+
max_workers=max_workers
|
94
|
+
) as executor:
|
95
|
+
# Submit all tasks and get futures
|
96
|
+
futures = [
|
97
|
+
executor.submit(agent.run, task) for agent in agents
|
98
|
+
]
|
99
|
+
|
100
|
+
# Wait for all futures to complete and get results
|
101
|
+
for future in concurrent.futures.as_completed(futures):
|
102
|
+
try:
|
103
|
+
result = future.result()
|
104
|
+
results.append(result)
|
105
|
+
except Exception as e:
|
106
|
+
# Append the error if an agent fails
|
107
|
+
results.append(e)
|
109
108
|
|
110
109
|
return results
|
111
110
|
|
@@ -16,12 +16,13 @@ from pydantic import BaseModel, Field
|
|
16
16
|
from swarms.utils.function_caller_model import OpenAIFunctionCaller
|
17
17
|
from swarms.structs.agent import Agent
|
18
18
|
from swarms.structs.conversation import Conversation
|
19
|
-
from swarms.
|
19
|
+
from swarms.utils.output_types import OutputType
|
20
20
|
from swarms.utils.any_to_str import any_to_str
|
21
21
|
from swarms.utils.history_output_formatter import (
|
22
22
|
history_output_formatter,
|
23
23
|
)
|
24
24
|
from swarms.utils.formatter import formatter
|
25
|
+
from typing import Callable, Union
|
25
26
|
|
26
27
|
|
27
28
|
class AgentResponse(BaseModel):
|
@@ -59,7 +60,7 @@ class MultiAgentRouter:
|
|
59
60
|
self,
|
60
61
|
name: str = "swarm-router",
|
61
62
|
description: str = "Routes tasks to specialized agents based on their capabilities",
|
62
|
-
agents: List[Agent] = [],
|
63
|
+
agents: List[Union[Agent, Callable]] = [],
|
63
64
|
model: str = "gpt-4o-mini",
|
64
65
|
temperature: float = 0.1,
|
65
66
|
shared_memory_system: callable = None,
|
swarms/structs/rearrange.py
CHANGED
@@ -2,7 +2,7 @@ import asyncio
|
|
2
2
|
import json
|
3
3
|
import uuid
|
4
4
|
from concurrent.futures import ThreadPoolExecutor
|
5
|
-
from typing import Any, Callable, Dict, List, Optional
|
5
|
+
from typing import Any, Callable, Dict, List, Optional, Union
|
6
6
|
|
7
7
|
|
8
8
|
from swarms.structs.agent import Agent
|
@@ -15,7 +15,7 @@ from swarms.utils.history_output_formatter import (
|
|
15
15
|
from swarms.utils.loguru_logger import initialize_logger
|
16
16
|
from swarms.telemetry.main import log_agent_data
|
17
17
|
from swarms.structs.conversation import Conversation
|
18
|
-
from swarms.
|
18
|
+
from swarms.utils.output_types import OutputType
|
19
19
|
from swarms.structs.multi_agent_exec import get_agents_info
|
20
20
|
|
21
21
|
logger = initialize_logger(log_folder="rearrange")
|
@@ -68,7 +68,7 @@ class AgentRearrange(BaseSwarm):
|
|
68
68
|
id: str = swarm_id(),
|
69
69
|
name: str = "AgentRearrange",
|
70
70
|
description: str = "A swarm of agents for rearranging tasks.",
|
71
|
-
agents: List[Agent] = None,
|
71
|
+
agents: List[Union[Agent, Callable]] = None,
|
72
72
|
flow: str = None,
|
73
73
|
max_loops: int = 1,
|
74
74
|
verbose: bool = True,
|
@@ -1,8 +1,8 @@
|
|
1
1
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
2
|
-
from typing import List, Optional
|
2
|
+
from typing import Callable, List, Optional, Union
|
3
3
|
|
4
4
|
from swarms.structs.agent import Agent
|
5
|
-
from swarms.
|
5
|
+
from swarms.utils.output_types import OutputType
|
6
6
|
from swarms.structs.rearrange import AgentRearrange
|
7
7
|
from swarms.utils.loguru_logger import initialize_logger
|
8
8
|
|
@@ -31,7 +31,7 @@ class SequentialWorkflow:
|
|
31
31
|
self,
|
32
32
|
name: str = "SequentialWorkflow",
|
33
33
|
description: str = "Sequential Workflow, where agents are executed in a sequence.",
|
34
|
-
agents: List[Agent] = [],
|
34
|
+
agents: List[Union[Agent, Callable]] = [],
|
35
35
|
max_loops: int = 1,
|
36
36
|
output_type: OutputType = "dict",
|
37
37
|
shared_memory_system: callable = None,
|