swarms 7.6.4__py3-none-any.whl → 7.6.5__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.
@@ -2,7 +2,7 @@ from swarms.structs.agent import Agent
2
2
  from swarms.structs.agent_builder import AgentsBuilder
3
3
  from swarms.structs.agents_available import showcase_available_agents
4
4
  from swarms.structs.async_workflow import AsyncWorkflow
5
- from swarms.structs.auto_swarm import AutoSwarm, AutoSwarmRouter
5
+ from experimental.auto_swarm import AutoSwarm, AutoSwarmRouter
6
6
  from swarms.structs.base_structure import BaseStructure
7
7
  from swarms.structs.base_swarm import BaseSwarm
8
8
  from swarms.structs.base_workflow import BaseWorkflow
@@ -85,8 +85,6 @@ from swarms.structs.swarming_architectures import (
85
85
  __all__ = [
86
86
  "Agent",
87
87
  "AsyncWorkflow",
88
- "AutoSwarm",
89
- "AutoSwarmRouter",
90
88
  "BaseStructure",
91
89
  "BaseSwarm",
92
90
  "BaseWorkflow",
swarms/structs/agent.py CHANGED
@@ -58,6 +58,12 @@ from swarms.utils.litellm_tokenizer import count_tokens
58
58
  from swarms.utils.pdf_to_text import pdf_to_text
59
59
  from swarms.utils.str_to_dict import str_to_dict
60
60
 
61
+ from swarms.tools.mcp_integration import (
62
+ batch_mcp_flow,
63
+ mcp_flow_get_tool_schema,
64
+ MCPServerSseParams,
65
+ )
66
+
61
67
 
62
68
  # Utils
63
69
  # Custom stopping condition
@@ -352,6 +358,7 @@ class Agent:
352
358
  role: agent_roles = "worker",
353
359
  no_print: bool = False,
354
360
  tools_list_dictionary: Optional[List[Dict[str, Any]]] = None,
361
+ mcp_servers: List[MCPServerSseParams] = [],
355
362
  *args,
356
363
  **kwargs,
357
364
  ):
@@ -471,6 +478,7 @@ class Agent:
471
478
  self.role = role
472
479
  self.no_print = no_print
473
480
  self.tools_list_dictionary = tools_list_dictionary
481
+ self.mcp_servers = mcp_servers
474
482
 
475
483
  if (
476
484
  self.agent_name is not None
@@ -584,6 +592,12 @@ class Agent:
584
592
  if self.llm is None:
585
593
  self.llm = self.llm_handling()
586
594
 
595
+ if (
596
+ self.tools_list_dictionary is None
597
+ and self.mcp_servers is not None
598
+ ):
599
+ self.tools_list_dictionary = self.mcp_tool_handling()
600
+
587
601
  def llm_handling(self):
588
602
  from swarms.utils.litellm_wrapper import LiteLLM
589
603
 
@@ -631,6 +645,69 @@ class Agent:
631
645
  logger.error(f"Error in llm_handling: {e}")
632
646
  return None
633
647
 
648
+ def mcp_execution_flow(self, response: any):
649
+ """
650
+ Executes the MCP (Model Context Protocol) flow based on the provided response.
651
+
652
+ This method takes a response, converts it from a string to a dictionary format,
653
+ and checks for the presence of a tool name or a name in the response. If either
654
+ is found, it retrieves the tool name and proceeds to call the batch_mcp_flow
655
+ function to execute the corresponding tool actions.
656
+
657
+ Args:
658
+ response (any): The response to be processed, which can be in string format
659
+ that represents a dictionary.
660
+
661
+ Returns:
662
+ The output from the batch_mcp_flow function, which contains the results of
663
+ the tool execution. If an error occurs during processing, it logs the error
664
+ and returns None.
665
+
666
+ Raises:
667
+ Exception: Logs any exceptions that occur during the execution flow.
668
+ """
669
+ try:
670
+ response = str_to_dict(response)
671
+
672
+ tool_output = batch_mcp_flow(
673
+ self.mcp_servers,
674
+ function_call=response,
675
+ )
676
+
677
+ return tool_output
678
+ except Exception as e:
679
+ logger.error(f"Error in mcp_execution_flow: {e}")
680
+ return None
681
+
682
+ def mcp_tool_handling(self):
683
+ """
684
+ Handles the retrieval of tool schemas from the MCP servers.
685
+
686
+ This method iterates over the list of MCP servers, retrieves the tool schema
687
+ for each server using the mcp_flow_get_tool_schema function, and compiles
688
+ these schemas into a list. The resulting list is stored in the
689
+ tools_list_dictionary attribute.
690
+
691
+ Returns:
692
+ list: A list of tool schemas retrieved from the MCP servers. If an error
693
+ occurs during the retrieval process, it logs the error and returns None.
694
+
695
+ Raises:
696
+ Exception: Logs any exceptions that occur during the tool handling process.
697
+ """
698
+ try:
699
+ self.tools_list_dictionary = []
700
+
701
+ for mcp_server in self.mcp_servers:
702
+ tool_schema = mcp_flow_get_tool_schema(mcp_server)
703
+ self.tools_list_dictionary.append(tool_schema)
704
+
705
+ print(self.tools_list_dictionary)
706
+ return self.tools_list_dictionary
707
+ except Exception as e:
708
+ logger.error(f"Error in mcp_tool_handling: {e}")
709
+ return None
710
+
634
711
  def setup_config(self):
635
712
  # The max_loops will be set dynamically if the dynamic_loop
636
713
  if self.dynamic_loops is True: