[MCP Deployment as an agent deploy method] [improve hiearchical marketing example]

pull/990/merge
Kye Gomez 3 days ago
parent ec406e9a2d
commit 2c22eeeec8

@ -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()

@ -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?")

@ -1,4 +1,5 @@
from swarms import Agent, HierarchicalSwarm from swarms import Agent, HierarchicalSwarm
from swarms_tools import exa_search
# ============================================================================= # =============================================================================
# HEAD OF CONTENT AGENT # HEAD OF CONTENT AGENT
@ -45,11 +46,10 @@ head_of_content_agent = Agent(
- Content ROI measurement and reporting - Content ROI measurement and reporting
You deliver strategic, data-driven content recommendations that drive engagement, conversions, and brand growth.""", 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, max_loops=1,
temperature=0.7, temperature=0.7,
dynamic_temperature_enabled=True, dynamic_temperature_enabled=True,
streaming_on=True,
print_on=True, print_on=True,
) )
@ -99,11 +99,11 @@ ad_creative_director_agent = Agent(
- Innovative advertising approaches and trends - Innovative advertising approaches and trends
You deliver creative solutions that are both strategically sound and creatively brilliant, driving brand awareness, engagement, and conversions.""", 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, max_loops=1,
tools=[exa_search],
temperature=0.8, temperature=0.8,
dynamic_temperature_enabled=True, dynamic_temperature_enabled=True,
streaming_on=True,
print_on=True, print_on=True,
) )
@ -165,11 +165,11 @@ seo_strategist_agent = Agent(
- Voice search and featured snippet optimization - 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.""", 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, max_loops=1,
temperature=0.6, temperature=0.6,
tools=[exa_search],
dynamic_temperature_enabled=True, dynamic_temperature_enabled=True,
streaming_on=True,
print_on=True, print_on=True,
) )
@ -239,11 +239,9 @@ brand_strategist_agent = Agent(
- Brand architecture and portfolio management - 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.""", 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, max_loops=1,
temperature=0.7, tools=[exa_search],
dynamic_temperature_enabled=True,
streaming_on=True,
print_on=True, print_on=True,
) )
@ -296,11 +294,10 @@ marketing_director_agent = Agent(
- Stakeholder communication and executive reporting - 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.""", 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, max_loops=1,
temperature=0.7, temperature=0.7,
dynamic_temperature_enabled=True, dynamic_temperature_enabled=True,
streaming_on=True,
print_on=True, print_on=True,
) )
@ -319,26 +316,26 @@ marketing_agents = [
marketing_swarm = HierarchicalSwarm( marketing_swarm = HierarchicalSwarm(
name="Hierarchical-Marketing-Swarm", name="Hierarchical-Marketing-Swarm",
description="A comprehensive marketing team with specialized agents for content, creative, SEO, and brand strategy, coordinated by a marketing director", 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, agents=marketing_agents,
max_loops=2, max_loops=1,
verbose=True, verbose=False,
director_reasoning_model_name="o3-mini",
# interactive=True,
) )
# ============================================================================= # =============================================================================
# EXAMPLE USAGE # EXAMPLE USAGE
# ============================================================================= # =============================================================================
if __name__ == "__main__": if __name__ == "__main__":
# Example marketing challenge """
task = """Develop a comprehensive marketing strategy for a new SaaS product launch. Example usage: Instruct the marketing swarm to research swarms.ai and develop a new marketing plan.
The product is a project management tool targeting small to medium businesses. """
Please coordinate the team to create: task = (
1. Content strategy and editorial plan "Research swarms.ai and come up with a new marketing plan. "
2. Creative campaign concepts and visual direction "Analyze the current market positioning, identify opportunities, and propose a comprehensive strategy. "
3. SEO strategy for organic growth "Include recommendations for content, creative campaigns, SEO, and brand differentiation. "
4. Brand positioning and market differentiation "Ensure the plan is actionable and tailored to swarms.ai's unique value proposition."
)
Ensure all elements work together cohesively to drive awareness, engagement, and conversions."""
result = marketing_swarm.run(task=task) result = marketing_swarm.run(task=task)
print("=" * 80) print("=" * 80)

@ -5,7 +5,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry] [tool.poetry]
name = "swarms" name = "swarms"
version = "8.1.3" version = "8.1.4"
description = "Swarms - TGSC" description = "Swarms - TGSC"
license = "MIT" license = "MIT"
authors = ["Kye Gomez <kye@apac.ai>"] authors = ["Kye Gomez <kye@apac.ai>"]

@ -1146,10 +1146,6 @@ class HierarchicalSwarm:
if task is None and self.interactive: if task is None and self.interactive:
task = self._get_interactive_task() task = self._get_interactive_task()
# if task is None:
# raise ValueError(
# "Task is required for swarm execution"
# )
current_loop = 0 current_loop = 0
last_output = None last_output = None

@ -31,7 +31,9 @@ class AgentLogInput(BaseModel):
) )
agent_name: str agent_name: str
task: 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): class AgentLogOutput(BaseModel):
@ -50,7 +52,9 @@ class AgentLogOutput(BaseModel):
) )
agent_name: str agent_name: str
result: Any 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): class TreeLog(BaseModel):
@ -72,7 +76,9 @@ class TreeLog(BaseModel):
tree_name: str tree_name: str
task: str task: str
selected_agent: 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 result: Any

Loading…
Cancel
Save