From abf1e7bcd026057efc2ff8cf2f856fc70a3ba5e2 Mon Sep 17 00:00:00 2001 From: Kye Gomez Date: Thu, 5 Jun 2025 13:19:07 -0700 Subject: [PATCH] agent with tools --- docs/mkdocs.yml | 4 +--- .../structs/dynamic_conversational_swarm.py | 4 +++- swarms/structs/ma_blocks.py | 20 +++++++++---------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index c321de28..fb9f16ee 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -343,8 +343,6 @@ nav: - Medical Swarm: "swarms/examples/swarms_api_medical.md" - Finance Swarm: "swarms/examples/swarms_api_finance.md" - ML Model Code Generation Swarm: "swarms/examples/swarms_api_ml_model.md" - - Swarms UI: - - Overview: "swarms/ui/main.md" - Swarm Models: - Overview: "swarms/models/index.md" @@ -389,9 +387,9 @@ nav: - Swarms Marketplace: - Overview: "swarms_platform/index.md" - # - Agent Marketplace: "swarms_platform/share_discover.md" - Swarm Platform API Keys: "swarms_platform/apikeys.md" - Account Management: "swarms_platform/account_management.md" + - Swarms Chat Tutorial: "swarms/ui/main.md" - Swarms Rust: - Overview: "swarms_rs/overview.md" diff --git a/swarms/structs/dynamic_conversational_swarm.py b/swarms/structs/dynamic_conversational_swarm.py index 158036b6..84355fa2 100644 --- a/swarms/structs/dynamic_conversational_swarm.py +++ b/swarms/structs/dynamic_conversational_swarm.py @@ -100,7 +100,9 @@ class DynamicConversationalSwarm: ValueError: If agent is not found RuntimeError: If there's an error running the agent """ - agent = find_agent_by_name(agents=self.agents, agent_name=agent_name) + agent = find_agent_by_name( + agents=self.agents, agent_name=agent_name + ) return agent.run(task) def fetch_random_agent_name(self) -> str: diff --git a/swarms/structs/ma_blocks.py b/swarms/structs/ma_blocks.py index 4565ce31..6311ac29 100644 --- a/swarms/structs/ma_blocks.py +++ b/swarms/structs/ma_blocks.py @@ -111,10 +111,10 @@ def run_agent( """ if agent is None: raise ValueError("Agent cannot be None") - + if task is None: raise ValueError("Task cannot be None") - + if not isinstance(agent, Agent): raise TypeError("Agent must be an instance of Agent") @@ -122,10 +122,11 @@ def run_agent( return agent.run(task=task, *args, **kwargs) except Exception as e: raise RuntimeError(f"Error running agent: {str(e)}") - - - -def find_agent_by_name(agents: List[Union[Agent, Callable]], agent_name: str) -> Agent: + + +def find_agent_by_name( + agents: List[Union[Agent, Callable]], agent_name: str +) -> Agent: """ Find an agent by its name in a list of agents. @@ -142,18 +143,17 @@ def find_agent_by_name(agents: List[Union[Agent, Callable]], agent_name: str) -> """ if not agents: raise ValueError("Agents list cannot be empty") - + if not isinstance(agent_name, str): raise TypeError("Agent name must be a string") - + if not agent_name.strip(): raise ValueError("Agent name cannot be empty or whitespace") try: for agent in agents: - if hasattr(agent, 'name') and agent.name == agent_name: + if hasattr(agent, "name") and agent.name == agent_name: return agent raise ValueError(f"Agent with name '{agent_name}' not found") except Exception as e: raise RuntimeError(f"Error finding agent: {str(e)}") -