From 2c22eeeec8319c2681c88acb30b0fa22a535a17d Mon Sep 17 00:00:00 2001 From: Kye Gomez Date: Sat, 30 Aug 2025 14:40:47 -0700 Subject: [PATCH] [MCP Deployment as an agent deploy method] [improve hiearchical marketing example] --- examples/mcp/mcp_agent_tool.py | 33 +++++++++++++ examples/tools/exa_search_agent.py | 12 +++++ ...g_team.py => hiearchical_marketing_team.py | 47 +++++++++---------- pyproject.toml | 2 +- swarms/structs/hiearchical_swarm.py | 4 -- swarms/structs/tree_swarm.py | 12 +++-- 6 files changed, 77 insertions(+), 33 deletions(-) create mode 100644 examples/mcp/mcp_agent_tool.py create mode 100644 examples/tools/exa_search_agent.py rename examples/multi_agent/hiearchical_swarm/hiearchical_marketing_team.py => hiearchical_marketing_team.py (94%) diff --git a/examples/mcp/mcp_agent_tool.py b/examples/mcp/mcp_agent_tool.py new file mode 100644 index 00000000..5a07f7fd --- /dev/null +++ b/examples/mcp/mcp_agent_tool.py @@ -0,0 +1,33 @@ +from mcp.server.fastmcp import FastMCP + +from swarms import Agent + +mcp = FastMCP("MCPAgentTool") + +@mcp.tool( + name="create_agent", + description="Create an agent with the specified name, system prompt, and model, then run a task.", +) +def create_agent(agent_name: str, system_prompt: str, model_name: str, task: str) -> str: + """ + Create an agent with the given parameters and execute the specified task. + + Args: + agent_name (str): The name of the agent to create. + system_prompt (str): The system prompt to initialize the agent with. + model_name (str): The model name to use for the agent. + task (str): The task for the agent to perform. + + Returns: + str: The result of the agent running the given task. + """ + agent = Agent( + agent_name=agent_name, + system_prompt=system_prompt, + model_name=model_name, + ) + return agent.run(task) + + +if __name__ == "__main__": + mcp.run() \ No newline at end of file diff --git a/examples/tools/exa_search_agent.py b/examples/tools/exa_search_agent.py new file mode 100644 index 00000000..c774fdb4 --- /dev/null +++ b/examples/tools/exa_search_agent.py @@ -0,0 +1,12 @@ +from swarms import Agent +from swarms_tools import exa_search + + +agent = Agent( + name="Exa Search Agent", + model_name="gpt-4o-mini", + tools=[exa_search], + tool_call_summary=False, +) + +agent.run("What are the latest experimental treatments for diabetes?") diff --git a/examples/multi_agent/hiearchical_swarm/hiearchical_marketing_team.py b/hiearchical_marketing_team.py similarity index 94% rename from examples/multi_agent/hiearchical_swarm/hiearchical_marketing_team.py rename to hiearchical_marketing_team.py index 6b492d07..621f2c70 100644 --- a/examples/multi_agent/hiearchical_swarm/hiearchical_marketing_team.py +++ b/hiearchical_marketing_team.py @@ -1,4 +1,5 @@ from swarms import Agent, HierarchicalSwarm +from swarms_tools import exa_search # ============================================================================= # HEAD OF CONTENT AGENT @@ -45,11 +46,10 @@ head_of_content_agent = Agent( - Content ROI measurement and reporting You deliver strategic, data-driven content recommendations that drive engagement, conversions, and brand growth.""", - model_name="claude-3-sonnet-20240229", + model_name="gpt-4.1", max_loops=1, temperature=0.7, dynamic_temperature_enabled=True, - streaming_on=True, print_on=True, ) @@ -99,11 +99,11 @@ ad_creative_director_agent = Agent( - Innovative advertising approaches and trends You deliver creative solutions that are both strategically sound and creatively brilliant, driving brand awareness, engagement, and conversions.""", - model_name="claude-3-sonnet-20240229", + model_name="gpt-4.1", max_loops=1, + tools=[exa_search], temperature=0.8, dynamic_temperature_enabled=True, - streaming_on=True, print_on=True, ) @@ -165,11 +165,11 @@ seo_strategist_agent = Agent( - Voice search and featured snippet optimization You deliver data-driven SEO strategies that drive sustainable organic growth, improve search visibility, and generate qualified traffic that converts.""", - model_name="claude-3-sonnet-20240229", + model_name="gpt-4.1", max_loops=1, temperature=0.6, + tools=[exa_search], dynamic_temperature_enabled=True, - streaming_on=True, print_on=True, ) @@ -239,11 +239,9 @@ brand_strategist_agent = Agent( - Brand architecture and portfolio management You deliver strategic brand solutions that create powerful market differentiation, build strong brand equity, and drive sustainable business growth through compelling brand positioning and experiences.""", - model_name="claude-3-sonnet-20240229", + model_name="gpt-4.1", max_loops=1, - temperature=0.7, - dynamic_temperature_enabled=True, - streaming_on=True, + tools=[exa_search], print_on=True, ) @@ -296,11 +294,10 @@ marketing_director_agent = Agent( - Stakeholder communication and executive reporting You deliver comprehensive marketing strategies that leverage the full expertise of your specialized team, ensuring all marketing efforts work together to drive business growth, brand awareness, and customer acquisition.""", - model_name="claude-3-sonnet-20240229", + model_name="gpt-4.1", max_loops=1, temperature=0.7, dynamic_temperature_enabled=True, - streaming_on=True, print_on=True, ) @@ -319,26 +316,26 @@ marketing_agents = [ marketing_swarm = HierarchicalSwarm( name="Hierarchical-Marketing-Swarm", description="A comprehensive marketing team with specialized agents for content, creative, SEO, and brand strategy, coordinated by a marketing director", - director=marketing_director_agent, agents=marketing_agents, - max_loops=2, - verbose=True, + max_loops=1, + verbose=False, + director_reasoning_model_name="o3-mini", + # interactive=True, ) # ============================================================================= # EXAMPLE USAGE # ============================================================================= if __name__ == "__main__": - # Example marketing challenge - task = """Develop a comprehensive marketing strategy for a new SaaS product launch. - The product is a project management tool targeting small to medium businesses. - Please coordinate the team to create: - 1. Content strategy and editorial plan - 2. Creative campaign concepts and visual direction - 3. SEO strategy for organic growth - 4. Brand positioning and market differentiation - - Ensure all elements work together cohesively to drive awareness, engagement, and conversions.""" + """ + Example usage: Instruct the marketing swarm to research swarms.ai and develop a new marketing plan. + """ + task = ( + "Research swarms.ai and come up with a new marketing plan. " + "Analyze the current market positioning, identify opportunities, and propose a comprehensive strategy. " + "Include recommendations for content, creative campaigns, SEO, and brand differentiation. " + "Ensure the plan is actionable and tailored to swarms.ai's unique value proposition." + ) result = marketing_swarm.run(task=task) print("=" * 80) diff --git a/pyproject.toml b/pyproject.toml index 043c3057..a67265fd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api" [tool.poetry] name = "swarms" -version = "8.1.3" +version = "8.1.4" description = "Swarms - TGSC" license = "MIT" authors = ["Kye Gomez "] diff --git a/swarms/structs/hiearchical_swarm.py b/swarms/structs/hiearchical_swarm.py index d2dc10f4..7f918274 100644 --- a/swarms/structs/hiearchical_swarm.py +++ b/swarms/structs/hiearchical_swarm.py @@ -1146,10 +1146,6 @@ class HierarchicalSwarm: if task is None and self.interactive: task = self._get_interactive_task() - # if task is None: - # raise ValueError( - # "Task is required for swarm execution" - # ) current_loop = 0 last_output = None diff --git a/swarms/structs/tree_swarm.py b/swarms/structs/tree_swarm.py index 624c0deb..15e9a1a5 100644 --- a/swarms/structs/tree_swarm.py +++ b/swarms/structs/tree_swarm.py @@ -31,7 +31,9 @@ class AgentLogInput(BaseModel): ) agent_name: str task: str - timestamp: datetime = Field(default_factory=lambda: datetime.now(datetime.UTC)) + timestamp: datetime = Field( + default_factory=lambda: datetime.now(datetime.UTC) + ) class AgentLogOutput(BaseModel): @@ -50,7 +52,9 @@ class AgentLogOutput(BaseModel): ) agent_name: str result: Any - timestamp: datetime = Field(default_factory=lambda: datetime.now(datetime.UTC)) + timestamp: datetime = Field( + default_factory=lambda: datetime.now(datetime.UTC) + ) class TreeLog(BaseModel): @@ -72,7 +76,9 @@ class TreeLog(BaseModel): tree_name: str task: str selected_agent: str - timestamp: datetime = Field(default_factory=lambda: datetime.now(datetime.UTC)) + timestamp: datetime = Field( + default_factory=lambda: datetime.now(datetime.UTC) + ) result: Any