swarms 7.8.4__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/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 +14 -11
- 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 +608 -87
- 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 +75 -0
- swarms/structs/majority_voting.py +1 -1
- swarms/structs/mixture_of_agents.py +1 -1
- 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 +500 -411
- 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 +5 -6
- swarms/utils/xml_utils.py +37 -2
- {swarms-7.8.4.dist-info → swarms-7.8.7.dist-info}/METADATA +31 -55
- {swarms-7.8.4.dist-info → swarms-7.8.7.dist-info}/RECORD +53 -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.4.dist-info → swarms-7.8.7.dist-info}/LICENSE +0 -0
- {swarms-7.8.4.dist-info → swarms-7.8.7.dist-info}/WHEEL +0 -0
- {swarms-7.8.4.dist-info → swarms-7.8.7.dist-info}/entry_points.txt +0 -0
swarms/structs/swarm_router.py
CHANGED
@@ -20,11 +20,13 @@ from swarms.structs.rearrange import AgentRearrange
|
|
20
20
|
from swarms.structs.sequential_workflow import SequentialWorkflow
|
21
21
|
from swarms.structs.spreadsheet_swarm import SpreadSheetSwarm
|
22
22
|
from swarms.structs.swarm_matcher import swarm_matcher
|
23
|
-
from swarms.
|
23
|
+
from swarms.utils.output_types import OutputType
|
24
24
|
from swarms.utils.loguru_logger import initialize_logger
|
25
25
|
from swarms.structs.malt import MALT
|
26
26
|
from swarms.structs.deep_research_swarm import DeepResearchSwarm
|
27
27
|
from swarms.structs.council_judge import CouncilAsAJudge
|
28
|
+
from swarms.structs.interactive_groupchat import InteractiveGroupChat
|
29
|
+
|
28
30
|
|
29
31
|
logger = initialize_logger(log_folder="swarm_router")
|
30
32
|
|
@@ -43,6 +45,7 @@ SwarmType = Literal[
|
|
43
45
|
"MALT",
|
44
46
|
"DeepResearchSwarm",
|
45
47
|
"CouncilAsAJudge",
|
48
|
+
"InteractiveGroupChat",
|
46
49
|
]
|
47
50
|
|
48
51
|
|
@@ -187,7 +190,7 @@ class SwarmRouter:
|
|
187
190
|
shared_memory_system: Any = None,
|
188
191
|
rules: str = None,
|
189
192
|
documents: List[str] = [], # A list of docs file paths
|
190
|
-
output_type: OutputType = "dict",
|
193
|
+
output_type: OutputType = "dict-all-except-first",
|
191
194
|
no_cluster_ops: bool = False,
|
192
195
|
speaker_fn: callable = None,
|
193
196
|
load_agents_from_csv: bool = False,
|
@@ -332,19 +335,7 @@ class SwarmRouter:
|
|
332
335
|
)
|
333
336
|
logger.info("🚀 [SYSTEM] Swarm is ready for deployment")
|
334
337
|
|
335
|
-
def _create_swarm(
|
336
|
-
self, task: str = None, *args, **kwargs
|
337
|
-
) -> Union[
|
338
|
-
AgentRearrange,
|
339
|
-
MixtureOfAgents,
|
340
|
-
SpreadSheetSwarm,
|
341
|
-
SequentialWorkflow,
|
342
|
-
ConcurrentWorkflow,
|
343
|
-
GroupChat,
|
344
|
-
MultiAgentRouter,
|
345
|
-
MajorityVoting,
|
346
|
-
HierarchicalSwarm,
|
347
|
-
]:
|
338
|
+
def _create_swarm(self, task: str = None, *args, **kwargs):
|
348
339
|
"""
|
349
340
|
Dynamically create and return the specified swarm type or automatically match the best swarm type for a given task.
|
350
341
|
|
@@ -397,6 +388,15 @@ class SwarmRouter:
|
|
397
388
|
base_agent=self.agents[0] if self.agents else None,
|
398
389
|
)
|
399
390
|
|
391
|
+
elif self.swarm_type == "InteractiveGroupChat":
|
392
|
+
return InteractiveGroupChat(
|
393
|
+
name=self.name,
|
394
|
+
description=self.description,
|
395
|
+
agents=self.agents,
|
396
|
+
max_loops=self.max_loops,
|
397
|
+
output_type=self.output_type,
|
398
|
+
)
|
399
|
+
|
400
400
|
elif self.swarm_type == "DeepResearchSwarm":
|
401
401
|
return DeepResearchSwarm(
|
402
402
|
name=self.name,
|
@@ -778,85 +778,3 @@ class SwarmRouter:
|
|
778
778
|
results.append(None)
|
779
779
|
|
780
780
|
return results
|
781
|
-
|
782
|
-
|
783
|
-
def swarm_router(
|
784
|
-
name: str = "swarm-router",
|
785
|
-
description: str = "Routes your task to the desired swarm",
|
786
|
-
max_loops: int = 1,
|
787
|
-
agents: List[Union[Agent, Callable]] = [],
|
788
|
-
swarm_type: SwarmType = "SequentialWorkflow", # "SpreadSheetSwarm" # "auto"
|
789
|
-
autosave: bool = False,
|
790
|
-
flow: str = None,
|
791
|
-
return_json: bool = True,
|
792
|
-
auto_generate_prompts: bool = False,
|
793
|
-
task: str = None,
|
794
|
-
rules: str = None,
|
795
|
-
*args,
|
796
|
-
**kwargs,
|
797
|
-
) -> SwarmRouter:
|
798
|
-
"""
|
799
|
-
Create and run a SwarmRouter instance with the given configuration.
|
800
|
-
|
801
|
-
Args:
|
802
|
-
name (str, optional): Name of the swarm router. Defaults to "swarm-router".
|
803
|
-
description (str, optional): Description of the router. Defaults to "Routes your task to the desired swarm".
|
804
|
-
max_loops (int, optional): Maximum number of execution loops. Defaults to 1.
|
805
|
-
agents (List[Union[Agent, Callable]], optional): List of agents or callables. Defaults to [].
|
806
|
-
swarm_type (SwarmType, optional): Type of swarm to use. Defaults to "SequentialWorkflow".
|
807
|
-
autosave (bool, optional): Whether to autosave results. Defaults to False.
|
808
|
-
flow (str, optional): Flow configuration. Defaults to None.
|
809
|
-
return_json (bool, optional): Whether to return results as JSON. Defaults to True.
|
810
|
-
auto_generate_prompts (bool, optional): Whether to auto-generate prompts. Defaults to False.
|
811
|
-
task (str, optional): Task to execute. Defaults to None.
|
812
|
-
*args: Additional positional arguments passed to SwarmRouter.run()
|
813
|
-
**kwargs: Additional keyword arguments passed to SwarmRouter.run()
|
814
|
-
|
815
|
-
Returns:
|
816
|
-
Any: Result from executing the swarm router
|
817
|
-
|
818
|
-
Raises:
|
819
|
-
ValueError: If invalid arguments are provided
|
820
|
-
Exception: If an error occurs during router creation or task execution
|
821
|
-
"""
|
822
|
-
try:
|
823
|
-
logger.info(
|
824
|
-
f"Creating SwarmRouter with name: {name}, swarm_type: {swarm_type}"
|
825
|
-
)
|
826
|
-
|
827
|
-
if not agents:
|
828
|
-
logger.warning(
|
829
|
-
"No agents provided, router may have limited functionality"
|
830
|
-
)
|
831
|
-
|
832
|
-
if task is None:
|
833
|
-
logger.warning("No task provided")
|
834
|
-
|
835
|
-
swarm_router = SwarmRouter(
|
836
|
-
name=name,
|
837
|
-
description=description,
|
838
|
-
max_loops=max_loops,
|
839
|
-
agents=agents,
|
840
|
-
swarm_type=swarm_type,
|
841
|
-
autosave=autosave,
|
842
|
-
flow=flow,
|
843
|
-
return_json=return_json,
|
844
|
-
auto_generate_prompts=auto_generate_prompts,
|
845
|
-
rules=rules,
|
846
|
-
)
|
847
|
-
|
848
|
-
logger.info(f"Executing task with SwarmRouter: {task}")
|
849
|
-
result = swarm_router.run(task, *args, **kwargs)
|
850
|
-
logger.info(
|
851
|
-
f"Task execution completed successfully: {result}"
|
852
|
-
)
|
853
|
-
return result
|
854
|
-
|
855
|
-
except ValueError as e:
|
856
|
-
logger.error(
|
857
|
-
f"Invalid arguments provided to swarm_router: {str(e)}"
|
858
|
-
)
|
859
|
-
raise
|
860
|
-
except Exception as e:
|
861
|
-
logger.error(f"Error in swarm_router execution: {str(e)}")
|
862
|
-
raise
|
@@ -9,7 +9,7 @@ from swarms.structs.conversation import Conversation
|
|
9
9
|
from swarms.utils.history_output_formatter import (
|
10
10
|
history_output_formatter,
|
11
11
|
)
|
12
|
-
from swarms.
|
12
|
+
from swarms.utils.output_types import OutputType
|
13
13
|
|
14
14
|
logger = initialize_logger(log_folder="swarming_architectures")
|
15
15
|
|
swarms/tools/mcp_client_call.py
CHANGED
@@ -494,6 +494,9 @@ async def execute_tool_call_simple(
|
|
494
494
|
*args,
|
495
495
|
**kwargs,
|
496
496
|
) -> List[Dict[str, Any]]:
|
497
|
+
if isinstance(response, str):
|
498
|
+
response = json.loads(response)
|
499
|
+
|
497
500
|
return await _execute_tool_call_simple(
|
498
501
|
response=response,
|
499
502
|
server_path=server_path,
|
swarms/utils/__init__.py
CHANGED
@@ -11,12 +11,18 @@ from swarms.utils.file_processing import (
|
|
11
11
|
create_file_in_folder,
|
12
12
|
zip_folders,
|
13
13
|
)
|
14
|
-
from swarms.utils.markdown_message import display_markdown_message
|
15
14
|
from swarms.utils.parse_code import extract_code_from_markdown
|
16
15
|
from swarms.utils.pdf_to_text import pdf_to_text
|
17
16
|
from swarms.utils.try_except_wrapper import try_except_wrapper
|
18
17
|
from swarms.utils.calculate_func_metrics import profile_func
|
19
18
|
from swarms.utils.litellm_tokenizer import count_tokens
|
19
|
+
from swarms.utils.output_types import HistoryOutputType
|
20
|
+
from swarms.utils.history_output_formatter import (
|
21
|
+
history_output_formatter,
|
22
|
+
)
|
23
|
+
from swarms.utils.check_all_model_max_tokens import (
|
24
|
+
check_all_model_max_tokens,
|
25
|
+
)
|
20
26
|
|
21
27
|
|
22
28
|
__all__ = [
|
@@ -29,10 +35,12 @@ __all__ = [
|
|
29
35
|
"zip_workspace",
|
30
36
|
"create_file_in_folder",
|
31
37
|
"zip_folders",
|
32
|
-
"display_markdown_message",
|
33
38
|
"extract_code_from_markdown",
|
34
39
|
"pdf_to_text",
|
35
40
|
"try_except_wrapper",
|
36
41
|
"profile_func",
|
37
42
|
"count_tokens",
|
43
|
+
"HistoryOutputType",
|
44
|
+
"history_output_formatter",
|
45
|
+
"check_all_model_max_tokens",
|
38
46
|
]
|
@@ -0,0 +1,43 @@
|
|
1
|
+
from litellm import model_list, get_max_tokens
|
2
|
+
from swarms.utils.formatter import formatter
|
3
|
+
|
4
|
+
# Add model overrides here
|
5
|
+
MODEL_MAX_TOKEN_OVERRIDES = {
|
6
|
+
"llama-2-70b-chat:2796ee9483c3fd7aa2e171d38f4ca12251a30609463dcfd4cd76703f22e96cdf": 4096, # Example override
|
7
|
+
}
|
8
|
+
|
9
|
+
|
10
|
+
def check_all_model_max_tokens():
|
11
|
+
"""
|
12
|
+
Check and display the maximum token limits for all available models.
|
13
|
+
|
14
|
+
This function iterates through all models in the litellm model list and attempts
|
15
|
+
to retrieve their maximum token limits. For models that are not properly mapped
|
16
|
+
in litellm, it checks for custom overrides in MODEL_MAX_TOKEN_OVERRIDES.
|
17
|
+
|
18
|
+
Returns:
|
19
|
+
None: Prints the results to console using formatter.print_panel()
|
20
|
+
|
21
|
+
Note:
|
22
|
+
Models that are not mapped in litellm and have no override set will be
|
23
|
+
marked with a [WARNING] in the output.
|
24
|
+
"""
|
25
|
+
text = ""
|
26
|
+
for model in model_list:
|
27
|
+
# skip model names
|
28
|
+
try:
|
29
|
+
max_tokens = get_max_tokens(model)
|
30
|
+
except Exception:
|
31
|
+
max_tokens = MODEL_MAX_TOKEN_OVERRIDES.get(
|
32
|
+
model, "[NOT MAPPED]"
|
33
|
+
)
|
34
|
+
if max_tokens == "[NOT MAPPED]":
|
35
|
+
text += f"[WARNING] {model}: not mapped in litellm and no override set.\n"
|
36
|
+
text += f"{model}: {max_tokens}\n"
|
37
|
+
text += "─" * 80 + "\n" # Add borderline for each model
|
38
|
+
formatter.print_panel(text, "All Model Max Tokens")
|
39
|
+
return text
|
40
|
+
|
41
|
+
|
42
|
+
# if __name__ == "__main__":
|
43
|
+
# print(check_all_model_max_tokens())
|
swarms/utils/generate_keys.py
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
import secrets
|
2
2
|
import string
|
3
|
-
import re
|
4
3
|
|
5
4
|
|
6
5
|
def generate_api_key(prefix: str = "sk-", length: int = 32) -> str:
|
@@ -36,29 +35,3 @@ def generate_api_key(prefix: str = "sk-", length: int = 32) -> str:
|
|
36
35
|
api_key = f"{prefix}{random_part}"
|
37
36
|
|
38
37
|
return api_key
|
39
|
-
|
40
|
-
|
41
|
-
def validate_api_key(api_key: str, prefix: str = "sk-") -> bool:
|
42
|
-
"""
|
43
|
-
Validate if an API key matches the expected format.
|
44
|
-
|
45
|
-
Args:
|
46
|
-
api_key (str): The API key to validate
|
47
|
-
prefix (str): The expected prefix (default: "sk-")
|
48
|
-
|
49
|
-
Returns:
|
50
|
-
bool: True if the API key is valid, False otherwise
|
51
|
-
"""
|
52
|
-
if not isinstance(api_key, str):
|
53
|
-
return False
|
54
|
-
|
55
|
-
# Check if key starts with prefix
|
56
|
-
if not api_key.startswith(prefix):
|
57
|
-
return False
|
58
|
-
|
59
|
-
# Check if the rest of the key contains only alphanumeric characters
|
60
|
-
random_part = api_key[len(prefix) :]
|
61
|
-
if not re.match(r"^[a-zA-Z0-9]+$", random_part):
|
62
|
-
return False
|
63
|
-
|
64
|
-
return True
|
@@ -1,28 +1,11 @@
|
|
1
1
|
import yaml
|
2
|
-
from
|
3
|
-
from typing import Literal, Union, List, Dict, Any
|
2
|
+
from typing import Union, List, Dict, Any
|
4
3
|
from swarms.utils.xml_utils import to_xml_string
|
5
|
-
|
6
|
-
HistoryOutputType = Literal[
|
7
|
-
"list",
|
8
|
-
"dict",
|
9
|
-
"dictionary",
|
10
|
-
"string",
|
11
|
-
"str",
|
12
|
-
"final",
|
13
|
-
"last",
|
14
|
-
"json",
|
15
|
-
"all",
|
16
|
-
"yaml",
|
17
|
-
"xml",
|
18
|
-
# "dict-final",
|
19
|
-
"dict-all-except-first",
|
20
|
-
"str-all-except-first",
|
21
|
-
]
|
4
|
+
from swarms.utils.output_types import HistoryOutputType
|
22
5
|
|
23
6
|
|
24
7
|
def history_output_formatter(
|
25
|
-
conversation:
|
8
|
+
conversation: callable, type: HistoryOutputType = "list"
|
26
9
|
) -> Union[List[Dict[str, Any]], Dict[str, Any], str]:
|
27
10
|
if type == "list":
|
28
11
|
return conversation.return_messages_as_list()
|
@@ -42,6 +25,8 @@ def history_output_formatter(
|
|
42
25
|
return conversation.return_all_except_first()
|
43
26
|
elif type == "str-all-except-first":
|
44
27
|
return conversation.return_all_except_first_string()
|
28
|
+
elif type == "dict-final":
|
29
|
+
return conversation.return_dict_final()
|
45
30
|
elif type == "xml":
|
46
31
|
data = conversation.to_dict()
|
47
32
|
return to_xml_string(data, root_tag="conversation")
|