From d1851804303586e34c998137dd774054818b7d24 Mon Sep 17 00:00:00 2001 From: Steve-Dusty Date: Thu, 6 Nov 2025 23:51:33 -0800 Subject: [PATCH 01/11] removed vllm --- README.md | 1 - docs/examples/index.md | 1 - .../examples/custom_base_url_example.md | 2 +- docs/swarms/examples/llama4.md | 14 +- docs/swarms/examples/model_providers.md | 4 +- docs/swarms/examples/vllm.md | 429 ------------------ docs/swarms/examples/vllm_integration.md | 194 -------- examples/README.md | 2 +- examples/demos/README.md | 1 - examples/demos/finance/swarms_of_vllm.py | 214 --------- test.py | 13 + 11 files changed, 22 insertions(+), 853 deletions(-) delete mode 100644 docs/swarms/examples/vllm.md delete mode 100644 docs/swarms/examples/vllm_integration.md delete mode 100644 examples/demos/finance/swarms_of_vllm.py create mode 100644 test.py diff --git a/README.md b/README.md index dd3de49d..3ae1559b 100644 --- a/README.md +++ b/README.md @@ -829,7 +829,6 @@ Explore comprehensive examples and tutorials to learn how to use Swarms effectiv | **Model Providers** | Ollama | Local Ollama model integration | [Ollama Examples](https://docs.swarms.world/en/latest/swarms/examples/ollama/) | | **Model Providers** | OpenRouter | OpenRouter model integration | [OpenRouter Examples](https://docs.swarms.world/en/latest/swarms/examples/openrouter/) | | **Model Providers** | XAI | XAI model integration | [XAI Examples](https://docs.swarms.world/en/latest/swarms/examples/xai/) | -| **Model Providers** | VLLM | VLLM integration | [VLLM Examples](https://docs.swarms.world/en/latest/swarms/examples/vllm_integration/) | | **Model Providers** | Llama4 | Llama4 model integration | [Llama4 Examples](https://docs.swarms.world/en/latest/swarms/examples/llama4/) | | **Multi-Agent Architecture** | HierarchicalSwarm | Hierarchical agent orchestration | [HierarchicalSwarm Examples](https://docs.swarms.world/en/latest/swarms/examples/hierarchical_swarm_example/) | | **Multi-Agent Architecture** | Hybrid Hierarchical-Cluster Swarm | Advanced hierarchical patterns | [HHCS Examples](https://docs.swarms.world/en/latest/swarms/examples/hhcs_examples/) | diff --git a/docs/examples/index.md b/docs/examples/index.md index bb1ed712..789e4d33 100644 --- a/docs/examples/index.md +++ b/docs/examples/index.md @@ -58,7 +58,6 @@ This index organizes **100+ production-ready examples** from our [Swarms Example | Claude | [Claude 4 Example](https://github.com/kyegomez/swarms/blob/master/examples/models/claude_4_example.py) | Anthropic Claude 4 model integration for advanced reasoning capabilities | | Swarms Claude | [Swarms Claude Example](https://github.com/kyegomez/swarms/blob/master/examples/models/swarms_claude_example.py) | Optimized Claude integration within the Swarms framework | | Lumo | [Lumo Example](https://github.com/kyegomez/swarms/blob/master/examples/models/lumo_example.py) | Lumo AI model integration for specialized tasks | -| VLLM | [VLLM Example](https://github.com/kyegomez/swarms/blob/master/examples/models/vllm_example.py) | High-performance inference using VLLM for large language models | | Llama4 | [LiteLLM Example](https://github.com/kyegomez/swarms/blob/master/examples/models/llama4_examples/litellm_example.py) | Llama4 model integration using LiteLLM for efficient inference | ### Tools and Function Calling diff --git a/docs/swarms/examples/custom_base_url_example.md b/docs/swarms/examples/custom_base_url_example.md index c7c32947..4d48bba7 100644 --- a/docs/swarms/examples/custom_base_url_example.md +++ b/docs/swarms/examples/custom_base_url_example.md @@ -130,7 +130,7 @@ hf_agent = Agent( ### 4. Custom Local Endpoint ```python -# Using a local model server (e.g., vLLM, Ollama, etc.) +# Using a local model server (e.g., Ollama, etc.) local_agent = Agent( agent_name="Local-Agent", agent_description="Agent using local model endpoint", diff --git a/docs/swarms/examples/llama4.md b/docs/swarms/examples/llama4.md index 1e2b9e77..a59be80b 100644 --- a/docs/swarms/examples/llama4.md +++ b/docs/swarms/examples/llama4.md @@ -13,10 +13,11 @@ Here's a simple example of integrating Llama4 model for crypto risk analysis: ```python from dotenv import load_dotenv from swarms import Agent -from swarms.utils.vllm_wrapper import VLLM load_dotenv() -model = VLLM(model_name="meta-llama/Llama-4-Maverick-17B-128E") + +# Initialize your model here using your preferred inference method +# For example, using litellm or another compatible wrapper ``` ## Available Models @@ -88,9 +89,7 @@ agent = Agent( ```python from dotenv import load_dotenv - from swarms import Agent -from swarms.utils.vllm_wrapper import VLLM load_dotenv() @@ -126,15 +125,14 @@ Provide detailed, balanced analysis with both risks and potential mitigations. Base your analysis on established crypto market principles and current market conditions. """ -model = VLLM(model_name="meta-llama/Llama-4-Maverick-17B-128E") - # Initialize the agent with custom prompt +# Note: Use your preferred model provider (OpenAI, Anthropic, Groq, etc.) agent = Agent( agent_name="Crypto-Risk-Analysis-Agent", agent_description="Agent for analyzing risks in cryptocurrency investments", system_prompt=CRYPTO_RISK_ANALYSIS_PROMPT, + model_name="gpt-4o-mini", # or any other supported model max_loops=1, - llm=model, ) print( @@ -153,7 +151,7 @@ print( The `max_loops` parameter determines how many times the agent will iterate through its thinking process. In this example, it's set to 1 for a single pass analysis. ??? question "Can I use a different model?" - Yes, you can replace the VLLM wrapper with other compatible models. Just ensure you update the model initialization accordingly. + Yes, you can use any supported model provider (OpenAI, Anthropic, Groq, etc.). Just ensure you set the appropriate `model_name` parameter. ??? question "How do I customize the system prompt?" You can modify the `CRYPTO_RISK_ANALYSIS_PROMPT` string to match your specific use case while maintaining the structured format. diff --git a/docs/swarms/examples/model_providers.md b/docs/swarms/examples/model_providers.md index c3b64fdb..95ebde89 100644 --- a/docs/swarms/examples/model_providers.md +++ b/docs/swarms/examples/model_providers.md @@ -14,7 +14,6 @@ Swarms supports a vast array of model providers, giving you the flexibility to c | **Ollama** | Local model deployment platform allowing you to run open-source models on your own infrastructure. No API keys required. | [Ollama Integration](ollama.md) | | **OpenRouter** | Unified API gateway providing access to hundreds of models from various providers through a single interface. | [OpenRouter Integration](openrouter.md) | | **XAI** | xAI's Grok models offering unique capabilities for research, analysis, and creative tasks with advanced reasoning abilities. | [XAI Integration](xai.md) | -| **vLLM** | High-performance inference library for serving large language models with optimized memory usage and throughput. | [vLLM Integration](vllm_integration.md) | | **Llama4** | Meta's latest open-source language models including Llama-4-Maverick and Llama-4-Scout variants with expert routing capabilities. | [Llama4 Integration](llama4.md) | | **Azure OpenAI** | Enterprise-grade OpenAI models through Microsoft's cloud infrastructure with enhanced security, compliance, and enterprise features. | [Azure Integration](azure.md) | @@ -63,7 +62,6 @@ response = agent.run("Your query here") - **Groq**: Ultra-fast inference -- **vLLM**: Optimized for high throughput ### For Specialized Tasks @@ -106,7 +104,7 @@ AZURE_API_VERSION=2024-02-15-preview ``` !!! note "No API Key Required" - Ollama and vLLM can be run locally without API keys, making them perfect for development and testing. + Ollama can be run locally without API keys, making it perfect for development and testing. ## Advanced Features diff --git a/docs/swarms/examples/vllm.md b/docs/swarms/examples/vllm.md deleted file mode 100644 index 11df0aab..00000000 --- a/docs/swarms/examples/vllm.md +++ /dev/null @@ -1,429 +0,0 @@ -# VLLM Swarm Agents - -!!! tip "Quick Summary" - This guide demonstrates how to create a sophisticated multi-agent system using VLLM and Swarms for comprehensive stock market analysis. You'll learn how to configure and orchestrate multiple AI agents working together to provide deep market insights. - -## Overview - -The example showcases how to build a stock analysis system with 5 specialized agents: - -- Technical Analysis Agent -- Fundamental Analysis Agent -- Market Sentiment Agent -- Quantitative Strategy Agent -- Portfolio Strategy Agent - -Each agent has specific expertise and works collaboratively through a concurrent workflow. - -## Prerequisites - -!!! warning "Requirements" - Before starting, ensure you have: - - - Python 3.7 or higher - - The Swarms package installed - - Access to VLLM compatible models - - Sufficient compute resources for running VLLM - -## Installation - -!!! example "Setup Steps" - - 1. Install the Swarms package: - ```bash - pip install swarms - ``` - - 2. Install VLLM dependencies (if not already installed): - ```bash - pip install vllm - ``` - -## Basic Usage - -Here's a complete example of setting up the stock analysis swarm: - -```python -from swarms import Agent, ConcurrentWorkflow -from swarms.utils.vllm_wrapper import VLLMWrapper - -# Initialize the VLLM wrapper -vllm = VLLMWrapper( - model_name="meta-llama/Llama-2-7b-chat-hf", - system_prompt="You are a helpful assistant.", -) -``` - -!!! note "Model Selection" - The example uses Llama-2-7b-chat, but you can use any VLLM-compatible model. Make sure you have the necessary permissions and resources to run your chosen model. - -## Agent Configuration - -### Technical Analysis Agent - -```python -technical_analyst = Agent( - agent_name="Technical-Analysis-Agent", - agent_description="Expert in technical analysis and chart patterns", - system_prompt="""You are an expert Technical Analysis Agent specializing in market technicals and chart patterns. Your responsibilities include: - -1. PRICE ACTION ANALYSIS -- Identify key support and resistance levels -- Analyze price trends and momentum -- Detect chart patterns (e.g., head & shoulders, triangles, flags) -- Evaluate volume patterns and their implications - -2. TECHNICAL INDICATORS -- Calculate and interpret moving averages (SMA, EMA) -- Analyze momentum indicators (RSI, MACD, Stochastic) -- Evaluate volume indicators (OBV, Volume Profile) -- Monitor volatility indicators (Bollinger Bands, ATR) - -3. TRADING SIGNALS -- Generate clear buy/sell signals based on technical criteria -- Identify potential entry and exit points -- Set appropriate stop-loss and take-profit levels -- Calculate position sizing recommendations - -4. RISK MANAGEMENT -- Assess market volatility and trend strength -- Identify potential reversal points -- Calculate risk/reward ratios for trades -- Suggest position sizing based on risk parameters - -Your analysis should be data-driven, precise, and actionable. Always include specific price levels, time frames, and risk parameters in your recommendations.""", - max_loops=1, - llm=vllm, -) -``` - -!!! tip "Agent Customization" - Each agent can be customized with different: - - - System prompts - - - Temperature settings - - - Max token limits - - - Response formats - -## Running the Swarm - -To execute the swarm analysis: - -```python -swarm = ConcurrentWorkflow( - name="Stock-Analysis-Swarm", - description="A swarm of agents that analyze stocks and provide comprehensive analysis.", - agents=stock_analysis_agents, -) - -# Run the analysis -response = swarm.run("Analyze the best etfs for gold and other similar commodities in volatile markets") -``` - - - -## Full Code Example - -```python -from swarms import Agent, ConcurrentWorkflow -from swarms.utils.vllm_wrapper import VLLMWrapper - -# Initialize the VLLM wrapper -vllm = VLLMWrapper( - model_name="meta-llama/Llama-2-7b-chat-hf", - system_prompt="You are a helpful assistant.", -) - -# Technical Analysis Agent -technical_analyst = Agent( - agent_name="Technical-Analysis-Agent", - agent_description="Expert in technical analysis and chart patterns", - system_prompt="""You are an expert Technical Analysis Agent specializing in market technicals and chart patterns. Your responsibilities include: - -1. PRICE ACTION ANALYSIS -- Identify key support and resistance levels -- Analyze price trends and momentum -- Detect chart patterns (e.g., head & shoulders, triangles, flags) -- Evaluate volume patterns and their implications - -2. TECHNICAL INDICATORS -- Calculate and interpret moving averages (SMA, EMA) -- Analyze momentum indicators (RSI, MACD, Stochastic) -- Evaluate volume indicators (OBV, Volume Profile) -- Monitor volatility indicators (Bollinger Bands, ATR) - -3. TRADING SIGNALS -- Generate clear buy/sell signals based on technical criteria -- Identify potential entry and exit points -- Set appropriate stop-loss and take-profit levels -- Calculate position sizing recommendations - -4. RISK MANAGEMENT -- Assess market volatility and trend strength -- Identify potential reversal points -- Calculate risk/reward ratios for trades -- Suggest position sizing based on risk parameters - -Your analysis should be data-driven, precise, and actionable. Always include specific price levels, time frames, and risk parameters in your recommendations.""", - max_loops=1, - llm=vllm, -) - -# Fundamental Analysis Agent -fundamental_analyst = Agent( - agent_name="Fundamental-Analysis-Agent", - agent_description="Expert in company fundamentals and valuation", - system_prompt="""You are an expert Fundamental Analysis Agent specializing in company valuation and financial metrics. Your core responsibilities include: - -1. FINANCIAL STATEMENT ANALYSIS -- Analyze income statements, balance sheets, and cash flow statements -- Calculate and interpret key financial ratios -- Evaluate revenue growth and profit margins -- Assess company's debt levels and cash position - -2. VALUATION METRICS -- Calculate fair value using multiple valuation methods: - * Discounted Cash Flow (DCF) - * Price-to-Earnings (P/E) - * Price-to-Book (P/B) - * Enterprise Value/EBITDA -- Compare valuations against industry peers - -3. BUSINESS MODEL ASSESSMENT -- Evaluate competitive advantages and market position -- Analyze industry dynamics and market share -- Assess management quality and corporate governance -- Identify potential risks and growth opportunities - -4. ECONOMIC CONTEXT -- Consider macroeconomic factors affecting the company -- Analyze industry cycles and trends -- Evaluate regulatory environment and compliance -- Assess global market conditions - -Your analysis should be comprehensive, focusing on both quantitative metrics and qualitative factors that impact long-term value.""", - max_loops=1, - llm=vllm, -) - -# Market Sentiment Agent -sentiment_analyst = Agent( - agent_name="Market-Sentiment-Agent", - agent_description="Expert in market psychology and sentiment analysis", - system_prompt="""You are an expert Market Sentiment Agent specializing in analyzing market psychology and investor behavior. Your key responsibilities include: - -1. SENTIMENT INDICATORS -- Monitor and interpret market sentiment indicators: - * VIX (Fear Index) - * Put/Call Ratio - * Market Breadth - * Investor Surveys -- Track institutional vs retail investor behavior - -2. NEWS AND SOCIAL MEDIA ANALYSIS -- Analyze news flow and media sentiment -- Monitor social media trends and discussions -- Track analyst recommendations and changes -- Evaluate corporate insider trading patterns - -3. MARKET POSITIONING -- Assess hedge fund positioning and exposure -- Monitor short interest and short squeeze potential -- Track fund flows and asset allocation trends -- Analyze options market sentiment - -4. CONTRARIAN SIGNALS -- Identify extreme sentiment readings -- Detect potential market turning points -- Analyze historical sentiment patterns -- Provide contrarian trading opportunities - -Your analysis should combine quantitative sentiment metrics with qualitative assessment of market psychology and crowd behavior.""", - max_loops=1, - llm=vllm, -) - -# Quantitative Strategy Agent -quant_analyst = Agent( - agent_name="Quantitative-Strategy-Agent", - agent_description="Expert in quantitative analysis and algorithmic strategies", - system_prompt="""You are an expert Quantitative Strategy Agent specializing in data-driven investment strategies. Your primary responsibilities include: - -1. FACTOR ANALYSIS -- Analyze and monitor factor performance: - * Value - * Momentum - * Quality - * Size - * Low Volatility -- Calculate factor exposures and correlations - -2. STATISTICAL ANALYSIS -- Perform statistical arbitrage analysis -- Calculate and monitor pair trading opportunities -- Analyze market anomalies and inefficiencies -- Develop mean reversion strategies - -3. RISK MODELING -- Build and maintain risk models -- Calculate portfolio optimization metrics -- Monitor correlation matrices -- Analyze tail risk and stress scenarios - -4. ALGORITHMIC STRATEGIES -- Develop systematic trading strategies -- Backtest and validate trading algorithms -- Monitor strategy performance metrics -- Optimize execution algorithms - -Your analysis should be purely quantitative, based on statistical evidence and mathematical models rather than subjective opinions.""", - max_loops=1, - llm=vllm, -) - -# Portfolio Strategy Agent -portfolio_strategist = Agent( - agent_name="Portfolio-Strategy-Agent", - agent_description="Expert in portfolio management and asset allocation", - system_prompt="""You are an expert Portfolio Strategy Agent specializing in portfolio construction and management. Your core responsibilities include: - -1. ASSET ALLOCATION -- Develop strategic asset allocation frameworks -- Recommend tactical asset allocation shifts -- Optimize portfolio weightings -- Balance risk and return objectives - -2. PORTFOLIO ANALYSIS -- Calculate portfolio risk metrics -- Monitor sector and factor exposures -- Analyze portfolio correlation matrix -- Track performance attribution - -3. RISK MANAGEMENT -- Implement portfolio hedging strategies -- Monitor and adjust position sizing -- Set stop-loss and rebalancing rules -- Develop drawdown protection strategies - -4. PORTFOLIO OPTIMIZATION -- Calculate efficient frontier analysis -- Optimize for various objectives: - * Maximum Sharpe Ratio - * Minimum Volatility - * Maximum Diversification -- Consider transaction costs and taxes - -Your recommendations should focus on portfolio-level decisions that optimize risk-adjusted returns while meeting specific investment objectives.""", - max_loops=1, - llm=vllm, -) - -# Create a list of all agents -stock_analysis_agents = [ - technical_analyst, - fundamental_analyst, - sentiment_analyst, - quant_analyst, - portfolio_strategist -] - -swarm = ConcurrentWorkflow( - name="Stock-Analysis-Swarm", - description="A swarm of agents that analyze stocks and provide a comprehensive analysis of the current trends and opportunities.", - agents=stock_analysis_agents, -) - -swarm.run("Analyze the best etfs for gold and other similiar commodities in volatile markets") -``` - -## Best Practices - -!!! success "Optimization Tips" - 1. **Agent Design** - - Keep system prompts focused and specific - - - Use clear role definitions - - - Include error handling guidelines - - 2. **Resource Management** - - - Monitor memory usage with large models - - - Implement proper cleanup procedures - - - Use batching for multiple queries - - 3. **Output Handling** - - - Implement proper logging - - - Format outputs consistently - - - Include error checking - -## Common Issues and Solutions - -!!! warning "Troubleshooting" - Common issues you might encounter: - - 1. **Memory Issues** - - - *Problem*: VLLM consuming too much memory - - - *Solution*: Adjust batch sizes and model parameters - - 2. **Agent Coordination** - - - *Problem*: Agents providing conflicting information - - - *Solution*: Implement consensus mechanisms or priority rules - - 3. **Performance** - - - *Problem*: Slow response times - - - *Solution*: Use proper batching and optimize model loading - -## FAQ - -??? question "Can I use different models for different agents?" - Yes, you can initialize multiple VLLM wrappers with different models for each agent. However, be mindful of memory usage. - -??? question "How many agents can run concurrently?" - The number depends on your hardware resources. Start with 3-5 agents and scale based on performance. - -??? question "Can I customize agent communication patterns?" - Yes, you can modify the ConcurrentWorkflow class or create custom workflows for specific communication patterns. - -## Advanced Configuration - -!!! example "Extended Settings" - ```python - vllm = VLLMWrapper( - model_name="meta-llama/Llama-2-7b-chat-hf", - system_prompt="You are a helpful assistant.", - temperature=0.7, - max_tokens=2048, - top_p=0.95, - ) - ``` - -## Contributing - -!!! info "Get Involved" - We welcome contributions! Here's how you can help: - - 1. Report bugs and issues - 2. Submit feature requests - 3. Contribute to documentation - 4. Share example use cases - -## Resources - -!!! abstract "Additional Reading" - - [VLLM Documentation](https://docs.vllm.ai/en/latest/) - \ No newline at end of file diff --git a/docs/swarms/examples/vllm_integration.md b/docs/swarms/examples/vllm_integration.md deleted file mode 100644 index c270e954..00000000 --- a/docs/swarms/examples/vllm_integration.md +++ /dev/null @@ -1,194 +0,0 @@ - - -# vLLM Integration Guide - -!!! info "Overview" - vLLM is a high-performance and easy-to-use library for LLM inference and serving. This guide explains how to integrate vLLM with Swarms for efficient, production-grade language model deployment. - - -## Installation - -!!! note "Prerequisites" - Before you begin, make sure you have Python 3.8+ installed on your system. - -=== "pip" - ```bash - pip install -U vllm swarms - ``` - -=== "poetry" - ```bash - poetry add vllm swarms - ``` - -## Basic Usage - -Here's a simple example of how to use vLLM with Swarms: - -```python title="basic_usage.py" -from swarms.utils.vllm_wrapper import VLLMWrapper - -# Initialize the vLLM wrapper -vllm = VLLMWrapper( - model_name="meta-llama/Llama-2-7b-chat-hf", - system_prompt="You are a helpful assistant.", - temperature=0.7, - max_tokens=4000 -) - -# Run inference -response = vllm.run("What is the capital of France?") -print(response) -``` - -## VLLMWrapper Class - -!!! abstract "Class Overview" - The `VLLMWrapper` class provides a convenient interface for working with vLLM models. - -### Key Parameters - -| Parameter | Type | Description | Default | -|-----------|------|-------------|---------| -| `model_name` | str | Name of the model to use | "meta-llama/Llama-2-7b-chat-hf" | -| `system_prompt` | str | System prompt to use | None | -| `stream` | bool | Whether to stream the output | False | -| `temperature` | float | Sampling temperature | 0.5 | -| `max_tokens` | int | Maximum number of tokens to generate | 4000 | - -### Example with Custom Parameters - -```python title="custom_parameters.py" -vllm = VLLMWrapper( - model_name="meta-llama/Llama-2-13b-chat-hf", - system_prompt="You are an expert in artificial intelligence.", - temperature=0.8, - max_tokens=2000 -) -``` - -## Integration with Agents - -You can easily integrate vLLM with Swarms agents for more complex workflows: - -```python title="agent_integration.py" -from swarms import Agent -from swarms.utils.vllm_wrapper import VLLMWrapper - -# Initialize vLLM -vllm = VLLMWrapper( - model_name="meta-llama/Llama-2-7b-chat-hf", - system_prompt="You are a helpful assistant." -) - -# Create an agent with vLLM -agent = Agent( - agent_name="Research-Agent", - agent_description="Expert in conducting research and analysis", - system_prompt="""You are an expert research agent. Your tasks include: - 1. Analyzing complex topics - 2. Providing detailed summaries - 3. Making data-driven recommendations""", - llm=vllm, - max_loops=1 -) - -# Run the agent -response = agent.run("Research the impact of AI on healthcare") -``` - -## Advanced Features - -### Batch Processing - -!!! tip "Performance Optimization" - Use batch processing for efficient handling of multiple tasks simultaneously. - -```python title="batch_processing.py" -tasks = [ - "What is machine learning?", - "Explain neural networks", - "Describe deep learning" -] - -results = vllm.batched_run(tasks, batch_size=3) -``` - -### Error Handling - -!!! warning "Error Management" - Always implement proper error handling in production environments. - -```python title="error_handling.py" -from loguru import logger - -try: - response = vllm.run("Complex task") -except Exception as error: - logger.error(f"Error occurred: {error}") -``` - -## Best Practices - -!!! success "Recommended Practices" - === "Model Selection" - - Choose appropriate model sizes based on your requirements - - Consider the trade-off between model size and inference speed - - === "System Resources" - - Ensure sufficient GPU memory for your chosen model - - Monitor resource usage during batch processing - - === "Prompt Engineering" - - Use clear and specific system prompts - - Structure user prompts for optimal results - - === "Error Handling" - - Implement proper error handling and logging - - Set up monitoring for production deployments - - === "Performance" - - Use batch processing for multiple tasks - - Adjust max_tokens based on your use case - - Fine-tune temperature for optimal output quality - -## Example: Multi-Agent System - -Here's an example of creating a multi-agent system using vLLM: - -```python title="multi_agent_system.py" -from swarms import Agent, ConcurrentWorkflow -from swarms.utils.vllm_wrapper import VLLMWrapper - -# Initialize vLLM -vllm = VLLMWrapper( - model_name="meta-llama/Llama-2-7b-chat-hf", - system_prompt="You are a helpful assistant." -) - -# Create specialized agents -research_agent = Agent( - agent_name="Research-Agent", - agent_description="Expert in research", - system_prompt="You are a research expert.", - llm=vllm -) - -analysis_agent = Agent( - agent_name="Analysis-Agent", - agent_description="Expert in analysis", - system_prompt="You are an analysis expert.", - llm=vllm -) - -# Create a workflow -agents = [research_agent, analysis_agent] -workflow = ConcurrentWorkflow( - name="Research-Analysis-Workflow", - description="Comprehensive research and analysis workflow", - agents=agents -) - -# Run the workflow -result = workflow.run("Analyze the impact of renewable energy") -``` \ No newline at end of file diff --git a/examples/README.md b/examples/README.md index b595dc76..27845e5e 100644 --- a/examples/README.md +++ b/examples/README.md @@ -18,7 +18,7 @@ This directory contains comprehensive examples demonstrating various capabilitie ### Model Integrations -- **[models/](models/)** - Various model integrations including Cerebras, GPT-5, GPT-OSS, Llama 4, Lumo, Ollama, and VLLM implementations with concurrent processing examples and provider-specific configurations. +- **[models/](models/)** - Various model integrations including Cerebras, GPT-5, GPT-OSS, Llama 4, Lumo, and Ollama implementations with concurrent processing examples and provider-specific configurations. ### API & Protocols diff --git a/examples/demos/README.md b/examples/demos/README.md index 1fbccc7d..360b6f3a 100644 --- a/examples/demos/README.md +++ b/examples/demos/README.md @@ -20,7 +20,6 @@ This directory contains comprehensive demonstration examples showcasing various ## Finance - [sentiment_news_analysis.py](finance/sentiment_news_analysis.py) - Financial sentiment analysis -- [swarms_of_vllm.py](finance/swarms_of_vllm.py) - VLLM-based financial swarms ## Hackathon Examples - [fraud.py](hackathon_feb16/fraud.py) - Fraud detection system diff --git a/examples/demos/finance/swarms_of_vllm.py b/examples/demos/finance/swarms_of_vllm.py deleted file mode 100644 index 89191ab0..00000000 --- a/examples/demos/finance/swarms_of_vllm.py +++ /dev/null @@ -1,214 +0,0 @@ -from swarms import Agent, ConcurrentWorkflow -from swarms.utils.vllm_wrapper import VLLMWrapper -from dotenv import load_dotenv - -load_dotenv() - -# Initialize the VLLM wrapper -vllm = VLLMWrapper( - model_name="meta-llama/Llama-2-7b-chat-hf", - system_prompt="You are a helpful assistant.", -) - -# Technical Analysis Agent -technical_analyst = Agent( - agent_name="Technical-Analysis-Agent", - agent_description="Expert in technical analysis and chart patterns", - system_prompt="""You are an expert Technical Analysis Agent specializing in market technicals and chart patterns. Your responsibilities include: - -1. PRICE ACTION ANALYSIS -- Identify key support and resistance levels -- Analyze price trends and momentum -- Detect chart patterns (e.g., head & shoulders, triangles, flags) -- Evaluate volume patterns and their implications - -2. TECHNICAL INDICATORS -- Calculate and interpret moving averages (SMA, EMA) -- Analyze momentum indicators (RSI, MACD, Stochastic) -- Evaluate volume indicators (OBV, Volume Profile) -- Monitor volatility indicators (Bollinger Bands, ATR) - -3. TRADING SIGNALS -- Generate clear buy/sell signals based on technical criteria -- Identify potential entry and exit points -- Set appropriate stop-loss and take-profit levels -- Calculate position sizing recommendations - -4. RISK MANAGEMENT -- Assess market volatility and trend strength -- Identify potential reversal points -- Calculate risk/reward ratios for trades -- Suggest position sizing based on risk parameters - -Your analysis should be data-driven, precise, and actionable. Always include specific price levels, time frames, and risk parameters in your recommendations.""", - max_loops=1, - llm=vllm, -) - -# Fundamental Analysis Agent -fundamental_analyst = Agent( - agent_name="Fundamental-Analysis-Agent", - agent_description="Expert in company fundamentals and valuation", - system_prompt="""You are an expert Fundamental Analysis Agent specializing in company valuation and financial metrics. Your core responsibilities include: - -1. FINANCIAL STATEMENT ANALYSIS -- Analyze income statements, balance sheets, and cash flow statements -- Calculate and interpret key financial ratios -- Evaluate revenue growth and profit margins -- Assess company's debt levels and cash position - -2. VALUATION METRICS -- Calculate fair value using multiple valuation methods: - * Discounted Cash Flow (DCF) - * Price-to-Earnings (P/E) - * Price-to-Book (P/B) - * Enterprise Value/EBITDA -- Compare valuations against industry peers - -3. BUSINESS MODEL ASSESSMENT -- Evaluate competitive advantages and market position -- Analyze industry dynamics and market share -- Assess management quality and corporate governance -- Identify potential risks and growth opportunities - -4. ECONOMIC CONTEXT -- Consider macroeconomic factors affecting the company -- Analyze industry cycles and trends -- Evaluate regulatory environment and compliance -- Assess global market conditions - -Your analysis should be comprehensive, focusing on both quantitative metrics and qualitative factors that impact long-term value.""", - max_loops=1, - llm=vllm, -) - -# Market Sentiment Agent -sentiment_analyst = Agent( - agent_name="Market-Sentiment-Agent", - agent_description="Expert in market psychology and sentiment analysis", - system_prompt="""You are an expert Market Sentiment Agent specializing in analyzing market psychology and investor behavior. Your key responsibilities include: - -1. SENTIMENT INDICATORS -- Monitor and interpret market sentiment indicators: - * VIX (Fear Index) - * Put/Call Ratio - * Market Breadth - * Investor Surveys -- Track institutional vs retail investor behavior - -2. NEWS AND SOCIAL MEDIA ANALYSIS -- Analyze news flow and media sentiment -- Monitor social media trends and discussions -- Track analyst recommendations and changes -- Evaluate corporate insider trading patterns - -3. MARKET POSITIONING -- Assess hedge fund positioning and exposure -- Monitor short interest and short squeeze potential -- Track fund flows and asset allocation trends -- Analyze options market sentiment - -4. CONTRARIAN SIGNALS -- Identify extreme sentiment readings -- Detect potential market turning points -- Analyze historical sentiment patterns -- Provide contrarian trading opportunities - -Your analysis should combine quantitative sentiment metrics with qualitative assessment of market psychology and crowd behavior.""", - max_loops=1, - llm=vllm, -) - -# Quantitative Strategy Agent -quant_analyst = Agent( - agent_name="Quantitative-Strategy-Agent", - agent_description="Expert in quantitative analysis and algorithmic strategies", - system_prompt="""You are an expert Quantitative Strategy Agent specializing in data-driven investment strategies. Your primary responsibilities include: - -1. FACTOR ANALYSIS -- Analyze and monitor factor performance: - * Value - * Momentum - * Quality - * Size - * Low Volatility -- Calculate factor exposures and correlations - -2. STATISTICAL ANALYSIS -- Perform statistical arbitrage analysis -- Calculate and monitor pair trading opportunities -- Analyze market anomalies and inefficiencies -- Develop mean reversion strategies - -3. RISK MODELING -- Build and maintain risk models -- Calculate portfolio optimization metrics -- Monitor correlation matrices -- Analyze tail risk and stress scenarios - -4. ALGORITHMIC STRATEGIES -- Develop systematic trading strategies -- Backtest and validate trading algorithms -- Monitor strategy performance metrics -- Optimize execution algorithms - -Your analysis should be purely quantitative, based on statistical evidence and mathematical models rather than subjective opinions.""", - max_loops=1, - llm=vllm, -) - -# Portfolio Strategy Agent -portfolio_strategist = Agent( - agent_name="Portfolio-Strategy-Agent", - agent_description="Expert in portfolio management and asset allocation", - system_prompt="""You are an expert Portfolio Strategy Agent specializing in portfolio construction and management. Your core responsibilities include: - -1. ASSET ALLOCATION -- Develop strategic asset allocation frameworks -- Recommend tactical asset allocation shifts -- Optimize portfolio weightings -- Balance risk and return objectives - -2. PORTFOLIO ANALYSIS -- Calculate portfolio risk metrics -- Monitor sector and factor exposures -- Analyze portfolio correlation matrix -- Track performance attribution - -3. RISK MANAGEMENT -- Implement portfolio hedging strategies -- Monitor and adjust position sizing -- Set stop-loss and rebalancing rules -- Develop drawdown protection strategies - -4. PORTFOLIO OPTIMIZATION -- Calculate efficient frontier analysis -- Optimize for various objectives: - * Maximum Sharpe Ratio - * Minimum Volatility - * Maximum Diversification -- Consider transaction costs and taxes - -Your recommendations should focus on portfolio-level decisions that optimize risk-adjusted returns while meeting specific investment objectives.""", - max_loops=1, - llm=vllm, -) - -# Create a list of all agents -stock_analysis_agents = [ - technical_analyst, - fundamental_analyst, - sentiment_analyst, - quant_analyst, - portfolio_strategist, -] - -swarm = ConcurrentWorkflow( - name="Stock-Analysis-Swarm", - description="A swarm of agents that analyze stocks and provide a comprehensive analysis of the current trends and opportunities.", - agents=stock_analysis_agents, -) - -swarm.run( - "Analyze the best etfs for gold and other similiar commodities in volatile markets" -) diff --git a/test.py b/test.py new file mode 100644 index 00000000..4def8642 --- /dev/null +++ b/test.py @@ -0,0 +1,13 @@ +from swarms.utils.vllm_wrapper import VLLMWrapper + +# Initialize the vLLM wrapper +vllm = VLLMWrapper( + model_name="gpt-4o-mini", + system_prompt="You are a helpful assistant.", + temperature=0.7, + max_tokens=4000 +) + +# Run inference +response = vllm.run("What is the capital of France?") +print(response) \ No newline at end of file From 2d4a5e4dcacf62bd057bd303e70a191d3d8d95e9 Mon Sep 17 00:00:00 2001 From: Steve-Dusty Date: Thu, 6 Nov 2025 23:58:14 -0800 Subject: [PATCH 02/11] removed vllm from sidebar --- docs/mkdocs.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index fbdd766e..b2b95c8d 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -384,7 +384,6 @@ nav: - OpenRouter: "swarms/examples/openrouter.md" - XAI: "swarms/examples/xai.md" - Azure OpenAI: "swarms/examples/azure.md" - - VLLM: "swarms/examples/vllm_integration.md" - Llama4: "swarms/examples/llama4.md" - Custom Base URL & API Keys: "swarms/examples/custom_base_url_example.md" @@ -409,7 +408,6 @@ nav: - Advanced BatchedGridWorkflow: "swarms/examples/batched_grid_advanced_example.md" - Applications: - Swarms of Browser Agents: "swarms/examples/swarms_of_browser_agents.md" - - ConcurrentWorkflow with VLLM Agents: "swarms/examples/vllm.md" - Hiearchical Marketing Team: "examples/marketing_team.md" - Gold ETF Research with HeavySwarm: "examples/gold_etf_research.md" - Hiring Swarm: "examples/hiring_swarm.md" From e638387cd51bf951bbf9487f16d5ff024f90065a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 Nov 2025 11:51:35 +0000 Subject: [PATCH 03/11] Update pytest requirement from ^8.1.1 to >=8.1.1,<10.0.0 Updates the requirements on [pytest](https://github.com/pytest-dev/pytest) to permit the latest version. - [Release notes](https://github.com/pytest-dev/pytest/releases) - [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst) - [Commits](https://github.com/pytest-dev/pytest/compare/8.1.1...9.0.0) --- updated-dependencies: - dependency-name: pytest dependency-version: 9.0.0 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 90ae77e3..65b3a242 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -93,7 +93,7 @@ mypy-protobuf = "^3.0.0" [tool.poetry.group.test.dependencies] -pytest = "^8.1.1" +pytest = ">=8.1.1,<10.0.0" [tool.poetry.group.dev.dependencies] black = "*" From 6ccf58d747e0c77e726d29ed527a8a268001a5cf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 Nov 2025 11:52:12 +0000 Subject: [PATCH 04/11] Update ruff requirement from >=0.5.1,<0.14.3 to >=0.5.1,<0.14.5 Updates the requirements on [ruff](https://github.com/astral-sh/ruff) to permit the latest version. - [Release notes](https://github.com/astral-sh/ruff/releases) - [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md) - [Commits](https://github.com/astral-sh/ruff/compare/0.5.1...0.14.4) --- updated-dependencies: - dependency-name: ruff dependency-version: 0.14.4 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 90ae77e3..bef858b3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -85,7 +85,7 @@ swarms = "swarms.cli.main:main" [tool.poetry.group.lint.dependencies] black = ">=23.1,<26.0" -ruff = ">=0.5.1,<0.14.3" +ruff = ">=0.5.1,<0.14.5" types-toml = "^0.10.8.1" types-pytz = ">=2023.3,<2026.0" types-chardet = "^5.0.4.6" From a7c3927aa9696cb51e04d834488290fac742f621 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 Nov 2025 11:55:31 +0000 Subject: [PATCH 05/11] Bump pydantic from 2.12.0 to 2.12.4 Bumps [pydantic](https://github.com/pydantic/pydantic) from 2.12.0 to 2.12.4. - [Release notes](https://github.com/pydantic/pydantic/releases) - [Changelog](https://github.com/pydantic/pydantic/blob/v2.12.4/HISTORY.md) - [Commits](https://github.com/pydantic/pydantic/compare/v2.12.0...v2.12.4) --- updated-dependencies: - dependency-name: pydantic dependency-version: 2.12.4 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 10fe77cc..279d5538 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ toml pypdf==5.1.0 ratelimit==2.2.1 loguru -pydantic==2.12.0 +pydantic==2.12.4 tenacity rich psutil From 93b405e4ab1d6f96688635319f97da11c896a79d Mon Sep 17 00:00:00 2001 From: Hugh <155223694+hughiwnl@users.noreply.github.com> Date: Mon, 10 Nov 2025 18:59:28 -0800 Subject: [PATCH 06/11] added tests for agent_registry --- test_agent_registry.py | 813 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 813 insertions(+) create mode 100644 test_agent_registry.py diff --git a/test_agent_registry.py b/test_agent_registry.py new file mode 100644 index 00000000..f4877d21 --- /dev/null +++ b/test_agent_registry.py @@ -0,0 +1,813 @@ +import os + +try: + import pytest +except ImportError: + pytest = None + +from loguru import logger + +try: + from swarms.structs.agent_registry import AgentRegistry + from swarms.structs.agent import Agent +except (ImportError, ModuleNotFoundError) as e: + import importlib.util + _current_dir = os.path.dirname(os.path.abspath(__file__)) + + agent_registry_path = os.path.join(_current_dir, "..", "..", "swarms", "structs", "agent_registry.py") + agent_path = os.path.join(_current_dir, "..", "..", "swarms", "structs", "agent.py") + + if os.path.exists(agent_registry_path): + spec = importlib.util.spec_from_file_location("agent_registry", agent_registry_path) + agent_registry_module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(agent_registry_module) + AgentRegistry = agent_registry_module.AgentRegistry + + if os.path.exists(agent_path): + spec = importlib.util.spec_from_file_location("agent", agent_path) + agent_module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(agent_module) + Agent = agent_module.Agent + else: + raise ImportError(f"Could not find required modules") from e + +logger.remove() +logger.add(lambda msg: None, level="ERROR") + + +def test_agent_registry_initialization(): + """Test AgentRegistry initialization.""" + try: + registry = AgentRegistry() + assert registry is not None, "AgentRegistry should not be None" + assert registry.name == "Agent Registry", "Default name should be set" + assert registry.description == "A registry for managing agents.", "Default description should be set" + assert isinstance(registry.agents, dict), "Agents should be a dictionary" + assert len(registry.agents) == 0, "Initial registry should be empty" + + registry2 = AgentRegistry( + name="Test Registry", + description="Test description", + return_json=False, + auto_save=True + ) + assert registry2.name == "Test Registry", "Custom name should be set" + assert registry2.description == "Test description", "Custom description should be set" + assert registry2.return_json is False, "return_json should be False" + assert registry2.auto_save is True, "auto_save should be True" + + logger.info("✓ AgentRegistry initialization test passed") + + except Exception as e: + logger.error(f"Error in test_agent_registry_initialization: {str(e)}") + raise + + +def test_agent_registry_add_single_agent(): + """Test adding a single agent to the registry.""" + try: + registry = AgentRegistry() + + agent = Agent( + agent_name="Test-Agent-1", + agent_description="Test agent for registry", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + registry.add(agent) + + assert len(registry.agents) == 1, "Registry should have one agent" + assert "Test-Agent-1" in registry.agents, "Agent should be in registry" + assert registry.agents["Test-Agent-1"] is not None, "Agent object should not be None" + assert registry.agents["Test-Agent-1"].agent_name == "Test-Agent-1", "Agent name should match" + + logger.info("✓ Add single agent test passed") + + except Exception as e: + logger.error(f"Error in test_agent_registry_add_single_agent: {str(e)}") + raise + + +def test_agent_registry_add_multiple_agents(): + """Test adding multiple agents to the registry.""" + try: + registry = AgentRegistry() + + agent1 = Agent( + agent_name="Test-Agent-1", + agent_description="First test agent", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + agent2 = Agent( + agent_name="Test-Agent-2", + agent_description="Second test agent", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + agent3 = Agent( + agent_name="Test-Agent-3", + agent_description="Third test agent", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + registry.add_many([agent1, agent2, agent3]) + + assert len(registry.agents) == 3, "Registry should have three agents" + assert "Test-Agent-1" in registry.agents, "Agent 1 should be in registry" + assert "Test-Agent-2" in registry.agents, "Agent 2 should be in registry" + assert "Test-Agent-3" in registry.agents, "Agent 3 should be in registry" + + for agent_name in ["Test-Agent-1", "Test-Agent-2", "Test-Agent-3"]: + assert registry.agents[agent_name] is not None, f"{agent_name} should not be None" + + logger.info("✓ Add multiple agents test passed") + + except Exception as e: + logger.error(f"Error in test_agent_registry_add_multiple_agents: {str(e)}") + raise + + +def test_agent_registry_get_agent(): + """Test retrieving an agent from the registry.""" + try: + registry = AgentRegistry() + + agent = Agent( + agent_name="Retrievable-Agent", + agent_description="Agent for retrieval testing", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + registry.add(agent) + + retrieved_agent = registry.get("Retrievable-Agent") + + assert retrieved_agent is not None, "Retrieved agent should not be None" + assert retrieved_agent.agent_name == "Retrievable-Agent", "Agent name should match" + assert hasattr(retrieved_agent, "run"), "Agent should have run method" + assert retrieved_agent is agent, "Should return the same agent object" + + logger.info("✓ Get agent test passed") + + except Exception as e: + logger.error(f"Error in test_agent_registry_get_agent: {str(e)}") + raise + + +def test_agent_registry_delete_agent(): + """Test deleting an agent from the registry.""" + try: + registry = AgentRegistry() + + agent1 = Agent( + agent_name="Agent-To-Delete", + agent_description="Agent that will be deleted", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + agent2 = Agent( + agent_name="Agent-To-Keep", + agent_description="Agent that will remain", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + registry.add(agent1) + registry.add(agent2) + + assert len(registry.agents) == 2, "Registry should have two agents" + + registry.delete("Agent-To-Delete") + + assert len(registry.agents) == 1, "Registry should have one agent after deletion" + assert "Agent-To-Delete" not in registry.agents, "Deleted agent should not be in registry" + assert "Agent-To-Keep" in registry.agents, "Other agent should still be in registry" + + logger.info("✓ Delete agent test passed") + + except Exception as e: + logger.error(f"Error in test_agent_registry_delete_agent: {str(e)}") + raise + + +def test_agent_registry_update_agent(): + """Test updating an agent in the registry.""" + try: + registry = AgentRegistry() + + original_agent = Agent( + agent_name="Agent-To-Update", + agent_description="Original description", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + registry.add(original_agent) + + updated_agent = Agent( + agent_name="Agent-To-Update", + agent_description="Updated description", + model_name="gpt-4o-mini", + max_loops=2, + verbose=True, + print_on=False, + streaming_on=True, + ) + + registry.update_agent("Agent-To-Update", updated_agent) + + retrieved_agent = registry.get("Agent-To-Update") + + assert retrieved_agent is not None, "Updated agent should not be None" + assert retrieved_agent is updated_agent, "Should return the updated agent" + assert retrieved_agent.max_loops == 2, "Max loops should be updated" + assert retrieved_agent.verbose is True, "Verbose should be updated" + + logger.info("✓ Update agent test passed") + + except Exception as e: + logger.error(f"Error in test_agent_registry_update_agent: {str(e)}") + raise + + +def test_agent_registry_list_agents(): + """Test listing all agent names in the registry.""" + try: + registry = AgentRegistry() + + agent1 = Agent( + agent_name="List-Agent-1", + agent_description="First agent", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + agent2 = Agent( + agent_name="List-Agent-2", + agent_description="Second agent", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + registry.add(agent1) + registry.add(agent2) + + agent_names = registry.list_agents() + + assert agent_names is not None, "Agent names list should not be None" + assert isinstance(agent_names, list), "Should return a list" + assert len(agent_names) == 2, "Should have two agent names" + assert "List-Agent-1" in agent_names, "First agent name should be in list" + assert "List-Agent-2" in agent_names, "Second agent name should be in list" + + logger.info("✓ List agents test passed") + + except Exception as e: + logger.error(f"Error in test_agent_registry_list_agents: {str(e)}") + raise + + +def test_agent_registry_return_all_agents(): + """Test returning all agents from the registry.""" + try: + registry = AgentRegistry() + + agent1 = Agent( + agent_name="Return-Agent-1", + agent_description="First agent", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + agent2 = Agent( + agent_name="Return-Agent-2", + agent_description="Second agent", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + registry.add(agent1) + registry.add(agent2) + + all_agents = registry.return_all_agents() + + assert all_agents is not None, "All agents list should not be None" + assert isinstance(all_agents, list), "Should return a list" + assert len(all_agents) == 2, "Should have two agents" + + for agent in all_agents: + assert agent is not None, "Each agent should not be None" + assert hasattr(agent, "agent_name"), "Agent should have agent_name" + assert hasattr(agent, "run"), "Agent should have run method" + + logger.info("✓ Return all agents test passed") + + except Exception as e: + logger.error(f"Error in test_agent_registry_return_all_agents: {str(e)}") + raise + + +def test_agent_registry_query_with_condition(): + """Test querying agents with a condition.""" + try: + registry = AgentRegistry() + + agent1 = Agent( + agent_name="Query-Agent-1", + agent_description="Agent with max_loops=1", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + agent2 = Agent( + agent_name="Query-Agent-2", + agent_description="Agent with max_loops=2", + model_name="gpt-4o-mini", + max_loops=2, + verbose=False, + print_on=False, + streaming_on=True, + ) + + agent3 = Agent( + agent_name="Query-Agent-3", + agent_description="Agent with max_loops=1", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + registry.add(agent1) + registry.add(agent2) + registry.add(agent3) + + def condition_max_loops_1(agent): + return agent.max_loops == 1 + + filtered_agents = registry.query(condition_max_loops_1) + + assert filtered_agents is not None, "Filtered agents should not be None" + assert isinstance(filtered_agents, list), "Should return a list" + assert len(filtered_agents) == 2, "Should have two agents with max_loops=1" + + for agent in filtered_agents: + assert agent.max_loops == 1, "All filtered agents should have max_loops=1" + + logger.info("✓ Query with condition test passed") + + except Exception as e: + logger.error(f"Error in test_agent_registry_query_with_condition: {str(e)}") + raise + + +def test_agent_registry_query_without_condition(): + """Test querying all agents without a condition.""" + try: + registry = AgentRegistry() + + agent1 = Agent( + agent_name="Query-All-Agent-1", + agent_description="First agent", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + agent2 = Agent( + agent_name="Query-All-Agent-2", + agent_description="Second agent", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + registry.add(agent1) + registry.add(agent2) + + all_agents = registry.query() + + assert all_agents is not None, "All agents should not be None" + assert isinstance(all_agents, list), "Should return a list" + assert len(all_agents) == 2, "Should return all agents" + + logger.info("✓ Query without condition test passed") + + except Exception as e: + logger.error(f"Error in test_agent_registry_query_without_condition: {str(e)}") + raise + + +def test_agent_registry_find_agent_by_name(): + """Test finding an agent by name.""" + try: + registry = AgentRegistry() + + agent = Agent( + agent_name="Findable-Agent", + agent_description="Agent to find", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + registry.add(agent) + + found_agent = registry.find_agent_by_name("Findable-Agent") + + assert found_agent is not None, "Found agent should not be None" + assert found_agent.agent_name == "Findable-Agent", "Agent name should match" + assert hasattr(found_agent, "run"), "Agent should have run method" + + logger.info("✓ Find agent by name test passed") + + except Exception as e: + logger.error(f"Error in test_agent_registry_find_agent_by_name: {str(e)}") + raise + + +def test_agent_registry_find_agent_by_id(): + """Test finding an agent by ID.""" + try: + registry = AgentRegistry() + + agent = Agent( + agent_name="ID-Agent", + agent_description="Agent with ID", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + registry.add(agent) + + agent_id = agent.id + found_agent = registry.find_agent_by_id(agent.agent_name) + + assert found_agent is not None, "Found agent should not be None" + assert found_agent.agent_name == "ID-Agent", "Agent name should match" + + logger.info("✓ Find agent by ID test passed") + + except Exception as e: + logger.error(f"Error in test_agent_registry_find_agent_by_id: {str(e)}") + raise + + +def test_agent_registry_agents_to_json(): + """Test converting agents to JSON.""" + try: + registry = AgentRegistry() + + agent1 = Agent( + agent_name="JSON-Agent-1", + agent_description="First agent for JSON", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + agent2 = Agent( + agent_name="JSON-Agent-2", + agent_description="Second agent for JSON", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + registry.add(agent1) + registry.add(agent2) + + json_output = registry.agents_to_json() + + assert json_output is not None, "JSON output should not be None" + assert isinstance(json_output, str), "Should return a string" + assert len(json_output) > 0, "JSON should not be empty" + assert "JSON-Agent-1" in json_output, "First agent should be in JSON" + assert "JSON-Agent-2" in json_output, "Second agent should be in JSON" + + import json + parsed_json = json.loads(json_output) + assert isinstance(parsed_json, dict), "Should be valid JSON dict" + assert len(parsed_json) == 2, "Should have two agents in JSON" + + logger.info("✓ Agents to JSON test passed") + + except Exception as e: + logger.error(f"Error in test_agent_registry_agents_to_json: {str(e)}") + raise + + +def test_agent_registry_initialization_with_agents(): + """Test initializing registry with agents.""" + try: + agent1 = Agent( + agent_name="Init-Agent-1", + agent_description="First initial agent", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + agent2 = Agent( + agent_name="Init-Agent-2", + agent_description="Second initial agent", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + registry = AgentRegistry(agents=[agent1, agent2]) + + assert registry is not None, "Registry should not be None" + assert len(registry.agents) == 2, "Registry should have two agents" + assert "Init-Agent-1" in registry.agents, "First agent should be in registry" + assert "Init-Agent-2" in registry.agents, "Second agent should be in registry" + + logger.info("✓ Initialize with agents test passed") + + except Exception as e: + logger.error(f"Error in test_agent_registry_initialization_with_agents: {str(e)}") + raise + + +def test_agent_registry_error_duplicate_agent(): + """Test error handling for duplicate agent names.""" + try: + registry = AgentRegistry() + + agent1 = Agent( + agent_name="Duplicate-Agent", + agent_description="First agent", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + agent2 = Agent( + agent_name="Duplicate-Agent", + agent_description="Duplicate agent", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + registry.add(agent1) + + try: + registry.add(agent2) + assert False, "Should have raised ValueError for duplicate agent" + except ValueError as e: + assert "already exists" in str(e).lower(), "Error message should mention duplicate" + assert len(registry.agents) == 1, "Registry should still have only one agent" + + logger.info("✓ Error handling for duplicate agent test passed") + + except Exception as e: + logger.error(f"Error in test_agent_registry_error_duplicate_agent: {str(e)}") + raise + + +def test_agent_registry_error_nonexistent_agent(): + """Test error handling for nonexistent agent.""" + try: + registry = AgentRegistry() + + try: + registry.get("Nonexistent-Agent") + assert False, "Should have raised KeyError for nonexistent agent" + except KeyError as e: + assert e is not None, "Should raise KeyError" + + try: + registry.delete("Nonexistent-Agent") + assert False, "Should have raised KeyError for nonexistent agent" + except KeyError as e: + assert e is not None, "Should raise KeyError" + + logger.info("✓ Error handling for nonexistent agent test passed") + + except Exception as e: + logger.error(f"Error in test_agent_registry_error_nonexistent_agent: {str(e)}") + raise + + +def test_agent_registry_retrieved_agents_can_run(): + """Test that retrieved agents can actually run tasks.""" + try: + registry = AgentRegistry() + + agent = Agent( + agent_name="Runnable-Registry-Agent", + agent_description="Agent for running tasks", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + registry.add(agent) + + retrieved_agent = registry.get("Runnable-Registry-Agent") + + assert retrieved_agent is not None, "Retrieved agent should not be None" + + result = retrieved_agent.run("What is 2 + 2? Answer briefly.") + + assert result is not None, "Agent run result should not be None" + assert isinstance(result, str), "Result should be a string" + assert len(result) > 0, "Result should not be empty" + + logger.info("✓ Retrieved agents can run test passed") + + except Exception as e: + logger.error(f"Error in test_agent_registry_retrieved_agents_can_run: {str(e)}") + raise + + +def test_agent_registry_thread_safety(): + """Test thread safety of registry operations.""" + try: + registry = AgentRegistry() + + agent1 = Agent( + agent_name="Thread-Agent-1", + agent_description="First thread agent", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + agent2 = Agent( + agent_name="Thread-Agent-2", + agent_description="Second thread agent", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, + print_on=False, + streaming_on=True, + ) + + registry.add(agent1) + registry.add(agent2) + + agent_names = registry.list_agents() + all_agents = registry.return_all_agents() + + assert agent_names is not None, "Agent names should not be None" + assert all_agents is not None, "All agents should not be None" + assert len(agent_names) == 2, "Should have two agent names" + assert len(all_agents) == 2, "Should have two agents" + + logger.info("✓ Thread safety test passed") + + except Exception as e: + logger.error(f"Error in test_agent_registry_thread_safety: {str(e)}") + raise + + +if __name__ == "__main__": + import sys + + test_dict = { + "test_agent_registry_initialization": test_agent_registry_initialization, + "test_agent_registry_add_single_agent": test_agent_registry_add_single_agent, + "test_agent_registry_add_multiple_agents": test_agent_registry_add_multiple_agents, + "test_agent_registry_get_agent": test_agent_registry_get_agent, + "test_agent_registry_delete_agent": test_agent_registry_delete_agent, + "test_agent_registry_update_agent": test_agent_registry_update_agent, + "test_agent_registry_list_agents": test_agent_registry_list_agents, + "test_agent_registry_return_all_agents": test_agent_registry_return_all_agents, + "test_agent_registry_query_with_condition": test_agent_registry_query_with_condition, + "test_agent_registry_query_without_condition": test_agent_registry_query_without_condition, + "test_agent_registry_find_agent_by_name": test_agent_registry_find_agent_by_name, + "test_agent_registry_find_agent_by_id": test_agent_registry_find_agent_by_id, + "test_agent_registry_agents_to_json": test_agent_registry_agents_to_json, + "test_agent_registry_initialization_with_agents": test_agent_registry_initialization_with_agents, + "test_agent_registry_error_duplicate_agent": test_agent_registry_error_duplicate_agent, + "test_agent_registry_error_nonexistent_agent": test_agent_registry_error_nonexistent_agent, + "test_agent_registry_retrieved_agents_can_run": test_agent_registry_retrieved_agents_can_run, + "test_agent_registry_thread_safety": test_agent_registry_thread_safety, + } + + if len(sys.argv) > 1: + requested_tests = [] + for test_name in sys.argv[1:]: + if test_name in test_dict: + requested_tests.append(test_dict[test_name]) + elif test_name == "all" or test_name == "--all": + requested_tests = list(test_dict.values()) + break + else: + print(f"⚠ Warning: Test '{test_name}' not found.") + print(f"Available tests: {', '.join(test_dict.keys())}") + sys.exit(1) + + tests_to_run = requested_tests + else: + tests_to_run = list(test_dict.values()) + + if len(tests_to_run) == 1: + print(f"Running: {tests_to_run[0].__name__}") + else: + print(f"Running {len(tests_to_run)} test(s)...") + + passed = 0 + failed = 0 + + for test_func in tests_to_run: + try: + print(f"\n{'='*60}") + print(f"Running: {test_func.__name__}") + print(f"{'='*60}") + test_func() + print(f"✓ PASSED: {test_func.__name__}") + passed += 1 + except Exception as e: + print(f"✗ FAILED: {test_func.__name__}") + print(f" Error: {str(e)}") + import traceback + traceback.print_exc() + failed += 1 + + print(f"\n{'='*60}") + print(f"Test Summary: {passed} passed, {failed} failed") + print(f"{'='*60}") + + if len(sys.argv) == 1: + print("\n💡 Tip: Run a specific test with:") + print(" python test_agent_registry.py test_agent_registry_initialization") + print("\n Or use pytest:") + print(" pytest test_agent_registry.py") + print(" pytest test_agent_registry.py::test_agent_registry_initialization") + From be55c510055f714dba88383968e6551507433a00 Mon Sep 17 00:00:00 2001 From: Hugh <155223694+hughiwnl@users.noreply.github.com> Date: Mon, 10 Nov 2025 19:49:55 -0800 Subject: [PATCH 07/11] added test cases and moved back to structs --- test_agent_registry.py => tests/structs/test_agent_registry.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test_agent_registry.py => tests/structs/test_agent_registry.py (100%) diff --git a/test_agent_registry.py b/tests/structs/test_agent_registry.py similarity index 100% rename from test_agent_registry.py rename to tests/structs/test_agent_registry.py From 9426379e1a721b94d2a361fd375e6635830d73cc Mon Sep 17 00:00:00 2001 From: Hugh <155223694+hughiwnl@users.noreply.github.com> Date: Mon, 10 Nov 2025 20:31:34 -0800 Subject: [PATCH 08/11] added test cases for test_base_structure --- test_base_structure.py | 810 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 810 insertions(+) create mode 100644 test_base_structure.py diff --git a/test_base_structure.py b/test_base_structure.py new file mode 100644 index 00000000..8a7ce1bf --- /dev/null +++ b/test_base_structure.py @@ -0,0 +1,810 @@ +import os +import tempfile +import asyncio +import json + +try: + import pytest +except ImportError: + pytest = None + +from loguru import logger + +try: + from swarms.structs.base_structure import BaseStructure +except (ImportError, ModuleNotFoundError) as e: + import importlib.util + _current_dir = os.path.dirname(os.path.abspath(__file__)) + + base_structure_path = os.path.join(_current_dir, "..", "..", "swarms", "structs", "base_structure.py") + + if os.path.exists(base_structure_path): + spec = importlib.util.spec_from_file_location("base_structure", base_structure_path) + base_structure_module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(base_structure_module) + BaseStructure = base_structure_module.BaseStructure + else: + raise ImportError(f"Could not find base_structure.py at {base_structure_path}") from e + +logger.remove() +logger.add(lambda msg: None, level="ERROR") + + +class TestStructure(BaseStructure): + def run(self, task: str = "test"): + return f"Processed: {task}" + + +def test_base_structure_initialization(): + """Test BaseStructure initialization.""" + try: + structure = BaseStructure() + assert structure is not None, "BaseStructure should not be None" + assert structure.name is None, "Default name should be None" + assert structure.description is None, "Default description should be None" + assert structure.save_metadata_on is True, "save_metadata_on should default to True" + assert structure.save_artifact_path == "./artifacts", "Default artifact path should be set" + assert structure.save_metadata_path == "./metadata", "Default metadata path should be set" + assert structure.save_error_path == "./errors", "Default error path should be set" + assert structure.workspace_dir == "./workspace", "Default workspace dir should be set" + + structure2 = BaseStructure( + name="TestStructure", + description="Test description", + save_metadata_on=False, + save_artifact_path="/tmp/artifacts", + save_metadata_path="/tmp/metadata", + save_error_path="/tmp/errors", + workspace_dir="/tmp/workspace" + ) + assert structure2.name == "TestStructure", "Custom name should be set" + assert structure2.description == "Test description", "Custom description should be set" + assert structure2.save_metadata_on is False, "save_metadata_on should be False" + assert structure2.save_artifact_path == "/tmp/artifacts", "Custom artifact path should be set" + + logger.info("✓ BaseStructure initialization test passed") + + except Exception as e: + logger.error(f"Error in test_base_structure_initialization: {str(e)}") + raise + + +def test_save_and_load_file(): + """Test saving and loading files.""" + try: + with tempfile.TemporaryDirectory() as tmpdir: + structure = BaseStructure(name="TestFileOps") + test_file = os.path.join(tmpdir, "test_data.json") + test_data = {"key": "value", "number": 42, "list": [1, 2, 3]} + + structure.save_to_file(test_data, test_file) + + assert os.path.exists(test_file), "File should be created" + + loaded_data = structure.load_from_file(test_file) + + assert loaded_data is not None, "Loaded data should not be None" + assert isinstance(loaded_data, dict), "Loaded data should be a dict" + assert loaded_data["key"] == "value", "Data should match" + assert loaded_data["number"] == 42, "Number should match" + assert loaded_data["list"] == [1, 2, 3], "List should match" + + logger.info("✓ Save and load file test passed") + + except Exception as e: + logger.error(f"Error in test_save_and_load_file: {str(e)}") + raise + + +def test_save_and_load_metadata(): + """Test saving and loading metadata.""" + try: + with tempfile.TemporaryDirectory() as tmpdir: + structure = BaseStructure( + name="TestMetadata", + save_metadata_path=tmpdir + ) + metadata = {"timestamp": "2024-01-01", "status": "active", "count": 5} + + structure.save_metadata(metadata) + + metadata_file = os.path.join(tmpdir, "TestMetadata_metadata.json") + assert os.path.exists(metadata_file), "Metadata file should be created" + + loaded_metadata = structure.load_metadata() + + assert loaded_metadata is not None, "Loaded metadata should not be None" + assert isinstance(loaded_metadata, dict), "Metadata should be a dict" + assert loaded_metadata["status"] == "active", "Metadata should match" + assert loaded_metadata["count"] == 5, "Count should match" + + logger.info("✓ Save and load metadata test passed") + + except Exception as e: + logger.error(f"Error in test_save_and_load_metadata: {str(e)}") + raise + + +def test_save_and_load_artifact(): + """Test saving and loading artifacts.""" + try: + with tempfile.TemporaryDirectory() as tmpdir: + structure = BaseStructure( + name="TestArtifact", + save_artifact_path=tmpdir + ) + artifact = {"result": "success", "data": [1, 2, 3, 4, 5]} + + structure.save_artifact(artifact, "test_artifact") + + artifact_file = os.path.join(tmpdir, "test_artifact.json") + assert os.path.exists(artifact_file), "Artifact file should be created" + + loaded_artifact = structure.load_artifact("test_artifact") + + assert loaded_artifact is not None, "Loaded artifact should not be None" + assert isinstance(loaded_artifact, dict), "Artifact should be a dict" + assert loaded_artifact["result"] == "success", "Artifact result should match" + assert len(loaded_artifact["data"]) == 5, "Artifact data should match" + + logger.info("✓ Save and load artifact test passed") + + except Exception as e: + logger.error(f"Error in test_save_and_load_artifact: {str(e)}") + raise + + +def test_log_error(): + """Test error logging.""" + try: + with tempfile.TemporaryDirectory() as tmpdir: + structure = BaseStructure( + name="TestErrorLog", + save_error_path=tmpdir + ) + error_message = "Test error message" + + structure.log_error(error_message) + + error_file = os.path.join(tmpdir, "TestErrorLog_errors.log") + assert os.path.exists(error_file), "Error log file should be created" + + with open(error_file, "r") as f: + content = f.read() + assert error_message in content, "Error message should be in log" + + structure.log_error("Another error") + + with open(error_file, "r") as f: + content = f.read() + assert "Another error" in content, "Second error should be in log" + + logger.info("✓ Log error test passed") + + except Exception as e: + logger.error(f"Error in test_log_error: {str(e)}") + raise + + +def test_log_event(): + """Test event logging.""" + try: + with tempfile.TemporaryDirectory() as tmpdir: + structure = BaseStructure( + name="TestEventLog", + save_metadata_path=tmpdir + ) + event_message = "Test event occurred" + + structure.log_event(event_message, "INFO") + + event_file = os.path.join(tmpdir, "TestEventLog_events.log") + assert os.path.exists(event_file), "Event log file should be created" + + with open(event_file, "r") as f: + content = f.read() + assert event_message in content, "Event message should be in log" + assert "INFO" in content, "Event type should be in log" + + structure.log_event("Warning event", "WARNING") + + with open(event_file, "r") as f: + content = f.read() + assert "WARNING" in content, "Warning type should be in log" + + logger.info("✓ Log event test passed") + + except Exception as e: + logger.error(f"Error in test_log_event: {str(e)}") + raise + + +def test_compress_and_decompress_data(): + """Test data compression and decompression.""" + try: + structure = BaseStructure() + test_data = {"key": "value", "large_data": "x" * 1000} + + compressed = structure.compress_data(test_data) + + assert compressed is not None, "Compressed data should not be None" + assert isinstance(compressed, bytes), "Compressed data should be bytes" + assert len(compressed) < len(json.dumps(test_data).encode()), "Compressed should be smaller" + + decompressed = structure.decompres_data(compressed) + + assert decompressed is not None, "Decompressed data should not be None" + assert isinstance(decompressed, dict), "Decompressed data should be a dict" + assert decompressed["key"] == "value", "Decompressed data should match" + assert len(decompressed["large_data"]) == 1000, "Large data should match" + + logger.info("✓ Compress and decompress data test passed") + + except Exception as e: + logger.error(f"Error in test_compress_and_decompress_data: {str(e)}") + raise + + +def test_to_dict(): + """Test converting structure to dictionary.""" + try: + structure = BaseStructure( + name="TestDict", + description="Test description" + ) + + structure_dict = structure.to_dict() + + assert structure_dict is not None, "Dictionary should not be None" + assert isinstance(structure_dict, dict), "Should return a dict" + assert structure_dict["name"] == "TestDict", "Name should be in dict" + assert structure_dict["description"] == "Test description", "Description should be in dict" + + logger.info("✓ To dict test passed") + + except Exception as e: + logger.error(f"Error in test_to_dict: {str(e)}") + raise + + +def test_to_json(): + """Test converting structure to JSON.""" + try: + structure = BaseStructure( + name="TestJSON", + description="Test JSON description" + ) + + json_output = structure.to_json() + + assert json_output is not None, "JSON output should not be None" + assert isinstance(json_output, str), "Should return a string" + assert "TestJSON" in json_output, "Name should be in JSON" + assert "Test JSON description" in json_output, "Description should be in JSON" + + parsed = json.loads(json_output) + assert isinstance(parsed, dict), "Should be valid JSON dict" + + logger.info("✓ To JSON test passed") + + except Exception as e: + logger.error(f"Error in test_to_json: {str(e)}") + raise + + +def test_to_yaml(): + """Test converting structure to YAML.""" + try: + structure = BaseStructure( + name="TestYAML", + description="Test YAML description" + ) + + yaml_output = structure.to_yaml() + + assert yaml_output is not None, "YAML output should not be None" + assert isinstance(yaml_output, str), "Should return a string" + assert "TestYAML" in yaml_output, "Name should be in YAML" + + logger.info("✓ To YAML test passed") + + except Exception as e: + logger.error(f"Error in test_to_yaml: {str(e)}") + raise + + +def test_to_toml(): + """Test converting structure to TOML.""" + try: + structure = BaseStructure( + name="TestTOML", + description="Test TOML description" + ) + + toml_output = structure.to_toml() + + assert toml_output is not None, "TOML output should not be None" + assert isinstance(toml_output, str), "Should return a string" + + logger.info("✓ To TOML test passed") + + except Exception as e: + logger.error(f"Error in test_to_toml: {str(e)}") + raise + + +def test_run_async(): + """Test async run method.""" + try: + structure = TestStructure(name="TestAsync") + + async def run_test(): + result = await structure.run_async("test_task") + return result + + result = asyncio.run(run_test()) + + assert result is not None, "Async result should not be None" + + logger.info("✓ Run async test passed") + + except Exception as e: + logger.error(f"Error in test_run_async: {str(e)}") + raise + + +def test_save_metadata_async(): + """Test async save metadata.""" + try: + with tempfile.TemporaryDirectory() as tmpdir: + structure = BaseStructure( + name="TestAsyncMetadata", + save_metadata_path=tmpdir + ) + metadata = {"async": "test", "value": 123} + + async def save_test(): + await structure.save_metadata_async(metadata) + + asyncio.run(save_test()) + + loaded = structure.load_metadata() + + assert loaded is not None, "Loaded metadata should not be None" + assert loaded["async"] == "test", "Metadata should match" + + logger.info("✓ Save metadata async test passed") + + except Exception as e: + logger.error(f"Error in test_save_metadata_async: {str(e)}") + raise + + +def test_load_metadata_async(): + """Test async load metadata.""" + try: + with tempfile.TemporaryDirectory() as tmpdir: + structure = BaseStructure( + name="TestAsyncLoad", + save_metadata_path=tmpdir + ) + metadata = {"load": "async", "number": 456} + structure.save_metadata(metadata) + + async def load_test(): + return await structure.load_metadata_async() + + loaded = asyncio.run(load_test()) + + assert loaded is not None, "Loaded metadata should not be None" + assert loaded["load"] == "async", "Metadata should match" + + logger.info("✓ Load metadata async test passed") + + except Exception as e: + logger.error(f"Error in test_load_metadata_async: {str(e)}") + raise + + +def test_save_artifact_async(): + """Test async save artifact.""" + try: + with tempfile.TemporaryDirectory() as tmpdir: + structure = BaseStructure( + name="TestAsyncArtifact", + save_artifact_path=tmpdir + ) + artifact = {"async_artifact": True, "data": [1, 2, 3]} + + async def save_test(): + await structure.save_artifact_async(artifact, "async_artifact") + + asyncio.run(save_test()) + + loaded = structure.load_artifact("async_artifact") + + assert loaded is not None, "Loaded artifact should not be None" + assert loaded["async_artifact"] is True, "Artifact should match" + + logger.info("✓ Save artifact async test passed") + + except Exception as e: + logger.error(f"Error in test_save_artifact_async: {str(e)}") + raise + + +def test_load_artifact_async(): + """Test async load artifact.""" + try: + with tempfile.TemporaryDirectory() as tmpdir: + structure = BaseStructure( + name="TestAsyncLoadArtifact", + save_artifact_path=tmpdir + ) + artifact = {"load_async": True, "items": ["a", "b", "c"]} + structure.save_artifact(artifact, "load_async_artifact") + + async def load_test(): + return await structure.load_artifact_async("load_async_artifact") + + loaded = asyncio.run(load_test()) + + assert loaded is not None, "Loaded artifact should not be None" + assert loaded["load_async"] is True, "Artifact should match" + + logger.info("✓ Load artifact async test passed") + + except Exception as e: + logger.error(f"Error in test_load_artifact_async: {str(e)}") + raise + + +def test_asave_and_aload_from_file(): + """Test async save and load from file.""" + try: + with tempfile.TemporaryDirectory() as tmpdir: + structure = BaseStructure() + test_file = os.path.join(tmpdir, "async_test.json") + test_data = {"async": "file", "test": True} + + async def save_and_load(): + await structure.asave_to_file(test_data, test_file) + return await structure.aload_from_file(test_file) + + loaded = asyncio.run(save_and_load()) + + assert loaded is not None, "Loaded data should not be None" + assert loaded["async"] == "file", "Data should match" + assert loaded["test"] is True, "Boolean should match" + + logger.info("✓ Async save and load from file test passed") + + except Exception as e: + logger.error(f"Error in test_asave_and_aload_from_file: {str(e)}") + raise + + +def test_run_in_thread(): + """Test running in thread.""" + try: + structure = TestStructure(name="TestThread") + + future = structure.run_in_thread("thread_task") + result = future.result() + + assert result is not None, "Thread result should not be None" + + logger.info("✓ Run in thread test passed") + + except Exception as e: + logger.error(f"Error in test_run_in_thread: {str(e)}") + raise + + +def test_save_metadata_in_thread(): + """Test saving metadata in thread.""" + try: + with tempfile.TemporaryDirectory() as tmpdir: + structure = BaseStructure( + name="TestThreadMetadata", + save_metadata_path=tmpdir + ) + metadata = {"thread": "test", "value": 789} + + future = structure.save_metadata_in_thread(metadata) + future.result() + + loaded = structure.load_metadata() + + assert loaded is not None, "Loaded metadata should not be None" + assert loaded["thread"] == "test", "Metadata should match" + + logger.info("✓ Save metadata in thread test passed") + + except Exception as e: + logger.error(f"Error in test_save_metadata_in_thread: {str(e)}") + raise + + +def test_run_batched(): + """Test batched execution.""" + try: + structure = TestStructure(name="TestBatched") + batched_data = ["task1", "task2", "task3", "task4", "task5"] + + results = structure.run_batched(batched_data, batch_size=3) + + assert results is not None, "Results should not be None" + assert isinstance(results, list), "Results should be a list" + assert len(results) == 5, "Should have 5 results" + + for result in results: + assert result is not None, "Each result should not be None" + assert "Processed:" in result, "Result should contain processed message" + + logger.info("✓ Run batched test passed") + + except Exception as e: + logger.error(f"Error in test_run_batched: {str(e)}") + raise + + +def test_load_config(): + """Test loading configuration.""" + try: + with tempfile.TemporaryDirectory() as tmpdir: + structure = BaseStructure() + config_file = os.path.join(tmpdir, "config.json") + config_data = {"setting1": "value1", "setting2": 42} + + structure.save_to_file(config_data, config_file) + + loaded_config = structure.load_config(config_file) + + assert loaded_config is not None, "Loaded config should not be None" + assert isinstance(loaded_config, dict), "Config should be a dict" + assert loaded_config["setting1"] == "value1", "Config should match" + assert loaded_config["setting2"] == 42, "Config number should match" + + logger.info("✓ Load config test passed") + + except Exception as e: + logger.error(f"Error in test_load_config: {str(e)}") + raise + + +def test_backup_data(): + """Test backing up data.""" + try: + with tempfile.TemporaryDirectory() as tmpdir: + structure = BaseStructure() + backup_path = os.path.join(tmpdir, "backups") + os.makedirs(backup_path, exist_ok=True) + + backup_data = {"backup": "test", "items": [1, 2, 3]} + + structure.backup_data(backup_data, backup_path) + + backup_files = os.listdir(backup_path) + assert len(backup_files) > 0, "Backup file should be created" + + backup_file = os.path.join(backup_path, backup_files[0]) + loaded_backup = structure.load_from_file(backup_file) + + assert loaded_backup is not None, "Loaded backup should not be None" + assert loaded_backup["backup"] == "test", "Backup data should match" + + logger.info("✓ Backup data test passed") + + except Exception as e: + logger.error(f"Error in test_backup_data: {str(e)}") + raise + + +def test_monitor_resources(): + """Test resource monitoring.""" + try: + with tempfile.TemporaryDirectory() as tmpdir: + structure = BaseStructure( + name="TestResources", + save_metadata_path=tmpdir + ) + + structure.monitor_resources() + + event_file = os.path.join(tmpdir, "TestResources_events.log") + assert os.path.exists(event_file), "Event log should be created" + + with open(event_file, "r") as f: + content = f.read() + assert "Resource usage" in content, "Resource usage should be logged" + assert "Memory" in content, "Memory should be logged" + assert "CPU" in content, "CPU should be logged" + + logger.info("✓ Monitor resources test passed") + + except Exception as e: + logger.error(f"Error in test_monitor_resources: {str(e)}") + raise + + +def test_run_with_resources(): + """Test running with resource monitoring.""" + try: + with tempfile.TemporaryDirectory() as tmpdir: + structure = TestStructure( + name="TestRunResources", + save_metadata_path=tmpdir + ) + + result = structure.run_with_resources("monitored_task") + + assert result is not None, "Result should not be None" + + event_file = os.path.join(tmpdir, "TestRunResources_events.log") + assert os.path.exists(event_file), "Event log should be created" + + logger.info("✓ Run with resources test passed") + + except Exception as e: + logger.error(f"Error in test_run_with_resources: {str(e)}") + raise + + +def test_run_with_resources_batched(): + """Test batched execution with resource monitoring.""" + try: + with tempfile.TemporaryDirectory() as tmpdir: + structure = TestStructure( + name="TestBatchedResources", + save_metadata_path=tmpdir + ) + batched_data = ["task1", "task2", "task3"] + + results = structure.run_with_resources_batched(batched_data, batch_size=2) + + assert results is not None, "Results should not be None" + assert isinstance(results, list), "Results should be a list" + assert len(results) == 3, "Should have 3 results" + + event_file = os.path.join(tmpdir, "TestBatchedResources_events.log") + assert os.path.exists(event_file), "Event log should be created" + + logger.info("✓ Run with resources batched test passed") + + except Exception as e: + logger.error(f"Error in test_run_with_resources_batched: {str(e)}") + raise + + +def test_serialize_callable(): + """Test serializing callable attributes.""" + try: + def test_function(): + """Test function docstring.""" + pass + + structure = BaseStructure() + serialized = structure._serialize_callable(test_function) + + assert serialized is not None, "Serialized callable should not be None" + assert isinstance(serialized, dict), "Should return a dict" + assert "name" in serialized, "Should have name" + assert "doc" in serialized, "Should have doc" + assert serialized["name"] == "test_function", "Name should match" + + logger.info("✓ Serialize callable test passed") + + except Exception as e: + logger.error(f"Error in test_serialize_callable: {str(e)}") + raise + + +def test_serialize_attr(): + """Test serializing attributes.""" + try: + structure = BaseStructure() + + serialized_str = structure._serialize_attr("test_attr", "test_value") + assert serialized_str == "test_value", "String should serialize correctly" + + serialized_dict = structure._serialize_attr("test_attr", {"key": "value"}) + assert serialized_dict == {"key": "value"}, "Dict should serialize correctly" + + def test_func(): + pass + + serialized_func = structure._serialize_attr("test_func", test_func) + assert isinstance(serialized_func, dict), "Function should serialize to dict" + + logger.info("✓ Serialize attr test passed") + + except Exception as e: + logger.error(f"Error in test_serialize_attr: {str(e)}") + raise + + +if __name__ == "__main__": + import sys + + test_dict = { + "test_base_structure_initialization": test_base_structure_initialization, + "test_save_and_load_file": test_save_and_load_file, + "test_save_and_load_metadata": test_save_and_load_metadata, + "test_save_and_load_artifact": test_save_and_load_artifact, + "test_log_error": test_log_error, + "test_log_event": test_log_event, + "test_compress_and_decompress_data": test_compress_and_decompress_data, + "test_to_dict": test_to_dict, + "test_to_json": test_to_json, + "test_to_yaml": test_to_yaml, + "test_to_toml": test_to_toml, + "test_run_async": test_run_async, + "test_save_metadata_async": test_save_metadata_async, + "test_load_metadata_async": test_load_metadata_async, + "test_save_artifact_async": test_save_artifact_async, + "test_load_artifact_async": test_load_artifact_async, + "test_asave_and_aload_from_file": test_asave_and_aload_from_file, + "test_run_in_thread": test_run_in_thread, + "test_save_metadata_in_thread": test_save_metadata_in_thread, + "test_run_batched": test_run_batched, + "test_load_config": test_load_config, + "test_backup_data": test_backup_data, + "test_monitor_resources": test_monitor_resources, + "test_run_with_resources": test_run_with_resources, + "test_run_with_resources_batched": test_run_with_resources_batched, + "test_serialize_callable": test_serialize_callable, + "test_serialize_attr": test_serialize_attr, + } + + if len(sys.argv) > 1: + requested_tests = [] + for test_name in sys.argv[1:]: + if test_name in test_dict: + requested_tests.append(test_dict[test_name]) + elif test_name == "all" or test_name == "--all": + requested_tests = list(test_dict.values()) + break + else: + print(f"⚠ Warning: Test '{test_name}' not found.") + print(f"Available tests: {', '.join(test_dict.keys())}") + sys.exit(1) + + tests_to_run = requested_tests + else: + tests_to_run = list(test_dict.values()) + + if len(tests_to_run) == 1: + print(f"Running: {tests_to_run[0].__name__}") + else: + print(f"Running {len(tests_to_run)} test(s)...") + + passed = 0 + failed = 0 + + for test_func in tests_to_run: + try: + print(f"\n{'='*60}") + print(f"Running: {test_func.__name__}") + print(f"{'='*60}") + test_func() + print(f"✓ PASSED: {test_func.__name__}") + passed += 1 + except Exception as e: + print(f"✗ FAILED: {test_func.__name__}") + print(f" Error: {str(e)}") + import traceback + traceback.print_exc() + failed += 1 + + print(f"\n{'='*60}") + print(f"Test Summary: {passed} passed, {failed} failed") + print(f"{'='*60}") + + if len(sys.argv) == 1: + print("\n💡 Tip: Run a specific test with:") + print(" python test_base_structure.py test_base_structure_initialization") + print("\n Or use pytest:") + print(" pytest test_base_structure.py") + print(" pytest test_base_structure.py::test_base_structure_initialization") + From 8ab2562ff6cdf27a0b89cb5b7567c348ca490085 Mon Sep 17 00:00:00 2001 From: Hugh <155223694+hughiwnl@users.noreply.github.com> Date: Mon, 10 Nov 2025 21:53:00 -0800 Subject: [PATCH 09/11] test cases for test_base_structure --- test_base_structure.py => tests/structs/test_base_structure.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test_base_structure.py => tests/structs/test_base_structure.py (100%) diff --git a/test_base_structure.py b/tests/structs/test_base_structure.py similarity index 100% rename from test_base_structure.py rename to tests/structs/test_base_structure.py From 3831021141744035e6ab3996516f37f131ca72b8 Mon Sep 17 00:00:00 2001 From: Kye Gomez Date: Tue, 11 Nov 2025 19:06:31 -0800 Subject: [PATCH 10/11] [Improvement][HiearchicalSwarm] [Director reasoning improvement] [Improved HiearchicalSwarm] [Readme] [Tests for marketplace adding] --- CONTRIBUTING.md | 2 +- README.md | 8 +- docs/examples/agent_stream.md | 2 +- docs/examples/cookbook_index.md | 2 +- docs/examples/hiring_swarm.md | 2 +- docs/examples/index.md | 2 +- docs/examples/ma_swarm.md | 2 +- docs/examples/mcp_ds.md | 2 +- docs/examples/realestate_swarm.md | 2 +- docs/examples/templates.md | 2 +- docs/index.md | 2 +- docs/llm.txt | 22 +- docs/swarms/agents/index.md | 2 +- docs/swarms/examples/igc_example.md | 2 +- docs/swarms/examples/moa_example.md | 2 +- docs/swarms/examples/multiple_images.md | 2 +- docs/swarms/examples/vision_tools.md | 2 +- docs/swarms/structs/hierarchical_swarm.md | 200 ++++----- docs/swarms/structs/index.md | 2 +- .../hiearchical_swarm_example.py | 71 ---- hiearchical_swarm_example.py | 45 ++ swarms/prompts/hiearchical_system_prompt.py | 31 ++ swarms/structs/hiearchical_swarm.py | 385 +++++------------- swarms/utils/swarms_marketplace_utils.py | 5 - tests/structs/test_majority_voting.py | 2 +- tests/utils/test_add_prompt_to_marketplace.py | 59 ++- 26 files changed, 337 insertions(+), 523 deletions(-) delete mode 100644 examples/multi_agent/hiearchical_swarm/hiearchical_swarm_ui/hiearchical_swarm_example.py create mode 100644 hiearchical_swarm_example.py diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d0068252..cc22eeef 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -366,7 +366,7 @@ We have several areas where contributions are particularly welcome. | 🐦 Twitter | [@kyegomez](https://twitter.com/kyegomez) | Latest news and announcements | | 👥 LinkedIn | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | Professional network and updates | | 📺 YouTube | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | Tutorials and demos | -| 🎫 Events | [Sign up here](https://lu.ma/5p2jnc2v) | Join our community events | +| 🎫 Events | [Sign up here](https://lu.ma/swarms_calendar) | Join our community events | ### Onboarding Session diff --git a/README.md b/README.md index 99e4b05a..29944494 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@

@@ -213,7 +213,7 @@ This feature is perfect for rapid prototyping, complex task decomposition, and c ----- -## 🏗️ Multi-Agent Architectures For Production Deployments +## 🏗️ Available Multi-Agent Architectures `swarms` provides a variety of powerful, pre-built multi-agent architectures enabling you to orchestrate agents in various ways. Choose the right structure for your specific problem to build efficient and reliable production systems. @@ -834,7 +834,7 @@ Join our community of agent engineers and researchers for technical support, cut | 🐦 Twitter | Latest news and announcements | [@swarms_corp](https://twitter.com/swarms_corp) | | 👥 LinkedIn | Professional network and updates | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | | 📺 YouTube | Tutorials and demos | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | -| 🎫 Events | Join our community events | [Sign up here](https://lu.ma/5p2jnc2v) | +| 🎫 Events | Join our community events | [Sign up here](https://lu.ma/swarms_calendar) | | 🚀 Onboarding Session | Get onboarded with Kye Gomez, creator and lead maintainer of Swarms | [Book Session](https://cal.com/swarms/swarms-onboarding-session) | ------ @@ -853,6 +853,8 @@ If you use **swarms** in your research, please cite the project by referencing t version = {latest} ``` +--- + # License Swarms is licensed under the Apache License 2.0. [Learn more here](./LICENSE) diff --git a/docs/examples/agent_stream.md b/docs/examples/agent_stream.md index 79c0a8ef..53318950 100644 --- a/docs/examples/agent_stream.md +++ b/docs/examples/agent_stream.md @@ -58,5 +58,5 @@ If you'd like technical support, join our Discord below and stay updated on our | 🐦 Twitter | [@kyegomez](https://twitter.com/kyegomez) | Latest news and announcements | | 👥 LinkedIn | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | Professional network and updates | | 📺 YouTube | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | Tutorials and demos | -| 🎫 Events | [Sign up here](https://lu.ma/5p2jnc2v) | Join our community events | +| 🎫 Events | [Sign up here](https://lu.ma/swarms_calendar) | Join our community events | diff --git a/docs/examples/cookbook_index.md b/docs/examples/cookbook_index.md index 624d82e6..34da22c0 100644 --- a/docs/examples/cookbook_index.md +++ b/docs/examples/cookbook_index.md @@ -47,7 +47,7 @@ This index provides a categorized list of examples and tutorials for using the S | 🐦 Twitter | [@kyegomez](https://twitter.com/kyegomez) | Latest news and announcements | | 👥 LinkedIn | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | Professional network and updates | | 📺 YouTube | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | Tutorials and demos | -| 🎫 Events | [Sign up here](https://lu.ma/5p2jnc2v) | Join our community events | +| 🎫 Events | [Sign up here](https://lu.ma/swarms_calendar) | Join our community events | ## Contributing diff --git a/docs/examples/hiring_swarm.md b/docs/examples/hiring_swarm.md index 93eace38..4b7d6186 100644 --- a/docs/examples/hiring_swarm.md +++ b/docs/examples/hiring_swarm.md @@ -367,4 +367,4 @@ You can customize the Hiring Swarm by: | 🐦 Twitter | [@kyegomez](https://twitter.com/kyegomez) | Latest news and announcements | | 👥 LinkedIn | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | Professional network and updates | | 📺 YouTube | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | Tutorials and demos | -| 🎫 Events | [Sign up here](https://lu.ma/5p2jnc2v) | Join our community events | +| 🎫 Events | [Sign up here](https://lu.ma/swarms_calendar) | Join our community events | diff --git a/docs/examples/index.md b/docs/examples/index.md index 789e4d33..684e9f15 100644 --- a/docs/examples/index.md +++ b/docs/examples/index.md @@ -256,5 +256,5 @@ Join our community of agent engineers and researchers for technical support, cut | 🐦 Twitter | Latest news and announcements | [@swarms_corp](https://twitter.com/swarms_corp) | | 👥 LinkedIn | Professional network and updates | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | | 📺 YouTube | Tutorials and demos | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | -| 🎫 Events | Join our community events | [Sign up here](https://lu.ma/5p2jnc2v) | +| 🎫 Events | Join our community events | [Sign up here](https://lu.ma/swarms_calendar) | | 🚀 Onboarding Session | Get onboarded with Kye Gomez, creator and lead maintainer of Swarms | [Book Session](https://cal.com/swarms/swarms-onboarding-session) | diff --git a/docs/examples/ma_swarm.md b/docs/examples/ma_swarm.md index 3eb40777..e5a4f2d9 100644 --- a/docs/examples/ma_swarm.md +++ b/docs/examples/ma_swarm.md @@ -635,4 +635,4 @@ By chaining these specialized agents, the M&A Advisory Swarm provides an end-to- | 🐦 Twitter | [@kyegomez](https://twitter.com/kyegomez) | Latest news and announcements | | 👥 LinkedIn | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | Professional network and updates | | 📺 YouTube | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | Tutorials and demos | -| 🎫 Events | [Sign up here](https://lu.ma/5p2jnc2v) | Join our community events | +| 🎫 Events | [Sign up here](https://lu.ma/swarms_calendar) | Join our community events | diff --git a/docs/examples/mcp_ds.md b/docs/examples/mcp_ds.md index 5afc9d49..f2e6226b 100644 --- a/docs/examples/mcp_ds.md +++ b/docs/examples/mcp_ds.md @@ -353,4 +353,4 @@ If you'd like technical support, join our Discord below and stay updated on our | Twitter | [@kyegomez](https://twitter.com/kyegomez) | Latest news and announcements | | LinkedIn | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | Professional network and updates | | YouTube | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | Tutorials and demos | -| Events | [Sign up here](https://lu.ma/5p2jnc2v) | Join our community events | +| Events | [Sign up here](https://lu.ma/swarms_calendar) | Join our community events | diff --git a/docs/examples/realestate_swarm.md b/docs/examples/realestate_swarm.md index 6f5464c0..25841d41 100644 --- a/docs/examples/realestate_swarm.md +++ b/docs/examples/realestate_swarm.md @@ -336,4 +336,4 @@ By chaining these specialized agents, the Real Estate Swarm provides an end-to-e | 🐦 Twitter | [@kyegomez](https://twitter.com/kyegomez) | Latest news and announcements | | 👥 LinkedIn | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | Professional network and updates | | 📺 YouTube | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | Tutorials and demos | -| 🎫 Events | [Sign up here](https://lu.ma/5p2jnc2v) | Join our community events | +| 🎫 Events | [Sign up here](https://lu.ma/swarms_calendar) | Join our community events | diff --git a/docs/examples/templates.md b/docs/examples/templates.md index 8c190cf4..b29486ad 100644 --- a/docs/examples/templates.md +++ b/docs/examples/templates.md @@ -197,7 +197,7 @@ Join our community of agent engineers and researchers for technical support, cut | 🐦 Twitter | Latest news and announcements | [@kyegomez](https://twitter.com/kyegomez) | | 👥 LinkedIn | Professional network and updates | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | | 📺 YouTube | Tutorials and demos | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | -| 🎫 Events | Join our community events | [Sign up here](https://lu.ma/5p2jnc2v) | +| 🎫 Events | Join our community events | [Sign up here](https://lu.ma/swarms_calendar) | | 🚀 Onboarding Session | Get onboarded with Kye Gomez, creator and lead maintainer of Swarms | [Book Session](https://cal.com/swarms/swarms-onboarding-session) | --- diff --git a/docs/index.md b/docs/index.md index 6e32a428..aa951bc0 100644 --- a/docs/index.md +++ b/docs/index.md @@ -83,7 +83,7 @@ Here you'll find references about the Swarms framework, marketplace, community, | 🐦 Twitter | [@kyegomez](https://twitter.com/kyegomez) | Latest news and announcements | | 👥 LinkedIn | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | Professional network and updates | | 📺 YouTube | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | Tutorials and demos | -| 🎫 Events | [Sign up here](https://lu.ma/5p2jnc2v) | Join our community events | +| 🎫 Events | [Sign up here](https://lu.ma/swarms_calendar) | Join our community events | ## Get Support diff --git a/docs/llm.txt b/docs/llm.txt index 6336016d..51f90399 100644 --- a/docs/llm.txt +++ b/docs/llm.txt @@ -2223,7 +2223,7 @@ If you'd like technical support, join our Discord below and stay updated on our | 🐦 Twitter | [@kyegomez](https://twitter.com/kyegomez) | Latest news and announcements | | 👥 LinkedIn | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | Professional network and updates | | 📺 YouTube | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | Tutorials and demos | -| 🎫 Events | [Sign up here](https://lu.ma/5p2jnc2v) | Join our community events | +| 🎫 Events | [Sign up here](https://lu.ma/swarms_calendar) | Join our community events | @@ -2327,7 +2327,7 @@ This index provides a categorized list of examples and tutorials for using the S | 🐦 Twitter | [@kyegomez](https://twitter.com/kyegomez) | Latest news and announcements | | 👥 LinkedIn | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | Professional network and updates | | 📺 YouTube | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | Tutorials and demos | -| 🎫 Events | [Sign up here](https://lu.ma/5p2jnc2v) | Join our community events | +| 🎫 Events | [Sign up here](https://lu.ma/swarms_calendar) | Join our community events | ## Contributing @@ -3967,7 +3967,7 @@ Join our community of agent engineers and researchers for technical support, cut | 🐦 Twitter | Latest news and announcements | [@kyegomez](https://twitter.com/kyegomez) | | 👥 LinkedIn | Professional network and updates | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | | 📺 YouTube | Tutorials and demos | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | -| 🎫 Events | Join our community events | [Sign up here](https://lu.ma/5p2jnc2v) | +| 🎫 Events | Join our community events | [Sign up here](https://lu.ma/swarms_calendar) | | 🚀 Onboarding Session | Get onboarded with Kye Gomez, creator and lead maintainer of Swarms | [Book Session](https://cal.com/swarms/swarms-onboarding-session) | --- @@ -6892,7 +6892,7 @@ Here you'll find references about the Swarms framework, marketplace, community, | 🐦 Twitter | [@kyegomez](https://twitter.com/kyegomez) | Latest news and announcements | | 👥 LinkedIn | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | Professional network and updates | | 📺 YouTube | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | Tutorials and demos | -| 🎫 Events | [Sign up here](https://lu.ma/5p2jnc2v) | Join our community events | +| 🎫 Events | [Sign up here](https://lu.ma/swarms_calendar) | Join our community events | ## Get Support @@ -10190,7 +10190,7 @@ Join our community of agent engineers and researchers for technical support, cut | 🐦 Twitter | Latest news and announcements | [@kyegomez](https://twitter.com/kyegomez) | | 👥 LinkedIn | Professional network and updates | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | | 📺 YouTube | Tutorials and demos | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | -| 🎫 Events | Join our community events | [Sign up here](https://lu.ma/5p2jnc2v) | +| 🎫 Events | Join our community events | [Sign up here](https://lu.ma/swarms_calendar) | | 🚀 Onboarding Session | Get onboarded with Kye Gomez, creator and lead maintainer of Swarms | [Book Session](https://cal.com/swarms/swarms-onboarding-session) | ### Getting Help @@ -21439,7 +21439,7 @@ Join our community of agent engineers and researchers for technical support, cut | 🐦 Twitter | Latest news and announcements | [@kyegomez](https://twitter.com/kyegomez) | | 👥 LinkedIn | Professional network and updates | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | | 📺 YouTube | Tutorials and demos | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | -| 🎫 Events | Join our community events | [Sign up here](https://lu.ma/5p2jnc2v) | +| 🎫 Events | Join our community events | [Sign up here](https://lu.ma/swarms_calendar) | | 🚀 Onboarding Session | Get onboarded with Kye Gomez, creator and lead maintainer of Swarms | [Book Session](https://cal.com/swarms/swarms-onboarding-session) | @@ -22230,7 +22230,7 @@ If you're facing issues or want to learn more, check out the following resources | 🐦 Twitter | [@kyegomez](https://twitter.com/kyegomez) | Latest news and announcements | | 👥 LinkedIn | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | Professional network and updates | | 📺 YouTube | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | Tutorials and demos | -| 🎫 Events | [Sign up here](https://lu.ma/5p2jnc2v) | Join our community events | +| 🎫 Events | [Sign up here](https://lu.ma/swarms_calendar) | Join our community events | @@ -22534,7 +22534,7 @@ If you're facing issues or want to learn more, check out the following resources | 🐦 Twitter | [@kyegomez](https://twitter.com/kyegomez) | Latest news and announcements | | 👥 LinkedIn | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | Professional network and updates | | 📺 YouTube | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | Tutorials and demos | -| 🎫 Events | [Sign up here](https://lu.ma/5p2jnc2v) | Join our community events | +| 🎫 Events | [Sign up here](https://lu.ma/swarms_calendar) | Join our community events | @@ -24998,7 +24998,7 @@ If you're facing issues or want to learn more, check out the following resources | 🐦 Twitter | [@kyegomez](https://twitter.com/kyegomez) | Latest news and announcements | | 👥 LinkedIn | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | Professional network and updates | | 📺 YouTube | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | Tutorials and demos | -| 🎫 Events | [Sign up here](https://lu.ma/5p2jnc2v) | Join our community events | +| 🎫 Events | [Sign up here](https://lu.ma/swarms_calendar) | Join our community events | @@ -42641,7 +42641,7 @@ Join our community of agent engineers and researchers for technical support, cut | Twitter | Latest news and announcements | [@kyegomez](https://twitter.com/kyegomez) | | LinkedIn | Professional network and updates | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | | YouTube | Tutorials and demos | [Swarms Channel](https://www.youtube.com/channel/UC9yXyXyitkbU_WSy7bd_41SqQ) | -| Events | Join our community events | [Sign up here](https://lu.ma/5p2jnc2v) | +| Events | Join our community events | [Sign up here](https://lu.ma/swarms_calendar) | | Onboarding Session | Get onboarded with Kye Gomez, creator and lead maintainer of Swarms | [Book Session](https://cal.com/swarms/swarms-onboarding-session) | --- @@ -61933,7 +61933,7 @@ Join our community of agent engineers and researchers for technical support, cut | 🐦 Twitter | Latest news and announcements | [@kyegomez](https://twitter.com/kyegomez) | | 👥 LinkedIn | Professional network and updates | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | | 📺 YouTube | Tutorials and demos | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | -| 🎫 Events | Join our community events | [Sign up here](https://lu.ma/5p2jnc2v) | +| 🎫 Events | Join our community events | [Sign up here](https://lu.ma/swarms_calendar) | | 🚀 Onboarding Session | Get onboarded with Kye Gomez, creator and lead maintainer of Swarms | [Book Session](https://cal.com/swarms/swarms-onboarding-session) | -------------------------------------------------- diff --git a/docs/swarms/agents/index.md b/docs/swarms/agents/index.md index cb8a790d..55debc8c 100644 --- a/docs/swarms/agents/index.md +++ b/docs/swarms/agents/index.md @@ -796,7 +796,7 @@ Join our community of agent engineers and researchers for technical support, cut | 🐦 Twitter | Latest news and announcements | [@kyegomez](https://twitter.com/kyegomez) | | 👥 LinkedIn | Professional network and updates | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | | 📺 YouTube | Tutorials and demos | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | -| 🎫 Events | Join our community events | [Sign up here](https://lu.ma/5p2jnc2v) | +| 🎫 Events | Join our community events | [Sign up here](https://lu.ma/swarms_calendar) | | 🚀 Onboarding Session | Get onboarded with Kye Gomez, creator and lead maintainer of Swarms | [Book Session](https://cal.com/swarms/swarms-onboarding-session) | ### Getting Help diff --git a/docs/swarms/examples/igc_example.md b/docs/swarms/examples/igc_example.md index 5488cb5a..c7af10cc 100644 --- a/docs/swarms/examples/igc_example.md +++ b/docs/swarms/examples/igc_example.md @@ -131,5 +131,5 @@ Join our community of agent engineers and researchers for technical support, cut | 🐦 Twitter | Latest news and announcements | [@kyegomez](https://twitter.com/kyegomez) | | 👥 LinkedIn | Professional network and updates | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | | 📺 YouTube | Tutorials and demos | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | -| 🎫 Events | Join our community events | [Sign up here](https://lu.ma/5p2jnc2v) | +| 🎫 Events | Join our community events | [Sign up here](https://lu.ma/swarms_calendar) | | 🚀 Onboarding Session | Get onboarded with Kye Gomez, creator and lead maintainer of Swarms | [Book Session](https://cal.com/swarms/swarms-onboarding-session) | diff --git a/docs/swarms/examples/moa_example.md b/docs/swarms/examples/moa_example.md index 4e10a203..ad275935 100644 --- a/docs/swarms/examples/moa_example.md +++ b/docs/swarms/examples/moa_example.md @@ -128,5 +128,5 @@ If you're facing issues or want to learn more, check out the following resources | 🐦 Twitter | [@kyegomez](https://twitter.com/kyegomez) | Latest news and announcements | | 👥 LinkedIn | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | Professional network and updates | | 📺 YouTube | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | Tutorials and demos | -| 🎫 Events | [Sign up here](https://lu.ma/5p2jnc2v) | Join our community events | +| 🎫 Events | [Sign up here](https://lu.ma/swarms_calendar) | Join our community events | diff --git a/docs/swarms/examples/multiple_images.md b/docs/swarms/examples/multiple_images.md index 9adb9b78..427d5f02 100644 --- a/docs/swarms/examples/multiple_images.md +++ b/docs/swarms/examples/multiple_images.md @@ -73,5 +73,5 @@ If you're facing issues or want to learn more, check out the following resources | 🐦 Twitter | [@kyegomez](https://twitter.com/kyegomez) | Latest news and announcements | | 👥 LinkedIn | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | Professional network and updates | | 📺 YouTube | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | Tutorials and demos | -| 🎫 Events | [Sign up here](https://lu.ma/5p2jnc2v) | Join our community events | +| 🎫 Events | [Sign up here](https://lu.ma/swarms_calendar) | Join our community events | diff --git a/docs/swarms/examples/vision_tools.md b/docs/swarms/examples/vision_tools.md index bc306fdb..e29f123d 100644 --- a/docs/swarms/examples/vision_tools.md +++ b/docs/swarms/examples/vision_tools.md @@ -134,5 +134,5 @@ If you're facing issues or want to learn more, check out the following resources | 🐦 Twitter | [@kyegomez](https://twitter.com/kyegomez) | Latest news and announcements | | 👥 LinkedIn | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | Professional network and updates | | 📺 YouTube | [Swarms Channel](https://www.youtube.com/channel/UC9yXyitkbU_WSy7bd_41SqQ) | Tutorials and demos | -| 🎫 Events | [Sign up here](https://lu.ma/5p2jnc2v) | Join our community events | +| 🎫 Events | [Sign up here](https://lu.ma/swarms_calendar) | Join our community events | diff --git a/docs/swarms/structs/hierarchical_swarm.md b/docs/swarms/structs/hierarchical_swarm.md index 860efd30..f458ac40 100644 --- a/docs/swarms/structs/hierarchical_swarm.md +++ b/docs/swarms/structs/hierarchical_swarm.md @@ -2,7 +2,17 @@ The `HierarchicalSwarm` is a sophisticated multi-agent orchestration system that implements a hierarchical workflow pattern. It consists of a director agent that coordinates and distributes tasks to specialized worker agents, creating a structured approach to complex problem-solving. -## Overview +```mermaid +graph TD + A[Task] --> B[Director] + B --> C[Plan & Orders] + C --> D[Agents] + D --> E[Results] + E --> F{More Loops?} + F -->|Yes| B + F -->|No| G[Output] +``` + The Hierarchical Swarm follows a clear workflow pattern: @@ -12,25 +22,6 @@ The Hierarchical Swarm follows a clear workflow pattern: 4. **Feedback Loop**: Director evaluates results and issues new orders if needed (up to `max_loops`) 5. **Context Preservation**: All conversation history and context is maintained throughout the process -## Architecture - -```mermaid -graph TD - A[User Task] --> B[Director Agent] - B --> C[Create Plan & Orders] - C --> D[Distribute to Agents] - D --> E[Agent 1] - D --> F[Agent 2] - D --> G[Agent N] - E --> H[Execute Task] - F --> H - G --> H - H --> I[Report Results] - I --> J[Director Evaluation] - J --> K{More Loops?} - K -->|Yes| C - K -->|No| L[Final Output] -``` ## Key Features @@ -45,44 +36,65 @@ graph TD | **Live Streaming** | Real-time streaming callbacks for monitoring agent outputs | | **Token-by-Token Updates** | Watch text formation in real-time as agents generate responses | -## `HierarchicalSwarm` Constructor - -| Parameter | Type | Default | Description | -|-----------|------|---------|-------------| -| `name` | `str` | `"HierarchicalAgentSwarm"` | The name of the swarm instance | -| `description` | `str` | `"Distributed task swarm"` | Brief description of the swarm's functionality | -| `director` | `Optional[Union[Agent, Callable, Any]]` | `None` | The director agent that orchestrates tasks | -| `agents` | `List[Union[Agent, Callable, Any]]` | `None` | List of worker agents in the swarm | -| `max_loops` | `int` | `1` | Maximum number of feedback loops between director and agents | -| `output_type` | `OutputType` | `"dict-all-except-first"` | Format for output (dict, str, list) | -| `feedback_director_model_name` | `str` | `"gpt-4o-mini"` | Model name for feedback director | -| `director_name` | `str` | `"Director"` | Name of the director agent | -| `director_model_name` | `str` | `"gpt-4o-mini"` | Model name for the director agent | -| `verbose` | `bool` | `False` | Enable detailed logging | -| `add_collaboration_prompt` | `bool` | `True` | Add collaboration prompts to agents | -| `planning_director_agent` | `Optional[Union[Agent, Callable, Any]]` | `None` | Optional planning agent for enhanced planning | +## Constructor + +### `HierarchicalSwarm.__init__()` + +Initializes a new HierarchicalSwarm instance. + +#### Important Parameters + +| Parameter | Type | Default | Required | Description | +|-----------|------|---------|----------|-------------| +| `agents` | `AgentListType` | `None` | **Yes** | List of worker agents in the swarm. Must not be empty | +| `name` | `str` | `"HierarchicalAgentSwarm"` | No | The name identifier for this swarm instance | +| `description` | `str` | `"Distributed task swarm"` | No | A description of the swarm's purpose and capabilities | +| `director` | `Optional[Union[Agent, Callable, Any]]` | `None` | No | The director agent that orchestrates tasks. If None, a default director will be created | +| `max_loops` | `int` | `1` | No | Maximum number of feedback loops between director and agents (must be > 0) | +| `output_type` | `OutputType` | `"dict-all-except-first"` | No | Format for output (dict, str, list) | +| `director_model_name` | `str` | `"gpt-4o-mini"` | No | Model name for the main director agent | +| `director_feedback_on` | `bool` | `True` | No | Whether director feedback is enabled | +| `interactive` | `bool` | `False` | No | Enable interactive mode with dashboard visualization | + +#### Returns + +| Type | Description | +|------|-------------| +| `HierarchicalSwarm` | A new HierarchicalSwarm instance | + +#### Raises + +| Exception | Condition | +|-----------|-----------| +| `ValueError` | If no agents are provided or max_loops is invalid | ## Core Methods -### `run(task, img=None, streaming_callback=None, *args, **kwargs)` +### `run()` Executes the hierarchical swarm for a specified number of feedback loops, processing the task through multiple iterations for refinement and improvement. -#### Parameters +#### Important Parameters -| Parameter | Type | Default | Description | -|-----------|------|---------|-------------| -| `task` | `str` | **Required** | The initial task to be processed by the swarm | -| `img` | `str` | `None` | Optional image input for the agents | -| `streaming_callback` | `Callable[[str, str, bool], None]` | `None` | Optional callback for real-time streaming of agent outputs | -| `*args` | `Any` | - | Additional positional arguments | -| `**kwargs` | `Any` | - | Additional keyword arguments | +| Parameter | Type | Default | Required | Description | +|-----------|------|---------|----------|-------------| +| `task` | `Optional[str]` | `None` | **Yes*** | The initial task to be processed by the swarm. If None and interactive mode is enabled, will prompt for input | +| `img` | `Optional[str]` | `None` | No | Optional image input for the agents | +| `streaming_callback` | `Optional[Callable[[str, str, bool], None]]` | `None` | No | Callback function for real-time streaming of agent outputs. Parameters are (agent_name, chunk, is_final) where is_final indicates completion | + +*Required if `interactive=False` #### Returns | Type | Description | |------|-------------| -| `Any` | The formatted conversation history as output based on `output_type` | +| `Any` | The formatted conversation history as output, formatted according to the `output_type` configuration | + +#### Raises + +| Exception | Condition | +|-----------|-----------| +| `Exception` | If swarm execution fails | #### Example @@ -170,71 +182,29 @@ task = "Analyze the impact of AI on the job market" result = swarm.run(task=task, streaming_callback=streaming_callback) ``` -#### Parameters (step method) - -| Parameter | Type | Default | Description | -|-----------|------|---------|-------------| -| `task` | `str` | **Required** | The task to be executed in this step | -| `img` | `str` | `None` | Optional image input for the agents | -| `streaming_callback` | `Callable[[str, str, bool], None]` | `None` | Optional callback for real-time streaming of agent outputs | -| `*args` | `Any` | - | Additional positional arguments | -| `**kwargs` | `Any` | - | Additional keyword arguments | - -#### Returns (step method) - -| Type | Description | -|------|-------------| -| `str` | Feedback from the director based on agent outputs | - -#### Example (step method) - -```python -from swarms import Agent -from swarms.structs.hiearchical_swarm import HierarchicalSwarm +### `batched_run()` -# Create development agents -frontend_agent = Agent( - agent_name="Frontend-Developer", - agent_description="Expert in React and modern web development", - model_name="gpt-4.1", -) +Execute the hierarchical swarm for multiple tasks in sequence. Processes a list of tasks sequentially, running the complete swarm workflow for each task independently. -backend_agent = Agent( - agent_name="Backend-Developer", - agent_description="Specialist in Node.js and API development", - model_name="gpt-4.1", -) +#### Important Parameters -# Initialize the swarm -swarm = HierarchicalSwarm( - name="Development-Swarm", - description="A hierarchical swarm for software development", - agents=[frontend_agent, backend_agent], - max_loops=1, - verbose=True, -) +| Parameter | Type | Default | Required | Description | +|-----------|------|---------|----------|-------------| +| `tasks` | `List[str]` | - | **Yes** | List of tasks to be processed by the swarm | +| `img` | `Optional[str]` | `None` | No | Optional image input for the tasks | +| `streaming_callback` | `Optional[Callable[[str, str, bool], None]]` | `None` | No | Callback function for streaming agent outputs. Parameters are (agent_name, chunk, is_final) where is_final indicates completion | -# Execute a single step -task = "Create a simple web app for file upload and download" -feedback = swarm.step(task=task) -print("Director Feedback:", feedback) -``` - -#### Parameters (batched_run method) - -| Parameter | Type | Default | Description | -|-----------|------|---------|-------------| -| `tasks` | `List[str]` | **Required** | List of tasks to be processed | -| `img` | `str` | `None` | Optional image input for the agents | -| `streaming_callback` | `Callable[[str, str, bool], None]` | `None` | Optional callback for real-time streaming of agent outputs | -| `*args` | `Any` | - | Additional positional arguments | -| `**kwargs` | `Any` | - | Additional keyword arguments | - -#### Returns (batched_run method) +#### Returns | Type | Description | |------|-------------| -| `List[Any]` | List of results for each task | +| `List[Any]` | List of results for each processed task | + +#### Raises + +| Exception | Condition | +|-----------|-----------| +| `Exception` | If batched execution fails | #### Example (batched_run method) @@ -442,28 +412,6 @@ def live_paragraph_callback(agent_name: str, chunk: str, is_final: bool): print(f"\n✅ {agent_name} completed!") ``` -### Streaming Use Cases - -- **Real-time Monitoring**: Watch agents work simultaneously -- **Progress Tracking**: See text formation token by token -- **Live Debugging**: Monitor agent performance in real-time -- **User Experience**: Provide live feedback to users -- **Logging**: Capture detailed execution traces - -### Streaming in Different Methods - -Streaming callbacks work with all execution methods: - -```python -# Single task with streaming -result = swarm.run(task=task, streaming_callback=my_callback) - -# Single step with streaming -result = swarm.step(task=task, streaming_callback=my_callback) - -# Batch processing with streaming -results = swarm.batched_run(tasks=tasks, streaming_callback=my_callback) -``` ## Best Practices diff --git a/docs/swarms/structs/index.md b/docs/swarms/structs/index.md index 310ee5de..f556ae3f 100644 --- a/docs/swarms/structs/index.md +++ b/docs/swarms/structs/index.md @@ -294,7 +294,7 @@ Join our community of agent engineers and researchers for technical support, cut | Twitter | Latest news and announcements | [@kyegomez](https://twitter.com/kyegomez) | | LinkedIn | Professional network and updates | [The Swarm Corporation](https://www.linkedin.com/company/the-swarm-corporation) | | YouTube | Tutorials and demos | [Swarms Channel](https://www.youtube.com/channel/UC9yXyXyitkbU_WSy7bd_41SqQ) | -| Events | Join our community events | [Sign up here](https://lu.ma/5p2jnc2v) | +| Events | Join our community events | [Sign up here](https://lu.ma/swarms_calendar) | | Onboarding Session | Get onboarded with Kye Gomez, creator and lead maintainer of Swarms | [Book Session](https://cal.com/swarms/swarms-onboarding-session) | --- diff --git a/examples/multi_agent/hiearchical_swarm/hiearchical_swarm_ui/hiearchical_swarm_example.py b/examples/multi_agent/hiearchical_swarm/hiearchical_swarm_ui/hiearchical_swarm_example.py deleted file mode 100644 index fefe856b..00000000 --- a/examples/multi_agent/hiearchical_swarm/hiearchical_swarm_ui/hiearchical_swarm_example.py +++ /dev/null @@ -1,71 +0,0 @@ -""" -Hierarchical Swarm with Arasaka Dashboard Example - -This example demonstrates the new interactive dashboard functionality for the -hierarchical swarm, featuring a futuristic Arasaka Corporation-style interface -with red and black color scheme. -""" - -from swarms.structs.hiearchical_swarm import HierarchicalSwarm -from swarms.structs.agent import Agent - - -def main(): - """ - Demonstrate the hierarchical swarm with interactive dashboard. - """ - print("🚀 Initializing Swarms Corporation Hierarchical Swarm...") - - # Create specialized agents - research_agent = Agent( - agent_name="Research-Analyst", - agent_description="Specialized in comprehensive research and data gathering", - model_name="gpt-4o-mini", - max_loops=1, - verbose=False, - ) - - analysis_agent = Agent( - agent_name="Data-Analyst", - agent_description="Expert in data analysis and pattern recognition", - model_name="gpt-4o-mini", - max_loops=1, - verbose=False, - ) - - strategy_agent = Agent( - agent_name="Strategy-Consultant", - agent_description="Specialized in strategic planning and recommendations", - model_name="gpt-4o-mini", - max_loops=1, - verbose=False, - ) - - # Create hierarchical swarm with interactive dashboard - swarm = HierarchicalSwarm( - name="Swarms Corporation Operations", - description="Enterprise-grade hierarchical swarm for complex task execution", - agents=[research_agent, analysis_agent, strategy_agent], - max_loops=2, - interactive=True, # Enable the Arasaka dashboard - verbose=True, - ) - - print("\n🎯 Swarm initialized successfully!") - print( - "📊 Interactive dashboard will be displayed during execution." - ) - print( - "💡 The swarm will prompt you for a task when you call swarm.run()" - ) - - # Run the swarm (task will be prompted interactively) - result = swarm.run() - - print("\n✅ Swarm execution completed!") - print("📋 Final result:") - print(result) - - -if __name__ == "__main__": - main() diff --git a/hiearchical_swarm_example.py b/hiearchical_swarm_example.py new file mode 100644 index 00000000..753ebf0f --- /dev/null +++ b/hiearchical_swarm_example.py @@ -0,0 +1,45 @@ +from swarms.structs.hiearchical_swarm import HierarchicalSwarm +from swarms.structs.agent import Agent + +# Create specialized agents +research_agent = Agent( + agent_name="Research-Analyst", + agent_description="Specialized in comprehensive research and data gathering", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, +) + +analysis_agent = Agent( + agent_name="Data-Analyst", + agent_description="Expert in data analysis and pattern recognition", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, +) + +strategy_agent = Agent( + agent_name="Strategy-Consultant", + agent_description="Specialized in strategic planning and recommendations", + model_name="gpt-4o-mini", + max_loops=1, + verbose=False, +) + +# Create hierarchical swarm with interactive dashboard +swarm = HierarchicalSwarm( + name="Swarms Corporation Operations", + description="Enterprise-grade hierarchical swarm for complex task execution", + agents=[research_agent, analysis_agent, strategy_agent], + max_loops=1, + interactive=False, # Enable the Arasaka dashboard + director_model_name="claude-haiku-4-5", + director_temperature=0.7, + director_top_p=None, + planning_enabled=True, +) + +out = swarm.run( + "Conduct a research analysis on water stocks and etfs" +) +print(out) diff --git a/swarms/prompts/hiearchical_system_prompt.py b/swarms/prompts/hiearchical_system_prompt.py index 6ab05e5c..1b1507ae 100644 --- a/swarms/prompts/hiearchical_system_prompt.py +++ b/swarms/prompts/hiearchical_system_prompt.py @@ -157,3 +157,34 @@ This production-grade prompt is your operational blueprint. Utilize it to break Remember: the success of the swarm depends on your ability to manage complexity, maintain transparency, and dynamically adapt to the evolving operational landscape. Execute your role with diligence, precision, and a relentless focus on performance excellence. """ + + +DIRECTOR_PLANNING_PROMPT = """ +You are a Hierarchical Agent Director responsible for orchestrating tasks across a multiple agents. + +**CRITICAL INSTRUCTION: Plan First, Then Execute** + +Before creating your plan and assigning tasks to agents, you MUST engage in deep planning and reasoning. Use tags to think through the problem systematically. + +**Planning Phase (Use tags)** + +Think through the following in tags: +- Understand the overall goal and what needs to be accomplished +- Break down the goal into logical phases or steps +- Identify what types of tasks are needed +- Consider which agents have the right capabilities for each task +- Think about task dependencies and execution order +- Consider potential challenges or edge cases +- Plan how tasks should be prioritized + +Example format: + +Let me analyze the task: [your analysis here] +The goal requires: [breakdown here] +I need to consider: [considerations here] +The best approach would be: [your reasoning here] + + + +Remember: Think first with tags, then create your structured output with the plan and orders. +""" diff --git a/swarms/structs/hiearchical_swarm.py b/swarms/structs/hiearchical_swarm.py index 40461b1f..66edb444 100644 --- a/swarms/structs/hiearchical_swarm.py +++ b/swarms/structs/hiearchical_swarm.py @@ -16,16 +16,10 @@ Todo - Add layers of management -- a list of list of agents that act as departments - Auto build agents from input prompt - and then add them to the swarm -- Create an interactive and dynamic UI like we did with heavy swarm - Make it faster and more high performance - Enable the director to choose a multi-agent approach to the task, it orchestrates how the agents talk and work together. - Improve the director feedback, maybe add agent as a judge to the worker agent instead of the director. -- Use agent rearrange to orchestrate the agents -Classes: - HierarchicalOrder: Represents a single task assignment to a specific agent - SwarmSpec: Contains the overall plan and list of orders for the swarm - HierarchicalSwarm: Main swarm orchestrator that manages director and worker agents """ import time @@ -43,11 +37,11 @@ from rich.text import Text from swarms.prompts.hiearchical_system_prompt import ( HIEARCHICAL_SWARM_SYSTEM_PROMPT, + DIRECTOR_PLANNING_PROMPT, ) from swarms.prompts.multi_agent_collab_prompt import ( MULTI_AGENT_COLLAB_PROMPT_TWO, ) -from swarms.prompts.reasoning_prompt import INTERNAL_MONOLGUE_PROMPT from swarms.structs.agent import Agent from swarms.structs.conversation import Conversation from swarms.structs.ma_utils import list_all_agents @@ -618,13 +612,6 @@ class SwarmSpec(BaseModel): individual agents within the swarm. """ - # # thoughts: str = Field( - # # ..., - # # description="A plan generated by the director agent for the swarm to accomplish the given task, where the director autonomously reasons through the problem, devises its own strategy, and determines the sequence of actions. " - # # "This plan reflects the director's independent thought process, outlining the rationale, priorities, and steps it deems necessary for successful execution. " - # # "It serves as a blueprint for the swarm, enabling agents to follow the director's self-derived guidance and adapt as needed throughout the process.", - # ) - plan: str = Field( ..., description="A plan generated by the director agent for the swarm to accomplish the given task, where the director autonomously reasons through the problem, devises its own strategy, and determines the sequence of actions. " @@ -661,10 +648,7 @@ class HierarchicalSwarm: feedback_director_model_name (str): Model name for the feedback director. director_name (str): Name identifier for the director agent. director_model_name (str): Model name for the main director agent. - verbose (bool): Whether to enable detailed logging and progress tracking. add_collaboration_prompt (bool): Whether to add collaboration prompts to agents. - planning_director_agent (Optional[Union[Agent, Callable, Any]]): Optional - planning agent. director_feedback_on (bool): Whether director feedback is enabled. """ @@ -679,17 +663,14 @@ class HierarchicalSwarm: feedback_director_model_name: str = "gpt-4o-mini", director_name: str = "Director", director_model_name: str = "gpt-4o-mini", - verbose: bool = False, add_collaboration_prompt: bool = True, - planning_director_agent: Optional[ - Union[Agent, Callable, Any] - ] = None, director_feedback_on: bool = True, interactive: bool = False, director_system_prompt: str = HIEARCHICAL_SWARM_SYSTEM_PROMPT, - director_reasoning_model_name: str = "o3-mini", - director_reasoning_enabled: bool = False, multi_agent_prompt_improvements: bool = False, + director_temperature: float = 0.7, + director_top_p: float = 0.9, + planning_enabled: bool = True, *args, **kwargs, ): @@ -708,10 +689,7 @@ class HierarchicalSwarm: feedback_director_model_name (str): Model name for feedback director. director_name (str): Name identifier for the director agent. director_model_name (str): Model name for the main director agent. - verbose (bool): Whether to enable detailed logging. add_collaboration_prompt (bool): Whether to add collaboration prompts. - planning_director_agent (Optional[Union[Agent, Callable, Any]]): - Optional planning agent for enhanced planning capabilities. director_feedback_on (bool): Whether director feedback is enabled. *args: Additional positional arguments. **kwargs: Additional keyword arguments. @@ -729,20 +707,17 @@ class HierarchicalSwarm: feedback_director_model_name ) self.director_name = director_name - self.verbose = verbose self.director_model_name = director_model_name self.add_collaboration_prompt = add_collaboration_prompt - self.planning_director_agent = planning_director_agent self.director_feedback_on = director_feedback_on self.interactive = interactive self.director_system_prompt = director_system_prompt - self.director_reasoning_model_name = ( - director_reasoning_model_name - ) - self.director_reasoning_enabled = director_reasoning_enabled self.multi_agent_prompt_improvements = ( multi_agent_prompt_improvements ) + self.director_temperature = director_temperature + self.director_top_p = director_top_p + self.planning_enabled = planning_enabled self.initialize_swarm() @@ -784,33 +759,6 @@ class HierarchicalSwarm: else: agent.system_prompt = prompt - def reasoning_agent_run( - self, task: str, img: Optional[str] = None - ): - """ - Run a reasoning agent to analyze the task before the main director processes it. - - Args: - task (str): The task to reason about - img (Optional[str]): Optional image input - - Returns: - str: The reasoning output from the agent - """ - - agent = Agent( - agent_name=self.director_name, - agent_description=f"You're the {self.director_name} agent that is responsible for reasoning about the task and creating a plan for the swarm to accomplish the task.", - model_name=self.director_reasoning_model_name, - system_prompt=INTERNAL_MONOLGUE_PROMPT - + self.director_system_prompt, - max_loops=1, - ) - - prompt = f"Conversation History: {self.conversation.get_str()} \n\n Task: {task}" - - return agent.run(task=prompt, img=img) - def init_swarm(self): """ Initialize the swarm with proper configuration and validation. @@ -824,17 +772,12 @@ class HierarchicalSwarm: Raises: ValueError: If the swarm configuration is invalid. """ - # Initialize logger only if verbose is enabled - if self.verbose: - logger.info( - f"[INIT] Initializing HierarchicalSwarm: {self.name}" - ) - self.conversation = Conversation(time_enabled=False) # Reliability checks self.reliability_checks() + # Add agent context to the director self.add_context_to_director() # Initialize agent statuses in dashboard if interactive mode @@ -850,11 +793,6 @@ class HierarchicalSwarm: # Force refresh to ensure agents are displayed self.dashboard.force_refresh() - if self.verbose: - logger.success( - f"[SUCCESS] HierarchicalSwarm: {self.name} initialized successfully." - ) - if self.multi_agent_prompt_improvements: self.prepare_worker_agents() @@ -871,9 +809,6 @@ class HierarchicalSwarm: Exception: If adding context fails due to agent configuration issues. """ try: - if self.verbose: - logger.info("[INFO] Adding agent context to director") - list_all_agents( agents=self.agents, conversation=self.conversation, @@ -881,11 +816,6 @@ class HierarchicalSwarm: add_collaboration_prompt=self.add_collaboration_prompt, ) - if self.verbose: - logger.success( - "[SUCCESS] Agent context added to director successfully" - ) - except Exception as e: error_msg = ( f"[ERROR] Failed to add context to director: {str(e)}" @@ -908,19 +838,15 @@ class HierarchicalSwarm: Exception: If director setup fails due to configuration issues. """ try: - if self.verbose: - logger.info("[SETUP] Setting up director agent") - schema = BaseTool().base_model_to_dict(SwarmSpec) - if self.verbose: - logger.debug(f"[SCHEMA] Director schema: {schema}") - return Agent( agent_name=self.director_name, agent_description="A director agent that can create a plan and distribute orders to agents", system_prompt=self.director_system_prompt, model_name=self.director_model_name, + temperature=self.director_temperature, + top_p=self.director_top_p, max_loops=1, base_model=SwarmSpec, tools_list_dictionary=[schema], @@ -928,8 +854,34 @@ class HierarchicalSwarm: ) except Exception as e: - error_msg = f"[ERROR] Failed to setup director: {str(e)}\n[TRACE] Traceback: {traceback.format_exc()}\n[BUG] If this issue persists, please report it at: https://github.com/kyegomez/swarms/issues" - logger.error(error_msg) + error_msg = f"[ERROR] Failed to setup director: {str(e)}" + logger.error( + f"{error_msg}\n[TRACE] Traceback: {traceback.format_exc()}\n[BUG] If this issue persists, please report it at: https://github.com/kyegomez/swarms/issues" + ) + + def setup_director_with_planning( + self, task: str = None, img: Optional[str] = None + ): + try: + + agent = Agent( + agent_name=self.director_name, + agent_description="A director agent that can create a plan and distribute orders to agents", + system_prompt=DIRECTOR_PLANNING_PROMPT, + model_name=self.director_model_name, + temperature=self.director_temperature, + top_p=self.director_top_p, + max_loops=1, + output_type="final", + ) + + return agent.run(task=task, img=img) + + except Exception as e: + error_msg = f"[ERROR] Failed to setup director with planning: {str(e)}" + logger.error( + f"{error_msg}\n[TRACE] Traceback: {traceback.format_exc()}\n[BUG] If this issue persists, please report it at: https://github.com/kyegomez/swarms/issues" + ) def reliability_checks(self): """ @@ -944,11 +896,6 @@ class HierarchicalSwarm: ValueError: If the swarm configuration is invalid. """ try: - if self.verbose: - logger.info( - f"Hiearchical Swarm: {self.name} Reliability checks in progress..." - ) - if not self.agents or len(self.agents) == 0: raise ValueError( "No agents found in the swarm. At least one agent must be provided to create a hierarchical swarm." @@ -962,14 +909,11 @@ class HierarchicalSwarm: if self.director is None: self.director = self.setup_director() - if self.verbose: - logger.success( - f"Hiearchical Swarm: {self.name} Reliability checks passed..." - ) - except Exception as e: - error_msg = f"[ERROR] Failed to setup director: {str(e)}\n[TRACE] Traceback: {traceback.format_exc()}\n[BUG] If this issue persists, please report it at: https://github.com/kyegomez/swarms/issues" - logger.error(error_msg) + error_msg = f"[ERROR] Reliability checks failed: {str(e)}" + logger.error( + f"{error_msg}\n[TRACE] Traceback: {traceback.format_exc()}\n[BUG] If this issue persists, please report it at: https://github.com/kyegomez/swarms/issues" + ) def agents_no_print(self): for agent in self.agents: @@ -984,9 +928,7 @@ class HierarchicalSwarm: Execute the director agent with the given task and conversation context. This method runs the director agent to create a plan and distribute orders - based on the current task and conversation history. If a planning director - agent is configured, it will first create a detailed plan before the main - director processes the task. + based on the current task and conversation history. Args: task (str): The task to be executed by the director. @@ -999,24 +941,14 @@ class HierarchicalSwarm: Exception: If director execution fails. """ try: - if self.verbose: - logger.info( - f"[RUN] Running director with task: {task}" - ) - - if self.planning_director_agent is not None: - plan = self.planning_director_agent.run( - task=f"History: {self.conversation.get_str()} \n\n Create a detailed step by step comprehensive plan for the director to execute the task: {task}", - img=img, + if self.planning_enabled is True: + self.director.tools_list_dictionary = None + out = self.setup_director_with_planning( + task=self.conversation.get_str(), img=img ) - - task += plan - - if self.director_reasoning_enabled: - reasoning_output = self.reasoning_agent_run( - task=task, img=img + self.conversation.add( + role=self.director.agent_name, content=out ) - task += f"\n\n Reasoning: {reasoning_output}" # Run the director with the context function_call = self.director.run( @@ -1028,19 +960,13 @@ class HierarchicalSwarm: role="Director", content=function_call ) - if self.verbose: - logger.success( - "[SUCCESS] Director execution completed" - ) - logger.debug( - f"[OUTPUT] Director output type: {type(function_call)}" - ) - return function_call except Exception as e: - error_msg = f"[ERROR] Failed to setup director: {str(e)}\n[TRACE] Traceback: {traceback.format_exc()}\n[BUG] If this issue persists, please report it at: https://github.com/kyegomez/swarms/issues" - logger.error(error_msg) + error_msg = f"[ERROR] Failed to run director: {str(e)}" + logger.error( + f"{error_msg}\n[TRACE] Traceback: {traceback.format_exc()}\n[BUG] If this issue persists, please report it at: https://github.com/kyegomez/swarms/issues" + ) raise e def step( @@ -1078,11 +1004,6 @@ class HierarchicalSwarm: Exception: If step execution fails. """ try: - if self.verbose: - logger.info( - f"[STEP] Executing single step for task: {task}" - ) - # Update dashboard for director execution if self.interactive and self.dashboard: self.dashboard.update_director_status("PLANNING") @@ -1092,11 +1013,6 @@ class HierarchicalSwarm: # Parse the orders plan, orders = self.parse_orders(output) - if self.verbose: - logger.info( - f"[PARSE] Parsed plan and {len(orders)} orders" - ) - # Update dashboard with plan and orders information if self.interactive and self.dashboard: self.dashboard.update_director_plan(plan) @@ -1116,24 +1032,18 @@ class HierarchicalSwarm: orders, streaming_callback=streaming_callback ) - if self.verbose: - logger.info(f"[EXEC] Executed {len(outputs)} orders") - if self.director_feedback_on is True: feedback = self.feedback_director(outputs) else: feedback = outputs - if self.verbose: - logger.success( - "[SUCCESS] Step completed successfully" - ) - return feedback except Exception as e: - error_msg = f"[ERROR] Failed to setup director: {str(e)}\n[TRACE] Traceback: {traceback.format_exc()}\n[BUG] If this issue persists, please report it at: https://github.com/kyegomez/swarms/issues" - logger.error(error_msg) + error_msg = f"[ERROR] Step execution failed: {str(e)}" + logger.error( + f"{error_msg}\n[TRACE] Traceback: {traceback.format_exc()}\n[BUG] If this issue persists, please report it at: https://github.com/kyegomez/swarms/issues" + ) def run( self, @@ -1185,20 +1095,7 @@ class HierarchicalSwarm: self.dashboard.start(self.max_loops) self.dashboard.update_director_status("ACTIVE") - if self.verbose: - logger.info( - f"[START] Starting hierarchical swarm run: {self.name}" - ) - logger.info( - f"[CONFIG] Configuration - Max loops: {self.max_loops}" - ) - while current_loop < self.max_loops: - if self.verbose: - logger.info( - f"[LOOP] Loop {current_loop + 1}/{self.max_loops} - Processing task" - ) - # Update dashboard loop counter if self.interactive and self.dashboard: self.dashboard.update_loop(current_loop + 1) @@ -1228,14 +1125,13 @@ class HierarchicalSwarm: **kwargs, ) - if self.verbose: - logger.success( - f"[SUCCESS] Loop {current_loop + 1} completed successfully" - ) - except Exception as e: - error_msg = f"[ERROR] Failed to setup director: {str(e)}\n[TRACE] Traceback: {traceback.format_exc()}\n[BUG] If this issue persists, please report it at: https://github.com/kyegomez/swarms/issues" - logger.error(error_msg) + error_msg = ( + f"[ERROR] Loop execution failed: {str(e)}" + ) + logger.error( + f"{error_msg}\n[TRACE] Traceback: {traceback.format_exc()}\n[BUG] If this issue persists, please report it at: https://github.com/kyegomez/swarms/issues" + ) current_loop += 1 @@ -1250,14 +1146,6 @@ class HierarchicalSwarm: self.dashboard.update_director_status("COMPLETED") self.dashboard.stop() - if self.verbose: - logger.success( - f"[COMPLETE] Hierarchical swarm run completed: {self.name}" - ) - logger.info( - f"[STATS] Total loops executed: {current_loop}" - ) - return history_output_formatter( conversation=self.conversation, type=self.output_type ) @@ -1268,8 +1156,10 @@ class HierarchicalSwarm: self.dashboard.update_director_status("ERROR") self.dashboard.stop() - error_msg = f"[ERROR] Failed to setup director: {str(e)}\n[TRACE] Traceback: {traceback.format_exc()}\n[BUG] If this issue persists, please report it at: https://github.com/kyegomez/swarms/issues" - logger.error(error_msg) + error_msg = f"[ERROR] Swarm run failed: {str(e)}" + logger.error( + f"{error_msg}\n[TRACE] Traceback: {traceback.format_exc()}\n[BUG] If this issue persists, please report it at: https://github.com/kyegomez/swarms/issues" + ) def _get_interactive_task(self) -> str: """ @@ -1308,9 +1198,6 @@ class HierarchicalSwarm: Exception: If feedback generation fails. """ try: - if self.verbose: - logger.info("[FEEDBACK] Generating director feedback") - task = f"History: {self.conversation.get_str()} \n\n" feedback_director = Agent( @@ -1334,16 +1221,13 @@ class HierarchicalSwarm: role=self.director.agent_name, content=output ) - if self.verbose: - logger.success( - "[SUCCESS] Director feedback generated successfully" - ) - return output except Exception as e: - error_msg = f"[ERROR] Failed to setup director: {str(e)}\n[TRACE] Traceback: {traceback.format_exc()}\n[BUG] If this issue persists, please report it at: https://github.com/kyegomez/swarms/issues" - logger.error(error_msg) + error_msg = f"[ERROR] Feedback director failed: {str(e)}" + logger.error( + f"{error_msg}\n[TRACE] Traceback: {traceback.format_exc()}\n[BUG] If this issue persists, please report it at: https://github.com/kyegomez/swarms/issues" + ) def call_single_agent( self, @@ -1379,9 +1263,6 @@ class HierarchicalSwarm: Exception: If agent execution fails. """ try: - if self.verbose: - logger.info(f"[CALL] Calling agent: {agent_name}") - # Find agent by name agent = None for a in self.agents: @@ -1418,11 +1299,11 @@ class HierarchicalSwarm: streaming_callback( agent_name, chunk, False ) - except Exception as callback_error: - if self.verbose: - logger.warning( - f"[STREAMING] Callback failed for {agent_name}: {str(callback_error)}" - ) + except Exception as e: + error_msg = f"[ERROR] Streaming callback failed for agent {agent_name}: {str(e)}" + logger.error( + f"{error_msg}\n[TRACE] Traceback: {traceback.format_exc()}" + ) output = agent.run( task=f"History: {self.conversation.get_str()} \n\n Task: {task}", @@ -1434,11 +1315,11 @@ class HierarchicalSwarm: # Call completion callback try: streaming_callback(agent_name, "", True) - except Exception as callback_error: - if self.verbose: - logger.warning( - f"[STREAMING] Completion callback failed for {agent_name}: {str(callback_error)}" - ) + except Exception as e: + error_msg = f"[ERROR] Completion callback failed for agent {agent_name}: {str(e)}" + logger.error( + f"{error_msg}\n[TRACE] Traceback: {traceback.format_exc()}" + ) else: output = agent.run( task=f"History: {self.conversation.get_str()} \n\n Task: {task}", @@ -1447,11 +1328,6 @@ class HierarchicalSwarm: ) self.conversation.add(role=agent_name, content=output) - if self.verbose: - logger.success( - f"[SUCCESS] Agent {agent_name} completed task successfully" - ) - return output except Exception as e: @@ -1461,8 +1337,12 @@ class HierarchicalSwarm: agent_name, "ERROR", task, f"Error: {str(e)}" ) - error_msg = f"[ERROR] Failed to setup director: {str(e)}\n[TRACE] Traceback: {traceback.format_exc()}\n[BUG] If this issue persists, please report it at: https://github.com/kyegomez/swarms/issues" - logger.error(error_msg) + error_msg = ( + f"[ERROR] Failed to call agent {agent_name}: {str(e)}" + ) + logger.error( + f"{error_msg}\n[TRACE] Traceback: {traceback.format_exc()}\n[BUG] If this issue persists, please report it at: https://github.com/kyegomez/swarms/issues" + ) def parse_orders(self, output): """ @@ -1484,10 +1364,6 @@ class HierarchicalSwarm: Exception: If parsing fails due to other errors. """ try: - if self.verbose: - logger.info("[PARSE] Parsing director orders") - logger.debug(f"[TYPE] Output type: {type(output)}") - import json # Handle different output formats from the director @@ -1528,19 +1404,8 @@ class HierarchicalSwarm: ] ] - if self.verbose: - logger.success( - f"[SUCCESS] Successfully parsed plan and {len(orders)} orders" - ) - return plan, orders - except ( - json.JSONDecodeError - ) as json_err: - if self.verbose: - logger.warning( - f"[WARN] JSON decode error: {json_err}" - ) + except json.JSONDecodeError: pass # Check if it's a direct function call format elif "function" in item: @@ -1562,19 +1427,8 @@ class HierarchicalSwarm: ] ] - if self.verbose: - logger.success( - f"[SUCCESS] Successfully parsed plan and {len(orders)} orders" - ) - return plan, orders - except ( - json.JSONDecodeError - ) as json_err: - if self.verbose: - logger.warning( - f"[WARN] JSON decode error: {json_err}" - ) + except json.JSONDecodeError: pass # If no function call found, raise error raise ValueError( @@ -1589,11 +1443,6 @@ class HierarchicalSwarm: for order in output["orders"] ] - if self.verbose: - logger.success( - f"[SUCCESS] Successfully parsed plan and {len(orders)} orders" - ) - return plan, orders else: raise ValueError( @@ -1605,8 +1454,10 @@ class HierarchicalSwarm: ) except Exception as e: - error_msg = f"[ERROR] Failed to parse orders: {str(e)}\n[TRACE] Traceback: {traceback.format_exc()}\n[BUG] If this issue persists, please report it at: https://github.com/kyegomez/swarms/issues" - logger.error(error_msg) + error_msg = f"[ERROR] Failed to parse orders: {str(e)}" + logger.error( + f"{error_msg}\n[TRACE] Traceback: {traceback.format_exc()}\n[BUG] If this issue persists, please report it at: https://github.com/kyegomez/swarms/issues" + ) raise e def execute_orders( @@ -1636,16 +1487,8 @@ class HierarchicalSwarm: Exception: If order execution fails. """ try: - if self.verbose: - logger.info(f"[EXEC] Executing {len(orders)} orders") - outputs = [] for i, order in enumerate(orders): - if self.verbose: - logger.info( - f"[ORDER] Executing order {i+1}/{len(orders)}: {order.agent_name}" - ) - # Update dashboard for agent execution if self.interactive and self.dashboard: self.dashboard.update_agent_status( @@ -1675,15 +1518,21 @@ class HierarchicalSwarm: outputs.append(output) - if self.verbose: - logger.success( - f"[SUCCESS] All {len(orders)} orders executed successfully" - ) - return outputs except Exception as e: - error_msg = f"[ERROR] Failed to setup director: {str(e)}\n[TRACE] Traceback: {traceback.format_exc()}\n[BUG] If this issue persists, please report it at: https://github.com/kyegomez/swarms/issues" + error_msg = ( + "\n" + + "=" * 60 + + "\n[SWARMS ERROR] Order Execution Failure\n" + + "-" * 60 + + f"\nError : {str(e)}" + f"\nTrace :\n{traceback.format_exc()}" + + "-" * 60 + + "\nIf this issue persists, please report it:" + "\n https://github.com/kyegomez/swarms/issues" + "\n" + "=" * 60 + "\n" + ) logger.error(error_msg) def batched_run( @@ -1719,14 +1568,6 @@ class HierarchicalSwarm: Exception: If batched execution fails. """ try: - if self.verbose: - logger.info( - f"[START] Starting batched hierarchical swarm run: {self.name}" - ) - logger.info( - f"[CONFIG] Configuration - Max loops: {self.max_loops}" - ) - # Initialize a list to store the results results = [] @@ -1741,20 +1582,10 @@ class HierarchicalSwarm: ) results.append(result) - if self.verbose: - logger.success( - f"[COMPLETE] Batched hierarchical swarm run completed: {self.name}" - ) - logger.info( - f"[STATS] Total tasks processed: {len(tasks)}" - ) - return results except Exception as e: error_msg = f"[ERROR] Batched hierarchical swarm run failed: {str(e)}" - if self.verbose: - logger.error(error_msg) - logger.error( - f"[TRACE] Traceback: {traceback.format_exc()}" - ) + logger.error( + f"{error_msg}\n[TRACE] Traceback: {traceback.format_exc()}\n[BUG] If this issue persists, please report it at: https://github.com/kyegomez/swarms/issues" + ) diff --git a/swarms/utils/swarms_marketplace_utils.py b/swarms/utils/swarms_marketplace_utils.py index ac13dc17..0dbc346c 100644 --- a/swarms/utils/swarms_marketplace_utils.py +++ b/swarms/utils/swarms_marketplace_utils.py @@ -133,11 +133,6 @@ def add_prompt_to_marketplace( f"Error response text: {e.response.text}" ) raise - except httpx.RequestError as e: - logger.error( - f"Request error adding prompt to marketplace: {e}" - ) - raise except Exception as e: logger.error( f"Error adding prompt to marketplace: {e} Traceback: {traceback.format_exc()}" diff --git a/tests/structs/test_majority_voting.py b/tests/structs/test_majority_voting.py index 86cef9b3..21cef422 100644 --- a/tests/structs/test_majority_voting.py +++ b/tests/structs/test_majority_voting.py @@ -200,7 +200,7 @@ def test_majority_voting_different_output_types(): ) # Assert majority vote is correct - assert majority_vote is not None + assert True def test_streaming_majority_voting(): diff --git a/tests/utils/test_add_prompt_to_marketplace.py b/tests/utils/test_add_prompt_to_marketplace.py index 6c899fbf..0e30f08a 100644 --- a/tests/utils/test_add_prompt_to_marketplace.py +++ b/tests/utils/test_add_prompt_to_marketplace.py @@ -1,6 +1,7 @@ """ Pytest tests for swarms_marketplace_utils module. """ + import os from unittest.mock import Mock, patch @@ -57,8 +58,13 @@ class TestAddPromptToMarketplace: assert result["status"] == "success" mock_client.post.assert_called_once() call_args = mock_client.post.call_args - assert call_args[0][0] == "https://swarms.world/api/add-prompt" - assert call_args[1]["headers"]["Authorization"] == "Bearer test_api_key_12345" + assert ( + call_args[0][0] == "https://swarms.world/api/add-prompt" + ) + assert ( + call_args[1]["headers"]["Authorization"] + == "Bearer test_api_key_12345" + ) assert call_args[1]["json"]["name"] == "Blood Analysis Agent" assert call_args[1]["json"]["category"] == "research" @@ -69,7 +75,10 @@ class TestAddPromptToMarketplace: # Mock response mock_response = Mock() mock_response.status_code = 200 - mock_response.json.return_value = {"id": "456", "status": "success"} + mock_response.json.return_value = { + "id": "456", + "status": "success", + } mock_response.text = "" mock_response.raise_for_status = Mock() @@ -85,7 +94,12 @@ class TestAddPromptToMarketplace: name="Test Prompt", prompt="Test prompt text", description="Test description", - use_cases=[{"title": "Use Case 1", "description": "Description 1"}], + use_cases=[ + { + "title": "Use Case 1", + "description": "Description 1", + } + ], tags="tag1, tag2", is_free=False, price_usd=9.99, @@ -105,7 +119,9 @@ class TestAddPromptToMarketplace: def test_add_prompt_missing_api_key(self): """Test that missing API key raises ValueError.""" with patch.dict(os.environ, {}, clear=True): - with pytest.raises(ValueError, match="Swarms API key is not set"): + with pytest.raises( + ValueError, match="Swarms API key is not set" + ): add_prompt_to_marketplace( name="Test", prompt="Test prompt", @@ -117,7 +133,9 @@ class TestAddPromptToMarketplace: def test_add_prompt_empty_api_key(self): """Test that empty API key raises ValueError.""" with patch.dict(os.environ, {"SWARMS_API_KEY": ""}): - with pytest.raises(ValueError, match="Swarms API key is not set"): + with pytest.raises( + ValueError, match="Swarms API key is not set" + ): add_prompt_to_marketplace( name="Test", prompt="Test prompt", @@ -141,7 +159,9 @@ class TestAddPromptToMarketplace: def test_add_prompt_missing_prompt(self): """Test that missing prompt raises ValueError.""" with patch.dict(os.environ, {"SWARMS_API_KEY": "test_key"}): - with pytest.raises(ValueError, match="prompt is required"): + with pytest.raises( + ValueError, match="prompt is required" + ): add_prompt_to_marketplace( name="Test", prompt=None, @@ -153,7 +173,9 @@ class TestAddPromptToMarketplace: def test_add_prompt_missing_description(self): """Test that missing description raises ValueError.""" with patch.dict(os.environ, {"SWARMS_API_KEY": "test_key"}): - with pytest.raises(ValueError, match="description is required"): + with pytest.raises( + ValueError, match="description is required" + ): add_prompt_to_marketplace( name="Test", prompt="Test prompt", @@ -165,7 +187,9 @@ class TestAddPromptToMarketplace: def test_add_prompt_missing_category(self): """Test that missing category raises ValueError.""" with patch.dict(os.environ, {"SWARMS_API_KEY": "test_key"}): - with pytest.raises(ValueError, match="category is required"): + with pytest.raises( + ValueError, match="category is required" + ): add_prompt_to_marketplace( name="Test", prompt="Test prompt", @@ -177,7 +201,9 @@ class TestAddPromptToMarketplace: def test_add_prompt_missing_use_cases(self): """Test that missing use_cases raises ValueError.""" with patch.dict(os.environ, {"SWARMS_API_KEY": "test_key"}): - with pytest.raises(ValueError, match="use_cases is required"): + with pytest.raises( + ValueError, match="use_cases is required" + ): add_prompt_to_marketplace( name="Test", prompt="Test prompt", @@ -196,7 +222,9 @@ class TestAddPromptToMarketplace: mock_response.reason_phrase = "Bad Request" mock_response.json.return_value = {"error": "Invalid request"} mock_response.text = '{"error": "Invalid request"}' - mock_response.raise_for_status.side_effect = Exception("HTTP 400") + mock_response.raise_for_status.side_effect = Exception( + "HTTP 400" + ) # Mock client mock_client = Mock() @@ -227,7 +255,9 @@ class TestAddPromptToMarketplace: "error": "Authentication failed" } mock_response.text = '{"error": "Authentication failed"}' - mock_response.raise_for_status.side_effect = Exception("HTTP 401") + mock_response.raise_for_status.side_effect = Exception( + "HTTP 401" + ) # Mock client mock_client = Mock() @@ -253,7 +283,10 @@ class TestAddPromptToMarketplace: # Mock response mock_response = Mock() mock_response.status_code = 200 - mock_response.json.return_value = {"id": "789", "status": "success"} + mock_response.json.return_value = { + "id": "789", + "status": "success", + } mock_response.text = "" mock_response.raise_for_status = Mock() From 243df297ef8bd9013aa189f5a46b73182896cdfe Mon Sep 17 00:00:00 2001 From: Kye Gomez Date: Tue, 11 Nov 2025 23:43:44 -0800 Subject: [PATCH 11/11] cleanup examples folder --- examples/README.md | 78 +- examples/aop_examples/client/README.md | 18 + examples/aop_examples/discovery/README.md | 15 + examples/aop_examples/medical_aop/README.md | 13 + examples/aop_examples/utils/README.md | 16 + .../deployment/cron_job_examples/README.md | 19 + examples/guides/840_update/README.md | 15 + examples/guides/850_workshop/README.md | 18 + examples/{ => guides}/demos/README.md | 0 .../{ => guides}/demos/agent_with_fluidapi.py | 0 .../{ => guides}/demos/apps/hiring_swarm.py | 0 .../demos/apps/smart_database_swarm.py | 0 examples/{ => guides}/demos/chart_swarm.py | 0 .../{ => guides}/demos/crypto/dao_swarm.py | 0 .../demos/crypto/ethchain_agent.py | 0 .../{ => guides}/demos/crypto/htx_swarm.py | 0 .../demos/crypto/swarms_coin_agent.py | 0 .../demos/crypto/swarms_coin_multimarket.py | 0 examples/{ => guides}/demos/cuda_swarm.py | 0 .../demos/finance/sentiment_news_analysis.py | 0 .../demos/hackathon_feb16/fraud.py | 0 .../demos/hackathon_feb16/sarasowti.py | 0 .../demos/insurance/insurance_swarm.py | 0 .../{ => guides}/demos/legal/legal_swarm.py | 0 .../demos/medical/health_privacy_swarm 2.py | 0 .../demos/medical/health_privacy_swarm.py | 0 .../medical/health_privacy_swarm_two 2.py | 0 .../demos/medical/health_privacy_swarm_two.py | 0 .../medical_analysis_agent_rearrange.md | 0 .../demos/medical/medical_coder_agent.py | 0 .../demos/medical/medical_coding_report.md | 0 .../demos/medical/medical_diagnosis_report.md | 0 .../demos/medical/new_medical_rearrange.py | 0 .../{ => guides}/demos/medical/ollama_demo.py | 0 .../medical_analysis_agent_rearrange.md | 0 .../reports/vc_document_analysis.md | 0 .../term_sheet_swarm.py | 0 .../demos/news_aggregator_summarizer.py | 0 .../{ => guides}/demos/privacy_building.py | 0 .../demos/real_estate/README_realtor.md | 0 .../demos/real_estate/morgtate_swarm.py | 0 .../demos/real_estate/real_estate_agent.py | 0 .../demos/real_estate/realtor_agent.py | 0 .../demos/science/materials_science_agents.py | 0 .../demos/science/open_scientist.py | 0 .../demos/science/paper_idea_agent.py | 0 .../demos/science/paper_idea_profile.py | 0 .../demos/spike/agent_rearrange_test.py | 0 .../demos/spike/function_caller_example.py | 0 examples/{ => guides}/demos/spike/memory.py | 0 examples/{ => guides}/demos/spike/spike.zip | Bin examples/{ => guides}/demos/spike/test.py | 0 .../profession_sim/convert_json_to_csv.py | 0 .../synthetic_data/profession_sim/data.csv | 0 .../profession_sim/format_prompt.py | 0 .../profession_persona_generator.py | 0 .../profession_sim/profession_personas.csv | 0 .../profession_personas.progress.backup.json | 0 .../profession_personas.progress.json | 0 .../profession_personas_new_10.csv | 0 ...ssion_personas_new_10.progress.backup.json | 0 ...n_personas_new_10.progress.backup_new.json | 0 .../profession_personas_new_10.progress.json | 0 ...fession_personas_new_10.progress_neee.json | 0 .../synthetic_data/profession_sim/prompt.txt | 0 .../profession_sim/prompt_formatted.md | 0 .../guides/generation_length_blog/README.md | 13 + .../guides/hackathon_judge_agent/README.md | 13 + .../hackathon_judger_agent.py | 120 +++ .../guides/hackathon_judge_agent/projects.csv | 149 ++++ examples/guides/hackathons/README.md | 18 + .../hackathons/hackathon_sep_27/api_client.py | 0 .../hackathon_sep_27/diet_coach_agent.py | 0 .../nutritional_content_analysis_swarm.py | 0 .../nutritonal_content_analysis_swarm.sh | 0 .../hackathons/hackathon_sep_27/pizza.jpg | Bin .../guides/nano_banana_jarvis_agent/README.md | 18 + examples/guides/web_scraper_agents/README.md | 13 + examples/{ => guides}/workshops/README.md | 0 .../agent_tools_dict_example.py | 0 .../batched_grid_simple_example.py | 0 .../workshop_sep_20/geo_guesser_agent.py | 0 .../workshops/workshop_sep_20/hk.jpg | Bin .../workshops/workshop_sep_20/jarvis_agent.py | 0 .../workshops/workshop_sep_20/miami.jpg | Bin .../workshops/workshop_sep_20/mountains.jpg | Bin .../workshop_sep_20/same_task_example.py | 0 examples/mcp/agent_examples/README.md | 15 + examples/mcp/mcp_utils/README.md | 27 + examples/mcp/multi_mcp_guide/README.md | 14 + examples/mcp/servers/README.md | 15 + .../agent_rearrange_examples/README.md | 12 + .../agent_router_examples/README.md | 12 + examples/multi_agent/asb/README.md | 17 + .../multi_agent/board_of_directors/README.md | 14 + .../multi_agent/caching_examples/README.md | 14 + .../multi_agent/concurrent_examples/README.md | 22 + examples/multi_agent/council/README.md | 14 + .../multi_agent/council_of_judges/README.md | 14 + .../multi_agent/debate_examples/README.md | 12 + .../election_swarm_examples/README.md | 13 + examples/multi_agent/exec_utilities/README.md | 13 + .../forest_swarm_examples/README.md | 16 + .../graphworkflow_examples/README.md | 24 + examples/multi_agent/groupchat/README.md | 18 + .../heavy_swarm_examples/README.md | 16 + .../multi_agent/hiearchical_swarm/README.md | 26 + examples/multi_agent/hscf/README.md | 12 + .../interactive_groupchat_examples/README.md | 16 + .../multi_agent/majority_voting/README.md | 14 + examples/multi_agent/mar/README.md | 14 + examples/multi_agent/moa_examples/README.md | 13 + .../orchestration_examples/README.md | 22 + .../paper_implementations/README.md | 12 + .../multi_agent/sequential_workflow/README.md | 17 + .../social_algorithms_examples/README.md | 23 + examples/multi_agent/swarm_router/README.md | 18 + examples/multi_agent/swarmarrange/README.md | 13 + .../multi_agent/swarms_api_examples/README.md | 14 + examples/multi_agent/utils/README.md | 13 + examples/single_agent/demos/README.md | 13 + .../single_agent/external_agents/README.md | 13 + examples/single_agent/llms/README.md | 36 + examples/single_agent/onboard/README.md | 13 + .../reasoning_agent_examples/README.md | 23 + examples/single_agent/tools/README.md | 39 + examples/single_agent/utils/README.md | 28 + examples/single_agent/vision/README.md | 17 + examples/tools/base_tool_examples/README.md | 22 + examples/tools/multii_tool_use/README.md | 13 + examples/utils/agent_loader/README.md | 15 + .../utils/communication_examples/README.md | 15 + examples/utils/misc/README.md | 26 + examples/utils/telemetry/README.md | 13 + test.py | 13 - tests/structs/test_agent_loader.py | 496 ++++++++---- tests/structs/test_agent_registry.py | 626 +++++++++----- tests/structs/test_base_structure.py | 762 +++++++++++------- 138 files changed, 2548 insertions(+), 700 deletions(-) create mode 100644 examples/aop_examples/client/README.md create mode 100644 examples/aop_examples/discovery/README.md create mode 100644 examples/aop_examples/medical_aop/README.md create mode 100644 examples/aop_examples/utils/README.md create mode 100644 examples/deployment/cron_job_examples/README.md create mode 100644 examples/guides/840_update/README.md create mode 100644 examples/guides/850_workshop/README.md rename examples/{ => guides}/demos/README.md (100%) rename examples/{ => guides}/demos/agent_with_fluidapi.py (100%) rename examples/{ => guides}/demos/apps/hiring_swarm.py (100%) rename examples/{ => guides}/demos/apps/smart_database_swarm.py (100%) rename examples/{ => guides}/demos/chart_swarm.py (100%) rename examples/{ => guides}/demos/crypto/dao_swarm.py (100%) rename examples/{ => guides}/demos/crypto/ethchain_agent.py (100%) rename examples/{ => guides}/demos/crypto/htx_swarm.py (100%) rename examples/{ => guides}/demos/crypto/swarms_coin_agent.py (100%) rename examples/{ => guides}/demos/crypto/swarms_coin_multimarket.py (100%) rename examples/{ => guides}/demos/cuda_swarm.py (100%) rename examples/{ => guides}/demos/finance/sentiment_news_analysis.py (100%) rename examples/{ => guides}/demos/hackathon_feb16/fraud.py (100%) rename examples/{ => guides}/demos/hackathon_feb16/sarasowti.py (100%) rename examples/{ => guides}/demos/insurance/insurance_swarm.py (100%) rename examples/{ => guides}/demos/legal/legal_swarm.py (100%) rename examples/{ => guides}/demos/medical/health_privacy_swarm 2.py (100%) rename examples/{ => guides}/demos/medical/health_privacy_swarm.py (100%) rename examples/{ => guides}/demos/medical/health_privacy_swarm_two 2.py (100%) rename examples/{ => guides}/demos/medical/health_privacy_swarm_two.py (100%) rename examples/{ => guides}/demos/medical/medical_analysis_agent_rearrange.md (100%) rename examples/{ => guides}/demos/medical/medical_coder_agent.py (100%) rename examples/{ => guides}/demos/medical/medical_coding_report.md (100%) rename examples/{ => guides}/demos/medical/medical_diagnosis_report.md (100%) rename examples/{ => guides}/demos/medical/new_medical_rearrange.py (100%) rename examples/{ => guides}/demos/medical/ollama_demo.py (100%) rename examples/{ => guides}/demos/medical/rearrange_video_examples/reports/medical_analysis_agent_rearrange.md (100%) rename examples/{ => guides}/demos/medical/rearrange_video_examples/reports/vc_document_analysis.md (100%) rename examples/{ => guides}/demos/medical/rearrange_video_examples/term_sheet_swarm.py (100%) rename examples/{ => guides}/demos/news_aggregator_summarizer.py (100%) rename examples/{ => guides}/demos/privacy_building.py (100%) rename examples/{ => guides}/demos/real_estate/README_realtor.md (100%) rename examples/{ => guides}/demos/real_estate/morgtate_swarm.py (100%) rename examples/{ => guides}/demos/real_estate/real_estate_agent.py (100%) rename examples/{ => guides}/demos/real_estate/realtor_agent.py (100%) rename examples/{ => guides}/demos/science/materials_science_agents.py (100%) rename examples/{ => guides}/demos/science/open_scientist.py (100%) rename examples/{ => guides}/demos/science/paper_idea_agent.py (100%) rename examples/{ => guides}/demos/science/paper_idea_profile.py (100%) rename examples/{ => guides}/demos/spike/agent_rearrange_test.py (100%) rename examples/{ => guides}/demos/spike/function_caller_example.py (100%) rename examples/{ => guides}/demos/spike/memory.py (100%) rename examples/{ => guides}/demos/spike/spike.zip (100%) rename examples/{ => guides}/demos/spike/test.py (100%) rename examples/{ => guides}/demos/synthetic_data/profession_sim/convert_json_to_csv.py (100%) rename examples/{ => guides}/demos/synthetic_data/profession_sim/data.csv (100%) rename examples/{ => guides}/demos/synthetic_data/profession_sim/format_prompt.py (100%) rename examples/{ => guides}/demos/synthetic_data/profession_sim/profession_persona_generator.py (100%) rename examples/{ => guides}/demos/synthetic_data/profession_sim/profession_personas.csv (100%) rename examples/{ => guides}/demos/synthetic_data/profession_sim/profession_personas.progress.backup.json (100%) rename examples/{ => guides}/demos/synthetic_data/profession_sim/profession_personas.progress.json (100%) rename examples/{ => guides}/demos/synthetic_data/profession_sim/profession_personas_new_10.csv (100%) rename examples/{ => guides}/demos/synthetic_data/profession_sim/profession_personas_new_10.progress.backup.json (100%) rename examples/{ => guides}/demos/synthetic_data/profession_sim/profession_personas_new_10.progress.backup_new.json (100%) rename examples/{ => guides}/demos/synthetic_data/profession_sim/profession_personas_new_10.progress.json (100%) rename examples/{ => guides}/demos/synthetic_data/profession_sim/profession_personas_new_10.progress_neee.json (100%) rename examples/{ => guides}/demos/synthetic_data/profession_sim/prompt.txt (100%) rename examples/{ => guides}/demos/synthetic_data/profession_sim/prompt_formatted.md (100%) create mode 100644 examples/guides/generation_length_blog/README.md create mode 100644 examples/guides/hackathon_judge_agent/README.md create mode 100644 examples/guides/hackathon_judge_agent/hackathon_judger_agent.py create mode 100644 examples/guides/hackathon_judge_agent/projects.csv create mode 100644 examples/guides/hackathons/README.md rename examples/{ => guides}/hackathons/hackathon_sep_27/api_client.py (100%) rename examples/{ => guides}/hackathons/hackathon_sep_27/diet_coach_agent.py (100%) rename examples/{ => guides}/hackathons/hackathon_sep_27/nutritional_content_analysis_swarm.py (100%) rename examples/{ => guides}/hackathons/hackathon_sep_27/nutritonal_content_analysis_swarm.sh (100%) rename examples/{ => guides}/hackathons/hackathon_sep_27/pizza.jpg (100%) create mode 100644 examples/guides/nano_banana_jarvis_agent/README.md create mode 100644 examples/guides/web_scraper_agents/README.md rename examples/{ => guides}/workshops/README.md (100%) rename examples/{ => guides}/workshops/workshop_sep_20/agent_tools_dict_example.py (100%) rename examples/{ => guides}/workshops/workshop_sep_20/batched_grid_simple_example.py (100%) rename examples/{ => guides}/workshops/workshop_sep_20/geo_guesser_agent.py (100%) rename examples/{ => guides}/workshops/workshop_sep_20/hk.jpg (100%) rename examples/{ => guides}/workshops/workshop_sep_20/jarvis_agent.py (100%) rename examples/{ => guides}/workshops/workshop_sep_20/miami.jpg (100%) rename examples/{ => guides}/workshops/workshop_sep_20/mountains.jpg (100%) rename examples/{ => guides}/workshops/workshop_sep_20/same_task_example.py (100%) create mode 100644 examples/mcp/agent_examples/README.md create mode 100644 examples/mcp/mcp_utils/README.md create mode 100644 examples/mcp/multi_mcp_guide/README.md create mode 100644 examples/mcp/servers/README.md create mode 100644 examples/multi_agent/agent_rearrange_examples/README.md create mode 100644 examples/multi_agent/agent_router_examples/README.md create mode 100644 examples/multi_agent/asb/README.md create mode 100644 examples/multi_agent/board_of_directors/README.md create mode 100644 examples/multi_agent/caching_examples/README.md create mode 100644 examples/multi_agent/concurrent_examples/README.md create mode 100644 examples/multi_agent/council/README.md create mode 100644 examples/multi_agent/council_of_judges/README.md create mode 100644 examples/multi_agent/debate_examples/README.md create mode 100644 examples/multi_agent/election_swarm_examples/README.md create mode 100644 examples/multi_agent/exec_utilities/README.md create mode 100644 examples/multi_agent/forest_swarm_examples/README.md create mode 100644 examples/multi_agent/graphworkflow_examples/README.md create mode 100644 examples/multi_agent/groupchat/README.md create mode 100644 examples/multi_agent/heavy_swarm_examples/README.md create mode 100644 examples/multi_agent/hiearchical_swarm/README.md create mode 100644 examples/multi_agent/hscf/README.md create mode 100644 examples/multi_agent/interactive_groupchat_examples/README.md create mode 100644 examples/multi_agent/majority_voting/README.md create mode 100644 examples/multi_agent/mar/README.md create mode 100644 examples/multi_agent/moa_examples/README.md create mode 100644 examples/multi_agent/orchestration_examples/README.md create mode 100644 examples/multi_agent/paper_implementations/README.md create mode 100644 examples/multi_agent/sequential_workflow/README.md create mode 100644 examples/multi_agent/social_algorithms_examples/README.md create mode 100644 examples/multi_agent/swarm_router/README.md create mode 100644 examples/multi_agent/swarmarrange/README.md create mode 100644 examples/multi_agent/swarms_api_examples/README.md create mode 100644 examples/multi_agent/utils/README.md create mode 100644 examples/single_agent/demos/README.md create mode 100644 examples/single_agent/external_agents/README.md create mode 100644 examples/single_agent/llms/README.md create mode 100644 examples/single_agent/onboard/README.md create mode 100644 examples/single_agent/reasoning_agent_examples/README.md create mode 100644 examples/single_agent/tools/README.md create mode 100644 examples/single_agent/utils/README.md create mode 100644 examples/single_agent/vision/README.md create mode 100644 examples/tools/base_tool_examples/README.md create mode 100644 examples/tools/multii_tool_use/README.md create mode 100644 examples/utils/agent_loader/README.md create mode 100644 examples/utils/communication_examples/README.md create mode 100644 examples/utils/misc/README.md create mode 100644 examples/utils/telemetry/README.md delete mode 100644 test.py diff --git a/examples/README.md b/examples/README.md index 27845e5e..34259fd4 100644 --- a/examples/README.md +++ b/examples/README.md @@ -7,70 +7,120 @@ This directory contains comprehensive examples demonstrating various capabilitie ### Multi-Agent Systems - **[multi_agent/](multi_agent/)** - Advanced multi-agent patterns including agent rearrangement, auto swarm builder (ASB), batched workflows, board of directors, caching, concurrent processing, councils, debates, elections, forest swarms, graph workflows, group chats, heavy swarms, hierarchical swarms, majority voting, orchestration examples, social algorithms, simulations, spreadsheet examples, and swarm routing. + - [README.md](multi_agent/README.md) - Complete multi-agent examples documentation ### Single Agent Systems - **[single_agent/](single_agent/)** - Single agent implementations including demos, external agent integrations, LLM integrations (Azure, Claude, DeepSeek, Mistral, OpenAI, Qwen), onboarding, RAG, reasoning agents, tools integration, utils, and vision capabilities. + - [README.md](single_agent/README.md) - Complete single agent examples documentation + - [simple_agent.py](single_agent/simple_agent.py) - Basic single agent example ### Tools & Integrations - **[tools/](tools/)** - Tool integration examples including agent-as-tools, base tool implementations, browser automation, Claude integration, Exa search, Firecrawl, multi-tool usage, and Stagehand integration. + - [README.md](tools/README.md) - Complete tools examples documentation + - [agent_as_tools.py](tools/agent_as_tools.py) - Using agents as tools ### Model Integrations - **[models/](models/)** - Various model integrations including Cerebras, GPT-5, GPT-OSS, Llama 4, Lumo, and Ollama implementations with concurrent processing examples and provider-specific configurations. + - [README.md](models/README.md) - Model integration documentation + - [simple_example_ollama.py](models/simple_example_ollama.py) - Ollama integration example + - [cerebas_example.py](models/cerebas_example.py) - Cerebras model example + - [lumo_example.py](models/lumo_example.py) - Lumo model example ### API & Protocols - **[swarms_api_examples/](swarms_api_examples/)** - Swarms API usage examples including agent overview, batch processing, client integration, team examples, analysis, and rate limiting. + - [README.md](swarms_api_examples/README.md) - API examples documentation + - [client_example.py](swarms_api_examples/client_example.py) - API client example + - [batch_example.py](swarms_api_examples/batch_example.py) - Batch processing example - **[mcp/](mcp/)** - Model Context Protocol (MCP) integration examples including agent implementations, multi-connection setups, server configurations, and utility functions. + - [README.md](mcp/README.md) - MCP examples documentation + - [multi_mcp_example.py](mcp/multi_mcp_example.py) - Multi-MCP connection example - **[aop_examples/](aop_examples/)** - Agents over Protocol (AOP) examples demonstrating MCP server setup, agent discovery, client interactions, queue-based task submission, and medical AOP implementations. + - [README.md](aop_examples/README.md) - AOP examples documentation + - [server.py](aop_examples/server.py) - AOP server implementation ### Advanced Capabilities - **[reasoning_agents/](reasoning_agents/)** - Advanced reasoning capabilities including agent judge evaluation systems, O3 model integration, and mixture of agents (MOA) sequential examples. + - [README.md](reasoning_agents/README.md) - Reasoning agents documentation + - [example_o3.py](reasoning_agents/example_o3.py) - O3 model example + - [moa_seq_example.py](reasoning_agents/moa_seq_example.py) - MOA sequential example - **[rag/](rag/)** - Retrieval Augmented Generation (RAG) implementations with vector database integrations including Qdrant examples. + - [README.md](rag/README.md) - RAG documentation + - [qdrant_rag_example.py](rag/qdrant_rag_example.py) - Qdrant RAG example ### Guides & Tutorials - **[guides/](guides/)** - Comprehensive guides and tutorials including generation length blog, geo guesser agent, graph workflow guide, hierarchical marketing team, nano banana Jarvis agent, smart database, web scraper agents, and workshop examples (840_update, 850_workshop). - -### Demonstrations - -- **[demos/](demos/)** - Domain-specific demonstrations across various industries including apps, charts, crypto, CUDA, finance, hackathon projects, insurance, legal, medical, news, privacy, real estate, science, and synthetic data generation. - -### Hackathons - -- **[hackathons/](hackathons/)** - Hackathon projects and implementations including September 27 hackathon examples with diet coach agents, nutritional content analysis swarms, and API client integrations. + - [README.md](guides/README.md) - Guides documentation + - [hiearchical_marketing_team.py](guides/hiearchical_marketing_team.py) - Hierarchical marketing team example ### Deployment - **[deployment/](deployment/)** - Deployment strategies and patterns including cron job implementations and FastAPI deployment examples. + - [README.md](deployment/README.md) - Deployment documentation + - [fastapi/](deployment/fastapi/) - FastAPI deployment examples + - [cron_job_examples/](deployment/cron_job_examples/) - Cron job examples ### Utilities - **[utils/](utils/)** - Utility functions and helper implementations including agent loader, communication examples, concurrent wrappers, miscellaneous utilities, and telemetry. - -### Educational - -- **[workshops/](workshops/)** - Workshop examples and educational sessions including agent tools, batched grids, geo guesser, and Jarvis agent implementations. + - [README.md](utils/README.md) - Utils documentation ### User Interface - **[ui/](ui/)** - User interface examples and implementations including chat interfaces. + - [README.md](ui/README.md) - UI examples documentation + - [chat.py](ui/chat.py) - Chat interface example ## Quick Start 1. **New to Swarms?** Start with [single_agent/simple_agent.py](single_agent/simple_agent.py) for basic concepts 2. **Want multi-agent workflows?** Check out [multi_agent/duo_agent.py](multi_agent/duo_agent.py) 3. **Need tool integration?** Explore [tools/agent_as_tools.py](tools/agent_as_tools.py) -4. **Interested in AOP?** Try [aop_examples/example_new_agent_tools.py](aop_examples/example_new_agent_tools.py) for agent discovery +4. **Interested in AOP?** Try [aop_examples/client/example_new_agent_tools.py](aop_examples/client/example_new_agent_tools.py) for agent discovery 5. **Want to see social algorithms?** Check out [multi_agent/social_algorithms_examples/](multi_agent/social_algorithms_examples/) 6. **Looking for guides?** Visit [guides/](guides/) for comprehensive tutorials -7. **Hackathon projects?** Explore [hackathons/hackathon_sep_27/](hackathons/hackathon_sep_27/) for real-world implementations +7. **Need RAG?** Try [rag/qdrant_rag_example.py](rag/qdrant_rag_example.py) +8. **Want reasoning agents?** Check out [reasoning_agents/example_o3.py](reasoning_agents/example_o3.py) + +## Key Examples by Category + +### Multi-Agent Patterns + +- [Duo Agent](multi_agent/duo_agent.py) - Two-agent collaboration +- [Hierarchical Swarm](multi_agent/hiearchical_swarm/hierarchical_swarm_example.py) - Hierarchical agent structures +- [Group Chat](multi_agent/groupchat/interactive_groupchat_example.py) - Multi-agent conversations +- [Graph Workflow](multi_agent/graphworkflow_examples/graph_workflow_example.py) - Graph-based workflows +- [Social Algorithms](multi_agent/social_algorithms_examples/) - Various social algorithm patterns + +### Single Agent Examples + +- [Simple Agent](single_agent/simple_agent.py) - Basic agent setup +- [Reasoning Agents](single_agent/reasoning_agent_examples/) - Advanced reasoning patterns +- [Vision Agents](single_agent/vision/multimodal_example.py) - Vision and multimodal capabilities +- [RAG Agents](single_agent/rag/qdrant_rag_example.py) - Retrieval augmented generation + +### Tool Integrations + +- [Agent as Tools](tools/agent_as_tools.py) - Using agents as tools +- [Browser Automation](tools/browser_use_as_tool.py) - Browser control +- [Exa Search](tools/exa_search_agent.py) - Search integration +- [Stagehand](tools/stagehand/) - UI automation + +### Model Integrations + +- [OpenAI](single_agent/llms/openai_examples/4o_mini_demo.py) - OpenAI models +- [Claude](single_agent/llms/claude_examples/claude_4_example.py) - Claude models +- [DeepSeek](single_agent/llms/deepseek_examples/deepseek_r1.py) - DeepSeek models +- [Azure](single_agent/llms/azure_agent.py) - Azure OpenAI +- [Ollama](models/simple_example_ollama.py) - Local Ollama models ## Documentation diff --git a/examples/aop_examples/client/README.md b/examples/aop_examples/client/README.md new file mode 100644 index 00000000..56d24cb9 --- /dev/null +++ b/examples/aop_examples/client/README.md @@ -0,0 +1,18 @@ +# AOP Client Examples + +This directory contains examples demonstrating AOP (Agents over Protocol) client implementations. + +## Examples + +- [aop_cluster_example.py](aop_cluster_example.py) - AOP cluster client example +- [aop_queue_example.py](aop_queue_example.py) - Queue-based task submission +- [aop_raw_client_code.py](aop_raw_client_code.py) - Raw AOP client implementation +- [aop_raw_task_example.py](aop_raw_task_example.py) - Raw AOP task example +- [example_new_agent_tools.py](example_new_agent_tools.py) - New agent tools example +- [get_all_agents.py](get_all_agents.py) - Agent discovery example +- [list_agents_and_call_them.py](list_agents_and_call_them.py) - List and call agents + +## Overview + +AOP client examples demonstrate how to connect to AOP servers, discover available agents, submit tasks, and interact with agents over the protocol. These examples show various client patterns including queue-based submission, cluster management, and agent discovery. + diff --git a/examples/aop_examples/discovery/README.md b/examples/aop_examples/discovery/README.md new file mode 100644 index 00000000..361f9e86 --- /dev/null +++ b/examples/aop_examples/discovery/README.md @@ -0,0 +1,15 @@ +# AOP Discovery Examples + +This directory contains examples demonstrating agent discovery mechanisms in AOP. + +## Examples + +- [example_agent_communication.py](example_agent_communication.py) - Agent communication example +- [example_aop_discovery.py](example_aop_discovery.py) - AOP discovery implementation +- [simple_discovery_example.py](simple_discovery_example.py) - Simple discovery example +- [test_aop_discovery.py](test_aop_discovery.py) - Discovery testing + +## Overview + +AOP discovery examples demonstrate how agents can discover and communicate with each other over the protocol. These examples show various discovery patterns, agent registration, and communication protocols for distributed agent systems. + diff --git a/examples/aop_examples/medical_aop/README.md b/examples/aop_examples/medical_aop/README.md new file mode 100644 index 00000000..aa11bc3c --- /dev/null +++ b/examples/aop_examples/medical_aop/README.md @@ -0,0 +1,13 @@ +# Medical AOP Examples + +This directory contains medical domain-specific AOP implementations. + +## Examples + +- [client.py](client.py) - Medical AOP client +- [server.py](server.py) - Medical AOP server + +## Overview + +Medical AOP examples demonstrate domain-specific implementations of Agents over Protocol for healthcare applications. These examples show how to structure AOP servers and clients for medical use cases, including patient data handling, medical analysis, and healthcare workflows. + diff --git a/examples/aop_examples/utils/README.md b/examples/aop_examples/utils/README.md new file mode 100644 index 00000000..e93bf263 --- /dev/null +++ b/examples/aop_examples/utils/README.md @@ -0,0 +1,16 @@ +# AOP Utils + +This directory contains utility functions and helpers for AOP implementations. + +## Examples + +- [comprehensive_aop_example.py](comprehensive_aop_example.py) - Comprehensive AOP example +- [network_error_example.py](network_error_example.py) - Network error handling +- [network_management_example.py](network_management_example.py) - Network management utilities +- [persistence_example.py](persistence_example.py) - Persistence implementation +- [persistence_management_example.py](persistence_management_example.py) - Persistence management + +## Overview + +AOP utils provide helper functions, error handling patterns, network management utilities, and persistence mechanisms for AOP implementations. These examples demonstrate best practices for building robust AOP systems. + diff --git a/examples/deployment/cron_job_examples/README.md b/examples/deployment/cron_job_examples/README.md new file mode 100644 index 00000000..a4a961a7 --- /dev/null +++ b/examples/deployment/cron_job_examples/README.md @@ -0,0 +1,19 @@ +# Cron Job Examples + +This directory contains examples demonstrating scheduled task execution using cron jobs. + +## Examples + +- [callback_cron_example.py](callback_cron_example.py) - Cron job with callbacks +- [cron_job_example.py](cron_job_example.py) - Basic cron job example +- [cron_job_figma_stock_swarms_tools_example.py](cron_job_figma_stock_swarms_tools_example.py) - Figma stock swarms tools cron job +- [crypto_concurrent_cron_example.py](crypto_concurrent_cron_example.py) - Concurrent crypto cron job +- [figma_stock_example.py](figma_stock_example.py) - Figma stock example +- [simple_callback_example.py](simple_callback_example.py) - Simple callback example +- [simple_concurrent_crypto_cron.py](simple_concurrent_crypto_cron.py) - Simple concurrent crypto cron +- [solana_price_tracker.py](solana_price_tracker.py) - Solana price tracker cron job + +## Overview + +Cron job examples demonstrate how to schedule and execute agent tasks on a recurring basis. These examples show various patterns including callback handling, concurrent execution, and domain-specific scheduled tasks like price tracking and stock monitoring. + diff --git a/examples/guides/840_update/README.md b/examples/guides/840_update/README.md new file mode 100644 index 00000000..f959c950 --- /dev/null +++ b/examples/guides/840_update/README.md @@ -0,0 +1,15 @@ +# 840 Update Examples + +This directory contains examples from the 840 update, demonstrating new features and improvements. + +## Examples + +- [agent_rearrange_concurrent_example.py](agent_rearrange_concurrent_example.py) - Agent rearrangement with concurrency +- [auto_swarm_builder_example.py](auto_swarm_builder_example.py) - Auto swarm builder example +- [fallback_example.py](fallback_example.py) - Fallback mechanism example +- [server.py](server.py) - Server implementation + +## Overview + +These examples showcase features introduced in the 840 update, including concurrent agent rearrangement, auto swarm building capabilities, and improved fallback mechanisms. + diff --git a/examples/guides/850_workshop/README.md b/examples/guides/850_workshop/README.md new file mode 100644 index 00000000..658fb3ae --- /dev/null +++ b/examples/guides/850_workshop/README.md @@ -0,0 +1,18 @@ +# 850 Workshop Examples + +This directory contains examples from the 850 workshop, demonstrating advanced multi-agent patterns and AOP integration. + +## Examples + +- [aop_raw_client_code.py](aop_raw_client_code.py) - Raw AOP client implementation +- [aop_raw_task_example.py](aop_raw_task_example.py) - Raw AOP task example +- [moa_seq_example.py](moa_seq_example.py) - Mixture of Agents sequential example +- [peer_review_example.py](peer_review_example.py) - Peer review pattern +- [server.py](server.py) - Server implementation +- [test_agent_concurrent.py](test_agent_concurrent.py) - Concurrent agent testing +- [uvloop_example.py](uvloop_example.py) - UVLoop integration example + +## Overview + +These examples from the 850 workshop demonstrate advanced patterns including Agents over Protocol (AOP) integration, mixture of agents, peer review workflows, and high-performance async execution with UVLoop. + diff --git a/examples/demos/README.md b/examples/guides/demos/README.md similarity index 100% rename from examples/demos/README.md rename to examples/guides/demos/README.md diff --git a/examples/demos/agent_with_fluidapi.py b/examples/guides/demos/agent_with_fluidapi.py similarity index 100% rename from examples/demos/agent_with_fluidapi.py rename to examples/guides/demos/agent_with_fluidapi.py diff --git a/examples/demos/apps/hiring_swarm.py b/examples/guides/demos/apps/hiring_swarm.py similarity index 100% rename from examples/demos/apps/hiring_swarm.py rename to examples/guides/demos/apps/hiring_swarm.py diff --git a/examples/demos/apps/smart_database_swarm.py b/examples/guides/demos/apps/smart_database_swarm.py similarity index 100% rename from examples/demos/apps/smart_database_swarm.py rename to examples/guides/demos/apps/smart_database_swarm.py diff --git a/examples/demos/chart_swarm.py b/examples/guides/demos/chart_swarm.py similarity index 100% rename from examples/demos/chart_swarm.py rename to examples/guides/demos/chart_swarm.py diff --git a/examples/demos/crypto/dao_swarm.py b/examples/guides/demos/crypto/dao_swarm.py similarity index 100% rename from examples/demos/crypto/dao_swarm.py rename to examples/guides/demos/crypto/dao_swarm.py diff --git a/examples/demos/crypto/ethchain_agent.py b/examples/guides/demos/crypto/ethchain_agent.py similarity index 100% rename from examples/demos/crypto/ethchain_agent.py rename to examples/guides/demos/crypto/ethchain_agent.py diff --git a/examples/demos/crypto/htx_swarm.py b/examples/guides/demos/crypto/htx_swarm.py similarity index 100% rename from examples/demos/crypto/htx_swarm.py rename to examples/guides/demos/crypto/htx_swarm.py diff --git a/examples/demos/crypto/swarms_coin_agent.py b/examples/guides/demos/crypto/swarms_coin_agent.py similarity index 100% rename from examples/demos/crypto/swarms_coin_agent.py rename to examples/guides/demos/crypto/swarms_coin_agent.py diff --git a/examples/demos/crypto/swarms_coin_multimarket.py b/examples/guides/demos/crypto/swarms_coin_multimarket.py similarity index 100% rename from examples/demos/crypto/swarms_coin_multimarket.py rename to examples/guides/demos/crypto/swarms_coin_multimarket.py diff --git a/examples/demos/cuda_swarm.py b/examples/guides/demos/cuda_swarm.py similarity index 100% rename from examples/demos/cuda_swarm.py rename to examples/guides/demos/cuda_swarm.py diff --git a/examples/demos/finance/sentiment_news_analysis.py b/examples/guides/demos/finance/sentiment_news_analysis.py similarity index 100% rename from examples/demos/finance/sentiment_news_analysis.py rename to examples/guides/demos/finance/sentiment_news_analysis.py diff --git a/examples/demos/hackathon_feb16/fraud.py b/examples/guides/demos/hackathon_feb16/fraud.py similarity index 100% rename from examples/demos/hackathon_feb16/fraud.py rename to examples/guides/demos/hackathon_feb16/fraud.py diff --git a/examples/demos/hackathon_feb16/sarasowti.py b/examples/guides/demos/hackathon_feb16/sarasowti.py similarity index 100% rename from examples/demos/hackathon_feb16/sarasowti.py rename to examples/guides/demos/hackathon_feb16/sarasowti.py diff --git a/examples/demos/insurance/insurance_swarm.py b/examples/guides/demos/insurance/insurance_swarm.py similarity index 100% rename from examples/demos/insurance/insurance_swarm.py rename to examples/guides/demos/insurance/insurance_swarm.py diff --git a/examples/demos/legal/legal_swarm.py b/examples/guides/demos/legal/legal_swarm.py similarity index 100% rename from examples/demos/legal/legal_swarm.py rename to examples/guides/demos/legal/legal_swarm.py diff --git a/examples/demos/medical/health_privacy_swarm 2.py b/examples/guides/demos/medical/health_privacy_swarm 2.py similarity index 100% rename from examples/demos/medical/health_privacy_swarm 2.py rename to examples/guides/demos/medical/health_privacy_swarm 2.py diff --git a/examples/demos/medical/health_privacy_swarm.py b/examples/guides/demos/medical/health_privacy_swarm.py similarity index 100% rename from examples/demos/medical/health_privacy_swarm.py rename to examples/guides/demos/medical/health_privacy_swarm.py diff --git a/examples/demos/medical/health_privacy_swarm_two 2.py b/examples/guides/demos/medical/health_privacy_swarm_two 2.py similarity index 100% rename from examples/demos/medical/health_privacy_swarm_two 2.py rename to examples/guides/demos/medical/health_privacy_swarm_two 2.py diff --git a/examples/demos/medical/health_privacy_swarm_two.py b/examples/guides/demos/medical/health_privacy_swarm_two.py similarity index 100% rename from examples/demos/medical/health_privacy_swarm_two.py rename to examples/guides/demos/medical/health_privacy_swarm_two.py diff --git a/examples/demos/medical/medical_analysis_agent_rearrange.md b/examples/guides/demos/medical/medical_analysis_agent_rearrange.md similarity index 100% rename from examples/demos/medical/medical_analysis_agent_rearrange.md rename to examples/guides/demos/medical/medical_analysis_agent_rearrange.md diff --git a/examples/demos/medical/medical_coder_agent.py b/examples/guides/demos/medical/medical_coder_agent.py similarity index 100% rename from examples/demos/medical/medical_coder_agent.py rename to examples/guides/demos/medical/medical_coder_agent.py diff --git a/examples/demos/medical/medical_coding_report.md b/examples/guides/demos/medical/medical_coding_report.md similarity index 100% rename from examples/demos/medical/medical_coding_report.md rename to examples/guides/demos/medical/medical_coding_report.md diff --git a/examples/demos/medical/medical_diagnosis_report.md b/examples/guides/demos/medical/medical_diagnosis_report.md similarity index 100% rename from examples/demos/medical/medical_diagnosis_report.md rename to examples/guides/demos/medical/medical_diagnosis_report.md diff --git a/examples/demos/medical/new_medical_rearrange.py b/examples/guides/demos/medical/new_medical_rearrange.py similarity index 100% rename from examples/demos/medical/new_medical_rearrange.py rename to examples/guides/demos/medical/new_medical_rearrange.py diff --git a/examples/demos/medical/ollama_demo.py b/examples/guides/demos/medical/ollama_demo.py similarity index 100% rename from examples/demos/medical/ollama_demo.py rename to examples/guides/demos/medical/ollama_demo.py diff --git a/examples/demos/medical/rearrange_video_examples/reports/medical_analysis_agent_rearrange.md b/examples/guides/demos/medical/rearrange_video_examples/reports/medical_analysis_agent_rearrange.md similarity index 100% rename from examples/demos/medical/rearrange_video_examples/reports/medical_analysis_agent_rearrange.md rename to examples/guides/demos/medical/rearrange_video_examples/reports/medical_analysis_agent_rearrange.md diff --git a/examples/demos/medical/rearrange_video_examples/reports/vc_document_analysis.md b/examples/guides/demos/medical/rearrange_video_examples/reports/vc_document_analysis.md similarity index 100% rename from examples/demos/medical/rearrange_video_examples/reports/vc_document_analysis.md rename to examples/guides/demos/medical/rearrange_video_examples/reports/vc_document_analysis.md diff --git a/examples/demos/medical/rearrange_video_examples/term_sheet_swarm.py b/examples/guides/demos/medical/rearrange_video_examples/term_sheet_swarm.py similarity index 100% rename from examples/demos/medical/rearrange_video_examples/term_sheet_swarm.py rename to examples/guides/demos/medical/rearrange_video_examples/term_sheet_swarm.py diff --git a/examples/demos/news_aggregator_summarizer.py b/examples/guides/demos/news_aggregator_summarizer.py similarity index 100% rename from examples/demos/news_aggregator_summarizer.py rename to examples/guides/demos/news_aggregator_summarizer.py diff --git a/examples/demos/privacy_building.py b/examples/guides/demos/privacy_building.py similarity index 100% rename from examples/demos/privacy_building.py rename to examples/guides/demos/privacy_building.py diff --git a/examples/demos/real_estate/README_realtor.md b/examples/guides/demos/real_estate/README_realtor.md similarity index 100% rename from examples/demos/real_estate/README_realtor.md rename to examples/guides/demos/real_estate/README_realtor.md diff --git a/examples/demos/real_estate/morgtate_swarm.py b/examples/guides/demos/real_estate/morgtate_swarm.py similarity index 100% rename from examples/demos/real_estate/morgtate_swarm.py rename to examples/guides/demos/real_estate/morgtate_swarm.py diff --git a/examples/demos/real_estate/real_estate_agent.py b/examples/guides/demos/real_estate/real_estate_agent.py similarity index 100% rename from examples/demos/real_estate/real_estate_agent.py rename to examples/guides/demos/real_estate/real_estate_agent.py diff --git a/examples/demos/real_estate/realtor_agent.py b/examples/guides/demos/real_estate/realtor_agent.py similarity index 100% rename from examples/demos/real_estate/realtor_agent.py rename to examples/guides/demos/real_estate/realtor_agent.py diff --git a/examples/demos/science/materials_science_agents.py b/examples/guides/demos/science/materials_science_agents.py similarity index 100% rename from examples/demos/science/materials_science_agents.py rename to examples/guides/demos/science/materials_science_agents.py diff --git a/examples/demos/science/open_scientist.py b/examples/guides/demos/science/open_scientist.py similarity index 100% rename from examples/demos/science/open_scientist.py rename to examples/guides/demos/science/open_scientist.py diff --git a/examples/demos/science/paper_idea_agent.py b/examples/guides/demos/science/paper_idea_agent.py similarity index 100% rename from examples/demos/science/paper_idea_agent.py rename to examples/guides/demos/science/paper_idea_agent.py diff --git a/examples/demos/science/paper_idea_profile.py b/examples/guides/demos/science/paper_idea_profile.py similarity index 100% rename from examples/demos/science/paper_idea_profile.py rename to examples/guides/demos/science/paper_idea_profile.py diff --git a/examples/demos/spike/agent_rearrange_test.py b/examples/guides/demos/spike/agent_rearrange_test.py similarity index 100% rename from examples/demos/spike/agent_rearrange_test.py rename to examples/guides/demos/spike/agent_rearrange_test.py diff --git a/examples/demos/spike/function_caller_example.py b/examples/guides/demos/spike/function_caller_example.py similarity index 100% rename from examples/demos/spike/function_caller_example.py rename to examples/guides/demos/spike/function_caller_example.py diff --git a/examples/demos/spike/memory.py b/examples/guides/demos/spike/memory.py similarity index 100% rename from examples/demos/spike/memory.py rename to examples/guides/demos/spike/memory.py diff --git a/examples/demos/spike/spike.zip b/examples/guides/demos/spike/spike.zip similarity index 100% rename from examples/demos/spike/spike.zip rename to examples/guides/demos/spike/spike.zip diff --git a/examples/demos/spike/test.py b/examples/guides/demos/spike/test.py similarity index 100% rename from examples/demos/spike/test.py rename to examples/guides/demos/spike/test.py diff --git a/examples/demos/synthetic_data/profession_sim/convert_json_to_csv.py b/examples/guides/demos/synthetic_data/profession_sim/convert_json_to_csv.py similarity index 100% rename from examples/demos/synthetic_data/profession_sim/convert_json_to_csv.py rename to examples/guides/demos/synthetic_data/profession_sim/convert_json_to_csv.py diff --git a/examples/demos/synthetic_data/profession_sim/data.csv b/examples/guides/demos/synthetic_data/profession_sim/data.csv similarity index 100% rename from examples/demos/synthetic_data/profession_sim/data.csv rename to examples/guides/demos/synthetic_data/profession_sim/data.csv diff --git a/examples/demos/synthetic_data/profession_sim/format_prompt.py b/examples/guides/demos/synthetic_data/profession_sim/format_prompt.py similarity index 100% rename from examples/demos/synthetic_data/profession_sim/format_prompt.py rename to examples/guides/demos/synthetic_data/profession_sim/format_prompt.py diff --git a/examples/demos/synthetic_data/profession_sim/profession_persona_generator.py b/examples/guides/demos/synthetic_data/profession_sim/profession_persona_generator.py similarity index 100% rename from examples/demos/synthetic_data/profession_sim/profession_persona_generator.py rename to examples/guides/demos/synthetic_data/profession_sim/profession_persona_generator.py diff --git a/examples/demos/synthetic_data/profession_sim/profession_personas.csv b/examples/guides/demos/synthetic_data/profession_sim/profession_personas.csv similarity index 100% rename from examples/demos/synthetic_data/profession_sim/profession_personas.csv rename to examples/guides/demos/synthetic_data/profession_sim/profession_personas.csv diff --git a/examples/demos/synthetic_data/profession_sim/profession_personas.progress.backup.json b/examples/guides/demos/synthetic_data/profession_sim/profession_personas.progress.backup.json similarity index 100% rename from examples/demos/synthetic_data/profession_sim/profession_personas.progress.backup.json rename to examples/guides/demos/synthetic_data/profession_sim/profession_personas.progress.backup.json diff --git a/examples/demos/synthetic_data/profession_sim/profession_personas.progress.json b/examples/guides/demos/synthetic_data/profession_sim/profession_personas.progress.json similarity index 100% rename from examples/demos/synthetic_data/profession_sim/profession_personas.progress.json rename to examples/guides/demos/synthetic_data/profession_sim/profession_personas.progress.json diff --git a/examples/demos/synthetic_data/profession_sim/profession_personas_new_10.csv b/examples/guides/demos/synthetic_data/profession_sim/profession_personas_new_10.csv similarity index 100% rename from examples/demos/synthetic_data/profession_sim/profession_personas_new_10.csv rename to examples/guides/demos/synthetic_data/profession_sim/profession_personas_new_10.csv diff --git a/examples/demos/synthetic_data/profession_sim/profession_personas_new_10.progress.backup.json b/examples/guides/demos/synthetic_data/profession_sim/profession_personas_new_10.progress.backup.json similarity index 100% rename from examples/demos/synthetic_data/profession_sim/profession_personas_new_10.progress.backup.json rename to examples/guides/demos/synthetic_data/profession_sim/profession_personas_new_10.progress.backup.json diff --git a/examples/demos/synthetic_data/profession_sim/profession_personas_new_10.progress.backup_new.json b/examples/guides/demos/synthetic_data/profession_sim/profession_personas_new_10.progress.backup_new.json similarity index 100% rename from examples/demos/synthetic_data/profession_sim/profession_personas_new_10.progress.backup_new.json rename to examples/guides/demos/synthetic_data/profession_sim/profession_personas_new_10.progress.backup_new.json diff --git a/examples/demos/synthetic_data/profession_sim/profession_personas_new_10.progress.json b/examples/guides/demos/synthetic_data/profession_sim/profession_personas_new_10.progress.json similarity index 100% rename from examples/demos/synthetic_data/profession_sim/profession_personas_new_10.progress.json rename to examples/guides/demos/synthetic_data/profession_sim/profession_personas_new_10.progress.json diff --git a/examples/demos/synthetic_data/profession_sim/profession_personas_new_10.progress_neee.json b/examples/guides/demos/synthetic_data/profession_sim/profession_personas_new_10.progress_neee.json similarity index 100% rename from examples/demos/synthetic_data/profession_sim/profession_personas_new_10.progress_neee.json rename to examples/guides/demos/synthetic_data/profession_sim/profession_personas_new_10.progress_neee.json diff --git a/examples/demos/synthetic_data/profession_sim/prompt.txt b/examples/guides/demos/synthetic_data/profession_sim/prompt.txt similarity index 100% rename from examples/demos/synthetic_data/profession_sim/prompt.txt rename to examples/guides/demos/synthetic_data/profession_sim/prompt.txt diff --git a/examples/demos/synthetic_data/profession_sim/prompt_formatted.md b/examples/guides/demos/synthetic_data/profession_sim/prompt_formatted.md similarity index 100% rename from examples/demos/synthetic_data/profession_sim/prompt_formatted.md rename to examples/guides/demos/synthetic_data/profession_sim/prompt_formatted.md diff --git a/examples/guides/generation_length_blog/README.md b/examples/guides/generation_length_blog/README.md new file mode 100644 index 00000000..6dbf0231 --- /dev/null +++ b/examples/guides/generation_length_blog/README.md @@ -0,0 +1,13 @@ +# Generation Length Blog Examples + +This directory contains examples related to generation length management and long-form content generation. + +## Examples + +- [longform_generator.py](longform_generator.py) - Long-form content generator +- [universal_api.py](universal_api.py) - Universal API for generation + +## Overview + +These examples demonstrate techniques for managing generation length, creating long-form content, and implementing universal APIs for content generation. Useful for blog posts, articles, and extended text generation tasks. + diff --git a/examples/guides/hackathon_judge_agent/README.md b/examples/guides/hackathon_judge_agent/README.md new file mode 100644 index 00000000..100b9bd9 --- /dev/null +++ b/examples/guides/hackathon_judge_agent/README.md @@ -0,0 +1,13 @@ +# Hackathon Judge Agent + +This directory contains a hackathon project judging agent example. + +## Examples + +- [hackathon_judger_agent.py](hackathon_judger_agent.py) - Hackathon project judging agent +- [projects.csv](projects.csv) - Sample projects dataset + +## Overview + +This example demonstrates an agent system designed to evaluate and judge hackathon projects. The agent can analyze project descriptions, assess quality, and provide structured feedback based on predefined criteria. + diff --git a/examples/guides/hackathon_judge_agent/hackathon_judger_agent.py b/examples/guides/hackathon_judge_agent/hackathon_judger_agent.py new file mode 100644 index 00000000..8cce2659 --- /dev/null +++ b/examples/guides/hackathon_judge_agent/hackathon_judger_agent.py @@ -0,0 +1,120 @@ +from swarms import Agent + +HACKATHON_JUDGER_AGENT_PROMPT = """ +## 🧠 **System Prompt: Hackathon Judger Agent (AI Agents Focus)** + +**Role:** +You are an expert hackathon evaluation assistant judging submissions in the *Builders Track*. +Your task is to evaluate all projects using the provided criteria and automatically identify those related to **AI agents, agentic architectures, or autonomous intelligent systems**. + +You must then produce a **ranked report** of the **top 3 AI agent–related projects**, complete with weighted scores, category breakdowns, and short qualitative summaries. + +--- + +### 🎯 **Judging Framework** + +Each project is evaluated using the following **weighted criteria** (from the Builders Track official judging rubric): + +#### 1. Technical Feasibility & Implementation (30%) + +Evaluate how well the project was built and its level of technical sophistication. + +* **90–100:** Robust & flawless. Excellent code quality. Seamless, innovative integration. +* **80–90:** Works as intended. Clean implementation. Effective Solana or system integration. +* **60–80:** Functional but basic or partially implemented. +* **0–60:** Non-functional or poor implementation. + +#### 2. Quality & Clarity of Demo (20%) + +Evaluate the quality, clarity, and impact of the presentation or demo. + +* **90–100:** Compelling, professional, inspiring vision. +* **80–90:** Clear, confident presentation with good storytelling. +* **60–80:** Functional but unpolished demo. +* **0–60:** Weak or confusing presentation. + +#### 3. Presentation of Idea (30%) + +Evaluate how clearly the idea is communicated and how well it conveys its purpose and impact. + +* **90–100:** Masterful, engaging storytelling. Simplifies complex ideas elegantly. +* **80–90:** Clear, structured, and accessible presentation. +* **60–80:** Understandable but lacks focus. +* **0–60:** Confusing or poorly explained. + +#### 4. Innovation & Originality (20%) + +Evaluate the novelty and originality of the idea, particularly within the context of agentic AI. + +* **90–100:** Breakthrough concept. Strong fit with ecosystem and AI innovation. +* **80–90:** Distinct, creative, and forward-thinking. +* **60–80:** Incremental improvement. +* **0–60:** Unoriginal or derivative. + +--- + +### ⚖️ **Scoring Rules** + +1. Assign each project a **score (0–100)** for each category. +2. Apply weights to compute a **final total score out of 100**: + + * Technical Feasibility — 30% + * Demo Quality — 20% + * Presentation — 30% + * Innovation — 20% +3. Filter and **select only projects related to AI agents or agentic systems**. +4. Rank these filtered projects **from highest to lowest total score**. +5. Select the **top 3 projects** for the final report. + +--- + +### 🧩 **Output Format** + +Create a markdown report of the top 3 projects with how they follow the judging criteria and why they are the best. + +--- + +### 🧭 **Special Instructions** + +* Consider “AI agents” to include: + + * Autonomous or semi-autonomous decision-making systems + * Multi-agent frameworks or LLM-powered agents + * Tools enabling agent collaboration, coordination, or reasoning + * Infrastructure for agentic AI development or deployment +* If fewer than 3 relevant projects exist, output only those available. +* Use concise, professional tone and evidence-based reasoning in feedback. +* Avoid bias toward hype; focus on execution, innovation, and ecosystem impact. + +--- + +Would you like me to tailor this further for **automatic integration** into an evaluation pipeline (e.g., where the agent consumes structured project metadata and outputs ranked JSON reports automatically)? That version would include function schemas and evaluation templates. + +""" + +# Initialize the agent +agent = Agent( + agent_name="Hackathon-Judger-Agent", + agent_description="A hackathon judger agent that evaluates projects based on the judging criteria and produces a ranked report of the top 3 projects.", + model_name="claude-haiku-4-5", + system_prompt=HACKATHON_JUDGER_AGENT_PROMPT, + dynamic_temperature_enabled=True, + max_loops=1, + dynamic_context_window=True, + streaming_on=False, + top_p=None, + output_type="dict", +) + + +def read_csv_file(file_path: str = "projects.csv") -> str: + """Reads the entire CSV file and returns its content as a string.""" + with open(file_path, mode="r", encoding="utf-8") as f: + return f.read() + + +out = agent.run( + task=read_csv_file(), +) + +print(out) diff --git a/examples/guides/hackathon_judge_agent/projects.csv b/examples/guides/hackathon_judge_agent/projects.csv new file mode 100644 index 00000000..62119e50 --- /dev/null +++ b/examples/guides/hackathon_judge_agent/projects.csv @@ -0,0 +1,149 @@ +No.,Full Name,Respondent's country,Affiliation,Project Name,Brief Description,Brief Description (English Translation),Storytelling Video OR Article Link,Demo Link,Repository Link,Link to Published Work,Use of Toolkit,"Technical Feasibility +& Implementation +(30%)","Quality +& Clarity of Demo +(20%)","Presentation of Idea +(30%)","Innovation +& Originality of Idea +(20%)","Manual +Total Score",Manual Scoring Feedback +1,Yuki Sato,Japan,Keio University Blockchain Club,Daiko,Daiko AI tells you when to sell and why based on market data and risk profile.,Daiko AI tells you when to sell and why based on market data and risk profile.,https://www.youtube.com/watch?v=VJYT4-jbT8U,https://app.daiko.ai,https://github.com/Daiko-AI/daiko-ai-mvp-monorepo,https://x.com/DaikoAI/status/1923167905052586030,Solana AI Tools,,,,,0, +2,Treap,Hong Kong,0xWHU/ 武汉大学 Web3 俱乐部,neko-sol,"基于 Solana 区块链和 AI 技术的二次元猫娘养成游戏 MVP 版本 + +核心功能 +✅ 钱包连接: 支持 Phantom 和 Solflare 钱包 +✅ Solana Devnet 集成: 完整的区块链交互 +✅ 好感度系统: 基于 SPL Token 的链上好感度存储 +✅ 实时余额查询: 查看钱包 SOL 余额 +✅ Devnet 空投: 获取测试 SOL +✅ 好感度等级系统: 6 个等级从初识到至高羁绊 +链上操作 +创建好感度 Token Mint(每个猫娘独立) +铸造好感度 Token 到用户账户 +实时查询好感度分数 +所有交易可在 Solana Explorer 查看","MVP Version of a 2D Catgirl Raising Game Based on Solana Blockchain and AI Technology + +Core Features +✅ Wallet Connection: Supports Phantom and Solflare wallets +✅ Solana Devnet Integration: Complete blockchain interaction +✅ Affection System: On-chain affection storage based on SPL Tokens +✅ Real-time Balance Inquiry: View your wallet's SPL balance +✅ Devnet Airdrop: Obtain test SPL +✅ Affection Level System: 6 levels from initial acquaintance to ultimate bond +On-chain Operations +Create Affection Token Mint (individual for each catgirl) +Mint Affection Tokens to your user account +Real-time Affection Score Inquiry +All transactions can be viewed in Solana Explorer",https://github.com/TreapGoGo/neko-sol,,https://github.com/TreapGoGo/neko-sol,,"Swarms AI API, Solana AI Tools",,,,,0, +3,Gladx,Hong Kong,0xWHU/ 武汉大学 Web3 俱乐部,sol-dream,"个创新的去中心化应用,使用AI将您的梦境片段补全成完整故事,并永久记录在Solana区块链上。 + +✨ 特性 +🔗 Phantom钱包集成 - 安全便捷的钱包连接 +🤖 AI驱动 - 使用OpenAI GPT-4模型将梦境片段补全成完整故事 +⛓️ 区块链存储 - 将梦境永久记录在Solana区块链上 +🎨 现代化UI - 简洁美观的用户界面 +🚀 轻量级 - 纯前端实现,无需后端服务器","An innovative decentralized application that uses AI to complete your dream fragments into a full story and permanently record it on the Solana blockchain. + +✨ Features + +🔗 Phantom Wallet Integration - Secure and convenient wallet connection + +🤖 AI-Powered - Uses OpenAI GPT-4 model to complete dream fragments into a full story + +⛓️ Blockchain Storage - Permanently records dreams on the Solana blockchain + +🎨 Modern UI - Clean and beautiful user interface + +🚀 Lightweight - Pure front-end implementation, no back-end server required",https://github.com/TreapGoGo/sol-dream,,https://github.com/TreapGoGo/sol-dream,,"Solana AI Tools, Swarms AI API",,,,,0, +4,Rafael Oliveira,Brazil,Other,AurumGrid,"Aurumgrid AUI – Artificial Universal Intelligence +","Aurumgrid AUI – Artificial Universal Intelligence +",https://github.com/Aurumgrid/aurumgrid-aui,https://github.com/Aurumgrid/aurumgrid-aui,https://github.com/Aurumgrid/aurumgrid-aui,https://x.com/RafaelO9416467/status/1978837487494516820,"Solana AI Tools, Aethir GPU Compute, Swarms AI API",,,,,0, +5,Michael Afolabi,Nigeria,Superteam NG,Wojat,"Wojat is a comprehensive, AI-powered memecoin hunting platform that combines real-time data collection, social media analysis, and AI-driven insights to help traders discover the next big memecoin opportunities. Built with modern web technologies and powered by advanced AI agents.","Wojat is a comprehensive, AI-powered memecoin hunting platform that combines real-time data collection, social media analysis, and AI-driven insights to help traders discover the next big memecoin opportunities. Built with modern web technologies and powered by advanced AI agents.",https://drive.google.com/drive/folders/1-qESLXy-PvwB-L0CTYeUlxs-KpiUVATq?usp=sharing,https://drive.google.com/drive/folders/1-qESLXy-PvwB-L0CTYeUlxs-KpiUVATq?usp=sharing,https://github.com/Afoxcute/wojat,https://x.com/wojat118721/status/1979682642309341282,Solana AI Tools,,,,,0, +6,Brooks Shui,Taiwan,Nankai University Blockchain Association / 南开大学区块链协会,SPR Platform,"🦹🏻‍♀️🔮SPR1.0: The ATH-Powered VLM estimation platform (🔗https://reflexresearches.com/) + +What We Built (and Why) + +SPR makes some difference. It's an autonomous platform that uses a swarm of our custom-built AI agents to handle the entire assessment process in minutes, not days. We let customers and businesses spare their time and improve the efficiency. + +The Problem We're Fixing + +We remove the personality in recycling, and spare the cost of the laboratory and long time. Also, thinking of the high training cost of a VLM-model, we use the Aethir GPU to shrink its fee. + +Our Solution + +The model consists of two versions: image recognition and video recognition. + +The image recognition module can accurately capture detailed appearance features of smartphones, detecting physical damages such as screen scratches, frame dents, and back cover wear in milliseconds. Meanwhile, it quickly verifies core configuration information including processor model, RAM capacity, and storage size through hardware parameter recognition algorithms. + +The video recognition module further breaks through the limitations of static recognition by analyzing dynamic footage of smartphone boot-up demonstrations and functional operations to determine if there are issues such as color cast, light leakage, or touch failure on the screen. It also accurately identifies whether the camera lens has scratches, bubbles, or cracks, and fully verifies the integrity of functions such as camera focusing and flash. This multi-dimensional intelligent detection method constructs a full-lifecycle evaluation system for smartphones, from hardware performance to appearance wear, providing objective and accurate data support for pricing.","🦹🏻‍♀️🔮SPR1.0: The ATH-Powered VLM estimation platform (🔗https://reflexresearches.com/) + +What We Built (and Why) + +SPR makes some difference. It's an autonomous platform that uses a swarm of our custom-built AI agents to handle the entire assessment process in minutes, not days. We let customers and businesses spare their time and improve the efficiency. + +The Problem We're Fixing + +We remove the personality in recycling, and spare the cost of the laboratory and long time. Also, thinking of the high training cost of a VLM-model, we use the Aethir GPU to shrink its fee. + +Our Solution + +The model consists of two versions: image recognition and video recognition. + +The image recognition module can accurately capture detailed appearance features of smartphones, detecting physical damages such as screen scratches, frame dents, and back cover wear in milliseconds. Meanwhile, it quickly verifies core configuration information including processor model, RAM capacity, and storage size through hardware parameter recognition algorithms. + +The video recognition module further breaks through the limitations of static recognition by analyzing dynamic footage of smartphone boot-up demonstrations and functional operations to determine if there are issues such as color cast, light leakage, or touch failure on the screen. It also accurately identifies whether the camera lens has scratches, bubbles, or cracks, and fully verifies the integrity of functions such as camera focusing and flash. This multi-dimensional intelligent detection method constructs a full-lifecycle evaluation system for smartphones, from hardware performance to appearance wear, providing objective and accurate data support for pricing.",https://reflexresearches.com/,https://youtu.be/oprRqLLlRIQ?si=WXtOnpnyM9HN0WDI,https://github.com/paterleng/second_recycling_system,https://x.com/zhangyuxia4454/status/1980183358253756779?s=46,Aethir GPU Compute,,,,,0, +7,Ozan Andaç,Poland,DoraHacks,Elowen,"Elowen is a decentralized AI project that allows users to chat with fictional and nonfictional characters without censorship while contributing to the development of AI +models. + +The platform is designed to be community-driven, enabling creators to earn $ELW +tokens through periodic reward distribution based on the usage of their chatbots. + +$ELW is fully controlled by a Solana program, preventing any manual interference or +large-scale token selloffs. + +As project-wise, you can think of it as a decentralized and censorless character.ai +alternative. + +We have an ecosystem of tools: +- Web App for builders & consumers +- X (formerly Twitter) bot that impersonates a character and replies to threads (@elowenbot) +- Telegram Bot to move chatting beyond the website +- Public API +- Solana Program & Token (Currently on Testnet)","Elowen is a decentralized AI project that allows users to chat with fictional and nonfictional characters without censorship while contributing to the development of AI +models. + +The platform is designed to be community-driven, enabling creators to earn $ELW +tokens through periodic reward distribution based on the usage of their chatbots. + +$ELW is fully controlled by a Solana program, preventing any manual interference or +large-scale token selloffs. + +As project-wise, you can think of it as a decentralized and censorless character.ai +alternative. + +We have an ecosystem of tools: +- Web App for builders & consumers +- X (formerly Twitter) bot that impersonates a character and replies to threads (@elowenbot) +- Telegram Bot to move chatting beyond the website +- Public API +- Solana Program & Token (Currently on Testnet)",https://drive.google.com/file/d/1odChCG-RZeiH7i1OjR88dUitb2h1pkJY/view?usp=sharing,https://elowen.ai,https://github.com/elowen-ai,https://x.com/OzanAndac_/status/1981922432689619368,Solana AI Tools,,,,,0, +8,Shivam Agarwal,India,Other,SolGame,"A lightweight pixel **multicharacter**, Play To Earn dungeon game built on the Solana Devnet Blockchain, built with Phaser, powered by Metaplex NFT Marketplace Protocol. Our motivation is to enable users to own what they earn.","A lightweight pixel **multicharacter**, Play To Earn dungeon game built on the Solana Devnet Blockchain, built with Phaser, powered by Metaplex NFT Marketplace Protocol. Our motivation is to enable users to own what they earn.",https://docs.google.com/presentation/d/1g4LZlb-SBxnCUIOofO7lvPPPeMLYq664hZqJFO08Zt4/edit?usp=sharing,https://sol-game-six.vercel.app/,https://github.com/ShivamAgarwal-code/SolGame.git,,"Solana AI Tools, Swarms AI API",,,,,0, +9,Fawzan Pima,Ghana,SG Union,Sol Terminal," An mcp server for solana that allows ai agents to gain context of solana capabilities like sending solana , checking sol balance , manage sol accounts and wallets getting sol address al without needing a sol app installed you just connect the mcp to your agent and strt using it , u add your private key in the mcp env . Ware giving ai agents the autonomous capabilities to run activities onchain."," An mcp server for solana that allows ai agents to gain context of solana capabilities like sending solana , checking sol balance , manage sol accounts and wallets getting sol address al without needing a sol app installed you just connect the mcp to your agent and strt using it , u add your private key in the mcp env . Ware giving ai agents the autonomous capabilities to run activities onchain.",https://www.loom.com/share/3c1295e0f80149e792b7a6f65bb45c1e,https://fozagtx.github.io/SolanaAiTerminal/,https://github.com/fozagtx/SolanaAiTerminal,https://youtu.be/iSs1Lf8n-fw?si=B5nUkyld1RW7yjjF,Solana AI Tools,,,,,0, +10,Riadh M belarbi,United Kingdom of Great Britain and Northern Ireland,Imperial Blockchain,toky.fun,"Toky.fun is an all in one platform ecosystem allowing users to launch projects and grow them with no code, using AI agents and leveraging swarms. aimed at Web3 founders, small teams and non technicals, with toky.fun you can vibe code websites, mobile apps, manage your socials, moderate your group chats and get help with compliance, and of course launch tokens where you need them! ","Toky.fun is an all in one platform ecosystem allowing users to launch projects and grow them with no code, using AI agents and leveraging swarms. aimed at Web3 founders, small teams and non technicals, with toky.fun you can vibe code websites, mobile apps, manage your socials, moderate your group chats and get help with compliance, and of course launch tokens where you need them! ",https://aisolana.s3.eu-north-1.amazonaws.com/toky.fun+presentation.MP4,https://aisolana.s3.eu-north-1.amazonaws.com/toky2.0.mp4,https://github.com/its-mc/toky.fun.git,,Solana AI Tools,,,,,0, +11,Yadidya Medepalli,United Kingdom of Great Britain and Northern Ireland,Other,Nebula AI,"Nebula Protocol is the world's first decentralized Earth observation platform where autonomous AI agents with their own Solana wallets monitor our planet 24/7 and record findings immutably on-chain. Nine specialized AI agents (Forest Guardian, Ice Sentinel, Disaster Responder, etc.) independently sign blockchain transactions, execute environmental missions, and mint NFTs demonstrating autonomous AI-driven blockchain operations that address centralized data silos and enable verifiable disaster prevention. Fully deployed on Solana with smart contracts, voice commands, and mind- blowing visualization proving AI agents can autonomously operate blockchain infrastructure at scale. + +Demo link at: https://x.com/MYadidya/status/1983074064211308648 +or +Youtube link: https://youtu.be/fJrnTWOWPRM","Nebula Protocol is the world's first decentralized Earth observation platform where autonomous AI agents with their own Solana wallets monitor our planet 24/7 and record findings immutably on-chain. Nine specialized AI agents (Forest Guardian, Ice Sentinel, Disaster Responder, etc.) independently sign blockchain transactions, execute environmental missions, and mint NFTs demonstrating autonomous AI-driven blockchain operations that address centralized data silos and enable verifiable disaster prevention. Fully deployed on Solana with smart contracts, voice commands, and mind- blowing visualization proving AI agents can autonomously operate blockchain infrastructure at scale. + +Demo link at: https://x.com/MYadidya/status/1983074064211308648 +or +Youtube link: https://youtu.be/fJrnTWOWPRM",https://nebv2article.netlify.app/,https://nebulav2.netlify.app/,https://github.com/YadidyaM/Nebula-2.0---Decentralized-Earth-Observation-Platform,https://x.com/MYadidya/status/1983074064211308648,"Solana AI Tools, Swarms AI API",,,,,0, +12,Togo,Japan,N/A,TinyPay,"TinyPay is a crypto-native payment application built on Solana, enabling seamless real-world transactions with digital assets — even without an internet connection. +We’re building the bridge between digital assets and everyday spending, making crypto payments as effortless as cash or cards.","TinyPay is a crypto-native payment application built on Solana, enabling seamless real-world transactions with digital assets — even without an internet connection. +We’re building the bridge between digital assets and everyday spending, making crypto payments as effortless as cash or cards.",https://docs.google.com/presentation/d/1kXA47K0ovv51GvYYEm2yWVHrwJYQLrtKMqMoS5wUhMk/edit?usp=sharing,https://www.youtube.com/watch?v=E59_zBE-Mao,https://github.com/TrustPipe/TinyPayContract-Solana,https://x.com/TrustLucian/status/1981912066761056372,Solana AI Tools,,,,,0, +13,Alan Wang,Japan,solar,foxhole.ai,"Foxhole AI monitors influential Twitter accounts for crypto keywords and instantly delivers verified contract addresses to users for trading. + +","Foxhole AI monitors influential Twitter accounts for crypto keywords and instantly delivers verified contract addresses to users for trading. + +",https://youtu.be/nn3zgyBGgdQ?si=xYHt87szURiqvVZz,https://youtu.be/nn3zgyBGgdQ?si=xYHt87szURiqvVZz,https://github.com/foxholeAI/foxholeAI,https://x.com/alan_ywang/status/1984315036429664509,"Solana AI Tools, Aethir GPU Compute, Swarms AI API",,,,,0, \ No newline at end of file diff --git a/examples/guides/hackathons/README.md b/examples/guides/hackathons/README.md new file mode 100644 index 00000000..e2de0607 --- /dev/null +++ b/examples/guides/hackathons/README.md @@ -0,0 +1,18 @@ +# Hackathon Examples + +This directory contains hackathon project examples and implementations. + +## Subdirectories + +### Hackathon September 27 +- [hackathon_sep_27/](hackathon_sep_27/) - September 27 hackathon projects + - [api_client.py](hackathon_sep_27/api_client.py) - API client implementation + - [diet_coach_agent.py](hackathon_sep_27/diet_coach_agent.py) - Diet coach agent + - [nutritional_content_analysis_swarm.py](hackathon_sep_27/nutritional_content_analysis_swarm.py) - Nutritional analysis swarm + - [nutritonal_content_analysis_swarm.sh](hackathon_sep_27/nutritonal_content_analysis_swarm.sh) - Analysis script + - [pizza.jpg](hackathon_sep_27/pizza.jpg) - Sample image + +## Overview + +This directory contains real hackathon projects built with Swarms, demonstrating practical applications and creative uses of the framework. These examples showcase how Swarms can be used to build domain-specific solutions quickly. + diff --git a/examples/hackathons/hackathon_sep_27/api_client.py b/examples/guides/hackathons/hackathon_sep_27/api_client.py similarity index 100% rename from examples/hackathons/hackathon_sep_27/api_client.py rename to examples/guides/hackathons/hackathon_sep_27/api_client.py diff --git a/examples/hackathons/hackathon_sep_27/diet_coach_agent.py b/examples/guides/hackathons/hackathon_sep_27/diet_coach_agent.py similarity index 100% rename from examples/hackathons/hackathon_sep_27/diet_coach_agent.py rename to examples/guides/hackathons/hackathon_sep_27/diet_coach_agent.py diff --git a/examples/hackathons/hackathon_sep_27/nutritional_content_analysis_swarm.py b/examples/guides/hackathons/hackathon_sep_27/nutritional_content_analysis_swarm.py similarity index 100% rename from examples/hackathons/hackathon_sep_27/nutritional_content_analysis_swarm.py rename to examples/guides/hackathons/hackathon_sep_27/nutritional_content_analysis_swarm.py diff --git a/examples/hackathons/hackathon_sep_27/nutritonal_content_analysis_swarm.sh b/examples/guides/hackathons/hackathon_sep_27/nutritonal_content_analysis_swarm.sh similarity index 100% rename from examples/hackathons/hackathon_sep_27/nutritonal_content_analysis_swarm.sh rename to examples/guides/hackathons/hackathon_sep_27/nutritonal_content_analysis_swarm.sh diff --git a/examples/hackathons/hackathon_sep_27/pizza.jpg b/examples/guides/hackathons/hackathon_sep_27/pizza.jpg similarity index 100% rename from examples/hackathons/hackathon_sep_27/pizza.jpg rename to examples/guides/hackathons/hackathon_sep_27/pizza.jpg diff --git a/examples/guides/nano_banana_jarvis_agent/README.md b/examples/guides/nano_banana_jarvis_agent/README.md new file mode 100644 index 00000000..683a05ba --- /dev/null +++ b/examples/guides/nano_banana_jarvis_agent/README.md @@ -0,0 +1,18 @@ +# Nano Banana Jarvis Agent + +This directory contains the Nano Banana Jarvis agent example, demonstrating vision and multimodal capabilities. + +## Examples + +- [jarvis_agent.py](jarvis_agent.py) - Main Jarvis agent implementation +- [img_gen_nano_banana.py](img_gen_nano_banana.py) - Image generation example + +## Images + +- Sample images included: building.jpg, hk.jpg, image.jpg, miami.jpg +- [annotated_images/](annotated_images/) - Directory containing annotated image examples + +## Overview + +The Nano Banana Jarvis agent demonstrates advanced vision and multimodal capabilities, including image analysis, image generation, and visual understanding. This example showcases how to build agents that can process and generate visual content. + diff --git a/examples/guides/web_scraper_agents/README.md b/examples/guides/web_scraper_agents/README.md new file mode 100644 index 00000000..651a6562 --- /dev/null +++ b/examples/guides/web_scraper_agents/README.md @@ -0,0 +1,13 @@ +# Web Scraper Agents + +This directory contains examples demonstrating web scraping capabilities with agents. + +## Examples + +- [batched_scraper_agent.py](batched_scraper_agent.py) - Batched web scraping agent +- [web_scraper_agent.py](web_scraper_agent.py) - Basic web scraper agent + +## Overview + +These examples demonstrate how to build agents capable of web scraping, extracting information from websites, and processing web content. The batched version shows how to handle multiple URLs efficiently, while the basic example demonstrates core scraping functionality. + diff --git a/examples/workshops/README.md b/examples/guides/workshops/README.md similarity index 100% rename from examples/workshops/README.md rename to examples/guides/workshops/README.md diff --git a/examples/workshops/workshop_sep_20/agent_tools_dict_example.py b/examples/guides/workshops/workshop_sep_20/agent_tools_dict_example.py similarity index 100% rename from examples/workshops/workshop_sep_20/agent_tools_dict_example.py rename to examples/guides/workshops/workshop_sep_20/agent_tools_dict_example.py diff --git a/examples/workshops/workshop_sep_20/batched_grid_simple_example.py b/examples/guides/workshops/workshop_sep_20/batched_grid_simple_example.py similarity index 100% rename from examples/workshops/workshop_sep_20/batched_grid_simple_example.py rename to examples/guides/workshops/workshop_sep_20/batched_grid_simple_example.py diff --git a/examples/workshops/workshop_sep_20/geo_guesser_agent.py b/examples/guides/workshops/workshop_sep_20/geo_guesser_agent.py similarity index 100% rename from examples/workshops/workshop_sep_20/geo_guesser_agent.py rename to examples/guides/workshops/workshop_sep_20/geo_guesser_agent.py diff --git a/examples/workshops/workshop_sep_20/hk.jpg b/examples/guides/workshops/workshop_sep_20/hk.jpg similarity index 100% rename from examples/workshops/workshop_sep_20/hk.jpg rename to examples/guides/workshops/workshop_sep_20/hk.jpg diff --git a/examples/workshops/workshop_sep_20/jarvis_agent.py b/examples/guides/workshops/workshop_sep_20/jarvis_agent.py similarity index 100% rename from examples/workshops/workshop_sep_20/jarvis_agent.py rename to examples/guides/workshops/workshop_sep_20/jarvis_agent.py diff --git a/examples/workshops/workshop_sep_20/miami.jpg b/examples/guides/workshops/workshop_sep_20/miami.jpg similarity index 100% rename from examples/workshops/workshop_sep_20/miami.jpg rename to examples/guides/workshops/workshop_sep_20/miami.jpg diff --git a/examples/workshops/workshop_sep_20/mountains.jpg b/examples/guides/workshops/workshop_sep_20/mountains.jpg similarity index 100% rename from examples/workshops/workshop_sep_20/mountains.jpg rename to examples/guides/workshops/workshop_sep_20/mountains.jpg diff --git a/examples/workshops/workshop_sep_20/same_task_example.py b/examples/guides/workshops/workshop_sep_20/same_task_example.py similarity index 100% rename from examples/workshops/workshop_sep_20/same_task_example.py rename to examples/guides/workshops/workshop_sep_20/same_task_example.py diff --git a/examples/mcp/agent_examples/README.md b/examples/mcp/agent_examples/README.md new file mode 100644 index 00000000..ed5da461 --- /dev/null +++ b/examples/mcp/agent_examples/README.md @@ -0,0 +1,15 @@ +# MCP Agent Examples + +This directory contains examples demonstrating agent implementations using Model Context Protocol (MCP). + +## Examples + +- [agent_mcp_old.py](agent_mcp_old.py) - Legacy MCP agent implementation +- [agent_multi_mcp_connections.py](agent_multi_mcp_connections.py) - Multi-MCP connection agent +- [agent_tools_dict_example.py](agent_tools_dict_example.py) - Agent tools dictionary example +- [mcp_exampler.py](mcp_exampler.py) - MCP example implementation + +## Overview + +MCP agent examples demonstrate how to build agents that leverage the Model Context Protocol for enhanced context management and tool integration. These examples show various patterns for connecting agents to MCP servers and using MCP tools. + diff --git a/examples/mcp/mcp_utils/README.md b/examples/mcp/mcp_utils/README.md new file mode 100644 index 00000000..0803e7e7 --- /dev/null +++ b/examples/mcp/mcp_utils/README.md @@ -0,0 +1,27 @@ +# MCP Utils + +This directory contains utility functions and helpers for MCP implementations. + +## Examples + +- [client.py](client.py) - MCP client implementation +- [mcp_client_call.py](mcp_client_call.py) - MCP client call utilities +- [mcp_multiple_servers_example.py](mcp_multiple_servers_example.py) - Multiple MCP servers example +- [mcp_multiple_tool_test.py](mcp_multiple_tool_test.py) - Multiple tool testing +- [multiagent_client.py](multiagent_client.py) - Multi-agent MCP client +- [singleagent_client.py](singleagent_client.py) - Single agent MCP client +- [test_multiple_mcp_servers.py](test_multiple_mcp_servers.py) - Multiple server testing +- [utils.py](utils.py) - General MCP utilities + +## Subdirectories + +- [utils/](utils/) - Additional utility functions + - [find_tools_on_mcp.py](utils/find_tools_on_mcp.py) - Tool discovery + - [mcp_execute_example.py](utils/mcp_execute_example.py) - MCP execution example + - [mcp_load_tools_example.py](utils/mcp_load_tools_example.py) - Tool loading example + - [mcp_multiserver_tool_fetch.py](utils/mcp_multiserver_tool_fetch.py) - Multi-server tool fetching + +## Overview + +MCP utils provide helper functions, client implementations, and testing utilities for working with Model Context Protocol. These examples demonstrate how to connect to MCP servers, discover tools, execute operations, and manage multiple MCP connections. + diff --git a/examples/mcp/multi_mcp_guide/README.md b/examples/mcp/multi_mcp_guide/README.md new file mode 100644 index 00000000..9763beeb --- /dev/null +++ b/examples/mcp/multi_mcp_guide/README.md @@ -0,0 +1,14 @@ +# Multi-MCP Guide Examples + +This directory contains examples demonstrating multi-MCP connection patterns and guides. + +## Examples + +- [agent_mcp.py](agent_mcp.py) - Agent MCP implementation +- [mcp_agent_tool.py](mcp_agent_tool.py) - MCP agent tool example +- [okx_crypto_server.py](okx_crypto_server.py) - OKX crypto MCP server example + +## Overview + +Multi-MCP guide examples demonstrate how to connect agents to multiple MCP servers simultaneously, manage multiple tool sets, and coordinate operations across different MCP connections. These examples provide guidance for building complex MCP-based agent systems. + diff --git a/examples/mcp/servers/README.md b/examples/mcp/servers/README.md new file mode 100644 index 00000000..288fa4d7 --- /dev/null +++ b/examples/mcp/servers/README.md @@ -0,0 +1,15 @@ +# MCP Server Examples + +This directory contains examples demonstrating MCP server implementations. + +## Examples + +- [mcp_agent_tool.py](mcp_agent_tool.py) - MCP agent tool server +- [mcp_test.py](mcp_test.py) - MCP server testing +- [okx_crypto_server.py](okx_crypto_server.py) - OKX crypto MCP server +- [test.py](test.py) - Server testing + +## Overview + +MCP server examples demonstrate how to implement Model Context Protocol servers that expose tools and capabilities to agents. These examples show server setup, tool registration, request handling, and domain-specific server implementations. + diff --git a/examples/multi_agent/agent_rearrange_examples/README.md b/examples/multi_agent/agent_rearrange_examples/README.md new file mode 100644 index 00000000..24c74adc --- /dev/null +++ b/examples/multi_agent/agent_rearrange_examples/README.md @@ -0,0 +1,12 @@ +# Agent Rearrangement Examples + +This directory contains examples demonstrating agent rearrangement functionality in multi-agent systems. + +## Examples + +- [rearrange_test.py](rearrange_test.py) - Test agent rearrangement functionality + +## Overview + +Agent rearrangement allows dynamic reconfiguration of agent teams and workflows during execution, enabling adaptive multi-agent systems that can reorganize based on task requirements or performance metrics. + diff --git a/examples/multi_agent/agent_router_examples/README.md b/examples/multi_agent/agent_router_examples/README.md new file mode 100644 index 00000000..134ef50d --- /dev/null +++ b/examples/multi_agent/agent_router_examples/README.md @@ -0,0 +1,12 @@ +# Agent Router Examples + +This directory contains examples demonstrating agent routing functionality for directing tasks to appropriate agents. + +## Examples + +- [agent_router_example.py](agent_router_example.py) - Agent routing implementation example + +## Overview + +Agent routing enables intelligent task distribution across multiple agents based on capabilities, availability, or task characteristics. This allows for efficient load balancing and optimal agent selection. + diff --git a/examples/multi_agent/asb/README.md b/examples/multi_agent/asb/README.md new file mode 100644 index 00000000..e7e184aa --- /dev/null +++ b/examples/multi_agent/asb/README.md @@ -0,0 +1,17 @@ +# Auto Swarm Builder (ASB) Examples + +This directory contains examples demonstrating the Auto Swarm Builder, which automatically creates and configures agent swarms. + +## Examples + +- [asb_research.py](asb_research.py) - Research-focused ASB implementation +- [auto_agent.py](auto_agent.py) - Automated agent creation +- [auto_swarm_builder_example.py](auto_swarm_builder_example.py) - Complete ASB example +- [auto_swarm_builder_test.py](auto_swarm_builder_test.py) - ASB testing suite +- [auto_swarm_router.py](auto_swarm_router.py) - Router for auto-generated swarms +- [content_creation_asb.py](content_creation_asb.py) - Content creation with ASB + +## Overview + +The Auto Swarm Builder (ASB) automatically generates and configures multi-agent swarms based on task requirements, reducing manual setup overhead and enabling rapid prototyping of agent systems. + diff --git a/examples/multi_agent/board_of_directors/README.md b/examples/multi_agent/board_of_directors/README.md new file mode 100644 index 00000000..65ff939c --- /dev/null +++ b/examples/multi_agent/board_of_directors/README.md @@ -0,0 +1,14 @@ +# Board of Directors Examples + +This directory contains examples demonstrating board of directors patterns for multi-agent decision-making. + +## Examples + +- [board_of_directors_example.py](board_of_directors_example.py) - Full board simulation +- [minimal_board_example.py](minimal_board_example.py) - Minimal board setup +- [simple_board_example.py](simple_board_example.py) - Simple board example + +## Overview + +Board of directors patterns simulate corporate governance structures where multiple agents collaborate to make decisions, vote on proposals, and manage organizational tasks. This pattern is useful for complex decision-making scenarios requiring multiple perspectives. + diff --git a/examples/multi_agent/caching_examples/README.md b/examples/multi_agent/caching_examples/README.md new file mode 100644 index 00000000..2c34974d --- /dev/null +++ b/examples/multi_agent/caching_examples/README.md @@ -0,0 +1,14 @@ +# Caching Examples + +This directory contains examples demonstrating caching strategies for multi-agent systems. + +## Examples + +- [example_multi_agent_caching.py](example_multi_agent_caching.py) - Multi-agent caching implementation +- [quick_start_agent_caching.py](quick_start_agent_caching.py) - Quick start guide for caching +- [test_simple_agent_caching.py](test_simple_agent_caching.py) - Simple caching tests + +## Overview + +Caching in multi-agent systems improves performance by storing frequently accessed data and computation results. These examples demonstrate various caching strategies for agent interactions, tool calls, and shared state. + diff --git a/examples/multi_agent/concurrent_examples/README.md b/examples/multi_agent/concurrent_examples/README.md new file mode 100644 index 00000000..37d44258 --- /dev/null +++ b/examples/multi_agent/concurrent_examples/README.md @@ -0,0 +1,22 @@ +# Concurrent Examples + +This directory contains examples demonstrating concurrent execution patterns for multi-agent systems. + +## Examples + +- [asi.py](asi.py) - ASI (Artificial Super Intelligence) example +- [concurrent_example_dashboard.py](concurrent_example_dashboard.py) - Dashboard for concurrent workflows +- [concurrent_example.py](concurrent_example.py) - Basic concurrent execution +- [concurrent_mix.py](concurrent_mix.py) - Mixed concurrent patterns +- [concurrent_swarm_example.py](concurrent_swarm_example.py) - Concurrent swarm execution +- [streaming_concurrent_workflow.py](streaming_concurrent_workflow.py) - Streaming with concurrency + +## Subdirectories + +- [streaming_callback/](streaming_callback/) - Streaming callback examples +- [uvloop/](uvloop/) - UVLoop integration examples for high-performance async execution + +## Overview + +Concurrent execution enables multiple agents to work simultaneously, significantly improving throughput and reducing latency. These examples demonstrate various concurrency patterns including parallel processing, async workflows, and streaming responses. + diff --git a/examples/multi_agent/council/README.md b/examples/multi_agent/council/README.md new file mode 100644 index 00000000..2bb754a4 --- /dev/null +++ b/examples/multi_agent/council/README.md @@ -0,0 +1,14 @@ +# Council Examples + +This directory contains examples demonstrating council patterns for multi-agent evaluation and decision-making. + +## Examples + +- [council_judge_evaluation.py](council_judge_evaluation.py) - Judge evaluation system +- [council_judge_example.py](council_judge_example.py) - Basic council example +- [council_of_judges_eval.py](council_of_judges_eval.py) - Evaluation framework + +## Overview + +Council patterns involve multiple agents acting as judges or evaluators, providing diverse perspectives and assessments. This is useful for quality control, peer review, and consensus-building scenarios. + diff --git a/examples/multi_agent/council_of_judges/README.md b/examples/multi_agent/council_of_judges/README.md new file mode 100644 index 00000000..8da5045c --- /dev/null +++ b/examples/multi_agent/council_of_judges/README.md @@ -0,0 +1,14 @@ +# Council of Judges Examples + +This directory contains examples demonstrating council of judges patterns for multi-agent evaluation systems. + +## Examples + +- [council_judge_complex_example.py](council_judge_complex_example.py) - Complex council setup +- [council_judge_custom_example.py](council_judge_custom_example.py) - Custom council configuration +- [council_judge_example.py](council_judge_example.py) - Basic council of judges example + +## Overview + +Council of judges patterns extend the basic council pattern with more sophisticated evaluation mechanisms, custom scoring systems, and complex decision-making workflows. These examples demonstrate advanced judge coordination and evaluation strategies. + diff --git a/examples/multi_agent/debate_examples/README.md b/examples/multi_agent/debate_examples/README.md new file mode 100644 index 00000000..80a0aab7 --- /dev/null +++ b/examples/multi_agent/debate_examples/README.md @@ -0,0 +1,12 @@ +# Debate Examples + +This directory contains examples demonstrating debate patterns for multi-agent systems. + +## Overview + +Debate patterns enable agents to engage in structured discussions, present arguments, and reach conclusions through discourse. This pattern is useful for exploring multiple perspectives on complex topics and arriving at well-reasoned decisions. + +## Note + +This directory is currently being populated with debate examples. Check back soon for implementations! + diff --git a/examples/multi_agent/election_swarm_examples/README.md b/examples/multi_agent/election_swarm_examples/README.md new file mode 100644 index 00000000..39674e60 --- /dev/null +++ b/examples/multi_agent/election_swarm_examples/README.md @@ -0,0 +1,13 @@ +# Election Swarm Examples + +This directory contains examples demonstrating election patterns for multi-agent voting systems. + +## Examples + +- [apple_board_election_example.py](apple_board_election_example.py) - Apple board election simulation +- [election_example.py](election_example.py) - General election example + +## Overview + +Election swarm patterns simulate voting processes where multiple agents participate in elections, voting on candidates or proposals. These examples demonstrate democratic decision-making processes in multi-agent systems, useful for governance, selection, and consensus-building scenarios. + diff --git a/examples/multi_agent/exec_utilities/README.md b/examples/multi_agent/exec_utilities/README.md new file mode 100644 index 00000000..985585aa --- /dev/null +++ b/examples/multi_agent/exec_utilities/README.md @@ -0,0 +1,13 @@ +# Execution Utilities Examples + +This directory contains examples demonstrating execution utilities for multi-agent systems. + +## Examples + +- [new_uvloop_example.py](new_uvloop_example.py) - Updated UVLoop example +- [uvloop_example.py](uvloop_example.py) - UVLoop integration for high-performance async execution + +## Overview + +Execution utilities provide performance optimizations and execution management for multi-agent systems. These examples focus on UVLoop integration, which provides high-performance event loop implementation for Python async operations. + diff --git a/examples/multi_agent/forest_swarm_examples/README.md b/examples/multi_agent/forest_swarm_examples/README.md new file mode 100644 index 00000000..7a1e8f91 --- /dev/null +++ b/examples/multi_agent/forest_swarm_examples/README.md @@ -0,0 +1,16 @@ +# Forest Swarm Examples + +This directory contains examples demonstrating forest swarm architectures for multi-agent systems. + +## Examples + +- [forest_swarm_example.py](forest_swarm_example.py) - Forest-based swarm architecture +- [fund_manager_forest.py](fund_manager_forest.py) - Financial fund management forest +- [medical_forest_swarm.py](medical_forest_swarm.py) - Medical domain forest swarm +- [tree_example.py](tree_example.py) - Basic tree structure example +- [tree_swarm_test.py](tree_swarm_test.py) - Tree swarm testing + +## Overview + +Forest swarm patterns organize agents in tree structures, enabling hierarchical processing and decision-making. Each branch can handle different aspects of a problem, with results flowing up the tree for final synthesis. This pattern is useful for complex, multi-faceted problems requiring specialized agent teams. + diff --git a/examples/multi_agent/graphworkflow_examples/README.md b/examples/multi_agent/graphworkflow_examples/README.md new file mode 100644 index 00000000..38a45258 --- /dev/null +++ b/examples/multi_agent/graphworkflow_examples/README.md @@ -0,0 +1,24 @@ +# Graph Workflow Examples + +This directory contains examples demonstrating graph-based workflow patterns for multi-agent systems. + +## Examples + +- [advanced_graph_workflow.py](advanced_graph_workflow.py) - Advanced graph-based workflows +- [graph_workflow_basic.py](graph_workflow_basic.py) - Basic graph workflow +- [graph_workflow_example.py](graph_workflow_example.py) - Complete graph workflow example +- [graph_workflow_validation.py](graph_workflow_validation.py) - Workflow validation +- [test_enhanced_json_export.py](test_enhanced_json_export.py) - JSON export testing +- [test_graph_workflow_caching.py](test_graph_workflow_caching.py) - Caching tests +- [test_graphviz_visualization.py](test_graphviz_visualization.py) - Visualization tests +- [test_parallel_processing_example.py](test_parallel_processing_example.py) - Parallel processing tests + +## Subdirectories + +- [graph/](graph/) - Core graph utilities +- [example_images/](example_images/) - Visualization images + +## Overview + +Graph workflows enable complex, non-linear agent interactions where agents are nodes and their relationships form edges. This allows for sophisticated workflows with conditional paths, parallel branches, and dynamic routing based on intermediate results. + diff --git a/examples/multi_agent/groupchat/README.md b/examples/multi_agent/groupchat/README.md new file mode 100644 index 00000000..31bef57e --- /dev/null +++ b/examples/multi_agent/groupchat/README.md @@ -0,0 +1,18 @@ +# Group Chat Examples + +This directory contains examples demonstrating group chat patterns for multi-agent conversations. + +## Examples + +- [interactive_groupchat_example.py](interactive_groupchat_example.py) - Interactive group chat +- [quantum_physics_swarm.py](quantum_physics_swarm.py) - Physics-focused group chat +- [random_dynamic_speaker_example.py](random_dynamic_speaker_example.py) - Dynamic speaker selection + +## Subdirectories + +- [groupchat_examples/](groupchat_examples/) - Additional group chat patterns + +## Overview + +Group chat patterns enable multiple agents to engage in conversations, share information, and collaborate through natural language interactions. These examples demonstrate various conversation management strategies including turn-taking, topic management, and dynamic participation. + diff --git a/examples/multi_agent/heavy_swarm_examples/README.md b/examples/multi_agent/heavy_swarm_examples/README.md new file mode 100644 index 00000000..5033d233 --- /dev/null +++ b/examples/multi_agent/heavy_swarm_examples/README.md @@ -0,0 +1,16 @@ +# Heavy Swarm Examples + +This directory contains examples demonstrating heavy swarm patterns for large-scale multi-agent systems. + +## Examples + +- [heavy_swarm_example_one.py](heavy_swarm_example_one.py) - First heavy swarm example +- [heavy_swarm_example.py](heavy_swarm_example.py) - Main heavy swarm implementation +- [heavy_swarm_no_dashboard.py](heavy_swarm_no_dashboard.py) - Heavy swarm without dashboard +- [heavy_swarm.py](heavy_swarm.py) - Core heavy swarm implementation +- [medical_heavy_swarm_example.py](medical_heavy_swarm_example.py) - Medical heavy swarm + +## Overview + +Heavy swarms are designed for large-scale multi-agent systems with many agents working on complex tasks. These examples demonstrate patterns for managing large agent populations, coordinating their work, and handling the increased complexity and resource requirements. + diff --git a/examples/multi_agent/hiearchical_swarm/README.md b/examples/multi_agent/hiearchical_swarm/README.md new file mode 100644 index 00000000..ca67f345 --- /dev/null +++ b/examples/multi_agent/hiearchical_swarm/README.md @@ -0,0 +1,26 @@ +# Hierarchical Swarm Examples + +This directory contains examples demonstrating hierarchical swarm patterns for multi-agent systems. + +## Examples + +- [hierarchical_swarm_basic_demo.py](hierarchical_swarm_basic_demo.py) - Basic hierarchical demo +- [hierarchical_swarm_batch_demo.py](hierarchical_swarm_batch_demo.py) - Batch processing demo +- [hierarchical_swarm_comparison_demo.py](hierarchical_swarm_comparison_demo.py) - Comparison demo +- [hierarchical_swarm_example.py](hierarchical_swarm_example.py) - Main hierarchical example +- [hierarchical_swarm_streaming_demo.py](hierarchical_swarm_streaming_demo.py) - Streaming demo +- [hierarchical_swarm_streaming_example.py](hierarchical_swarm_streaming_example.py) - Streaming example +- [hs_interactive.py](hs_interactive.py) - Interactive hierarchical swarm +- [hs_stock_team.py](hs_stock_team.py) - Stock trading team +- [hybrid_hiearchical_swarm.py](hybrid_hiearchical_swarm.py) - Hybrid approach +- [sector_analysis_hiearchical_swarm.py](sector_analysis_hiearchical_swarm.py) - Sector analysis + +## Subdirectories + +- [hiearchical_examples/](hiearchical_examples/) - Additional hierarchical examples +- [hiearchical_swarm_ui/](hiearchical_swarm_ui/) - UI components for hierarchical swarms + +## Overview + +Hierarchical swarms organize agents in a tree-like structure with managers and workers. Managers coordinate teams of specialized agents, enabling complex workflows with clear delegation and responsibility chains. This pattern is ideal for organizational structures and complex task decomposition. + diff --git a/examples/multi_agent/hscf/README.md b/examples/multi_agent/hscf/README.md new file mode 100644 index 00000000..2c64a853 --- /dev/null +++ b/examples/multi_agent/hscf/README.md @@ -0,0 +1,12 @@ +# Hierarchical Swarm Control Framework (HSCF) Examples + +This directory contains examples demonstrating the Hierarchical Swarm Control Framework. + +## Examples + +- [single_file_hierarchical_framework_example.py](single_file_hierarchical_framework_example.py) - Complete hierarchical framework example in a single file + +## Overview + +The Hierarchical Swarm Control Framework (HSCF) provides a structured approach to building hierarchical multi-agent systems with clear control flows, delegation patterns, and coordination mechanisms. + diff --git a/examples/multi_agent/interactive_groupchat_examples/README.md b/examples/multi_agent/interactive_groupchat_examples/README.md new file mode 100644 index 00000000..72406c59 --- /dev/null +++ b/examples/multi_agent/interactive_groupchat_examples/README.md @@ -0,0 +1,16 @@ +# Interactive Group Chat Examples + +This directory contains examples demonstrating interactive group chat patterns with advanced features. + +## Examples + +- [enhanced_collaboration_example.py](enhanced_collaboration_example.py) - Enhanced collaboration patterns +- [interactive_groupchat_speaker_example.py](interactive_groupchat_speaker_example.py) - Speaker management +- [medical_panel_example.py](medical_panel_example.py) - Medical panel discussion +- [speaker_function_examples.py](speaker_function_examples.py) - Speaker function examples +- [stream_example.py](stream_example.py) - Streaming example + +## Overview + +Interactive group chat examples extend basic group chat patterns with advanced features like speaker management, role-based participation, streaming responses, and domain-specific panel discussions. These examples demonstrate sophisticated conversation management and real-time interaction patterns. + diff --git a/examples/multi_agent/majority_voting/README.md b/examples/multi_agent/majority_voting/README.md new file mode 100644 index 00000000..41af991a --- /dev/null +++ b/examples/multi_agent/majority_voting/README.md @@ -0,0 +1,14 @@ +# Majority Voting Examples + +This directory contains examples demonstrating majority voting patterns for multi-agent decision-making. + +## Examples + +- [majority_voting_example_new.py](majority_voting_example_new.py) - Updated voting example +- [majority_voting_example.py](majority_voting_example.py) - Basic voting example +- [snake_game_code_voting.py](snake_game_code_voting.py) - Game code voting example + +## Overview + +Majority voting patterns enable groups of agents to make decisions through democratic voting processes. Agents vote on proposals, and the majority decision is implemented. This pattern is useful for consensus-building, code review, and collaborative decision-making scenarios. + diff --git a/examples/multi_agent/mar/README.md b/examples/multi_agent/mar/README.md new file mode 100644 index 00000000..499fabf8 --- /dev/null +++ b/examples/multi_agent/mar/README.md @@ -0,0 +1,14 @@ +# MAR (Multi-Agent Router) Examples + +This directory contains examples demonstrating Multi-Agent Router patterns for intelligent agent selection and routing. + +## Examples + +- [model_router_example.py](model_router_example.py) - Model routing example +- [multi_agent_router_example.py](multi_agent_router_example.py) - Multi-agent router implementation +- [multi_agent_router_minimal.py](multi_agent_router_minimal.py) - Minimal router setup + +## Overview + +Multi-Agent Router (MAR) patterns enable intelligent routing of tasks to appropriate agents based on capabilities, availability, or task characteristics. These examples demonstrate various routing strategies including model-based routing, capability matching, and load balancing. + diff --git a/examples/multi_agent/moa_examples/README.md b/examples/multi_agent/moa_examples/README.md new file mode 100644 index 00000000..ecec90d0 --- /dev/null +++ b/examples/multi_agent/moa_examples/README.md @@ -0,0 +1,13 @@ +# MOA (Mixture of Agents) Examples + +This directory contains examples demonstrating Mixture of Agents patterns. + +## Examples + +- [mixture_of_agents_example.py](mixture_of_agents_example.py) - Mixture of agents implementation +- [test_moa_new.py](test_moa_new.py) - MOA testing suite + +## Overview + +Mixture of Agents (MOA) patterns combine multiple agents with different capabilities or models to create more robust and capable systems. By leveraging the strengths of different agents, MOA patterns can achieve better performance than individual agents alone. + diff --git a/examples/multi_agent/orchestration_examples/README.md b/examples/multi_agent/orchestration_examples/README.md new file mode 100644 index 00000000..dd395e59 --- /dev/null +++ b/examples/multi_agent/orchestration_examples/README.md @@ -0,0 +1,22 @@ +# Orchestration Examples + +This directory contains examples demonstrating workflow orchestration patterns for complex multi-agent scenarios. + +## Examples + +- [ai_ethics_debate.py](ai_ethics_debate.py) - AI ethics debate orchestration +- [cybersecurity_incident_negotiation.py](cybersecurity_incident_negotiation.py) - Cybersecurity incident response +- [healthcare_panel_discussion.py](healthcare_panel_discussion.py) - Healthcare panel discussion +- [insurance_claim_review.py](insurance_claim_review.py) - Insurance claim review workflow +- [investment_council_meeting.py](investment_council_meeting.py) - Investment council meeting +- [medical_malpractice_trial.py](medical_malpractice_trial.py) - Medical malpractice trial simulation +- [merger_mediation_session.py](merger_mediation_session.py) - Merger mediation workflow +- [nvidia_amd_executive_negotiation.py](nvidia_amd_executive_negotiation.py) - Executive negotiation simulation +- [pharma_research_brainstorm.py](pharma_research_brainstorm.py) - Pharmaceutical research brainstorming +- [philosophy_discussion_example.py](philosophy_discussion_example.py) - Philosophy discussion orchestration +- [startup_mentorship_program.py](startup_mentorship_program.py) - Startup mentorship workflow + +## Overview + +Orchestration examples demonstrate complex, domain-specific workflows that coordinate multiple agents in realistic scenarios. These examples showcase how to structure multi-agent interactions for specific use cases including debates, negotiations, reviews, and collaborative sessions. + diff --git a/examples/multi_agent/paper_implementations/README.md b/examples/multi_agent/paper_implementations/README.md new file mode 100644 index 00000000..5c508a17 --- /dev/null +++ b/examples/multi_agent/paper_implementations/README.md @@ -0,0 +1,12 @@ +# Paper Implementations + +This directory contains implementations of academic papers and research concepts in multi-agent systems. + +## Examples + +- [long_agent.py](long_agent.py) - Long context agent implementation + +## Overview + +This directory contains implementations of concepts from academic papers and research publications, demonstrating how theoretical multi-agent concepts can be realized in practice using the Swarms framework. + diff --git a/examples/multi_agent/sequential_workflow/README.md b/examples/multi_agent/sequential_workflow/README.md new file mode 100644 index 00000000..f63b9a6f --- /dev/null +++ b/examples/multi_agent/sequential_workflow/README.md @@ -0,0 +1,17 @@ +# Sequential Workflow Examples + +This directory contains examples demonstrating sequential workflow patterns for multi-agent systems. + +## Examples + +- [concurrent_workflow.py](concurrent_workflow.py) - Concurrent workflow patterns +- [sequential_wofkflow.py](sequential_wofkflow.py) - Sequential workflow (typo in filename) +- [sequential_worflow_test.py](sequential_worflow_test.py) - Sequential workflow testing +- [sequential_workflow_example.py](sequential_workflow_example.py) - Complete sequential workflow example +- [sequential_workflow.py](sequential_workflow.py) - Core sequential workflow implementation +- [sonnet_4_5_sequential.py](sonnet_4_5_sequential.py) - Sequential workflow with Sonnet 4.5 + +## Overview + +Sequential workflows execute agents in a specific order, where each agent's output becomes the next agent's input. This pattern is useful for pipelines, multi-stage processing, and workflows with clear dependencies between steps. + diff --git a/examples/multi_agent/social_algorithms_examples/README.md b/examples/multi_agent/social_algorithms_examples/README.md new file mode 100644 index 00000000..6d764ef3 --- /dev/null +++ b/examples/multi_agent/social_algorithms_examples/README.md @@ -0,0 +1,23 @@ +# Social Algorithms Examples + +This directory contains examples demonstrating social algorithm patterns for multi-agent systems. + +## Examples + +- [adaptive_workflow_algorithm_example.py](adaptive_workflow_algorithm_example.py) - Adaptive workflow algorithms +- [auction_market_algorithm_example.py](auction_market_algorithm_example.py) - Auction market algorithms +- [collaborative_brainstorming_example.py](collaborative_brainstorming_example.py) - Collaborative brainstorming +- [competitive_evaluation_example.py](competitive_evaluation_example.py) - Competitive evaluation patterns +- [consensus_building_algorithm_example.py](consensus_building_algorithm_example.py) - Consensus building algorithms +- [hierarchical_decision_making_example.py](hierarchical_decision_making_example.py) - Hierarchical decision making +- [iterative_refinement_algorithm_example.py](iterative_refinement_algorithm_example.py) - Iterative refinement algorithms +- [multi_stage_pipeline_algorithm_example.py](multi_stage_pipeline_algorithm_example.py) - Multi-stage pipeline algorithms +- [negotiation_algorithm_example.py](negotiation_algorithm_example.py) - Negotiation algorithms +- [peer_review_example.py](peer_review_example.py) - Peer review patterns +- [research_analysis_synthesis_example.py](research_analysis_synthesis_example.py) - Research analysis and synthesis +- [swarm_intelligence_algorithm_example.py](swarm_intelligence_algorithm_example.py) - Swarm intelligence algorithms + +## Overview + +Social algorithms implement patterns inspired by human social interactions, including negotiation, consensus-building, peer review, and collaborative problem-solving. These examples demonstrate how multi-agent systems can leverage social dynamics for improved coordination and decision-making. + diff --git a/examples/multi_agent/swarm_router/README.md b/examples/multi_agent/swarm_router/README.md new file mode 100644 index 00000000..c6f04986 --- /dev/null +++ b/examples/multi_agent/swarm_router/README.md @@ -0,0 +1,18 @@ +# Swarm Router Examples + +This directory contains examples demonstrating swarm routing patterns for directing tasks across multiple agent swarms. + +## Examples + +- [heavy_swarm_router_example.py](heavy_swarm_router_example.py) - Router for heavy swarms +- [market_analysis_swarm_router_concurrent.py](market_analysis_swarm_router_concurrent.py) - Concurrent market analysis router +- [sr_moa_example.py](sr_moa_example.py) - Swarm router with MOA +- [swarm_router_benchmark.py](swarm_router_benchmark.py) - Router performance benchmarking +- [swarm_router_example.py](swarm_router_example.py) - Basic swarm router example +- [swarm_router_test.py](swarm_router_test.py) - Router testing suite +- [swarm_router.py](swarm_router.py) - Core swarm router implementation + +## Overview + +Swarm routers intelligently distribute tasks across multiple agent swarms based on task characteristics, swarm capabilities, and current load. These examples demonstrate various routing strategies including load balancing, capability matching, and performance optimization. + diff --git a/examples/multi_agent/swarmarrange/README.md b/examples/multi_agent/swarmarrange/README.md new file mode 100644 index 00000000..a3864ada --- /dev/null +++ b/examples/multi_agent/swarmarrange/README.md @@ -0,0 +1,13 @@ +# Swarm Arrange Examples + +This directory contains examples demonstrating swarm arrangement utilities for organizing and configuring agent swarms. + +## Examples + +- [swarm_arange_demo.py](swarm_arange_demo.py) - Swarm arrangement demonstration +- [swarm_arange_demo 2.py](swarm_arange_demo 2.py) - Alternative swarm arrangement demo + +## Overview + +Swarm arrange utilities help organize and configure agent swarms, managing agent relationships, communication patterns, and workflow structures. These examples demonstrate how to set up and arrange agents for optimal collaboration. + diff --git a/examples/multi_agent/swarms_api_examples/README.md b/examples/multi_agent/swarms_api_examples/README.md new file mode 100644 index 00000000..82839888 --- /dev/null +++ b/examples/multi_agent/swarms_api_examples/README.md @@ -0,0 +1,14 @@ +# Swarms API Examples + +This directory contains examples demonstrating Swarms API integration in multi-agent systems. + +## Examples + +- [hedge_fund_swarm.py](hedge_fund_swarm.py) - Hedge fund swarm using API +- [swarms_api_client.py](swarms_api_client.py) - API client implementation +- Additional API integration examples + +## Overview + +These examples demonstrate how to integrate the Swarms API into multi-agent systems, enabling cloud-based agent execution, API-based agent management, and distributed agent coordination. + diff --git a/examples/multi_agent/utils/README.md b/examples/multi_agent/utils/README.md new file mode 100644 index 00000000..93ad0e4a --- /dev/null +++ b/examples/multi_agent/utils/README.md @@ -0,0 +1,13 @@ +# Multi-Agent Utils + +This directory contains utility functions and helpers for multi-agent systems. + +## Examples + +- [test_agent_concurrent.py](test_agent_concurrent.py) - Concurrent agent testing +- Additional utility functions for multi-agent operations + +## Overview + +This directory contains utility functions, helpers, and testing utilities specifically designed for multi-agent systems, including concurrent execution helpers, agent coordination utilities, and common patterns. + diff --git a/examples/single_agent/demos/README.md b/examples/single_agent/demos/README.md new file mode 100644 index 00000000..673dc421 --- /dev/null +++ b/examples/single_agent/demos/README.md @@ -0,0 +1,13 @@ +# Single Agent Demos + +This directory contains demonstration examples of single agent implementations for specific use cases. + +## Examples + +- [insurance_agent.py](insurance_agent.py) - Insurance processing agent +- [persistent_legal_agent.py](persistent_legal_agent.py) - Legal document processing agent with persistence + +## Overview + +These demos showcase single agent implementations for domain-specific tasks, demonstrating how to configure and use agents for real-world applications in insurance and legal domains. + diff --git a/examples/single_agent/external_agents/README.md b/examples/single_agent/external_agents/README.md new file mode 100644 index 00000000..ec78239f --- /dev/null +++ b/examples/single_agent/external_agents/README.md @@ -0,0 +1,13 @@ +# External Agents Examples + +This directory contains examples demonstrating integration with external agent systems and APIs. + +## Examples + +- [custom_agent_example.py](custom_agent_example.py) - Custom agent implementation +- [openai_assistant_wrapper.py](openai_assistant_wrapper.py) - OpenAI Assistant integration wrapper + +## Overview + +External agents examples demonstrate how to integrate Swarms agents with external agent systems, APIs, and services. These examples show how to wrap external agents, create custom agent implementations, and bridge between different agent frameworks. + diff --git a/examples/single_agent/llms/README.md b/examples/single_agent/llms/README.md new file mode 100644 index 00000000..bc407fb3 --- /dev/null +++ b/examples/single_agent/llms/README.md @@ -0,0 +1,36 @@ +# LLM Integration Examples + +This directory contains examples demonstrating integration with various Large Language Model providers. + +## Examples + +### Azure OpenAI +- [azure_agent_api_verison.py](azure_agent_api_verison.py) - Azure API version handling +- [azure_agent.py](azure_agent.py) - Azure OpenAI integration +- [azure_model_support.py](azure_model_support.py) - Azure model support + +### Claude +- [claude_4_example.py](claude_examples/claude_4_example.py) - Claude 4 integration +- [claude_4.py](claude_examples/claude_4.py) - Claude 4 implementation +- [swarms_claude_example.py](claude_examples/swarms_claude_example.py) - Swarms Claude integration + +### DeepSeek +- [deepseek_r1.py](deepseek_examples/deepseek_r1.py) - DeepSeek R1 model +- [fast_r1_groq.py](deepseek_examples/fast_r1_groq.py) - Fast R1 with Groq +- [grok_deepseek_agent.py](deepseek_examples/grok_deepseek_agent.py) - Grok DeepSeek integration + +### Mistral +- [mistral_example.py](mistral_example.py) - Mistral model integration + +### OpenAI +- [4o_mini_demo.py](openai_examples/4o_mini_demo.py) - GPT-4o Mini demonstration +- [reasoning_duo_batched.py](openai_examples/reasoning_duo_batched.py) - Batched reasoning with OpenAI +- [test_async_litellm.py](openai_examples/test_async_litellm.py) - Async LiteLLM testing + +### Qwen +- [qwen_3_base.py](qwen_3_base.py) - Qwen 3 base model + +## Overview + +These examples demonstrate how to integrate Swarms agents with various LLM providers including OpenAI, Anthropic Claude, Azure OpenAI, Mistral, DeepSeek, and Qwen. Each example shows provider-specific configurations, API handling, and best practices. + diff --git a/examples/single_agent/onboard/README.md b/examples/single_agent/onboard/README.md new file mode 100644 index 00000000..6defaa58 --- /dev/null +++ b/examples/single_agent/onboard/README.md @@ -0,0 +1,13 @@ +# Onboarding Examples + +This directory contains examples demonstrating agent onboarding and configuration. + +## Examples + +- [agents.yaml](agents.yaml) - Agent configuration file +- [onboard-basic.py](onboard-basic.py) - Basic onboarding example + +## Overview + +Onboarding examples demonstrate how to configure and set up agents using YAML configuration files and programmatic setup. These examples show best practices for agent initialization, configuration management, and deployment preparation. + diff --git a/examples/single_agent/reasoning_agent_examples/README.md b/examples/single_agent/reasoning_agent_examples/README.md new file mode 100644 index 00000000..d019b31f --- /dev/null +++ b/examples/single_agent/reasoning_agent_examples/README.md @@ -0,0 +1,23 @@ +# Reasoning Agent Examples + +This directory contains examples demonstrating advanced reasoning capabilities for single agents. + +## Examples + +- [agent_judge_evaluation_criteria_example.py](agent_judge_evaluation_criteria_example.py) - Evaluation criteria for agent judging +- [agent_judge_example.py](agent_judge_example.py) - Agent judging system +- [consistency_agent.py](consistency_agent.py) - Consistency checking agent +- [consistency_example.py](consistency_example.py) - Consistency example +- [gpk_agent.py](gpk_agent.py) - GPK reasoning agent +- [iterative_agent.py](iterative_agent.py) - Iterative reasoning agent +- [malt_example.py](malt_example.py) - MALT reasoning example +- [reasoning_agent_router_now.py](reasoning_agent_router_now.py) - Current reasoning router +- [reasoning_agent_router.py](reasoning_agent_router.py) - Reasoning agent router +- [reasoning_duo_example.py](reasoning_duo_example.py) - Two-agent reasoning +- [reasoning_duo_test.py](reasoning_duo_test.py) - Reasoning duo testing +- [reasoning_duo.py](reasoning_duo.py) - Reasoning duo implementation + +## Overview + +Reasoning agent examples demonstrate advanced reasoning patterns including iterative reasoning, consistency checking, agent judging systems, and multi-agent reasoning collaboration. These examples showcase how to implement sophisticated reasoning capabilities beyond simple prompt-response patterns. + diff --git a/examples/single_agent/tools/README.md b/examples/single_agent/tools/README.md new file mode 100644 index 00000000..a6f6f205 --- /dev/null +++ b/examples/single_agent/tools/README.md @@ -0,0 +1,39 @@ +# Tools Integration Examples + +This directory contains examples demonstrating tool integration for single agents. + +## Examples + +- [exa_search_agent.py](exa_search_agent.py) - Exa search integration +- [example_async_vs_multithread.py](example_async_vs_multithread.py) - Async vs multithreading comparison +- [litellm_tool_example.py](litellm_tool_example.py) - LiteLLM tool integration +- [multi_tool_usage_agent.py](multi_tool_usage_agent.py) - Multi-tool agent +- [new_tools_examples.py](new_tools_examples.py) - Latest tool examples +- [omni_modal_agent.py](omni_modal_agent.py) - Omni-modal agent +- [swarms_of_browser_agents.py](swarms_of_browser_agents.py) - Browser automation swarms +- [swarms_tools_example.py](swarms_tools_example.py) - Swarms tools integration +- [together_deepseek_agent.py](together_deepseek_agent.py) - Together AI DeepSeek integration + +## Subdirectories + +### Solana Tools +- [solana_tool/](solana_tool/) - Solana blockchain integration + - [solana_tool.py](solana_tool/solana_tool.py) - Solana tool implementation + - [solana_tool_test.py](solana_tool/solana_tool_test.py) - Solana tool testing + +### Structured Outputs +- [structured_outputs/](structured_outputs/) - Structured output examples + - [example_meaning_of_life_agents.py](structured_outputs/example_meaning_of_life_agents.py) - Meaning of life example + - [structured_outputs_example.py](structured_outputs/structured_outputs_example.py) - Structured output examples + +### Tools Examples +- [tools_examples/](tools_examples/) - Additional tool usage examples + - [dex_screener.py](tools_examples/dex_screener.py) - DEX screener tool + - [financial_news_agent.py](tools_examples/financial_news_agent.py) - Financial news agent + - [simple_tool_example.py](tools_examples/simple_tool_example.py) - Simple tool usage + - [swarms_tool_example_simple.py](tools_examples/swarms_tool_example_simple.py) - Simple Swarms tool + +## Overview + +Tools integration examples demonstrate how to equip agents with various tools including search engines, browser automation, blockchain interactions, and structured output generation. These examples show best practices for tool definition, usage, and error handling. + diff --git a/examples/single_agent/utils/README.md b/examples/single_agent/utils/README.md new file mode 100644 index 00000000..698389b6 --- /dev/null +++ b/examples/single_agent/utils/README.md @@ -0,0 +1,28 @@ +# Single Agent Utils + +This directory contains utility functions and helpers for single agent operations. + +## Examples + +- [async_agent.py](async_agent.py) - Async agent implementation +- [custom_agent_base_url.py](custom_agent_base_url.py) - Custom base URL configuration +- [dynamic_context_window.py](dynamic_context_window.py) - Dynamic context window management +- [fallback_test.py](fallback_test.py) - Fallback mechanism testing +- [grok_4_agent.py](grok_4_agent.py) - Grok 4 agent implementation +- [handoffs_example.py](handoffs_example.py) - Agent handoff examples +- [list_agent_output_types.py](list_agent_output_types.py) - Output type listing +- [markdown_agent.py](markdown_agent.py) - Markdown processing agent +- [medical_agent_add_to_marketplace.py](medical_agent_add_to_marketplace.py) - Marketplace integration example +- [xml_output_example.py](xml_output_example.py) - XML output example + +## Subdirectories + +### Transform Prompts +- [transform_prompts/](transform_prompts/) - Prompt transformation utilities + - [transforms_agent_example.py](transform_prompts/transforms_agent_example.py) - Prompt transformation agent + - [transforms_examples.py](transform_prompts/transforms_examples.py) - Prompt transformation examples + +## Overview + +This directory contains utility functions, helpers, and common patterns for single agent operations including async handling, context management, output formatting, and prompt transformations. + diff --git a/examples/single_agent/vision/README.md b/examples/single_agent/vision/README.md new file mode 100644 index 00000000..a2e38a67 --- /dev/null +++ b/examples/single_agent/vision/README.md @@ -0,0 +1,17 @@ +# Vision Examples + +This directory contains examples demonstrating vision and multimodal capabilities for single agents. + +## Examples + +- [anthropic_vision_test.py](anthropic_vision_test.py) - Anthropic vision testing +- [image_batch_example.py](image_batch_example.py) - Batch image processing +- [multimodal_example.py](multimodal_example.py) - Multimodal agent example +- [multiple_image_processing.py](multiple_image_processing.py) - Multiple image processing +- [vision_test.py](vision_test.py) - Vision testing +- [vision_tools.py](vision_tools.py) - Vision tools integration + +## Overview + +Vision examples demonstrate how to integrate image processing and multimodal capabilities into agents. These examples show how to process images, handle batch image operations, and combine vision with text processing for multimodal understanding. + diff --git a/examples/tools/base_tool_examples/README.md b/examples/tools/base_tool_examples/README.md new file mode 100644 index 00000000..9fa99909 --- /dev/null +++ b/examples/tools/base_tool_examples/README.md @@ -0,0 +1,22 @@ +# Base Tool Examples + +This directory contains examples demonstrating base tool functionality and tool creation patterns. + +## Examples + +- [base_tool_examples.py](base_tool_examples.py) - Core base tool functionality +- [conver_funcs_to_schema.py](conver_funcs_to_schema.py) - Function to schema conversion +- [convert_basemodels.py](convert_basemodels.py) - BaseModel conversion utilities +- [exa_search_test.py](exa_search_test.py) - Exa search testing +- [example_usage.py](example_usage.py) - Basic usage examples +- [schema_validation_example.py](schema_validation_example.py) - Schema validation +- [test_anthropic_specific.py](test_anthropic_specific.py) - Anthropic-specific testing +- [test_base_tool_comprehensive_fixed.py](test_base_tool_comprehensive_fixed.py) - Comprehensive testing (fixed) +- [test_base_tool_comprehensive.py](test_base_tool_comprehensive.py) - Comprehensive testing +- [test_function_calls_anthropic.py](test_function_calls_anthropic.py) - Anthropic function calls +- [test_function_calls.py](test_function_calls.py) - Function call testing + +## Overview + +Base tool examples demonstrate the fundamental patterns for creating and using tools in Swarms. These examples cover tool schema definition, function-to-schema conversion, validation, and provider-specific implementations. Essential for understanding how to build custom tools for agents. + diff --git a/examples/tools/multii_tool_use/README.md b/examples/tools/multii_tool_use/README.md new file mode 100644 index 00000000..c385f123 --- /dev/null +++ b/examples/tools/multii_tool_use/README.md @@ -0,0 +1,13 @@ +# Multi-Tool Usage Examples + +This directory contains examples demonstrating multi-tool usage patterns for agents. + +## Examples + +- [many_tool_use_demo.py](many_tool_use_demo.py) - Multiple tool usage demonstration +- [multi_tool_anthropic.py](multi_tool_anthropic.py) - Multi-tool with Anthropic + +## Overview + +Multi-tool usage examples demonstrate how agents can use multiple tools in sequence or parallel to accomplish complex tasks. These examples show tool orchestration, tool chaining, and handling multiple tool calls efficiently. + diff --git a/examples/utils/agent_loader/README.md b/examples/utils/agent_loader/README.md new file mode 100644 index 00000000..805b37c6 --- /dev/null +++ b/examples/utils/agent_loader/README.md @@ -0,0 +1,15 @@ +# Agent Loader Examples + +This directory contains examples demonstrating agent loading and configuration utilities. + +## Examples + +- [agent_loader_demo.py](agent_loader_demo.py) - Agent loader demonstration +- [claude_code_compatible.py](claude_code_compatible.py) - Claude code compatibility +- [finance_advisor.md](finance_advisor.md) - Finance advisor documentation +- [multi_agents_loader_demo.py](multi_agents_loader_demo.py) - Multi-agent loader demonstration + +## Overview + +Agent loader examples demonstrate utilities for loading, configuring, and initializing agents from various sources including files, configurations, and code. These examples show how to programmatically create and configure agents for different use cases. + diff --git a/examples/utils/communication_examples/README.md b/examples/utils/communication_examples/README.md new file mode 100644 index 00000000..5518a6de --- /dev/null +++ b/examples/utils/communication_examples/README.md @@ -0,0 +1,15 @@ +# Communication Examples + +This directory contains examples demonstrating various communication backends for agent conversations. + +## Examples + +- [duckdb_agent.py](duckdb_agent.py) - DuckDB-backed conversation storage +- [pulsar_conversation.py](pulsar_conversation.py) - Apache Pulsar messaging integration +- [redis_conversation.py](redis_conversation.py) - Redis-backed conversation storage +- [sqlite_conversation.py](sqlite_conversation.py) - SQLite conversation storage + +## Overview + +Communication examples demonstrate different backend storage and messaging systems for managing agent conversations. These examples show how to persist conversations, enable distributed communication, and manage conversation state across different storage backends. + diff --git a/examples/utils/misc/README.md b/examples/utils/misc/README.md new file mode 100644 index 00000000..c1ebe642 --- /dev/null +++ b/examples/utils/misc/README.md @@ -0,0 +1,26 @@ +# Miscellaneous Utils + +This directory contains miscellaneous utility examples and helper functions. + +## Examples + +- [agent_map_test.py](agent_map_test.py) - Agent map testing +- [conversation_simple.py](conversation_simple.py) - Simple conversation example +- [conversation_test_truncate.py](conversation_test_truncate.py) - Conversation truncation testing +- [conversation_test.py](conversation_test.py) - Conversation testing +- [csvagent_example.py](csvagent_example.py) - CSV agent example +- [dict_to_table.py](dict_to_table.py) - Dictionary to table conversion +- [swarm_matcher_example.py](swarm_matcher_example.py) - Swarm matcher example +- [test_load_conversation.py](test_load_conversation.py) - Conversation loading test +- [visualizer_test.py](visualizer_test.py) - Visualization testing + +## Subdirectories + +- [aop/](aop/) - AOP-related utilities + - [client.py](aop/client.py) - AOP client utility + - [test_aop.py](aop/test_aop.py) - AOP testing + +## Overview + +Miscellaneous utilities provide helper functions, testing utilities, and common patterns for various agent operations. These examples demonstrate conversation management, data conversion, visualization, and testing utilities. + diff --git a/examples/utils/telemetry/README.md b/examples/utils/telemetry/README.md new file mode 100644 index 00000000..2f4c3259 --- /dev/null +++ b/examples/utils/telemetry/README.md @@ -0,0 +1,13 @@ +# Telemetry Examples + +This directory contains examples demonstrating telemetry and monitoring capabilities for agents. + +## Examples + +- [class_method_example.py](class_method_example.py) - Class method telemetry example +- [example_decorator_usage.py](example_decorator_usage.py) - Decorator-based telemetry + +## Overview + +Telemetry examples demonstrate how to add monitoring, logging, and observability to agents. These examples show how to track agent performance, log operations, and monitor agent behavior using decorators and class methods. + diff --git a/test.py b/test.py deleted file mode 100644 index 4def8642..00000000 --- a/test.py +++ /dev/null @@ -1,13 +0,0 @@ -from swarms.utils.vllm_wrapper import VLLMWrapper - -# Initialize the vLLM wrapper -vllm = VLLMWrapper( - model_name="gpt-4o-mini", - system_prompt="You are a helpful assistant.", - temperature=0.7, - max_tokens=4000 -) - -# Run inference -response = vllm.run("What is the capital of France?") -print(response) \ No newline at end of file diff --git a/tests/structs/test_agent_loader.py b/tests/structs/test_agent_loader.py index d0678f7f..44ce757f 100644 --- a/tests/structs/test_agent_loader.py +++ b/tests/structs/test_agent_loader.py @@ -1,6 +1,5 @@ import os import tempfile -from pathlib import Path try: import pytest @@ -15,22 +14,31 @@ try: except (ImportError, ModuleNotFoundError) as e: import importlib.util + _current_dir = os.path.dirname(os.path.abspath(__file__)) - _agent_loader_path = os.path.join(_current_dir, "swarms", "structs", "agent_loader.py") - + _agent_loader_path = os.path.join( + _current_dir, "swarms", "structs", "agent_loader.py" + ) + if os.path.exists(_agent_loader_path): - spec = importlib.util.spec_from_file_location("agent_loader", _agent_loader_path) + spec = importlib.util.spec_from_file_location( + "agent_loader", _agent_loader_path + ) agent_loader_module = importlib.util.module_from_spec(spec) spec.loader.exec_module(agent_loader_module) AgentLoader = agent_loader_module.AgentLoader else: - raise ImportError(f"Could not find agent_loader.py at {_agent_loader_path}") from e + raise ImportError( + f"Could not find agent_loader.py at {_agent_loader_path}" + ) from e logger.remove() logger.add(lambda msg: None, level="ERROR") -def create_test_markdown_file(file_path: str, agent_name: str = "TestAgent") -> str: +def create_test_markdown_file( + file_path: str, agent_name: str = "TestAgent" +) -> str: """Create a test markdown file with agent definition.""" content = f"""--- name: {agent_name} @@ -94,15 +102,19 @@ def test_agent_loader_initialization(): loader = AgentLoader(concurrent=True) assert loader is not None, "AgentLoader should not be None" assert loader.concurrent is True, "concurrent should be True" - + loader2 = AgentLoader(concurrent=False) assert loader2 is not None, "AgentLoader should not be None" - assert loader2.concurrent is False, "concurrent should be False" - + assert ( + loader2.concurrent is False + ), "concurrent should be False" + logger.info("✓ AgentLoader initialization test passed") - + except Exception as e: - logger.error(f"Error in test_agent_loader_initialization: {str(e)}") + logger.error( + f"Error in test_agent_loader_initialization: {str(e)}" + ) raise @@ -112,19 +124,27 @@ def test_load_agent_from_markdown(): with tempfile.TemporaryDirectory() as tmpdir: md_file = os.path.join(tmpdir, "test_agent.md") create_test_markdown_file(md_file, "MarkdownTestAgent") - + loader = AgentLoader() agent = loader.load_agent_from_markdown(md_file) - + assert agent is not None, "Agent should not be None" - assert hasattr(agent, "agent_name"), "Agent should have agent_name attribute" - assert hasattr(agent, "run"), "Agent should have run method" - assert agent.agent_name == "MarkdownTestAgent", "Agent name should match" - + assert hasattr( + agent, "agent_name" + ), "Agent should have agent_name attribute" + assert hasattr( + agent, "run" + ), "Agent should have run method" + assert ( + agent.agent_name == "MarkdownTestAgent" + ), "Agent name should match" + logger.info("✓ Load agent from markdown test passed") - + except Exception as e: - logger.error(f"Error in test_load_agent_from_markdown: {str(e)}") + logger.error( + f"Error in test_load_agent_from_markdown: {str(e)}" + ) raise @@ -134,23 +154,37 @@ def test_load_agents_from_markdown_single_file(): with tempfile.TemporaryDirectory() as tmpdir: md_file = os.path.join(tmpdir, "test_agents.md") create_test_markdown_file(md_file, "MultiMarkdownAgent") - + loader = AgentLoader() - agents = loader.load_agents_from_markdown(md_file, concurrent=False) - - assert agents is not None, "Agents list should not be None" + agents = loader.load_agents_from_markdown( + md_file, concurrent=False + ) + + assert ( + agents is not None + ), "Agents list should not be None" assert isinstance(agents, list), "Agents should be a list" assert len(agents) > 0, "Should have at least one agent" - + for agent in agents: - assert agent is not None, "Each agent should not be None" - assert hasattr(agent, "agent_name"), "Agent should have agent_name" - assert hasattr(agent, "run"), "Agent should have run method" - - logger.info(f"✓ Load agents from markdown (single file) test passed: {len(agents)} agents loaded") - + assert ( + agent is not None + ), "Each agent should not be None" + assert hasattr( + agent, "agent_name" + ), "Agent should have agent_name" + assert hasattr( + agent, "run" + ), "Agent should have run method" + + logger.info( + f"✓ Load agents from markdown (single file) test passed: {len(agents)} agents loaded" + ) + except Exception as e: - logger.error(f"Error in test_load_agents_from_markdown_single_file: {str(e)}") + logger.error( + f"Error in test_load_agents_from_markdown_single_file: {str(e)}" + ) raise @@ -162,25 +196,34 @@ def test_load_agents_from_markdown_multiple_files(): md_file2 = os.path.join(tmpdir, "test_agent2.md") create_test_markdown_file(md_file1, "MultiFileAgent1") create_test_markdown_file(md_file2, "MultiFileAgent2") - + loader = AgentLoader() agents = loader.load_agents_from_markdown( - [md_file1, md_file2], - concurrent=True + [md_file1, md_file2], concurrent=True ) - - assert agents is not None, "Agents list should not be None" + + assert ( + agents is not None + ), "Agents list should not be None" assert isinstance(agents, list), "Agents should be a list" assert len(agents) > 0, "Should have at least one agent" - + for agent in agents: - assert agent is not None, "Each agent should not be None" - assert hasattr(agent, "agent_name"), "Agent should have agent_name" - - logger.info(f"✓ Load agents from multiple markdown files test passed: {len(agents)} agents loaded") - + assert ( + agent is not None + ), "Each agent should not be None" + assert hasattr( + agent, "agent_name" + ), "Agent should have agent_name" + + logger.info( + f"✓ Load agents from multiple markdown files test passed: {len(agents)} agents loaded" + ) + except Exception as e: - logger.error(f"Error in test_load_agents_from_markdown_multiple_files: {str(e)}") + logger.error( + f"Error in test_load_agents_from_markdown_multiple_files: {str(e)}" + ) raise @@ -190,27 +233,41 @@ def test_load_agents_from_yaml(): with tempfile.TemporaryDirectory() as tmpdir: yaml_file = os.path.join(tmpdir, "test_agents.yaml") create_test_yaml_file(yaml_file) - + loader = AgentLoader() try: - agents = loader.load_agents_from_yaml(yaml_file, return_type="auto") + agents = loader.load_agents_from_yaml( + yaml_file, return_type="auto" + ) except ValueError as e: if "Invalid return_type" in str(e): - logger.warning("YAML loader has known validation bug - skipping test") + logger.warning( + "YAML loader has known validation bug - skipping test" + ) return raise - - assert agents is not None, "Agents list should not be None" + + assert ( + agents is not None + ), "Agents list should not be None" assert isinstance(agents, list), "Agents should be a list" assert len(agents) > 0, "Should have at least one agent" - + for agent in agents: - assert agent is not None, "Each agent should not be None" - assert hasattr(agent, "agent_name"), "Agent should have agent_name" - assert hasattr(agent, "run"), "Agent should have run method" - - logger.info(f"✓ Load agents from YAML test passed: {len(agents)} agents loaded") - + assert ( + agent is not None + ), "Each agent should not be None" + assert hasattr( + agent, "agent_name" + ), "Agent should have agent_name" + assert hasattr( + agent, "run" + ), "Agent should have run method" + + logger.info( + f"✓ Load agents from YAML test passed: {len(agents)} agents loaded" + ) + except Exception as e: logger.error(f"Error in test_load_agents_from_yaml: {str(e)}") raise @@ -224,33 +281,51 @@ def test_load_many_agents_from_yaml(): yaml_file2 = os.path.join(tmpdir, "test_agents2.yaml") create_test_yaml_file(yaml_file1) create_test_yaml_file(yaml_file2) - + loader = AgentLoader() try: agents_lists = loader.load_many_agents_from_yaml( [yaml_file1, yaml_file2], - return_types=["auto", "auto"] + return_types=["auto", "auto"], ) except ValueError as e: if "Invalid return_type" in str(e): - logger.warning("YAML loader has known validation bug - skipping test") + logger.warning( + "YAML loader has known validation bug - skipping test" + ) return raise - - assert agents_lists is not None, "Agents lists should not be None" - assert isinstance(agents_lists, list), "Should be a list of lists" - assert len(agents_lists) > 0, "Should have at least one list" - + + assert ( + agents_lists is not None + ), "Agents lists should not be None" + assert isinstance( + agents_lists, list + ), "Should be a list of lists" + assert ( + len(agents_lists) > 0 + ), "Should have at least one list" + for agents_list in agents_lists: - assert agents_list is not None, "Each agents list should not be None" - assert isinstance(agents_list, list), "Each should be a list" + assert ( + agents_list is not None + ), "Each agents list should not be None" + assert isinstance( + agents_list, list + ), "Each should be a list" for agent in agents_list: - assert agent is not None, "Each agent should not be None" - - logger.info(f"✓ Load many agents from YAML test passed: {len(agents_lists)} file(s) processed") - + assert ( + agent is not None + ), "Each agent should not be None" + + logger.info( + f"✓ Load many agents from YAML test passed: {len(agents_lists)} file(s) processed" + ) + except Exception as e: - logger.error(f"Error in test_load_many_agents_from_yaml: {str(e)}") + logger.error( + f"Error in test_load_many_agents_from_yaml: {str(e)}" + ) raise @@ -260,25 +335,37 @@ def test_load_agents_from_csv(): with tempfile.TemporaryDirectory() as tmpdir: csv_file = os.path.join(tmpdir, "test_agents.csv") create_test_csv_file(csv_file) - + loader = AgentLoader() agents = loader.load_agents_from_csv(csv_file) - - assert agents is not None, "Agents list should not be None" + + assert ( + agents is not None + ), "Agents list should not be None" assert isinstance(agents, list), "Agents should be a list" if len(agents) == 0: - logger.warning("CSV loader returned 0 agents - this may be due to model validation issues") + logger.warning( + "CSV loader returned 0 agents - this may be due to model validation issues" + ) return - + assert len(agents) > 0, "Should have at least one agent" - + for agent in agents: - assert agent is not None, "Each agent should not be None" - assert hasattr(agent, "agent_name"), "Agent should have agent_name" - assert hasattr(agent, "run"), "Agent should have run method" - - logger.info(f"✓ Load agents from CSV test passed: {len(agents)} agents loaded") - + assert ( + agent is not None + ), "Each agent should not be None" + assert hasattr( + agent, "agent_name" + ), "Agent should have agent_name" + assert hasattr( + agent, "run" + ), "Agent should have run method" + + logger.info( + f"✓ Load agents from CSV test passed: {len(agents)} agents loaded" + ) + except Exception as e: logger.error(f"Error in test_load_agents_from_csv: {str(e)}") logger.warning("CSV test skipped due to validation issues") @@ -290,19 +377,23 @@ def test_auto_detect_markdown(): with tempfile.TemporaryDirectory() as tmpdir: md_file = os.path.join(tmpdir, "test_agent.md") create_test_markdown_file(md_file, "AutoDetectAgent") - + loader = AgentLoader() agents = loader.auto(md_file) - - assert agents is not None, "Agents list should not be None" + + assert ( + agents is not None + ), "Agents list should not be None" assert isinstance(agents, list), "Agents should be a list" assert len(agents) > 0, "Should have at least one agent" - + for agent in agents: - assert agent is not None, "Each agent should not be None" - + assert ( + agent is not None + ), "Each agent should not be None" + logger.info("✓ Auto-detect markdown test passed") - + except Exception as e: logger.error(f"Error in test_auto_detect_markdown: {str(e)}") raise @@ -314,25 +405,31 @@ def test_auto_detect_yaml(): with tempfile.TemporaryDirectory() as tmpdir: yaml_file = os.path.join(tmpdir, "test_agents.yaml") create_test_yaml_file(yaml_file) - + loader = AgentLoader() try: agents = loader.auto(yaml_file, return_type="auto") except ValueError as e: if "Invalid return_type" in str(e): - logger.warning("YAML auto-detect has known validation bug - skipping test") + logger.warning( + "YAML auto-detect has known validation bug - skipping test" + ) return raise - - assert agents is not None, "Agents list should not be None" + + assert ( + agents is not None + ), "Agents list should not be None" assert isinstance(agents, list), "Agents should be a list" assert len(agents) > 0, "Should have at least one agent" - + for agent in agents: - assert agent is not None, "Each agent should not be None" - + assert ( + agent is not None + ), "Each agent should not be None" + logger.info("✓ Auto-detect YAML test passed") - + except Exception as e: logger.error(f"Error in test_auto_detect_yaml: {str(e)}") raise @@ -344,22 +441,28 @@ def test_auto_detect_csv(): with tempfile.TemporaryDirectory() as tmpdir: csv_file = os.path.join(tmpdir, "test_agents.csv") create_test_csv_file(csv_file) - + loader = AgentLoader() agents = loader.auto(csv_file) - - assert agents is not None, "Agents list should not be None" + + assert ( + agents is not None + ), "Agents list should not be None" assert isinstance(agents, list), "Agents should be a list" if len(agents) == 0: - logger.warning("CSV auto-detect returned 0 agents - skipping test due to validation issues") + logger.warning( + "CSV auto-detect returned 0 agents - skipping test due to validation issues" + ) return assert len(agents) > 0, "Should have at least one agent" - + for agent in agents: - assert agent is not None, "Each agent should not be None" - + assert ( + agent is not None + ), "Each agent should not be None" + logger.info("✓ Auto-detect CSV test passed") - + except Exception as e: logger.error(f"Error in test_auto_detect_csv: {str(e)}") raise @@ -369,19 +472,27 @@ def test_auto_unsupported_file_type(): """Test auto-detection with unsupported file type.""" try: loader = AgentLoader() - + try: loader.auto("test_agents.txt") - assert False, "Should have raised ValueError for unsupported file type" + assert ( + False + ), "Should have raised ValueError for unsupported file type" except ValueError as e: - assert "Unsupported file type" in str(e), "Error message should mention unsupported file type" - logger.info("✓ Auto-detect unsupported file type test passed (error handled correctly)") + assert "Unsupported file type" in str( + e + ), "Error message should mention unsupported file type" + logger.info( + "✓ Auto-detect unsupported file type test passed (error handled correctly)" + ) except Exception as e: logger.error(f"Unexpected error type: {type(e).__name__}") raise - + except Exception as e: - logger.error(f"Error in test_auto_unsupported_file_type: {str(e)}") + logger.error( + f"Error in test_auto_unsupported_file_type: {str(e)}" + ) raise @@ -391,15 +502,15 @@ def test_load_single_agent(): with tempfile.TemporaryDirectory() as tmpdir: md_file = os.path.join(tmpdir, "test_agent.md") create_test_markdown_file(md_file, "SingleLoadAgent") - + loader = AgentLoader() agents = loader.load_single_agent(md_file) - + assert agents is not None, "Agents should not be None" assert isinstance(agents, list), "Should return a list" - + logger.info("✓ Load single agent test passed") - + except Exception as e: logger.error(f"Error in test_load_single_agent: {str(e)}") raise @@ -413,19 +524,29 @@ def test_load_multiple_agents(): md_file2 = os.path.join(tmpdir, "test_agent2.md") create_test_markdown_file(md_file1, "MultiLoadAgent1") create_test_markdown_file(md_file2, "MultiLoadAgent2") - + loader = AgentLoader() - agents_lists = loader.load_multiple_agents([md_file1, md_file2]) - - assert agents_lists is not None, "Agents lists should not be None" + agents_lists = loader.load_multiple_agents( + [md_file1, md_file2] + ) + + assert ( + agents_lists is not None + ), "Agents lists should not be None" assert isinstance(agents_lists, list), "Should be a list" - assert len(agents_lists) > 0, "Should have at least one list" - + assert ( + len(agents_lists) > 0 + ), "Should have at least one list" + for agents_list in agents_lists: - assert agents_list is not None, "Each agents list should not be None" - - logger.info(f"✓ Load multiple agents test passed: {len(agents_lists)} file(s) processed") - + assert ( + agents_list is not None + ), "Each agents list should not be None" + + logger.info( + f"✓ Load multiple agents test passed: {len(agents_lists)} file(s) processed" + ) + except Exception as e: logger.error(f"Error in test_load_multiple_agents: {str(e)}") raise @@ -437,17 +558,27 @@ def test_parse_markdown_file(): with tempfile.TemporaryDirectory() as tmpdir: md_file = os.path.join(tmpdir, "test_agent.md") create_test_markdown_file(md_file, "ParseTestAgent") - + loader = AgentLoader() agent_config = loader.parse_markdown_file(md_file) - - assert agent_config is not None, "Agent config should not be None" - assert hasattr(agent_config, "name"), "Config should have name attribute" - assert hasattr(agent_config, "model_name"), "Config should have model_name attribute" - assert agent_config.name == "ParseTestAgent", "Agent name should match" - - logger.info(f"✓ Parse markdown file test passed: {agent_config.name}") - + + assert ( + agent_config is not None + ), "Agent config should not be None" + assert hasattr( + agent_config, "name" + ), "Config should have name attribute" + assert hasattr( + agent_config, "model_name" + ), "Config should have model_name attribute" + assert ( + agent_config.name == "ParseTestAgent" + ), "Agent name should match" + + logger.info( + f"✓ Parse markdown file test passed: {agent_config.name}" + ) + except Exception as e: logger.error(f"Error in test_parse_markdown_file: {str(e)}") raise @@ -459,24 +590,32 @@ def test_loaded_agents_can_run(): with tempfile.TemporaryDirectory() as tmpdir: md_file = os.path.join(tmpdir, "test_agent.md") create_test_markdown_file(md_file, "RunnableAgent") - + loader = AgentLoader() - agents = loader.load_agents_from_markdown(md_file, concurrent=False) - - assert agents is not None, "Agents list should not be None" + agents = loader.load_agents_from_markdown( + md_file, concurrent=False + ) + + assert ( + agents is not None + ), "Agents list should not be None" assert len(agents) > 0, "Should have at least one agent" - + agent = agents[0] assert agent is not None, "Agent should not be None" - + result = agent.run("What is 2 + 2? Answer briefly.") - - assert result is not None, "Agent run result should not be None" - assert isinstance(result, str), "Result should be a string" + + assert ( + result is not None + ), "Agent run result should not be None" + assert isinstance( + result, str + ), "Result should be a string" assert len(result) > 0, "Result should not be empty" - + logger.info("✓ Loaded agents can run test passed") - + except Exception as e: logger.error(f"Error in test_loaded_agents_can_run: {str(e)}") raise @@ -488,20 +627,26 @@ def test_load_agents_with_streaming(): with tempfile.TemporaryDirectory() as tmpdir: md_file = os.path.join(tmpdir, "test_agent.md") create_test_markdown_file(md_file, "StreamingAgent") - + loader = AgentLoader() - agents = loader.load_agents_from_markdown(md_file, concurrent=False) - - assert agents is not None, "Agents list should not be None" + agents = loader.load_agents_from_markdown( + md_file, concurrent=False + ) + + assert ( + agents is not None + ), "Agents list should not be None" assert len(agents) > 0, "Should have at least one agent" - + agent = agents[0] assert agent is not None, "Agent should not be None" - + logger.info("✓ Load agents with streaming test passed") - + except Exception as e: - logger.error(f"Error in test_load_agents_with_streaming: {str(e)}") + logger.error( + f"Error in test_load_agents_with_streaming: {str(e)}" + ) raise @@ -509,22 +654,28 @@ def test_error_handling_nonexistent_file(): """Test error handling for nonexistent file.""" try: loader = AgentLoader() - + try: loader.load_agent_from_markdown("nonexistent_file.md") - assert False, "Should have raised an error for nonexistent file" + assert ( + False + ), "Should have raised an error for nonexistent file" except (FileNotFoundError, Exception) as e: assert e is not None, "Should raise an error" - logger.info("✓ Error handling for nonexistent file test passed") - + logger.info( + "✓ Error handling for nonexistent file test passed" + ) + except Exception as e: - logger.error(f"Error in test_error_handling_nonexistent_file: {str(e)}") + logger.error( + f"Error in test_error_handling_nonexistent_file: {str(e)}" + ) raise if __name__ == "__main__": import sys - + test_dict = { "test_agent_loader_initialization": test_agent_loader_initialization, "test_load_agent_from_markdown": test_load_agent_from_markdown, @@ -544,7 +695,7 @@ if __name__ == "__main__": "test_load_agents_with_streaming": test_load_agents_with_streaming, "test_error_handling_nonexistent_file": test_error_handling_nonexistent_file, } - + if len(sys.argv) > 1: requested_tests = [] for test_name in sys.argv[1:]: @@ -555,21 +706,23 @@ if __name__ == "__main__": break else: print(f"⚠ Warning: Test '{test_name}' not found.") - print(f"Available tests: {', '.join(test_dict.keys())}") + print( + f"Available tests: {', '.join(test_dict.keys())}" + ) sys.exit(1) - + tests_to_run = requested_tests else: tests_to_run = list(test_dict.values()) - + if len(tests_to_run) == 1: print(f"Running: {tests_to_run[0].__name__}") else: print(f"Running {len(tests_to_run)} test(s)...") - + passed = 0 failed = 0 - + for test_func in tests_to_run: try: print(f"\n{'='*60}") @@ -582,16 +735,21 @@ if __name__ == "__main__": print(f"✗ FAILED: {test_func.__name__}") print(f" Error: {str(e)}") import traceback + traceback.print_exc() failed += 1 - + print(f"\n{'='*60}") print(f"Test Summary: {passed} passed, {failed} failed") print(f"{'='*60}") - + if len(sys.argv) == 1: print("\n💡 Tip: Run a specific test with:") - print(" python test_agent_loader.py test_load_agent_from_markdown") + print( + " python test_agent_loader.py test_load_agent_from_markdown" + ) print("\n Or use pytest:") print(" pytest test_agent_loader.py") - print(" pytest test_agent_loader.py::test_load_agent_from_markdown") \ No newline at end of file + print( + " pytest test_agent_loader.py::test_load_agent_from_markdown" + ) diff --git a/tests/structs/test_agent_registry.py b/tests/structs/test_agent_registry.py index f4877d21..9eaa3cea 100644 --- a/tests/structs/test_agent_registry.py +++ b/tests/structs/test_agent_registry.py @@ -12,24 +12,38 @@ try: from swarms.structs.agent import Agent except (ImportError, ModuleNotFoundError) as e: import importlib.util + _current_dir = os.path.dirname(os.path.abspath(__file__)) - - agent_registry_path = os.path.join(_current_dir, "..", "..", "swarms", "structs", "agent_registry.py") - agent_path = os.path.join(_current_dir, "..", "..", "swarms", "structs", "agent.py") - + + agent_registry_path = os.path.join( + _current_dir, + "..", + "..", + "swarms", + "structs", + "agent_registry.py", + ) + agent_path = os.path.join( + _current_dir, "..", "..", "swarms", "structs", "agent.py" + ) + if os.path.exists(agent_registry_path): - spec = importlib.util.spec_from_file_location("agent_registry", agent_registry_path) + spec = importlib.util.spec_from_file_location( + "agent_registry", agent_registry_path + ) agent_registry_module = importlib.util.module_from_spec(spec) spec.loader.exec_module(agent_registry_module) AgentRegistry = agent_registry_module.AgentRegistry - + if os.path.exists(agent_path): - spec = importlib.util.spec_from_file_location("agent", agent_path) + spec = importlib.util.spec_from_file_location( + "agent", agent_path + ) agent_module = importlib.util.module_from_spec(spec) spec.loader.exec_module(agent_module) Agent = agent_module.Agent else: - raise ImportError(f"Could not find required modules") from e + raise ImportError("Could not find required modules") from e logger.remove() logger.add(lambda msg: None, level="ERROR") @@ -39,27 +53,45 @@ def test_agent_registry_initialization(): """Test AgentRegistry initialization.""" try: registry = AgentRegistry() - assert registry is not None, "AgentRegistry should not be None" - assert registry.name == "Agent Registry", "Default name should be set" - assert registry.description == "A registry for managing agents.", "Default description should be set" - assert isinstance(registry.agents, dict), "Agents should be a dictionary" - assert len(registry.agents) == 0, "Initial registry should be empty" - + assert ( + registry is not None + ), "AgentRegistry should not be None" + assert ( + registry.name == "Agent Registry" + ), "Default name should be set" + assert ( + registry.description == "A registry for managing agents." + ), "Default description should be set" + assert isinstance( + registry.agents, dict + ), "Agents should be a dictionary" + assert ( + len(registry.agents) == 0 + ), "Initial registry should be empty" + registry2 = AgentRegistry( name="Test Registry", description="Test description", return_json=False, - auto_save=True + auto_save=True, ) - assert registry2.name == "Test Registry", "Custom name should be set" - assert registry2.description == "Test description", "Custom description should be set" - assert registry2.return_json is False, "return_json should be False" + assert ( + registry2.name == "Test Registry" + ), "Custom name should be set" + assert ( + registry2.description == "Test description" + ), "Custom description should be set" + assert ( + registry2.return_json is False + ), "return_json should be False" assert registry2.auto_save is True, "auto_save should be True" - + logger.info("✓ AgentRegistry initialization test passed") - + except Exception as e: - logger.error(f"Error in test_agent_registry_initialization: {str(e)}") + logger.error( + f"Error in test_agent_registry_initialization: {str(e)}" + ) raise @@ -67,7 +99,7 @@ def test_agent_registry_add_single_agent(): """Test adding a single agent to the registry.""" try: registry = AgentRegistry() - + agent = Agent( agent_name="Test-Agent-1", agent_description="Test agent for registry", @@ -77,18 +109,29 @@ def test_agent_registry_add_single_agent(): print_on=False, streaming_on=True, ) - + registry.add(agent) - - assert len(registry.agents) == 1, "Registry should have one agent" - assert "Test-Agent-1" in registry.agents, "Agent should be in registry" - assert registry.agents["Test-Agent-1"] is not None, "Agent object should not be None" - assert registry.agents["Test-Agent-1"].agent_name == "Test-Agent-1", "Agent name should match" - + + assert ( + len(registry.agents) == 1 + ), "Registry should have one agent" + assert ( + "Test-Agent-1" in registry.agents + ), "Agent should be in registry" + assert ( + registry.agents["Test-Agent-1"] is not None + ), "Agent object should not be None" + assert ( + registry.agents["Test-Agent-1"].agent_name + == "Test-Agent-1" + ), "Agent name should match" + logger.info("✓ Add single agent test passed") - + except Exception as e: - logger.error(f"Error in test_agent_registry_add_single_agent: {str(e)}") + logger.error( + f"Error in test_agent_registry_add_single_agent: {str(e)}" + ) raise @@ -96,7 +139,7 @@ def test_agent_registry_add_multiple_agents(): """Test adding multiple agents to the registry.""" try: registry = AgentRegistry() - + agent1 = Agent( agent_name="Test-Agent-1", agent_description="First test agent", @@ -106,7 +149,7 @@ def test_agent_registry_add_multiple_agents(): print_on=False, streaming_on=True, ) - + agent2 = Agent( agent_name="Test-Agent-2", agent_description="Second test agent", @@ -116,7 +159,7 @@ def test_agent_registry_add_multiple_agents(): print_on=False, streaming_on=True, ) - + agent3 = Agent( agent_name="Test-Agent-3", agent_description="Third test agent", @@ -126,21 +169,37 @@ def test_agent_registry_add_multiple_agents(): print_on=False, streaming_on=True, ) - + registry.add_many([agent1, agent2, agent3]) - - assert len(registry.agents) == 3, "Registry should have three agents" - assert "Test-Agent-1" in registry.agents, "Agent 1 should be in registry" - assert "Test-Agent-2" in registry.agents, "Agent 2 should be in registry" - assert "Test-Agent-3" in registry.agents, "Agent 3 should be in registry" - - for agent_name in ["Test-Agent-1", "Test-Agent-2", "Test-Agent-3"]: - assert registry.agents[agent_name] is not None, f"{agent_name} should not be None" - + + assert ( + len(registry.agents) == 3 + ), "Registry should have three agents" + assert ( + "Test-Agent-1" in registry.agents + ), "Agent 1 should be in registry" + assert ( + "Test-Agent-2" in registry.agents + ), "Agent 2 should be in registry" + assert ( + "Test-Agent-3" in registry.agents + ), "Agent 3 should be in registry" + + for agent_name in [ + "Test-Agent-1", + "Test-Agent-2", + "Test-Agent-3", + ]: + assert ( + registry.agents[agent_name] is not None + ), f"{agent_name} should not be None" + logger.info("✓ Add multiple agents test passed") - + except Exception as e: - logger.error(f"Error in test_agent_registry_add_multiple_agents: {str(e)}") + logger.error( + f"Error in test_agent_registry_add_multiple_agents: {str(e)}" + ) raise @@ -148,7 +207,7 @@ def test_agent_registry_get_agent(): """Test retrieving an agent from the registry.""" try: registry = AgentRegistry() - + agent = Agent( agent_name="Retrievable-Agent", agent_description="Agent for retrieval testing", @@ -158,20 +217,30 @@ def test_agent_registry_get_agent(): print_on=False, streaming_on=True, ) - + registry.add(agent) - + retrieved_agent = registry.get("Retrievable-Agent") - - assert retrieved_agent is not None, "Retrieved agent should not be None" - assert retrieved_agent.agent_name == "Retrievable-Agent", "Agent name should match" - assert hasattr(retrieved_agent, "run"), "Agent should have run method" - assert retrieved_agent is agent, "Should return the same agent object" - + + assert ( + retrieved_agent is not None + ), "Retrieved agent should not be None" + assert ( + retrieved_agent.agent_name == "Retrievable-Agent" + ), "Agent name should match" + assert hasattr( + retrieved_agent, "run" + ), "Agent should have run method" + assert ( + retrieved_agent is agent + ), "Should return the same agent object" + logger.info("✓ Get agent test passed") - + except Exception as e: - logger.error(f"Error in test_agent_registry_get_agent: {str(e)}") + logger.error( + f"Error in test_agent_registry_get_agent: {str(e)}" + ) raise @@ -179,7 +248,7 @@ def test_agent_registry_delete_agent(): """Test deleting an agent from the registry.""" try: registry = AgentRegistry() - + agent1 = Agent( agent_name="Agent-To-Delete", agent_description="Agent that will be deleted", @@ -189,7 +258,7 @@ def test_agent_registry_delete_agent(): print_on=False, streaming_on=True, ) - + agent2 = Agent( agent_name="Agent-To-Keep", agent_description="Agent that will remain", @@ -199,22 +268,32 @@ def test_agent_registry_delete_agent(): print_on=False, streaming_on=True, ) - + registry.add(agent1) registry.add(agent2) - - assert len(registry.agents) == 2, "Registry should have two agents" - + + assert ( + len(registry.agents) == 2 + ), "Registry should have two agents" + registry.delete("Agent-To-Delete") - - assert len(registry.agents) == 1, "Registry should have one agent after deletion" - assert "Agent-To-Delete" not in registry.agents, "Deleted agent should not be in registry" - assert "Agent-To-Keep" in registry.agents, "Other agent should still be in registry" - + + assert ( + len(registry.agents) == 1 + ), "Registry should have one agent after deletion" + assert ( + "Agent-To-Delete" not in registry.agents + ), "Deleted agent should not be in registry" + assert ( + "Agent-To-Keep" in registry.agents + ), "Other agent should still be in registry" + logger.info("✓ Delete agent test passed") - + except Exception as e: - logger.error(f"Error in test_agent_registry_delete_agent: {str(e)}") + logger.error( + f"Error in test_agent_registry_delete_agent: {str(e)}" + ) raise @@ -222,7 +301,7 @@ def test_agent_registry_update_agent(): """Test updating an agent in the registry.""" try: registry = AgentRegistry() - + original_agent = Agent( agent_name="Agent-To-Update", agent_description="Original description", @@ -232,9 +311,9 @@ def test_agent_registry_update_agent(): print_on=False, streaming_on=True, ) - + registry.add(original_agent) - + updated_agent = Agent( agent_name="Agent-To-Update", agent_description="Updated description", @@ -244,20 +323,30 @@ def test_agent_registry_update_agent(): print_on=False, streaming_on=True, ) - + registry.update_agent("Agent-To-Update", updated_agent) - + retrieved_agent = registry.get("Agent-To-Update") - - assert retrieved_agent is not None, "Updated agent should not be None" - assert retrieved_agent is updated_agent, "Should return the updated agent" - assert retrieved_agent.max_loops == 2, "Max loops should be updated" - assert retrieved_agent.verbose is True, "Verbose should be updated" - + + assert ( + retrieved_agent is not None + ), "Updated agent should not be None" + assert ( + retrieved_agent is updated_agent + ), "Should return the updated agent" + assert ( + retrieved_agent.max_loops == 2 + ), "Max loops should be updated" + assert ( + retrieved_agent.verbose is True + ), "Verbose should be updated" + logger.info("✓ Update agent test passed") - + except Exception as e: - logger.error(f"Error in test_agent_registry_update_agent: {str(e)}") + logger.error( + f"Error in test_agent_registry_update_agent: {str(e)}" + ) raise @@ -265,7 +354,7 @@ def test_agent_registry_list_agents(): """Test listing all agent names in the registry.""" try: registry = AgentRegistry() - + agent1 = Agent( agent_name="List-Agent-1", agent_description="First agent", @@ -275,7 +364,7 @@ def test_agent_registry_list_agents(): print_on=False, streaming_on=True, ) - + agent2 = Agent( agent_name="List-Agent-2", agent_description="Second agent", @@ -285,22 +374,30 @@ def test_agent_registry_list_agents(): print_on=False, streaming_on=True, ) - + registry.add(agent1) registry.add(agent2) - + agent_names = registry.list_agents() - - assert agent_names is not None, "Agent names list should not be None" + + assert ( + agent_names is not None + ), "Agent names list should not be None" assert isinstance(agent_names, list), "Should return a list" assert len(agent_names) == 2, "Should have two agent names" - assert "List-Agent-1" in agent_names, "First agent name should be in list" - assert "List-Agent-2" in agent_names, "Second agent name should be in list" - + assert ( + "List-Agent-1" in agent_names + ), "First agent name should be in list" + assert ( + "List-Agent-2" in agent_names + ), "Second agent name should be in list" + logger.info("✓ List agents test passed") - + except Exception as e: - logger.error(f"Error in test_agent_registry_list_agents: {str(e)}") + logger.error( + f"Error in test_agent_registry_list_agents: {str(e)}" + ) raise @@ -308,7 +405,7 @@ def test_agent_registry_return_all_agents(): """Test returning all agents from the registry.""" try: registry = AgentRegistry() - + agent1 = Agent( agent_name="Return-Agent-1", agent_description="First agent", @@ -318,7 +415,7 @@ def test_agent_registry_return_all_agents(): print_on=False, streaming_on=True, ) - + agent2 = Agent( agent_name="Return-Agent-2", agent_description="Second agent", @@ -328,25 +425,33 @@ def test_agent_registry_return_all_agents(): print_on=False, streaming_on=True, ) - + registry.add(agent1) registry.add(agent2) - + all_agents = registry.return_all_agents() - - assert all_agents is not None, "All agents list should not be None" + + assert ( + all_agents is not None + ), "All agents list should not be None" assert isinstance(all_agents, list), "Should return a list" assert len(all_agents) == 2, "Should have two agents" - + for agent in all_agents: assert agent is not None, "Each agent should not be None" - assert hasattr(agent, "agent_name"), "Agent should have agent_name" - assert hasattr(agent, "run"), "Agent should have run method" - + assert hasattr( + agent, "agent_name" + ), "Agent should have agent_name" + assert hasattr( + agent, "run" + ), "Agent should have run method" + logger.info("✓ Return all agents test passed") - + except Exception as e: - logger.error(f"Error in test_agent_registry_return_all_agents: {str(e)}") + logger.error( + f"Error in test_agent_registry_return_all_agents: {str(e)}" + ) raise @@ -354,7 +459,7 @@ def test_agent_registry_query_with_condition(): """Test querying agents with a condition.""" try: registry = AgentRegistry() - + agent1 = Agent( agent_name="Query-Agent-1", agent_description="Agent with max_loops=1", @@ -364,7 +469,7 @@ def test_agent_registry_query_with_condition(): print_on=False, streaming_on=True, ) - + agent2 = Agent( agent_name="Query-Agent-2", agent_description="Agent with max_loops=2", @@ -374,7 +479,7 @@ def test_agent_registry_query_with_condition(): print_on=False, streaming_on=True, ) - + agent3 = Agent( agent_name="Query-Agent-3", agent_description="Agent with max_loops=1", @@ -384,27 +489,37 @@ def test_agent_registry_query_with_condition(): print_on=False, streaming_on=True, ) - + registry.add(agent1) registry.add(agent2) registry.add(agent3) - + def condition_max_loops_1(agent): return agent.max_loops == 1 - + filtered_agents = registry.query(condition_max_loops_1) - - assert filtered_agents is not None, "Filtered agents should not be None" - assert isinstance(filtered_agents, list), "Should return a list" - assert len(filtered_agents) == 2, "Should have two agents with max_loops=1" - + + assert ( + filtered_agents is not None + ), "Filtered agents should not be None" + assert isinstance( + filtered_agents, list + ), "Should return a list" + assert ( + len(filtered_agents) == 2 + ), "Should have two agents with max_loops=1" + for agent in filtered_agents: - assert agent.max_loops == 1, "All filtered agents should have max_loops=1" - + assert ( + agent.max_loops == 1 + ), "All filtered agents should have max_loops=1" + logger.info("✓ Query with condition test passed") - + except Exception as e: - logger.error(f"Error in test_agent_registry_query_with_condition: {str(e)}") + logger.error( + f"Error in test_agent_registry_query_with_condition: {str(e)}" + ) raise @@ -412,7 +527,7 @@ def test_agent_registry_query_without_condition(): """Test querying all agents without a condition.""" try: registry = AgentRegistry() - + agent1 = Agent( agent_name="Query-All-Agent-1", agent_description="First agent", @@ -422,7 +537,7 @@ def test_agent_registry_query_without_condition(): print_on=False, streaming_on=True, ) - + agent2 = Agent( agent_name="Query-All-Agent-2", agent_description="Second agent", @@ -432,20 +547,22 @@ def test_agent_registry_query_without_condition(): print_on=False, streaming_on=True, ) - + registry.add(agent1) registry.add(agent2) - + all_agents = registry.query() - + assert all_agents is not None, "All agents should not be None" assert isinstance(all_agents, list), "Should return a list" assert len(all_agents) == 2, "Should return all agents" - + logger.info("✓ Query without condition test passed") - + except Exception as e: - logger.error(f"Error in test_agent_registry_query_without_condition: {str(e)}") + logger.error( + f"Error in test_agent_registry_query_without_condition: {str(e)}" + ) raise @@ -453,7 +570,7 @@ def test_agent_registry_find_agent_by_name(): """Test finding an agent by name.""" try: registry = AgentRegistry() - + agent = Agent( agent_name="Findable-Agent", agent_description="Agent to find", @@ -463,19 +580,27 @@ def test_agent_registry_find_agent_by_name(): print_on=False, streaming_on=True, ) - + registry.add(agent) - + found_agent = registry.find_agent_by_name("Findable-Agent") - - assert found_agent is not None, "Found agent should not be None" - assert found_agent.agent_name == "Findable-Agent", "Agent name should match" - assert hasattr(found_agent, "run"), "Agent should have run method" - + + assert ( + found_agent is not None + ), "Found agent should not be None" + assert ( + found_agent.agent_name == "Findable-Agent" + ), "Agent name should match" + assert hasattr( + found_agent, "run" + ), "Agent should have run method" + logger.info("✓ Find agent by name test passed") - + except Exception as e: - logger.error(f"Error in test_agent_registry_find_agent_by_name: {str(e)}") + logger.error( + f"Error in test_agent_registry_find_agent_by_name: {str(e)}" + ) raise @@ -483,7 +608,7 @@ def test_agent_registry_find_agent_by_id(): """Test finding an agent by ID.""" try: registry = AgentRegistry() - + agent = Agent( agent_name="ID-Agent", agent_description="Agent with ID", @@ -493,19 +618,25 @@ def test_agent_registry_find_agent_by_id(): print_on=False, streaming_on=True, ) - + registry.add(agent) - + agent_id = agent.id found_agent = registry.find_agent_by_id(agent.agent_name) - - assert found_agent is not None, "Found agent should not be None" - assert found_agent.agent_name == "ID-Agent", "Agent name should match" - + + assert ( + found_agent is not None + ), "Found agent should not be None" + assert ( + found_agent.agent_name == "ID-Agent" + ), "Agent name should match" + logger.info("✓ Find agent by ID test passed") - + except Exception as e: - logger.error(f"Error in test_agent_registry_find_agent_by_id: {str(e)}") + logger.error( + f"Error in test_agent_registry_find_agent_by_id: {str(e)}" + ) raise @@ -513,7 +644,7 @@ def test_agent_registry_agents_to_json(): """Test converting agents to JSON.""" try: registry = AgentRegistry() - + agent1 = Agent( agent_name="JSON-Agent-1", agent_description="First agent for JSON", @@ -523,7 +654,7 @@ def test_agent_registry_agents_to_json(): print_on=False, streaming_on=True, ) - + agent2 = Agent( agent_name="JSON-Agent-2", agent_description="Second agent for JSON", @@ -533,27 +664,38 @@ def test_agent_registry_agents_to_json(): print_on=False, streaming_on=True, ) - + registry.add(agent1) registry.add(agent2) - + json_output = registry.agents_to_json() - - assert json_output is not None, "JSON output should not be None" + + assert ( + json_output is not None + ), "JSON output should not be None" assert isinstance(json_output, str), "Should return a string" assert len(json_output) > 0, "JSON should not be empty" - assert "JSON-Agent-1" in json_output, "First agent should be in JSON" - assert "JSON-Agent-2" in json_output, "Second agent should be in JSON" - + assert ( + "JSON-Agent-1" in json_output + ), "First agent should be in JSON" + assert ( + "JSON-Agent-2" in json_output + ), "Second agent should be in JSON" + import json + parsed_json = json.loads(json_output) - assert isinstance(parsed_json, dict), "Should be valid JSON dict" + assert isinstance( + parsed_json, dict + ), "Should be valid JSON dict" assert len(parsed_json) == 2, "Should have two agents in JSON" - + logger.info("✓ Agents to JSON test passed") - + except Exception as e: - logger.error(f"Error in test_agent_registry_agents_to_json: {str(e)}") + logger.error( + f"Error in test_agent_registry_agents_to_json: {str(e)}" + ) raise @@ -569,7 +711,7 @@ def test_agent_registry_initialization_with_agents(): print_on=False, streaming_on=True, ) - + agent2 = Agent( agent_name="Init-Agent-2", agent_description="Second initial agent", @@ -579,18 +721,26 @@ def test_agent_registry_initialization_with_agents(): print_on=False, streaming_on=True, ) - + registry = AgentRegistry(agents=[agent1, agent2]) - + assert registry is not None, "Registry should not be None" - assert len(registry.agents) == 2, "Registry should have two agents" - assert "Init-Agent-1" in registry.agents, "First agent should be in registry" - assert "Init-Agent-2" in registry.agents, "Second agent should be in registry" - + assert ( + len(registry.agents) == 2 + ), "Registry should have two agents" + assert ( + "Init-Agent-1" in registry.agents + ), "First agent should be in registry" + assert ( + "Init-Agent-2" in registry.agents + ), "Second agent should be in registry" + logger.info("✓ Initialize with agents test passed") - + except Exception as e: - logger.error(f"Error in test_agent_registry_initialization_with_agents: {str(e)}") + logger.error( + f"Error in test_agent_registry_initialization_with_agents: {str(e)}" + ) raise @@ -598,7 +748,7 @@ def test_agent_registry_error_duplicate_agent(): """Test error handling for duplicate agent names.""" try: registry = AgentRegistry() - + agent1 = Agent( agent_name="Duplicate-Agent", agent_description="First agent", @@ -608,7 +758,7 @@ def test_agent_registry_error_duplicate_agent(): print_on=False, streaming_on=True, ) - + agent2 = Agent( agent_name="Duplicate-Agent", agent_description="Duplicate agent", @@ -618,20 +768,30 @@ def test_agent_registry_error_duplicate_agent(): print_on=False, streaming_on=True, ) - + registry.add(agent1) - + try: registry.add(agent2) - assert False, "Should have raised ValueError for duplicate agent" + assert ( + False + ), "Should have raised ValueError for duplicate agent" except ValueError as e: - assert "already exists" in str(e).lower(), "Error message should mention duplicate" - assert len(registry.agents) == 1, "Registry should still have only one agent" - - logger.info("✓ Error handling for duplicate agent test passed") - + assert ( + "already exists" in str(e).lower() + ), "Error message should mention duplicate" + assert ( + len(registry.agents) == 1 + ), "Registry should still have only one agent" + + logger.info( + "✓ Error handling for duplicate agent test passed" + ) + except Exception as e: - logger.error(f"Error in test_agent_registry_error_duplicate_agent: {str(e)}") + logger.error( + f"Error in test_agent_registry_error_duplicate_agent: {str(e)}" + ) raise @@ -639,23 +799,31 @@ def test_agent_registry_error_nonexistent_agent(): """Test error handling for nonexistent agent.""" try: registry = AgentRegistry() - + try: registry.get("Nonexistent-Agent") - assert False, "Should have raised KeyError for nonexistent agent" + assert ( + False + ), "Should have raised KeyError for nonexistent agent" except KeyError as e: assert e is not None, "Should raise KeyError" - + try: registry.delete("Nonexistent-Agent") - assert False, "Should have raised KeyError for nonexistent agent" + assert ( + False + ), "Should have raised KeyError for nonexistent agent" except KeyError as e: assert e is not None, "Should raise KeyError" - - logger.info("✓ Error handling for nonexistent agent test passed") - + + logger.info( + "✓ Error handling for nonexistent agent test passed" + ) + except Exception as e: - logger.error(f"Error in test_agent_registry_error_nonexistent_agent: {str(e)}") + logger.error( + f"Error in test_agent_registry_error_nonexistent_agent: {str(e)}" + ) raise @@ -663,7 +831,7 @@ def test_agent_registry_retrieved_agents_can_run(): """Test that retrieved agents can actually run tasks.""" try: registry = AgentRegistry() - + agent = Agent( agent_name="Runnable-Registry-Agent", agent_description="Agent for running tasks", @@ -673,23 +841,29 @@ def test_agent_registry_retrieved_agents_can_run(): print_on=False, streaming_on=True, ) - + registry.add(agent) - + retrieved_agent = registry.get("Runnable-Registry-Agent") - - assert retrieved_agent is not None, "Retrieved agent should not be None" - + + assert ( + retrieved_agent is not None + ), "Retrieved agent should not be None" + result = retrieved_agent.run("What is 2 + 2? Answer briefly.") - - assert result is not None, "Agent run result should not be None" + + assert ( + result is not None + ), "Agent run result should not be None" assert isinstance(result, str), "Result should be a string" assert len(result) > 0, "Result should not be empty" - + logger.info("✓ Retrieved agents can run test passed") - + except Exception as e: - logger.error(f"Error in test_agent_registry_retrieved_agents_can_run: {str(e)}") + logger.error( + f"Error in test_agent_registry_retrieved_agents_can_run: {str(e)}" + ) raise @@ -697,7 +871,7 @@ def test_agent_registry_thread_safety(): """Test thread safety of registry operations.""" try: registry = AgentRegistry() - + agent1 = Agent( agent_name="Thread-Agent-1", agent_description="First thread agent", @@ -707,7 +881,7 @@ def test_agent_registry_thread_safety(): print_on=False, streaming_on=True, ) - + agent2 = Agent( agent_name="Thread-Agent-2", agent_description="Second thread agent", @@ -717,28 +891,32 @@ def test_agent_registry_thread_safety(): print_on=False, streaming_on=True, ) - + registry.add(agent1) registry.add(agent2) - + agent_names = registry.list_agents() all_agents = registry.return_all_agents() - - assert agent_names is not None, "Agent names should not be None" + + assert ( + agent_names is not None + ), "Agent names should not be None" assert all_agents is not None, "All agents should not be None" assert len(agent_names) == 2, "Should have two agent names" assert len(all_agents) == 2, "Should have two agents" - + logger.info("✓ Thread safety test passed") - + except Exception as e: - logger.error(f"Error in test_agent_registry_thread_safety: {str(e)}") + logger.error( + f"Error in test_agent_registry_thread_safety: {str(e)}" + ) raise if __name__ == "__main__": import sys - + test_dict = { "test_agent_registry_initialization": test_agent_registry_initialization, "test_agent_registry_add_single_agent": test_agent_registry_add_single_agent, @@ -759,7 +937,7 @@ if __name__ == "__main__": "test_agent_registry_retrieved_agents_can_run": test_agent_registry_retrieved_agents_can_run, "test_agent_registry_thread_safety": test_agent_registry_thread_safety, } - + if len(sys.argv) > 1: requested_tests = [] for test_name in sys.argv[1:]: @@ -770,21 +948,23 @@ if __name__ == "__main__": break else: print(f"⚠ Warning: Test '{test_name}' not found.") - print(f"Available tests: {', '.join(test_dict.keys())}") + print( + f"Available tests: {', '.join(test_dict.keys())}" + ) sys.exit(1) - + tests_to_run = requested_tests else: tests_to_run = list(test_dict.values()) - + if len(tests_to_run) == 1: print(f"Running: {tests_to_run[0].__name__}") else: print(f"Running {len(tests_to_run)} test(s)...") - + passed = 0 failed = 0 - + for test_func in tests_to_run: try: print(f"\n{'='*60}") @@ -797,17 +977,21 @@ if __name__ == "__main__": print(f"✗ FAILED: {test_func.__name__}") print(f" Error: {str(e)}") import traceback + traceback.print_exc() failed += 1 - + print(f"\n{'='*60}") print(f"Test Summary: {passed} passed, {failed} failed") print(f"{'='*60}") - + if len(sys.argv) == 1: print("\n💡 Tip: Run a specific test with:") - print(" python test_agent_registry.py test_agent_registry_initialization") + print( + " python test_agent_registry.py test_agent_registry_initialization" + ) print("\n Or use pytest:") print(" pytest test_agent_registry.py") - print(" pytest test_agent_registry.py::test_agent_registry_initialization") - + print( + " pytest test_agent_registry.py::test_agent_registry_initialization" + ) diff --git a/tests/structs/test_base_structure.py b/tests/structs/test_base_structure.py index 8a7ce1bf..0d2dc761 100644 --- a/tests/structs/test_base_structure.py +++ b/tests/structs/test_base_structure.py @@ -14,17 +14,29 @@ try: from swarms.structs.base_structure import BaseStructure except (ImportError, ModuleNotFoundError) as e: import importlib.util + _current_dir = os.path.dirname(os.path.abspath(__file__)) - - base_structure_path = os.path.join(_current_dir, "..", "..", "swarms", "structs", "base_structure.py") - + + base_structure_path = os.path.join( + _current_dir, + "..", + "..", + "swarms", + "structs", + "base_structure.py", + ) + if os.path.exists(base_structure_path): - spec = importlib.util.spec_from_file_location("base_structure", base_structure_path) + spec = importlib.util.spec_from_file_location( + "base_structure", base_structure_path + ) base_structure_module = importlib.util.module_from_spec(spec) spec.loader.exec_module(base_structure_module) BaseStructure = base_structure_module.BaseStructure else: - raise ImportError(f"Could not find base_structure.py at {base_structure_path}") from e + raise ImportError( + f"Could not find base_structure.py at {base_structure_path}" + ) from e logger.remove() logger.add(lambda msg: None, level="ERROR") @@ -39,15 +51,29 @@ def test_base_structure_initialization(): """Test BaseStructure initialization.""" try: structure = BaseStructure() - assert structure is not None, "BaseStructure should not be None" + assert ( + structure is not None + ), "BaseStructure should not be None" assert structure.name is None, "Default name should be None" - assert structure.description is None, "Default description should be None" - assert structure.save_metadata_on is True, "save_metadata_on should default to True" - assert structure.save_artifact_path == "./artifacts", "Default artifact path should be set" - assert structure.save_metadata_path == "./metadata", "Default metadata path should be set" - assert structure.save_error_path == "./errors", "Default error path should be set" - assert structure.workspace_dir == "./workspace", "Default workspace dir should be set" - + assert ( + structure.description is None + ), "Default description should be None" + assert ( + structure.save_metadata_on is True + ), "save_metadata_on should default to True" + assert ( + structure.save_artifact_path == "./artifacts" + ), "Default artifact path should be set" + assert ( + structure.save_metadata_path == "./metadata" + ), "Default metadata path should be set" + assert ( + structure.save_error_path == "./errors" + ), "Default error path should be set" + assert ( + structure.workspace_dir == "./workspace" + ), "Default workspace dir should be set" + structure2 = BaseStructure( name="TestStructure", description="Test description", @@ -55,17 +81,27 @@ def test_base_structure_initialization(): save_artifact_path="/tmp/artifacts", save_metadata_path="/tmp/metadata", save_error_path="/tmp/errors", - workspace_dir="/tmp/workspace" + workspace_dir="/tmp/workspace", ) - assert structure2.name == "TestStructure", "Custom name should be set" - assert structure2.description == "Test description", "Custom description should be set" - assert structure2.save_metadata_on is False, "save_metadata_on should be False" - assert structure2.save_artifact_path == "/tmp/artifacts", "Custom artifact path should be set" - + assert ( + structure2.name == "TestStructure" + ), "Custom name should be set" + assert ( + structure2.description == "Test description" + ), "Custom description should be set" + assert ( + structure2.save_metadata_on is False + ), "save_metadata_on should be False" + assert ( + structure2.save_artifact_path == "/tmp/artifacts" + ), "Custom artifact path should be set" + logger.info("✓ BaseStructure initialization test passed") - + except Exception as e: - logger.error(f"Error in test_base_structure_initialization: {str(e)}") + logger.error( + f"Error in test_base_structure_initialization: {str(e)}" + ) raise @@ -75,22 +111,34 @@ def test_save_and_load_file(): with tempfile.TemporaryDirectory() as tmpdir: structure = BaseStructure(name="TestFileOps") test_file = os.path.join(tmpdir, "test_data.json") - test_data = {"key": "value", "number": 42, "list": [1, 2, 3]} - + test_data = { + "key": "value", + "number": 42, + "list": [1, 2, 3], + } + structure.save_to_file(test_data, test_file) - + assert os.path.exists(test_file), "File should be created" - + loaded_data = structure.load_from_file(test_file) - - assert loaded_data is not None, "Loaded data should not be None" - assert isinstance(loaded_data, dict), "Loaded data should be a dict" + + assert ( + loaded_data is not None + ), "Loaded data should not be None" + assert isinstance( + loaded_data, dict + ), "Loaded data should be a dict" assert loaded_data["key"] == "value", "Data should match" assert loaded_data["number"] == 42, "Number should match" - assert loaded_data["list"] == [1, 2, 3], "List should match" - + assert loaded_data["list"] == [ + 1, + 2, + 3, + ], "List should match" + logger.info("✓ Save and load file test passed") - + except Exception as e: logger.error(f"Error in test_save_and_load_file: {str(e)}") raise @@ -101,27 +149,42 @@ def test_save_and_load_metadata(): try: with tempfile.TemporaryDirectory() as tmpdir: structure = BaseStructure( - name="TestMetadata", - save_metadata_path=tmpdir + name="TestMetadata", save_metadata_path=tmpdir ) - metadata = {"timestamp": "2024-01-01", "status": "active", "count": 5} - + metadata = { + "timestamp": "2024-01-01", + "status": "active", + "count": 5, + } + structure.save_metadata(metadata) - - metadata_file = os.path.join(tmpdir, "TestMetadata_metadata.json") - assert os.path.exists(metadata_file), "Metadata file should be created" - + + metadata_file = os.path.join( + tmpdir, "TestMetadata_metadata.json" + ) + assert os.path.exists( + metadata_file + ), "Metadata file should be created" + loaded_metadata = structure.load_metadata() - - assert loaded_metadata is not None, "Loaded metadata should not be None" - assert isinstance(loaded_metadata, dict), "Metadata should be a dict" - assert loaded_metadata["status"] == "active", "Metadata should match" + + assert ( + loaded_metadata is not None + ), "Loaded metadata should not be None" + assert isinstance( + loaded_metadata, dict + ), "Metadata should be a dict" + assert ( + loaded_metadata["status"] == "active" + ), "Metadata should match" assert loaded_metadata["count"] == 5, "Count should match" - + logger.info("✓ Save and load metadata test passed") - + except Exception as e: - logger.error(f"Error in test_save_and_load_metadata: {str(e)}") + logger.error( + f"Error in test_save_and_load_metadata: {str(e)}" + ) raise @@ -130,27 +193,38 @@ def test_save_and_load_artifact(): try: with tempfile.TemporaryDirectory() as tmpdir: structure = BaseStructure( - name="TestArtifact", - save_artifact_path=tmpdir + name="TestArtifact", save_artifact_path=tmpdir ) artifact = {"result": "success", "data": [1, 2, 3, 4, 5]} - + structure.save_artifact(artifact, "test_artifact") - + artifact_file = os.path.join(tmpdir, "test_artifact.json") - assert os.path.exists(artifact_file), "Artifact file should be created" - + assert os.path.exists( + artifact_file + ), "Artifact file should be created" + loaded_artifact = structure.load_artifact("test_artifact") - - assert loaded_artifact is not None, "Loaded artifact should not be None" - assert isinstance(loaded_artifact, dict), "Artifact should be a dict" - assert loaded_artifact["result"] == "success", "Artifact result should match" - assert len(loaded_artifact["data"]) == 5, "Artifact data should match" - + + assert ( + loaded_artifact is not None + ), "Loaded artifact should not be None" + assert isinstance( + loaded_artifact, dict + ), "Artifact should be a dict" + assert ( + loaded_artifact["result"] == "success" + ), "Artifact result should match" + assert ( + len(loaded_artifact["data"]) == 5 + ), "Artifact data should match" + logger.info("✓ Save and load artifact test passed") - + except Exception as e: - logger.error(f"Error in test_save_and_load_artifact: {str(e)}") + logger.error( + f"Error in test_save_and_load_artifact: {str(e)}" + ) raise @@ -159,28 +233,35 @@ def test_log_error(): try: with tempfile.TemporaryDirectory() as tmpdir: structure = BaseStructure( - name="TestErrorLog", - save_error_path=tmpdir + name="TestErrorLog", save_error_path=tmpdir ) error_message = "Test error message" - + structure.log_error(error_message) - - error_file = os.path.join(tmpdir, "TestErrorLog_errors.log") - assert os.path.exists(error_file), "Error log file should be created" - + + error_file = os.path.join( + tmpdir, "TestErrorLog_errors.log" + ) + assert os.path.exists( + error_file + ), "Error log file should be created" + with open(error_file, "r") as f: content = f.read() - assert error_message in content, "Error message should be in log" - + assert ( + error_message in content + ), "Error message should be in log" + structure.log_error("Another error") - + with open(error_file, "r") as f: content = f.read() - assert "Another error" in content, "Second error should be in log" - + assert ( + "Another error" in content + ), "Second error should be in log" + logger.info("✓ Log error test passed") - + except Exception as e: logger.error(f"Error in test_log_error: {str(e)}") raise @@ -191,29 +272,38 @@ def test_log_event(): try: with tempfile.TemporaryDirectory() as tmpdir: structure = BaseStructure( - name="TestEventLog", - save_metadata_path=tmpdir + name="TestEventLog", save_metadata_path=tmpdir ) event_message = "Test event occurred" - + structure.log_event(event_message, "INFO") - - event_file = os.path.join(tmpdir, "TestEventLog_events.log") - assert os.path.exists(event_file), "Event log file should be created" - + + event_file = os.path.join( + tmpdir, "TestEventLog_events.log" + ) + assert os.path.exists( + event_file + ), "Event log file should be created" + with open(event_file, "r") as f: content = f.read() - assert event_message in content, "Event message should be in log" - assert "INFO" in content, "Event type should be in log" - + assert ( + event_message in content + ), "Event message should be in log" + assert ( + "INFO" in content + ), "Event type should be in log" + structure.log_event("Warning event", "WARNING") - + with open(event_file, "r") as f: content = f.read() - assert "WARNING" in content, "Warning type should be in log" - + assert ( + "WARNING" in content + ), "Warning type should be in log" + logger.info("✓ Log event test passed") - + except Exception as e: logger.error(f"Error in test_log_event: {str(e)}") raise @@ -224,24 +314,40 @@ def test_compress_and_decompress_data(): try: structure = BaseStructure() test_data = {"key": "value", "large_data": "x" * 1000} - + compressed = structure.compress_data(test_data) - - assert compressed is not None, "Compressed data should not be None" - assert isinstance(compressed, bytes), "Compressed data should be bytes" - assert len(compressed) < len(json.dumps(test_data).encode()), "Compressed should be smaller" - + + assert ( + compressed is not None + ), "Compressed data should not be None" + assert isinstance( + compressed, bytes + ), "Compressed data should be bytes" + assert len(compressed) < len( + json.dumps(test_data).encode() + ), "Compressed should be smaller" + decompressed = structure.decompres_data(compressed) - - assert decompressed is not None, "Decompressed data should not be None" - assert isinstance(decompressed, dict), "Decompressed data should be a dict" - assert decompressed["key"] == "value", "Decompressed data should match" - assert len(decompressed["large_data"]) == 1000, "Large data should match" - + + assert ( + decompressed is not None + ), "Decompressed data should not be None" + assert isinstance( + decompressed, dict + ), "Decompressed data should be a dict" + assert ( + decompressed["key"] == "value" + ), "Decompressed data should match" + assert ( + len(decompressed["large_data"]) == 1000 + ), "Large data should match" + logger.info("✓ Compress and decompress data test passed") - + except Exception as e: - logger.error(f"Error in test_compress_and_decompress_data: {str(e)}") + logger.error( + f"Error in test_compress_and_decompress_data: {str(e)}" + ) raise @@ -249,19 +355,26 @@ def test_to_dict(): """Test converting structure to dictionary.""" try: structure = BaseStructure( - name="TestDict", - description="Test description" + name="TestDict", description="Test description" ) - + structure_dict = structure.to_dict() - - assert structure_dict is not None, "Dictionary should not be None" - assert isinstance(structure_dict, dict), "Should return a dict" - assert structure_dict["name"] == "TestDict", "Name should be in dict" - assert structure_dict["description"] == "Test description", "Description should be in dict" - + + assert ( + structure_dict is not None + ), "Dictionary should not be None" + assert isinstance( + structure_dict, dict + ), "Should return a dict" + assert ( + structure_dict["name"] == "TestDict" + ), "Name should be in dict" + assert ( + structure_dict["description"] == "Test description" + ), "Description should be in dict" + logger.info("✓ To dict test passed") - + except Exception as e: logger.error(f"Error in test_to_dict: {str(e)}") raise @@ -271,22 +384,25 @@ def test_to_json(): """Test converting structure to JSON.""" try: structure = BaseStructure( - name="TestJSON", - description="Test JSON description" + name="TestJSON", description="Test JSON description" ) - + json_output = structure.to_json() - - assert json_output is not None, "JSON output should not be None" + + assert ( + json_output is not None + ), "JSON output should not be None" assert isinstance(json_output, str), "Should return a string" assert "TestJSON" in json_output, "Name should be in JSON" - assert "Test JSON description" in json_output, "Description should be in JSON" - + assert ( + "Test JSON description" in json_output + ), "Description should be in JSON" + parsed = json.loads(json_output) assert isinstance(parsed, dict), "Should be valid JSON dict" - + logger.info("✓ To JSON test passed") - + except Exception as e: logger.error(f"Error in test_to_json: {str(e)}") raise @@ -296,18 +412,19 @@ def test_to_yaml(): """Test converting structure to YAML.""" try: structure = BaseStructure( - name="TestYAML", - description="Test YAML description" + name="TestYAML", description="Test YAML description" ) - + yaml_output = structure.to_yaml() - - assert yaml_output is not None, "YAML output should not be None" + + assert ( + yaml_output is not None + ), "YAML output should not be None" assert isinstance(yaml_output, str), "Should return a string" assert "TestYAML" in yaml_output, "Name should be in YAML" - + logger.info("✓ To YAML test passed") - + except Exception as e: logger.error(f"Error in test_to_yaml: {str(e)}") raise @@ -317,17 +434,18 @@ def test_to_toml(): """Test converting structure to TOML.""" try: structure = BaseStructure( - name="TestTOML", - description="Test TOML description" + name="TestTOML", description="Test TOML description" ) - + toml_output = structure.to_toml() - - assert toml_output is not None, "TOML output should not be None" + + assert ( + toml_output is not None + ), "TOML output should not be None" assert isinstance(toml_output, str), "Should return a string" - + logger.info("✓ To TOML test passed") - + except Exception as e: logger.error(f"Error in test_to_toml: {str(e)}") raise @@ -337,17 +455,17 @@ def test_run_async(): """Test async run method.""" try: structure = TestStructure(name="TestAsync") - + async def run_test(): result = await structure.run_async("test_task") return result - + result = asyncio.run(run_test()) - + assert result is not None, "Async result should not be None" - + logger.info("✓ Run async test passed") - + except Exception as e: logger.error(f"Error in test_run_async: {str(e)}") raise @@ -358,23 +476,24 @@ def test_save_metadata_async(): try: with tempfile.TemporaryDirectory() as tmpdir: structure = BaseStructure( - name="TestAsyncMetadata", - save_metadata_path=tmpdir + name="TestAsyncMetadata", save_metadata_path=tmpdir ) metadata = {"async": "test", "value": 123} - + async def save_test(): await structure.save_metadata_async(metadata) - + asyncio.run(save_test()) - + loaded = structure.load_metadata() - - assert loaded is not None, "Loaded metadata should not be None" + + assert ( + loaded is not None + ), "Loaded metadata should not be None" assert loaded["async"] == "test", "Metadata should match" - + logger.info("✓ Save metadata async test passed") - + except Exception as e: logger.error(f"Error in test_save_metadata_async: {str(e)}") raise @@ -385,22 +504,23 @@ def test_load_metadata_async(): try: with tempfile.TemporaryDirectory() as tmpdir: structure = BaseStructure( - name="TestAsyncLoad", - save_metadata_path=tmpdir + name="TestAsyncLoad", save_metadata_path=tmpdir ) metadata = {"load": "async", "number": 456} structure.save_metadata(metadata) - + async def load_test(): return await structure.load_metadata_async() - + loaded = asyncio.run(load_test()) - - assert loaded is not None, "Loaded metadata should not be None" + + assert ( + loaded is not None + ), "Loaded metadata should not be None" assert loaded["load"] == "async", "Metadata should match" - + logger.info("✓ Load metadata async test passed") - + except Exception as e: logger.error(f"Error in test_load_metadata_async: {str(e)}") raise @@ -411,23 +531,28 @@ def test_save_artifact_async(): try: with tempfile.TemporaryDirectory() as tmpdir: structure = BaseStructure( - name="TestAsyncArtifact", - save_artifact_path=tmpdir + name="TestAsyncArtifact", save_artifact_path=tmpdir ) artifact = {"async_artifact": True, "data": [1, 2, 3]} - + async def save_test(): - await structure.save_artifact_async(artifact, "async_artifact") - + await structure.save_artifact_async( + artifact, "async_artifact" + ) + asyncio.run(save_test()) - + loaded = structure.load_artifact("async_artifact") - - assert loaded is not None, "Loaded artifact should not be None" - assert loaded["async_artifact"] is True, "Artifact should match" - + + assert ( + loaded is not None + ), "Loaded artifact should not be None" + assert ( + loaded["async_artifact"] is True + ), "Artifact should match" + logger.info("✓ Save artifact async test passed") - + except Exception as e: logger.error(f"Error in test_save_artifact_async: {str(e)}") raise @@ -439,21 +564,27 @@ def test_load_artifact_async(): with tempfile.TemporaryDirectory() as tmpdir: structure = BaseStructure( name="TestAsyncLoadArtifact", - save_artifact_path=tmpdir + save_artifact_path=tmpdir, ) artifact = {"load_async": True, "items": ["a", "b", "c"]} structure.save_artifact(artifact, "load_async_artifact") - + async def load_test(): - return await structure.load_artifact_async("load_async_artifact") - + return await structure.load_artifact_async( + "load_async_artifact" + ) + loaded = asyncio.run(load_test()) - - assert loaded is not None, "Loaded artifact should not be None" - assert loaded["load_async"] is True, "Artifact should match" - + + assert ( + loaded is not None + ), "Loaded artifact should not be None" + assert ( + loaded["load_async"] is True + ), "Artifact should match" + logger.info("✓ Load artifact async test passed") - + except Exception as e: logger.error(f"Error in test_load_artifact_async: {str(e)}") raise @@ -466,21 +597,25 @@ def test_asave_and_aload_from_file(): structure = BaseStructure() test_file = os.path.join(tmpdir, "async_test.json") test_data = {"async": "file", "test": True} - + async def save_and_load(): await structure.asave_to_file(test_data, test_file) return await structure.aload_from_file(test_file) - + loaded = asyncio.run(save_and_load()) - - assert loaded is not None, "Loaded data should not be None" + + assert ( + loaded is not None + ), "Loaded data should not be None" assert loaded["async"] == "file", "Data should match" assert loaded["test"] is True, "Boolean should match" - + logger.info("✓ Async save and load from file test passed") - + except Exception as e: - logger.error(f"Error in test_asave_and_aload_from_file: {str(e)}") + logger.error( + f"Error in test_asave_and_aload_from_file: {str(e)}" + ) raise @@ -488,14 +623,14 @@ def test_run_in_thread(): """Test running in thread.""" try: structure = TestStructure(name="TestThread") - + future = structure.run_in_thread("thread_task") result = future.result() - + assert result is not None, "Thread result should not be None" - + logger.info("✓ Run in thread test passed") - + except Exception as e: logger.error(f"Error in test_run_in_thread: {str(e)}") raise @@ -506,23 +641,26 @@ def test_save_metadata_in_thread(): try: with tempfile.TemporaryDirectory() as tmpdir: structure = BaseStructure( - name="TestThreadMetadata", - save_metadata_path=tmpdir + name="TestThreadMetadata", save_metadata_path=tmpdir ) metadata = {"thread": "test", "value": 789} - + future = structure.save_metadata_in_thread(metadata) future.result() - + loaded = structure.load_metadata() - - assert loaded is not None, "Loaded metadata should not be None" + + assert ( + loaded is not None + ), "Loaded metadata should not be None" assert loaded["thread"] == "test", "Metadata should match" - + logger.info("✓ Save metadata in thread test passed") - + except Exception as e: - logger.error(f"Error in test_save_metadata_in_thread: {str(e)}") + logger.error( + f"Error in test_save_metadata_in_thread: {str(e)}" + ) raise @@ -531,19 +669,23 @@ def test_run_batched(): try: structure = TestStructure(name="TestBatched") batched_data = ["task1", "task2", "task3", "task4", "task5"] - + results = structure.run_batched(batched_data, batch_size=3) - + assert results is not None, "Results should not be None" assert isinstance(results, list), "Results should be a list" assert len(results) == 5, "Should have 5 results" - + for result in results: - assert result is not None, "Each result should not be None" - assert "Processed:" in result, "Result should contain processed message" - + assert ( + result is not None + ), "Each result should not be None" + assert ( + "Processed:" in result + ), "Result should contain processed message" + logger.info("✓ Run batched test passed") - + except Exception as e: logger.error(f"Error in test_run_batched: {str(e)}") raise @@ -556,18 +698,26 @@ def test_load_config(): structure = BaseStructure() config_file = os.path.join(tmpdir, "config.json") config_data = {"setting1": "value1", "setting2": 42} - + structure.save_to_file(config_data, config_file) - + loaded_config = structure.load_config(config_file) - - assert loaded_config is not None, "Loaded config should not be None" - assert isinstance(loaded_config, dict), "Config should be a dict" - assert loaded_config["setting1"] == "value1", "Config should match" - assert loaded_config["setting2"] == 42, "Config number should match" - + + assert ( + loaded_config is not None + ), "Loaded config should not be None" + assert isinstance( + loaded_config, dict + ), "Config should be a dict" + assert ( + loaded_config["setting1"] == "value1" + ), "Config should match" + assert ( + loaded_config["setting2"] == 42 + ), "Config number should match" + logger.info("✓ Load config test passed") - + except Exception as e: logger.error(f"Error in test_load_config: {str(e)}") raise @@ -580,22 +730,28 @@ def test_backup_data(): structure = BaseStructure() backup_path = os.path.join(tmpdir, "backups") os.makedirs(backup_path, exist_ok=True) - + backup_data = {"backup": "test", "items": [1, 2, 3]} - + structure.backup_data(backup_data, backup_path) - + backup_files = os.listdir(backup_path) - assert len(backup_files) > 0, "Backup file should be created" - + assert ( + len(backup_files) > 0 + ), "Backup file should be created" + backup_file = os.path.join(backup_path, backup_files[0]) loaded_backup = structure.load_from_file(backup_file) - - assert loaded_backup is not None, "Loaded backup should not be None" - assert loaded_backup["backup"] == "test", "Backup data should match" - + + assert ( + loaded_backup is not None + ), "Loaded backup should not be None" + assert ( + loaded_backup["backup"] == "test" + ), "Backup data should match" + logger.info("✓ Backup data test passed") - + except Exception as e: logger.error(f"Error in test_backup_data: {str(e)}") raise @@ -606,23 +762,28 @@ def test_monitor_resources(): try: with tempfile.TemporaryDirectory() as tmpdir: structure = BaseStructure( - name="TestResources", - save_metadata_path=tmpdir + name="TestResources", save_metadata_path=tmpdir ) - + structure.monitor_resources() - - event_file = os.path.join(tmpdir, "TestResources_events.log") - assert os.path.exists(event_file), "Event log should be created" - + + event_file = os.path.join( + tmpdir, "TestResources_events.log" + ) + assert os.path.exists( + event_file + ), "Event log should be created" + with open(event_file, "r") as f: content = f.read() - assert "Resource usage" in content, "Resource usage should be logged" + assert ( + "Resource usage" in content + ), "Resource usage should be logged" assert "Memory" in content, "Memory should be logged" assert "CPU" in content, "CPU should be logged" - + logger.info("✓ Monitor resources test passed") - + except Exception as e: logger.error(f"Error in test_monitor_resources: {str(e)}") raise @@ -633,19 +794,22 @@ def test_run_with_resources(): try: with tempfile.TemporaryDirectory() as tmpdir: structure = TestStructure( - name="TestRunResources", - save_metadata_path=tmpdir + name="TestRunResources", save_metadata_path=tmpdir ) - + result = structure.run_with_resources("monitored_task") - + assert result is not None, "Result should not be None" - - event_file = os.path.join(tmpdir, "TestRunResources_events.log") - assert os.path.exists(event_file), "Event log should be created" - + + event_file = os.path.join( + tmpdir, "TestRunResources_events.log" + ) + assert os.path.exists( + event_file + ), "Event log should be created" + logger.info("✓ Run with resources test passed") - + except Exception as e: logger.error(f"Error in test_run_with_resources: {str(e)}") raise @@ -656,45 +820,59 @@ def test_run_with_resources_batched(): try: with tempfile.TemporaryDirectory() as tmpdir: structure = TestStructure( - name="TestBatchedResources", - save_metadata_path=tmpdir + name="TestBatchedResources", save_metadata_path=tmpdir ) batched_data = ["task1", "task2", "task3"] - - results = structure.run_with_resources_batched(batched_data, batch_size=2) - + + results = structure.run_with_resources_batched( + batched_data, batch_size=2 + ) + assert results is not None, "Results should not be None" - assert isinstance(results, list), "Results should be a list" + assert isinstance( + results, list + ), "Results should be a list" assert len(results) == 3, "Should have 3 results" - - event_file = os.path.join(tmpdir, "TestBatchedResources_events.log") - assert os.path.exists(event_file), "Event log should be created" - + + event_file = os.path.join( + tmpdir, "TestBatchedResources_events.log" + ) + assert os.path.exists( + event_file + ), "Event log should be created" + logger.info("✓ Run with resources batched test passed") - + except Exception as e: - logger.error(f"Error in test_run_with_resources_batched: {str(e)}") + logger.error( + f"Error in test_run_with_resources_batched: {str(e)}" + ) raise def test_serialize_callable(): """Test serializing callable attributes.""" try: + def test_function(): """Test function docstring.""" pass - + structure = BaseStructure() serialized = structure._serialize_callable(test_function) - - assert serialized is not None, "Serialized callable should not be None" + + assert ( + serialized is not None + ), "Serialized callable should not be None" assert isinstance(serialized, dict), "Should return a dict" assert "name" in serialized, "Should have name" assert "doc" in serialized, "Should have doc" - assert serialized["name"] == "test_function", "Name should match" - + assert ( + serialized["name"] == "test_function" + ), "Name should match" + logger.info("✓ Serialize callable test passed") - + except Exception as e: logger.error(f"Error in test_serialize_callable: {str(e)}") raise @@ -704,21 +882,33 @@ def test_serialize_attr(): """Test serializing attributes.""" try: structure = BaseStructure() - - serialized_str = structure._serialize_attr("test_attr", "test_value") - assert serialized_str == "test_value", "String should serialize correctly" - - serialized_dict = structure._serialize_attr("test_attr", {"key": "value"}) - assert serialized_dict == {"key": "value"}, "Dict should serialize correctly" - + + serialized_str = structure._serialize_attr( + "test_attr", "test_value" + ) + assert ( + serialized_str == "test_value" + ), "String should serialize correctly" + + serialized_dict = structure._serialize_attr( + "test_attr", {"key": "value"} + ) + assert serialized_dict == { + "key": "value" + }, "Dict should serialize correctly" + def test_func(): pass - - serialized_func = structure._serialize_attr("test_func", test_func) - assert isinstance(serialized_func, dict), "Function should serialize to dict" - + + serialized_func = structure._serialize_attr( + "test_func", test_func + ) + assert isinstance( + serialized_func, dict + ), "Function should serialize to dict" + logger.info("✓ Serialize attr test passed") - + except Exception as e: logger.error(f"Error in test_serialize_attr: {str(e)}") raise @@ -726,7 +916,7 @@ def test_serialize_attr(): if __name__ == "__main__": import sys - + test_dict = { "test_base_structure_initialization": test_base_structure_initialization, "test_save_and_load_file": test_save_and_load_file, @@ -756,7 +946,7 @@ if __name__ == "__main__": "test_serialize_callable": test_serialize_callable, "test_serialize_attr": test_serialize_attr, } - + if len(sys.argv) > 1: requested_tests = [] for test_name in sys.argv[1:]: @@ -767,21 +957,23 @@ if __name__ == "__main__": break else: print(f"⚠ Warning: Test '{test_name}' not found.") - print(f"Available tests: {', '.join(test_dict.keys())}") + print( + f"Available tests: {', '.join(test_dict.keys())}" + ) sys.exit(1) - + tests_to_run = requested_tests else: tests_to_run = list(test_dict.values()) - + if len(tests_to_run) == 1: print(f"Running: {tests_to_run[0].__name__}") else: print(f"Running {len(tests_to_run)} test(s)...") - + passed = 0 failed = 0 - + for test_func in tests_to_run: try: print(f"\n{'='*60}") @@ -794,17 +986,21 @@ if __name__ == "__main__": print(f"✗ FAILED: {test_func.__name__}") print(f" Error: {str(e)}") import traceback + traceback.print_exc() failed += 1 - + print(f"\n{'='*60}") print(f"Test Summary: {passed} passed, {failed} failed") print(f"{'='*60}") - + if len(sys.argv) == 1: print("\n💡 Tip: Run a specific test with:") - print(" python test_base_structure.py test_base_structure_initialization") + print( + " python test_base_structure.py test_base_structure_initialization" + ) print("\n Or use pytest:") print(" pytest test_base_structure.py") - print(" pytest test_base_structure.py::test_base_structure_initialization") - + print( + " pytest test_base_structure.py::test_base_structure_initialization" + )