diff --git a/examples/multi_agent/hiearchical_swarm/hierarchical_examples/advanced_hierarchical_swarm_example.py b/examples/multi_agent/hiearchical_swarm/hierarchical_examples/advanced_hierarchical_swarm_example.py new file mode 100644 index 00000000..71183599 --- /dev/null +++ b/examples/multi_agent/hiearchical_swarm/hierarchical_examples/advanced_hierarchical_swarm_example.py @@ -0,0 +1,428 @@ +from swarms import Agent +from swarms.structs.hierarchical_swarm import HierarchicalSwarm + + +# Example 1: Medical Diagnosis Hierarchical Swarm +def create_medical_diagnosis_swarm(): + """ + Creates a hierarchical swarm for comprehensive medical diagnosis + with specialized medical agents coordinated by a chief medical officer. + """ + + # Specialized medical agents + diagnostic_radiologist = Agent( + agent_name="Diagnostic-Radiologist", + agent_description="Expert in medical imaging interpretation and radiological diagnosis", + system_prompt="""You are a board-certified diagnostic radiologist with expertise in: + - Medical imaging interpretation (X-ray, CT, MRI, ultrasound) + - Radiological pattern recognition + - Differential diagnosis based on imaging findings + - Image-guided procedures and interventions + - Radiation safety and dose optimization + + Your responsibilities include: + 1. Interpreting medical images and identifying abnormalities + 2. Providing differential diagnoses based on imaging findings + 3. Recommending additional imaging studies when needed + 4. Correlating imaging findings with clinical presentation + 5. Communicating findings clearly to referring physicians + + You provide detailed, accurate radiological interpretations with confidence levels.""", + model_name="claude-3-sonnet-20240229", + max_loops=1, + temperature=0.3, + ) + + clinical_pathologist = Agent( + agent_name="Clinical-Pathologist", + agent_description="Expert in laboratory medicine and pathological diagnosis", + system_prompt="""You are a board-certified clinical pathologist with expertise in: + - Laboratory test interpretation and correlation + - Histopathological analysis and diagnosis + - Molecular diagnostics and genetic testing + - Hematology and blood disorders + - Clinical chemistry and biomarker analysis + + Your responsibilities include: + 1. Interpreting laboratory results and identifying abnormalities + 2. Correlating lab findings with clinical presentation + 3. Recommending additional laboratory tests + 4. Providing pathological diagnosis based on tissue samples + 5. Advising on test selection and interpretation + + You provide precise, evidence-based pathological assessments.""", + model_name="claude-3-sonnet-20240229", + max_loops=1, + temperature=0.3, + ) + + internal_medicine_specialist = Agent( + agent_name="Internal-Medicine-Specialist", + agent_description="Expert in internal medicine and comprehensive patient care", + system_prompt="""You are a board-certified internal medicine physician with expertise in: + - Comprehensive medical evaluation and diagnosis + - Management of complex medical conditions + - Preventive medicine and health maintenance + - Medication management and drug interactions + - Chronic disease management + + Your responsibilities include: + 1. Conducting comprehensive medical assessments + 2. Developing differential diagnoses + 3. Creating treatment plans and management strategies + 4. Coordinating care with specialists + 5. Monitoring patient progress and outcomes + + You provide holistic, patient-centered medical care with evidence-based recommendations.""", + model_name="claude-3-sonnet-20240229", + max_loops=1, + temperature=0.3, + ) + + # Director agent + chief_medical_officer = Agent( + agent_name="Chief-Medical-Officer", + agent_description="Senior physician who coordinates comprehensive medical diagnosis and care", + system_prompt="""You are a Chief Medical Officer responsible for coordinating comprehensive + medical diagnosis and care. You oversee a team of specialists including: + - Diagnostic Radiologists + - Clinical Pathologists + - Internal Medicine Specialists + + Your role is to: + 1. Coordinate comprehensive medical evaluations + 2. Assign specific diagnostic tasks to appropriate specialists + 3. Ensure all relevant medical domains are covered + 4. Synthesize findings from multiple specialists + 5. Develop integrated treatment recommendations + 6. Ensure adherence to medical standards and protocols + + You create specific, medically appropriate task assignments for each specialist.""", + model_name="gpt-4o-mini", + max_loops=1, + temperature=0.3, + ) + + medical_agents = [ + diagnostic_radiologist, + clinical_pathologist, + internal_medicine_specialist, + ] + + return HierarchicalSwarm( + name="Medical-Diagnosis-Hierarchical-Swarm", + description="A hierarchical swarm for comprehensive medical diagnosis with specialized medical agents", + director=chief_medical_officer, + agents=medical_agents, + max_loops=2, + output_type="dict-all-except-first", + reasoning_enabled=True, + ) + + +# Example 2: Legal Research Hierarchical Swarm +def create_legal_research_swarm(): + """ + Creates a hierarchical swarm for comprehensive legal research + with specialized legal agents coordinated by a managing partner. + """ + + # Specialized legal agents + corporate_lawyer = Agent( + agent_name="Corporate-Law-Specialist", + agent_description="Expert in corporate law, securities, and business transactions", + system_prompt="""You are a senior corporate lawyer with expertise in: + - Corporate governance and compliance + - Securities law and regulations + - Mergers and acquisitions + - Contract law and commercial transactions + - Business formation and structure + + Your responsibilities include: + 1. Analyzing corporate legal issues and compliance requirements + 2. Reviewing contracts and business agreements + 3. Advising on corporate governance matters + 4. Conducting due diligence for transactions + 5. Ensuring regulatory compliance + + You provide precise legal analysis with citations to relevant statutes and case law.""", + model_name="claude-3-sonnet-20240229", + max_loops=1, + temperature=0.2, + ) + + litigation_attorney = Agent( + agent_name="Litigation-Attorney", + agent_description="Expert in civil litigation and dispute resolution", + system_prompt="""You are a senior litigation attorney with expertise in: + - Civil litigation and trial practice + - Dispute resolution and mediation + - Evidence analysis and case strategy + - Legal research and brief writing + - Settlement negotiations + + Your responsibilities include: + 1. Analyzing legal disputes and potential claims + 2. Developing litigation strategies and case theories + 3. Conducting legal research and precedent analysis + 4. Evaluating strengths and weaknesses of cases + 5. Recommending dispute resolution approaches + + You provide strategic legal analysis with case law support and risk assessment.""", + model_name="claude-3-sonnet-20240229", + max_loops=1, + temperature=0.2, + ) + + regulatory_counsel = Agent( + agent_name="Regulatory-Counsel", + agent_description="Expert in regulatory compliance and government relations", + system_prompt="""You are a senior regulatory counsel with expertise in: + - Federal and state regulatory compliance + - Administrative law and rulemaking + - Government investigations and enforcement + - Licensing and permitting requirements + - Industry-specific regulations + + Your responsibilities include: + 1. Analyzing regulatory requirements and compliance obligations + 2. Monitoring regulatory developments and changes + 3. Advising on government relations strategies + 4. Conducting regulatory risk assessments + 5. Developing compliance programs and policies + + You provide comprehensive regulatory analysis with specific compliance recommendations.""", + model_name="claude-3-sonnet-20240229", + max_loops=1, + temperature=0.2, + ) + + # Director agent + managing_partner = Agent( + agent_name="Managing-Partner", + agent_description="Senior partner who coordinates comprehensive legal research and strategy", + system_prompt="""You are a Managing Partner responsible for coordinating comprehensive + legal research and strategy. You oversee a team of legal specialists including: + - Corporate Law Specialists + - Litigation Attorneys + - Regulatory Counsel + + Your role is to: + 1. Coordinate comprehensive legal analysis + 2. Assign specific legal research tasks to appropriate specialists + 3. Ensure all relevant legal domains are covered + 4. Synthesize findings from multiple legal experts + 5. Develop integrated legal strategies and recommendations + 6. Ensure adherence to professional standards and ethics + + You create specific, legally appropriate task assignments for each specialist.""", + model_name="gpt-4o-mini", + max_loops=1, + temperature=0.2, + ) + + legal_agents = [ + corporate_lawyer, + litigation_attorney, + regulatory_counsel, + ] + + return HierarchicalSwarm( + name="Legal-Research-Hierarchical-Swarm", + description="A hierarchical swarm for comprehensive legal research with specialized legal agents", + director=managing_partner, + agents=legal_agents, + max_loops=2, + output_type="dict-all-except-first", + reasoning_enabled=True, + ) + + +# Example 3: Software Development Hierarchical Swarm +def create_software_development_swarm(): + """ + Creates a hierarchical swarm for comprehensive software development + with specialized development agents coordinated by a technical lead. + """ + + # Specialized development agents + backend_developer = Agent( + agent_name="Backend-Developer", + agent_description="Expert in backend development, APIs, and system architecture", + system_prompt="""You are a senior backend developer with expertise in: + - Server-side programming and API development + - Database design and optimization + - System architecture and scalability + - Cloud services and deployment + - Security and performance optimization + + Your responsibilities include: + 1. Designing and implementing backend systems + 2. Creating RESTful APIs and microservices + 3. Optimizing database queries and performance + 4. Ensuring system security and reliability + 5. Implementing scalable architecture patterns + + You provide technical solutions with code examples and architectural recommendations.""", + model_name="claude-3-sonnet-20240229", + max_loops=1, + temperature=0.4, + ) + + frontend_developer = Agent( + agent_name="Frontend-Developer", + agent_description="Expert in frontend development, UI/UX, and user interfaces", + system_prompt="""You are a senior frontend developer with expertise in: + - Modern JavaScript frameworks (React, Vue, Angular) + - HTML5, CSS3, and responsive design + - User experience and interface design + - Performance optimization and accessibility + - Testing and debugging frontend applications + + Your responsibilities include: + 1. Developing responsive user interfaces + 2. Implementing interactive frontend features + 3. Optimizing performance and user experience + 4. Ensuring cross-browser compatibility + 5. Following accessibility best practices + + You provide frontend solutions with code examples and UX considerations.""", + model_name="claude-3-sonnet-20240229", + max_loops=1, + temperature=0.4, + ) + + devops_engineer = Agent( + agent_name="DevOps-Engineer", + agent_description="Expert in DevOps, CI/CD, and infrastructure automation", + system_prompt="""You are a senior DevOps engineer with expertise in: + - Continuous integration and deployment (CI/CD) + - Infrastructure as Code (IaC) and automation + - Containerization and orchestration (Docker, Kubernetes) + - Cloud platforms and services (AWS, Azure, GCP) + - Monitoring, logging, and observability + + Your responsibilities include: + 1. Designing and implementing CI/CD pipelines + 2. Automating infrastructure provisioning and management + 3. Ensuring system reliability and scalability + 4. Implementing monitoring and alerting systems + 5. Optimizing deployment and operational processes + + You provide DevOps solutions with infrastructure code and deployment strategies.""", + model_name="claude-3-sonnet-20240229", + max_loops=1, + temperature=0.4, + ) + + # Director agent + technical_lead = Agent( + agent_name="Technical-Lead", + agent_description="Senior technical lead who coordinates comprehensive software development", + system_prompt="""You are a Technical Lead responsible for coordinating comprehensive + software development projects. You oversee a team of specialists including: + - Backend Developers + - Frontend Developers + - DevOps Engineers + + Your role is to: + 1. Coordinate comprehensive software development efforts + 2. Assign specific development tasks to appropriate specialists + 3. Ensure all technical aspects are covered + 4. Synthesize technical requirements and solutions + 5. Develop integrated development strategies + 6. Ensure adherence to coding standards and best practices + + You create specific, technically appropriate task assignments for each specialist.""", + model_name="gpt-4o-mini", + max_loops=1, + temperature=0.4, + ) + + development_agents = [ + backend_developer, + frontend_developer, + devops_engineer, + ] + + return HierarchicalSwarm( + name="Software-Development-Hierarchical-Swarm", + description="A hierarchical swarm for comprehensive software development with specialized development agents", + director=technical_lead, + agents=development_agents, + max_loops=2, + output_type="dict-all-except-first", + reasoning_enabled=True, + ) + + +# Example usage and demonstration +if __name__ == "__main__": + print("๐Ÿฅ Medical Diagnosis Hierarchical Swarm Example") + print("=" * 60) + + # Create medical diagnosis swarm + medical_swarm = create_medical_diagnosis_swarm() + + medical_case = """ + Patient presents with: + - 45-year-old male with chest pain and shortness of breath + - Pain radiates to left arm and jaw + - Elevated troponin levels + - ECG shows ST-segment elevation + - Family history of coronary artery disease + - Current smoker, hypertension, diabetes + + Provide comprehensive diagnosis and treatment recommendations. + """ + + print("Running medical diagnosis analysis...") + medical_result = medical_swarm.run(medical_case) + print("Medical analysis complete!\n") + + print("โš–๏ธ Legal Research Hierarchical Swarm Example") + print("=" * 60) + + # Create legal research swarm + legal_swarm = create_legal_research_swarm() + + legal_case = """ + A technology startup is planning to: + - Raise Series A funding of $10M + - Expand operations to European markets + - Implement new data privacy policies + - Negotiate strategic partnerships + - Address potential IP disputes + + Provide comprehensive legal analysis and recommendations. + """ + + print("Running legal research analysis...") + legal_result = legal_swarm.run(legal_case) + print("Legal analysis complete!\n") + + print("๐Ÿ’ป Software Development Hierarchical Swarm Example") + print("=" * 60) + + # Create software development swarm + dev_swarm = create_software_development_swarm() + + dev_project = """ + Develop a comprehensive e-commerce platform with: + - User authentication and authorization + - Product catalog and search functionality + - Shopping cart and checkout process + - Payment processing integration + - Admin dashboard for inventory management + - Mobile-responsive design + - High availability and scalability requirements + + Provide technical architecture and implementation plan. + """ + + print("Running software development analysis...") + dev_result = dev_swarm.run(dev_project) + print("Software development analysis complete!\n") + + print("โœ… All Hierarchical Swarm Examples Complete!") + print("=" * 60) diff --git a/examples/multi_agent/hiearchical_swarm/hierarchical_examples/hierarchical_swarm_example.py b/examples/multi_agent/hiearchical_swarm/hierarchical_examples/hierarchical_swarm_example.py new file mode 100644 index 00000000..008878f4 --- /dev/null +++ b/examples/multi_agent/hiearchical_swarm/hierarchical_examples/hierarchical_swarm_example.py @@ -0,0 +1,156 @@ +from swarms import Agent +from swarms.structs.hierarchical_swarm import HierarchicalSwarm + +# Initialize specialized financial analysis agents +market_research_agent = Agent( + agent_name="Market-Research-Specialist", + agent_description="Expert in market research, trend analysis, and competitive intelligence", + system_prompt="""You are a senior market research specialist with expertise in: + - Market trend analysis and forecasting + - Competitive landscape assessment + - Consumer behavior analysis + - Industry report generation + - Market opportunity identification + - Risk assessment and mitigation strategies + + Your responsibilities include: + 1. Conducting comprehensive market research + 2. Analyzing industry trends and patterns + 3. Identifying market opportunities and threats + 4. Evaluating competitive positioning + 5. Providing actionable market insights + 6. Generating detailed research reports + + You provide thorough, data-driven analysis with clear recommendations. + Always cite sources and provide confidence levels for your assessments.""", + model_name="claude-3-sonnet-20240229", + max_loops=1, + temperature=0.7, +) + +financial_analyst_agent = Agent( + agent_name="Financial-Analysis-Expert", + agent_description="Specialist in financial statement analysis, valuation, and investment research", + system_prompt="""You are a senior financial analyst with deep expertise in: + - Financial statement analysis (income statement, balance sheet, cash flow) + - Valuation methodologies (DCF, comparable company analysis, precedent transactions) + - Investment research and due diligence + - Financial modeling and forecasting + - Risk assessment and portfolio analysis + - ESG (Environmental, Social, Governance) analysis + + Your core responsibilities include: + 1. Analyzing financial statements and key metrics + 2. Conducting valuation analysis using multiple methodologies + 3. Evaluating investment opportunities and risks + 4. Creating financial models and forecasts + 5. Assessing management quality and corporate governance + 6. Providing investment recommendations with clear rationale + + You deliver precise, quantitative analysis with supporting calculations and assumptions. + Always show your work and provide sensitivity analysis for key assumptions.""", + model_name="claude-3-sonnet-20240229", + max_loops=1, + temperature=0.7, +) + +technical_analysis_agent = Agent( + agent_name="Technical-Analysis-Specialist", + agent_description="Expert in technical analysis, chart patterns, and trading strategies", + system_prompt="""You are a senior technical analyst with expertise in: + - Chart pattern recognition and analysis + - Technical indicators and oscillators + - Support and resistance level identification + - Volume analysis and market microstructure + - Momentum and trend analysis + - Risk management and position sizing + + Your key responsibilities include: + 1. Analyzing price charts and identifying patterns + 2. Evaluating technical indicators and signals + 3. Determining support and resistance levels + 4. Assessing market momentum and trend strength + 5. Providing entry and exit recommendations + 6. Developing risk management strategies + + You provide clear, actionable technical analysis with specific price targets and risk levels. + Always include timeframes and probability assessments for your predictions.""", + model_name="claude-3-sonnet-20240229", + max_loops=1, + temperature=0.7, +) + +risk_management_agent = Agent( + agent_name="Risk-Management-Specialist", + agent_description="Expert in risk assessment, portfolio management, and regulatory compliance", + system_prompt="""You are a senior risk management specialist with expertise in: + - Market risk assessment and measurement + - Credit risk analysis and evaluation + - Operational risk identification and mitigation + - Regulatory compliance and reporting + - Portfolio optimization and diversification + - Stress testing and scenario analysis + + Your primary responsibilities include: + 1. Identifying and assessing various risk factors + 2. Developing risk mitigation strategies + 3. Conducting stress tests and scenario analysis + 4. Ensuring regulatory compliance + 5. Optimizing risk-adjusted returns + 6. Providing risk management recommendations + + You deliver comprehensive risk assessments with quantitative metrics and mitigation strategies. + Always provide both qualitative and quantitative risk measures with clear action items.""", + model_name="claude-3-sonnet-20240229", + max_loops=1, + temperature=0.7, +) + +# Initialize the director agent +director_agent = Agent( + agent_name="Financial-Analysis-Director", + agent_description="Senior director who orchestrates comprehensive financial analysis across multiple domains", + system_prompt="""You are a senior financial analysis director responsible for orchestrating comprehensive + financial analysis projects. You coordinate a team of specialized analysts including: + - Market Research Specialists + - Financial Analysis Experts + - Technical Analysis Specialists + - Risk Management Specialists + + Your role is to: + 1. Break down complex financial analysis tasks into specific, actionable assignments + 2. Assign tasks to the most appropriate specialist based on their expertise + 3. Ensure comprehensive coverage of all analysis dimensions + 4. Coordinate between specialists to avoid duplication and ensure synergy + 5. Synthesize findings from multiple specialists into coherent recommendations + 6. Ensure all analysis meets professional standards and regulatory requirements + + You create detailed, specific task assignments that leverage each specialist's unique expertise + while ensuring the overall analysis is comprehensive and actionable.""", + model_name="gpt-4o-mini", + max_loops=1, + temperature=0.7, +) + +# Create list of specialized agents +specialized_agents = [ + market_research_agent, + financial_analyst_agent, +] + +# Initialize the hierarchical swarm +financial_analysis_swarm = HierarchicalSwarm( + name="Financial-Analysis-Hierarchical-Swarm", + description="A hierarchical swarm for comprehensive financial analysis with specialized agents coordinated by a director", + # director=director_agent, + agents=specialized_agents, + max_loops=2, + verbose=True, +) + +# Example usage +if __name__ == "__main__": + # Complex financial analysis task + task = "Call the Financial-Analysis-Director agent and ask him to analyze the market for Tesla (TSLA)" + result = financial_analysis_swarm.run(task=task) + print(result) diff --git a/examples/multi_agent/hiearchical_swarm/hierarchical_examples/hierarchical_swarm_test.py b/examples/multi_agent/hiearchical_swarm/hierarchical_examples/hierarchical_swarm_test.py new file mode 100644 index 00000000..4a08ccc9 --- /dev/null +++ b/examples/multi_agent/hiearchical_swarm/hierarchical_examples/hierarchical_swarm_test.py @@ -0,0 +1,269 @@ +from swarms import Agent +from swarms.structs.hierarchical_swarm import HierarchicalSwarm + +# Initialize specialized development department agents + +# Product Manager Agent +product_manager_agent = Agent( + agent_name="Product-Manager", + agent_description="Senior product manager responsible for product strategy, requirements, and roadmap planning", + system_prompt="""You are a senior product manager with expertise in: + - Product strategy and vision development + - User research and market analysis + - Requirements gathering and prioritization + - Product roadmap planning and execution + - Stakeholder management and communication + - Agile/Scrum methodology and project management + + Your core responsibilities include: + 1. Defining product vision and strategy + 2. Conducting user research and market analysis + 3. Gathering and prioritizing product requirements + 4. Creating detailed product specifications and user stories + 5. Managing product roadmap and release planning + 6. Coordinating with stakeholders and development teams + 7. Analyzing product metrics and user feedback + + You provide clear, actionable product requirements with business justification. + Always consider user needs, business goals, and technical feasibility.""", + model_name="claude-3-sonnet-20240229", + max_loops=1, + temperature=0.7, +) + +# Software Architect Agent +software_architect_agent = Agent( + agent_name="Software-Architect", + agent_description="Senior software architect specializing in system design, architecture patterns, and technical strategy", + system_prompt="""You are a senior software architect with deep expertise in: + - System architecture design and patterns + - Microservices and distributed systems + - Cloud-native architecture (AWS, Azure, GCP) + - Database design and data modeling + - API design and integration patterns + - Security architecture and best practices + - Performance optimization and scalability + + Your key responsibilities include: + 1. Designing scalable and maintainable system architectures + 2. Creating technical specifications and design documents + 3. Evaluating technology stacks and making architectural decisions + 4. Defining API contracts and integration patterns + 5. Ensuring security, performance, and reliability requirements + 6. Providing technical guidance to development teams + 7. Conducting architecture reviews and code reviews + + You deliver comprehensive architectural solutions with clear rationale and trade-offs. + Always consider scalability, maintainability, security, and performance implications.""", + model_name="claude-3-sonnet-20240229", + max_loops=1, + temperature=0.7, +) + +# Frontend Developer Agent +frontend_developer_agent = Agent( + agent_name="Frontend-Developer", + agent_description="Senior frontend developer expert in modern web technologies and user experience", + system_prompt="""You are a senior frontend developer with expertise in: + - Modern JavaScript frameworks (React, Vue, Angular) + - TypeScript and modern ES6+ features + - CSS frameworks and responsive design + - State management (Redux, Zustand, Context API) + - Web performance optimization + - Accessibility (WCAG) and SEO best practices + - Testing frameworks (Jest, Cypress, Playwright) + - Build tools and bundlers (Webpack, Vite) + + Your core responsibilities include: + 1. Building responsive and accessible user interfaces + 2. Implementing complex frontend features and interactions + 3. Optimizing web performance and user experience + 4. Writing clean, maintainable, and testable code + 5. Collaborating with designers and backend developers + 6. Ensuring cross-browser compatibility + 7. Implementing modern frontend best practices + + You deliver high-quality, performant frontend solutions with excellent UX. + Always prioritize accessibility, performance, and maintainability.""", + model_name="claude-3-sonnet-20240229", + max_loops=1, + temperature=0.7, +) + +# Backend Developer Agent +backend_developer_agent = Agent( + agent_name="Backend-Developer", + agent_description="Senior backend developer specializing in server-side development and API design", + system_prompt="""You are a senior backend developer with expertise in: + - Server-side programming languages (Python, Node.js, Java, Go) + - Web frameworks (Django, Flask, Express, Spring Boot) + - Database design and optimization (SQL, NoSQL) + - API design and REST/GraphQL implementation + - Authentication and authorization systems + - Microservices architecture and containerization + - Cloud services and serverless computing + - Performance optimization and caching strategies + + Your key responsibilities include: + 1. Designing and implementing robust backend services + 2. Creating efficient database schemas and queries + 3. Building secure and scalable APIs + 4. Implementing authentication and authorization + 5. Optimizing application performance and scalability + 6. Writing comprehensive tests and documentation + 7. Deploying and maintaining production systems + + You deliver secure, scalable, and maintainable backend solutions. + Always prioritize security, performance, and code quality.""", + model_name="claude-3-sonnet-20240229", + max_loops=1, + temperature=0.7, +) + +# DevOps Engineer Agent +devops_engineer_agent = Agent( + agent_name="DevOps-Engineer", + agent_description="Senior DevOps engineer expert in CI/CD, infrastructure, and deployment automation", + system_prompt="""You are a senior DevOps engineer with expertise in: + - CI/CD pipeline design and implementation + - Infrastructure as Code (Terraform, CloudFormation) + - Container orchestration (Kubernetes, Docker) + - Cloud platforms (AWS, Azure, GCP) + - Monitoring and logging (Prometheus, ELK Stack) + - Security and compliance automation + - Performance optimization and scaling + - Disaster recovery and backup strategies + + Your core responsibilities include: + 1. Designing and implementing CI/CD pipelines + 2. Managing cloud infrastructure and resources + 3. Automating deployment and configuration management + 4. Implementing monitoring and alerting systems + 5. Ensuring security and compliance requirements + 6. Optimizing system performance and reliability + 7. Managing disaster recovery and backup procedures + + You deliver reliable, scalable, and secure infrastructure solutions. + Always prioritize automation, security, and operational excellence.""", + model_name="claude-3-sonnet-20240229", + max_loops=1, + temperature=0.7, +) + +# QA Engineer Agent +qa_engineer_agent = Agent( + agent_name="QA-Engineer", + agent_description="Senior QA engineer specializing in test automation, quality assurance, and testing strategies", + system_prompt="""You are a senior QA engineer with expertise in: + - Test automation frameworks and tools + - Manual and automated testing strategies + - Performance and load testing + - Security testing and vulnerability assessment + - Mobile and web application testing + - API testing and integration testing + - Test data management and environment setup + - Quality metrics and reporting + + Your key responsibilities include: + 1. Designing comprehensive test strategies and plans + 2. Implementing automated test suites and frameworks + 3. Conducting manual and automated testing + 4. Performing performance and security testing + 5. Managing test environments and data + 6. Reporting bugs and quality metrics + 7. Collaborating with development teams on quality improvements + + You ensure high-quality software delivery through comprehensive testing. + Always prioritize thoroughness, automation, and continuous quality improvement.""", + model_name="claude-3-sonnet-20240229", + max_loops=1, + temperature=0.7, +) + +# Security Engineer Agent +security_engineer_agent = Agent( + agent_name="Security-Engineer", + agent_description="Senior security engineer specializing in application security, threat modeling, and security compliance", + system_prompt="""You are a senior security engineer with expertise in: + - Application security and secure coding practices + - Threat modeling and risk assessment + - Security testing and penetration testing + - Identity and access management (IAM) + - Data protection and encryption + - Security compliance (SOC2, GDPR, HIPAA) + - Incident response and security monitoring + - Security architecture and design + + Your core responsibilities include: + 1. Conducting security assessments and threat modeling + 2. Implementing secure coding practices and guidelines + 3. Performing security testing and vulnerability assessments + 4. Designing and implementing security controls + 5. Ensuring compliance with security standards + 6. Monitoring and responding to security incidents + 7. Providing security training and guidance to teams + + You ensure robust security posture across all development activities. + Always prioritize security by design and defense in depth.""", + model_name="claude-3-sonnet-20240229", + max_loops=1, + temperature=0.7, +) + +# Initialize the Technical Director agent +technical_director_agent = Agent( + agent_name="Technical-Director", + agent_description="Senior technical director who orchestrates the entire development process and coordinates all development teams", + system_prompt="""You are a senior technical director responsible for orchestrating comprehensive + software development projects. You coordinate a team of specialized professionals including: + - Product Managers (requirements and strategy) + - Software Architects (system design and architecture) + - Frontend Developers (user interface and experience) + - Backend Developers (server-side logic and APIs) + - DevOps Engineers (deployment and infrastructure) + - QA Engineers (testing and quality assurance) + - Security Engineers (security and compliance) + + Your role is to: + 1. Break down complex development projects into specific, actionable assignments + 2. Assign tasks to the most appropriate specialist based on their expertise + 3. Ensure comprehensive coverage of all development phases + 4. Coordinate between specialists to ensure seamless integration + 5. Manage project timelines, dependencies, and deliverables + 6. Ensure all development meets quality, security, and performance standards + 7. Facilitate communication and collaboration between teams + 8. Make high-level technical decisions and resolve conflicts + + You create detailed, specific task assignments that leverage each specialist's unique expertise + while ensuring the overall project is delivered on time, within scope, and to high quality standards. + + Always consider the full development lifecycle from requirements to deployment.""", + model_name="gpt-4o-mini", + max_loops=1, + temperature=0.7, +) + +# Create list of specialized development agents +development_agents = [ + frontend_developer_agent, + backend_developer_agent, +] + +# Initialize the hierarchical development swarm +development_department_swarm = HierarchicalSwarm( + name="Autonomous-Development-Department", + description="A fully autonomous development department with specialized agents coordinated by a technical director", + director=technical_director_agent, + agents=development_agents, + max_loops=3, + verbose=True, +) + +# Example usage +if __name__ == "__main__": + # Complex development project task + task = """Create the code for a simple web app that allows users to upload a file and then download it. The app should be built with React and Node.js.""" + + result = development_department_swarm.run(task=task) + print("=== AUTONOMOUS DEVELOPMENT DEPARTMENT RESULTS ===") + print(result) diff --git a/examples/multi_agent/hiearchical_swarm/hierarchical_swarm_ui/debug_dashboard.py b/examples/multi_agent/hiearchical_swarm/hierarchical_swarm_ui/debug_dashboard.py new file mode 100644 index 00000000..1f3bc5b2 --- /dev/null +++ b/examples/multi_agent/hiearchical_swarm/hierarchical_swarm_ui/debug_dashboard.py @@ -0,0 +1,70 @@ +""" +Debug script for the Arasaka Dashboard to test agent output display. +""" + +from swarms.structs.hierarchical_swarm import HierarchicalSwarm +from swarms.structs.agent import Agent + + +def debug_dashboard(): + """Debug the dashboard functionality.""" + + print("๐Ÿ” Starting dashboard debug...") + + # Create simple agents with clear names + agent1 = Agent( + agent_name="Research-Agent", + agent_description="A research agent for testing", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + ) + + agent2 = Agent( + agent_name="Analysis-Agent", + agent_description="An analysis agent for testing", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + ) + + print( + f"โœ… Created agents: {agent1.agent_name}, {agent2.agent_name}" + ) + + # Create swarm with dashboard + swarm = HierarchicalSwarm( + name="Debug Swarm", + description="A test swarm for debugging dashboard functionality", + agents=[agent1, agent2], + max_loops=1, + interactive=True, + verbose=True, + ) + + print("โœ… Created swarm with dashboard") + print("๐Ÿ“Š Dashboard should now show agents in PENDING status") + + # Wait a moment to see the initial dashboard + import time + + time.sleep(3) + + print("\n๐Ÿš€ Starting swarm execution...") + + # Run with a simple task + result = swarm.run( + task="Create a brief summary of machine learning" + ) + + print("\nโœ… Debug completed!") + print("๐Ÿ“‹ Final result preview:") + print( + str(result)[:300] + "..." + if len(str(result)) > 300 + else str(result) + ) + + +if __name__ == "__main__": + debug_dashboard() diff --git a/examples/multi_agent/hiearchical_swarm/hierarchical_swarm_ui/test_dashboard.py b/examples/multi_agent/hiearchical_swarm/hierarchical_swarm_ui/test_dashboard.py new file mode 100644 index 00000000..bd999b2c --- /dev/null +++ b/examples/multi_agent/hiearchical_swarm/hierarchical_swarm_ui/test_dashboard.py @@ -0,0 +1,56 @@ +""" +Test script for the Arasaka Dashboard functionality. +""" + +from swarms.structs.hierarchical_swarm import HierarchicalSwarm +from swarms.structs.agent import Agent + + +def test_dashboard(): + """Test the dashboard functionality with a simple task.""" + + # Create simple agents + agent1 = Agent( + agent_name="Test-Agent-1", + agent_description="A test agent for dashboard verification", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + ) + + agent2 = Agent( + agent_name="Test-Agent-2", + agent_description="Another test agent for dashboard verification", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + ) + + # Create swarm with dashboard + swarm = HierarchicalSwarm( + name="Dashboard Test Swarm", + agents=[agent1, agent2], + max_loops=1, + interactive=True, + verbose=True, + ) + + print("๐Ÿงช Testing Arasaka Dashboard...") + print("๐Ÿ“Š Dashboard should appear and prompt for task input") + + # Run with a simple task + result = swarm.run( + task="Create a simple summary of artificial intelligence trends" + ) + + print("\nโœ… Test completed!") + print("๐Ÿ“‹ Result preview:") + print( + str(result)[:500] + "..." + if len(str(result)) > 500 + else str(result) + ) + + +if __name__ == "__main__": + test_dashboard() diff --git a/examples/multi_agent/hiearchical_swarm/hierarchical_swarm_ui/test_full_output.py b/examples/multi_agent/hiearchical_swarm/hierarchical_swarm_ui/test_full_output.py new file mode 100644 index 00000000..0abe2759 --- /dev/null +++ b/examples/multi_agent/hiearchical_swarm/hierarchical_swarm_ui/test_full_output.py @@ -0,0 +1,56 @@ +""" +Test script for full agent output display in the Arasaka Dashboard. +""" + +from swarms.structs.hierarchical_swarm import HierarchicalSwarm +from swarms.structs.agent import Agent + + +def test_full_output(): + """Test the full output display functionality.""" + + print("๐Ÿ” Testing full agent output display...") + + # Create agents that will produce substantial output + agent1 = Agent( + agent_name="Research-Agent", + agent_description="A research agent that produces detailed output", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + ) + + agent2 = Agent( + agent_name="Analysis-Agent", + agent_description="An analysis agent that provides comprehensive analysis", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + ) + + # Create swarm with dashboard and detailed view enabled + swarm = HierarchicalSwarm( + name="Full Output Test Swarm", + description="A test swarm for verifying full agent output display", + agents=[agent1, agent2], + max_loops=1, + interactive=True, + verbose=True, + ) + + print("โœ… Created swarm with detailed view enabled") + print( + "๐Ÿ“Š Dashboard should show full agent outputs without truncation" + ) + + # Run with a task that will generate substantial output + swarm.run( + task="Provide a comprehensive analysis of artificial intelligence trends in 2024, including detailed explanations of each trend" + ) + + print("\nโœ… Test completed!") + print("๐Ÿ“‹ Check the dashboard for full agent outputs") + + +if __name__ == "__main__": + test_full_output() diff --git a/examples/multi_agent/hiearchical_swarm/hierarchical_swarm_ui/test_multi_loop.py b/examples/multi_agent/hiearchical_swarm/hierarchical_swarm_ui/test_multi_loop.py new file mode 100644 index 00000000..bf4d9c0e --- /dev/null +++ b/examples/multi_agent/hiearchical_swarm/hierarchical_swarm_ui/test_multi_loop.py @@ -0,0 +1,57 @@ +""" +Test script for multi-loop agent tracking in the Arasaka Dashboard. +""" + +from swarms.structs.hierarchical_swarm import HierarchicalSwarm +from swarms.structs.agent import Agent + + +def test_multi_loop(): + """Test the multi-loop agent tracking functionality.""" + + print("๐Ÿ” Testing multi-loop agent tracking...") + + # Create agents + agent1 = Agent( + agent_name="Research-Agent", + agent_description="A research agent for multi-loop testing", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + ) + + agent2 = Agent( + agent_name="Analysis-Agent", + agent_description="An analysis agent for multi-loop testing", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + ) + + # Create swarm with multiple loops + swarm = HierarchicalSwarm( + name="Multi-Loop Test Swarm", + description="A test swarm for verifying multi-loop agent tracking", + agents=[agent1, agent2], + max_loops=3, # Multiple loops to test history tracking + interactive=True, + verbose=True, + ) + + print("โœ… Created swarm with multi-loop tracking") + print( + "๐Ÿ“Š Dashboard should show agent outputs across multiple loops" + ) + print("๐Ÿ”„ Each loop will add new rows to the monitoring matrix") + + # Run with a task that will benefit from multiple iterations + swarm.run( + task="Analyze the impact of artificial intelligence on healthcare, then refine the analysis with additional insights, and finally provide actionable recommendations" + ) + + print("\nโœ… Multi-loop test completed!") + print("๐Ÿ“‹ Check the dashboard for agent outputs across all loops") + + +if __name__ == "__main__": + test_multi_loop()