from swarms import Agent, HierarchicalSwarm
import os
# Configure your LLM - using OpenAI as example
api_key = os.getenv("OPENAI_API_KEY")
# Define specialized research agents
researcher_agent = Agent(
agent_name="Primary-Researcher",
system_prompt="""
You are an expert researcher specializing in gathering comprehensive information.
Your role is to:
- Identify key information sources and data points
- Gather relevant facts, statistics, and expert opinions
- Cite sources accurately
- Flag areas requiring deeper investigation
Provide thorough, well-sourced research findings.
""",
model_name="gpt-4o",
max_loops=1,
dynamic_temperature_enabled=True,
)
data_analyst = Agent(
agent_name="Data-Analyst",
system_prompt="""
You are a data analyst who transforms raw research into insights.
Your role is to:
- Identify patterns and trends in research data
- Perform statistical analysis where applicable
- Highlight key findings and anomalies
- Present data in clear, logical structures
Focus on extracting actionable insights from research.
""",
model_name="gpt-4o",
max_loops=1,
dynamic_temperature_enabled=True,
)
critical_analyst = Agent(
agent_name="Critical-Analyst",
system_prompt="""
You are a critical analyst who evaluates research quality.
Your role is to:
- Assess the validity and reliability of findings
- Identify gaps, biases, or logical inconsistencies
- Challenge assumptions and verify conclusions
- Suggest areas for additional investigation
Provide rigorous quality assurance for research outputs.
""",
model_name="gpt-4o",
max_loops=1,
dynamic_temperature_enabled=True,
)
report_writer = Agent(
agent_name="Report-Writer",
system_prompt="""
You are an expert technical writer who synthesizes research into reports.
Your role is to:
- Combine research, analysis, and critical feedback into coherent narratives
- Structure information logically with clear sections
- Write in clear, professional language
- Include executive summaries and key recommendations
Create publication-ready research reports.
""",
model_name="gpt-4o",
max_loops=1,
dynamic_temperature_enabled=True,
)
# Create the hierarchical research team
research_team = HierarchicalSwarm(
name="Research-Team-Swarm",
description="Autonomous research team for comprehensive analysis",
agents=[researcher_agent, data_analyst, critical_analyst, report_writer],
max_loops=1,
)
# Execute research project
if __name__ == "__main__":
research_query = """
Conduct a comprehensive research report on the current state of
artificial intelligence in healthcare, focusing on:
- Current applications and use cases
- Regulatory challenges and compliance
- Market size and growth projections
- Key players and competitive landscape
- Future trends and opportunities
Target audience: Healthcare executives and investors
"""
# Run the swarm
result = research_team.run(research_query)
# Save the report
with open("healthcare_ai_report.md", "w") as f:
f.write(result)
print("Research report completed and saved to healthcare_ai_report.md")