From d6b006c4fa79d52c409017c3ac7a20cdeb2186d8 Mon Sep 17 00:00:00 2001 From: Kye Gomez Date: Wed, 3 Sep 2025 16:23:40 -0700 Subject: [PATCH] [Improvement][HeavySwarm][Added tools to the agents and also initialized the agents in the __init__ removed the self.agents parameter] [improved the docs as well] --- docs/swarms/structs/heavy_swarm.md | 808 +++++++++++++++--- example.py | 1 + .../guides/hiearchical_marketing_team.py | 0 .../mcp/deploy_mcp_server/mcp_agent_tool.py | 8 +- .../deploy_mcp_server/multiagent_client.py | 40 +- .../deploy_mcp_server/singleagent_client.py | 46 +- .../heavy_swarm_example.py | 32 - .../majority_voting/snake_game_code_voting.py | 0 heavy_swarm_example.py | 27 + swarms/structs/heavy_swarm.py | 45 +- swarms/tools/tool_type.py | 7 + swarms/utils/litellm_wrapper.py | 79 +- 12 files changed, 832 insertions(+), 261 deletions(-) rename hiearchical_marketing_team.py => examples/guides/hiearchical_marketing_team.py (100%) delete mode 100644 examples/multi_agent/heavy_swarm_examples/heavy_swarm_example.py rename snake_game_code_voting.py => examples/multi_agent/majority_voting/snake_game_code_voting.py (100%) create mode 100644 heavy_swarm_example.py create mode 100644 swarms/tools/tool_type.py diff --git a/docs/swarms/structs/heavy_swarm.md b/docs/swarms/structs/heavy_swarm.md index 0cfa20c9..f40b9e5f 100644 --- a/docs/swarms/structs/heavy_swarm.md +++ b/docs/swarms/structs/heavy_swarm.md @@ -6,8 +6,6 @@ Inspired by X.AI's Grok 4 heavy implementation, HeavySwarm provides robust task ## Architecture -### System Design - The HeavySwarm follows a structured 5-phase workflow: 1. **Task Decomposition**: Complex tasks are broken down into specialized questions @@ -18,11 +16,13 @@ The HeavySwarm follows a structured 5-phase workflow: ### Agent Specialization -- **Research Agent**: Comprehensive information gathering and synthesis -- **Analysis Agent**: Pattern recognition and statistical analysis -- **Alternatives Agent**: Creative problem-solving and strategic options -- **Verification Agent**: Validation, feasibility assessment, and quality assurance -- **Synthesis Agent**: Multi-perspective integration and executive reporting +| Agent | Role/Function | +|---------------------|--------------------------------------------------------------------| +| **Research Agent** | Comprehensive information gathering and synthesis | +| **Analysis Agent** | Pattern recognition and statistical analysis | +| **Alternatives Agent** | Creative problem-solving and strategic options | +| **Verification Agent** | Validation, feasibility assessment, and quality assurance | +| **Synthesis Agent** | Multi-perspective integration and executive reporting | ## Architecture Diagram @@ -81,21 +81,32 @@ pip install swarms ## Quick Start ```python -from swarms import HeavySwarm +from swarms.structs.heavy_swarm import HeavySwarm +from swarms_tools import exa_search -# Initialize the swarm swarm = HeavySwarm( - name="MarketAnalysisSwarm", - description="Financial market analysis swarm", - question_agent_model_name="gpt-4o-mini", - worker_model_name="gpt-4o-mini", + name="Gold ETF Research Team", + description="A team of agents that research the best gold ETFs", + worker_model_name="claude-sonnet-4-20250514", show_dashboard=True, - verbose=True + question_agent_model_name="gpt-4.1", + loops_per_agent=1, + agent_prints_on=False, + worker_tools=[exa_search], + random_loops_per_agent=True, ) -# Execute analysis -result = swarm.run("Analyze the current cryptocurrency market trends and investment opportunities") -print(result) +prompt = ( + "Find the best 3 gold ETFs. For each ETF, provide the ticker symbol, " + "full name, current price, expense ratio, assets under management, and " + "a brief explanation of why it is considered among the best. Present the information " + "in a clear, structured format suitable for investors. Scrape the data from the web. " +) + +out = swarm.run(prompt) +print(out) + + ``` ## API Reference @@ -107,17 +118,38 @@ print(result) | Parameter | Type | Default | Description | |-----------|------|---------|-------------| | `name` | `str` | `"HeavySwarm"` | Identifier name for the swarm instance | -| `description` | `str` | `"A swarm of agents..."` | Description of the swarm's purpose | -| `agents` | `List[Agent]` | `None` | Pre-configured agent list (unused - agents created internally) | +| `description` | `str` | `"A swarm of agents that can analyze a task and generate specialized questions for each agent role"` | Description of the swarm's purpose and capabilities | | `timeout` | `int` | `300` | Maximum execution time per agent in seconds | -| `aggregation_strategy` | `str` | `"synthesis"` | Strategy for result aggregation | -| `loops_per_agent` | `int` | `1` | Number of execution loops per agent | -| `question_agent_model_name` | `str` | `"gpt-4o-mini"` | Model for question generation | -| `worker_model_name` | `str` | `"gpt-4o-mini"` | Model for specialized worker agents | -| `verbose` | `bool` | `False` | Enable detailed logging output | -| `max_workers` | `int` | `int(os.cpu_count() * 0.9)` | Maximum concurrent workers | -| `show_dashboard` | `bool` | `False` | Enable rich dashboard visualization | +| `aggregation_strategy` | `str` | `"synthesis"` | Strategy for result aggregation (currently only 'synthesis' is supported) | +| `loops_per_agent` | `int` | `1` | Number of execution loops each agent should perform | +| `question_agent_model_name` | `str` | `"gpt-4o-mini"` | Language model for question generation | +| `worker_model_name` | `str` | `"gpt-4o-mini"` | Language model for specialized worker agents | +| `verbose` | `bool` | `False` | Enable detailed logging and debug output | +| `max_workers` | `int` | `int(os.cpu_count() * 0.9)` | Maximum concurrent workers for parallel execution | +| `show_dashboard` | `bool` | `False` | Enable rich dashboard with progress visualization | | `agent_prints_on` | `bool` | `False` | Enable individual agent output printing | +| `output_type` | `str` | `"dict-all-except-first"` | Output formatting type for conversation history | +| `worker_tools` | `tool_type` | `None` | Tools available to worker agents for enhanced functionality | +| `random_loops_per_agent` | `bool` | `False` | Enable random number of loops per agent (1-10 range) | + +**Constructor Example:** +```python +swarm = HeavySwarm( + name="AdvancedAnalysisSwarm", + description="Comprehensive multi-agent analysis system", + timeout=600, + loops_per_agent=2, + question_agent_model_name="gpt-4o", + worker_model_name="gpt-4o", + verbose=True, + max_workers=8, + show_dashboard=True, + agent_prints_on=True, + output_type="dict-all-except-first", + worker_tools=None, + random_loops_per_agent=False +) +``` #### Methods @@ -127,9 +159,10 @@ Execute the complete HeavySwarm orchestration flow. **Parameters:** -- `task` (str): The main task to analyze and decompose - -- `img` (str, optional): Image input for visual analysis tasks +| Parameter | Type | Required | Default | Description | +|-----------|------|----------|---------|-------------| +| `task` | `str` | Yes | - | The main task to analyze and decompose | +| `img` | `str` | No | `None` | Image input for visual analysis tasks | **Returns:** - `str`: Comprehensive final analysis from synthesis agent @@ -137,186 +170,683 @@ Execute the complete HeavySwarm orchestration flow. **Example:** ```python result = swarm.run("Develop a go-to-market strategy for a new SaaS product") +print(result) ``` +--- + +##### `get_questions_only(task: str) -> Dict[str, str]` + +Generate and extract only the specialized questions without metadata or execution. + +**Parameters:** -## Real-World Applications +| Parameter | Type | Required | Default | Description | +|-----------|------|----------|---------|-------------| +| `task` | `str` | Yes | - | The main task or query to analyze and decompose into specialized questions | -### Financial Services +**Returns:** +- `Dict[str, str]`: Clean dictionary containing only the questions: + - `research_question` (str): Question for comprehensive information gathering + - `analysis_question` (str): Question for pattern analysis and insights + - `alternatives_question` (str): Question for exploring creative solutions + - `verification_question` (str): Question for validation and feasibility + - `error` (str): Error message if question generation fails (on error only) +**Example:** ```python -# Market Analysis -swarm = HeavySwarm( - name="FinanceSwarm", - worker_model_name="gpt-4o", - show_dashboard=True -) +questions = swarm.get_questions_only("Analyze market trends for EVs") +print(questions['research_question']) +print(questions['analysis_question']) +``` + +--- + +##### `get_questions_as_list(task: str) -> List[str]` + +Generate specialized questions and return them as an ordered list. + +**Parameters:** + +| Parameter | Type | Required | Default | Description | +|-----------|------|----------|---------|-------------| +| `task` | `str` | Yes | - | The main task or query to decompose into specialized questions | + +**Returns:** +- `List[str]`: Ordered list of 4 specialized questions: + - `[0]` Research question for comprehensive information gathering + - `[1]` Analysis question for pattern analysis and insights + - `[2]` Alternatives question for exploring creative solutions + - `[3]` Verification question for validation and feasibility assessment + - Single-item list containing error message (on error) + +**Example:** +```python +questions = swarm.get_questions_as_list("Optimize supply chain efficiency") +for i, question in enumerate(questions): + print(f"Agent {i+1}: {question}") +``` + +--- + +##### `show_swarm_info() -> None` + +Display comprehensive swarm configuration information in a rich dashboard format. + +**Parameters:** +- None + +**Returns:** +- `None`: This method only displays output and has no return value. + +**Example:** +```python +swarm.show_swarm_info() # Displays configuration dashboard +``` + +--- + +##### `reliability_check() -> None` + +Perform comprehensive reliability and configuration validation checks. + +**Parameters:** +- None + +**Returns:** +- `None`: This method only performs validation and has no return value. + +**Raises:** +- `ValueError`: If loops_per_agent is 0 or negative (agents won't execute) +- `ValueError`: If worker_model_name is None (agents can't be created) +- `ValueError`: If question_agent_model_name is None (questions can't be generated) + +**Example:** +```python +try: + swarm.reliability_check() # Automatically called in __init__ + print("All checks passed!") +except ValueError as e: + print(f"Configuration error: {e}") +``` + +--- + +##### `create_agents() -> Dict[str, Agent]` + +Create and cache the 4 specialized agents with detailed role-specific prompts. + +**Parameters:** +- None + +**Returns:** +- `Dict[str, Agent]`: Dictionary containing all 5 specialized agents: + - `'research'`: Research Agent instance + - `'analysis'`: Analysis Agent instance + - `'alternatives'`: Alternatives Agent instance + - `'verification'`: Verification Agent instance + - `'synthesis'`: Synthesis Agent instance -result = swarm.run(""" -Analyze the impact of recent Federal Reserve policy changes on: -1. Bond markets and yield curves -2. Equity market valuations -3. Currency exchange rates -4. Provide investment recommendations for institutional portfolios -""") +**Example:** +```python +agents = swarm.create_agents() +research_agent = agents['research'] +print(f"Research agent name: {research_agent.agent_name}") ``` -### Use-cases +## Comprehensive Full-Code Examples -| Use Case | Description | -|---------------------------------------------|---------------------------------------------| -| Portfolio optimization and risk assessment | Optimize asset allocation and assess risks | -| Market trend analysis and forecasting | Analyze and predict market movements | -| Regulatory compliance evaluation | Evaluate adherence to financial regulations | -| Investment strategy development | Develop and refine investment strategies | -| Credit risk analysis and modeling | Analyze and model credit risk | +### Example 1: Basic Gold ETF Research with Dashboard +```python +# heavy_swarm_example.py +""" +Complete example demonstrating HeavySwarm for financial research +with dashboard visualization and tool integration. +""" -------- +from swarms.structs.heavy_swarm import HeavySwarm +from swarms_tools import exa_search +# Initialize HeavySwarm with comprehensive configuration +swarm = HeavySwarm( + name="Gold ETF Research Team", + description="A team of agents that research the best gold ETFs", + worker_model_name="claude-sonnet-4-20250514", + question_agent_model_name="gpt-4o-mini", + show_dashboard=True, + loops_per_agent=1, + agent_prints_on=False, + worker_tools=[exa_search], + random_loops_per_agent=False, + timeout=300, + max_workers=4, + verbose=True +) -### Healthcare & Life Sciences +# Define the research prompt +prompt = ( + "Find the best 3 gold ETFs. For each ETF, provide the ticker symbol, " + "full name, current price, expense ratio, assets under management, and " + "a brief explanation of why it is considered among the best. Present the information " + "in a clear, structured format suitable for investors. Scrape the data from the web." +) + +# Execute the analysis +print("šŸš€ Starting HeavySwarm analysis...") +result = swarm.run(prompt) + +print("\nšŸ“Š Analysis Complete!") +print("=" * 50) +print(result) +``` + +### Example 2: Advanced Market Analysis with Multiple Loops ```python -# Clinical Research Analysis +# advanced_market_analysis.py +""" +Advanced example with multiple agent loops and comprehensive market analysis. +""" + +from swarms.structs.heavy_swarm import HeavySwarm +from swarms_tools import exa_search, calculator, web_scraper + +# Advanced configuration for in-depth analysis swarm = HeavySwarm( - name="HealthcareSwarm", + name="AdvancedMarketAnalysis", + description="Comprehensive market analysis with multiple iterations", worker_model_name="gpt-4o", - timeout=600, - loops_per_agent=2 + question_agent_model_name="gpt-4o", + show_dashboard=True, + loops_per_agent=3, # Multiple iterations for deeper analysis + agent_prints_on=True, + worker_tools=[exa_search, calculator, web_scraper], + random_loops_per_agent=False, + timeout=600, # Longer timeout for complex analysis + max_workers=8, + verbose=True ) -result = swarm.run(""" -Evaluate the potential of AI-driven personalized medicine: -1. Current technological capabilities and limitations -2. Regulatory landscape and approval pathways -3. Market opportunities and competitive analysis -4. Implementation strategies for healthcare systems -""") -``` +# Complex multi-dimensional analysis prompt +complex_prompt = """ +Conduct a comprehensive analysis of the renewable energy sector: ----- +1. Market Size & Growth: + - Current global market size + - Projected growth rates (5-year and 10-year) + - Key growth drivers and barriers -**Use Cases:** +2. Technology Landscape: + - Dominant technologies (solar, wind, hydro, etc.) + - Emerging technologies and innovations + - Technology adoption rates by region -| Use Case | Description | -|----------------------------------------|---------------------------------------------| -| Drug discovery and development analysis| Analyze and accelerate drug R&D processes | -| Clinical trial optimization | Improve design and efficiency of trials | -| Healthcare policy evaluation | Assess and inform healthcare policies | -| Medical device market analysis | Evaluate trends and opportunities in devices| -| Patient outcome prediction modeling | Predict and model patient health outcomes | +3. Investment Opportunities: + - Most promising investment sectors + - Risk assessment and mitigation strategies + - Return on investment projections ---- +4. Regulatory Environment: + - Current policy frameworks + - Upcoming regulatory changes + - Impact on industry development + +5. Competitive Analysis: + - Key players and market share + - Competitive advantages and disadvantages + - Market consolidation trends +Provide detailed analysis with data sources, assumptions, and confidence levels. +""" -### Technology & Innovation +print("šŸ”¬ Starting advanced market analysis...") +result = swarm.run(complex_prompt) +print(result) +``` + +### Example 3: Healthcare Policy Analysis with Random Loops ```python -# Tech Strategy Analysis +# healthcare_policy_analysis.py +""" +Healthcare policy analysis with random agent loops for diverse perspectives. +""" + +from swarms.structs.heavy_swarm import HeavySwarm +from swarms_tools import exa_search, data_analyzer, policy_tracker + +# Healthcare-focused configuration with random loops swarm = HeavySwarm( - name="TechSwarm", + name="HealthcarePolicyAnalyzer", + description="Multi-perspective healthcare policy analysis", worker_model_name="gpt-4o", + question_agent_model_name="gpt-4o-mini", show_dashboard=True, + loops_per_agent=1, # Base loops (will be randomized) + agent_prints_on=False, + worker_tools=[exa_search, data_analyzer, policy_tracker], + random_loops_per_agent=True, # Enable random loop variation + timeout=900, + max_workers=6, verbose=True ) -result = swarm.run(""" -Assess the strategic implications of quantum computing adoption: -1. Technical readiness and hardware developments -2. Industry applications and use cases -3. Competitive landscape and key players -4. Investment and implementation roadmap -""") +# Healthcare policy analysis prompt +healthcare_prompt = """ +Analyze the impact of recent healthcare policy changes on: + +1. **Access to Care**: + - Changes in healthcare accessibility + - Impact on underserved populations + - Telemedicine adoption and effectiveness + +2. **Cost Implications**: + - Healthcare spending trends + - Insurance premium changes + - Out-of-pocket expense analysis + +3. **Quality of Care**: + - Patient outcome metrics + - Provider satisfaction and retention + - Innovation in treatment protocols + +4. **Healthcare Workforce**: + - Staffing shortages and surpluses + - Training and education requirements + - Compensation and benefits trends + +5. **Technology Integration**: + - Electronic health records adoption + - AI and machine learning applications + - Cybersecurity and data privacy + +Provide evidence-based analysis with statistical data and policy recommendations. +""" + +print("šŸ„ Starting healthcare policy analysis...") +result = swarm.run(healthcare_prompt) +print(result) ``` -**Use Cases:** +### Example 4: Question Generation and Preview + +```python +# question_generation_example.py +""" +Example demonstrating question generation capabilities without full execution. +""" + +from swarms.structs.heavy_swarm import HeavySwarm + +# Configure swarm for question generation +swarm = HeavySwarm( + name="QuestionGenerator", + description="Specialized question generation for task analysis", + question_agent_model_name="gpt-4o", + worker_model_name="gpt-4o-mini", + show_dashboard=False, # No dashboard for clean output + verbose=False +) -| Use Case | Description | -|------------------------------------|---------------------------------------------| -| Technology roadmap development | Plan and prioritize technology initiatives | -| Competitive intelligence gathering | Analyze competitors and market trends | -| Innovation pipeline analysis | Evaluate and manage innovation projects | -| Digital transformation strategy | Develop and implement digital strategies | -| Emerging technology assessment | Assess new and disruptive technologies | +# Sample task for analysis +task = "Develop a comprehensive digital transformation strategy for a traditional manufacturing company" + +print("šŸ” Generating specialized questions...") +print("=" * 60) + +# Method 1: Get questions as dictionary +questions_dict = swarm.get_questions_only(task) +print("\nšŸ“‹ Questions as Dictionary:") +for key, question in questions_dict.items(): + if key != 'error': + print(f"\n{key.upper()}:") + print(f"{question}") + +# Method 2: Get questions as ordered list +questions_list = swarm.get_questions_as_list(task) +print("\n\nšŸ“ Questions as Ordered List:") +for i, question in enumerate(questions_list): + agent_names = ["Research Agent", "Analysis Agent", "Alternatives Agent", "Verification Agent"] + print(f"\n{i+1}. {agent_names[i]}:") + print(f" {question}") + +print("\n" + "=" * 60) +print("šŸ’” Use these questions to understand how HeavySwarm decomposes complex tasks!") +``` -### Manufacturing & Supply Chain +### Example 5: High-Performance Configuration for Enterprise Use ```python -# Supply Chain Optimization +# enterprise_configuration.py +""" +Enterprise-grade HeavySwarm configuration for high-performance analysis. +""" + +from swarms.structs.heavy_swarm import HeavySwarm +from swarms_tools import exa_search, data_analyzer, financial_modeler, risk_assessor + +# Enterprise configuration with maximum performance swarm = HeavySwarm( - name="ManufacturingSwarm", - worker_model_name="gpt-4o", - max_workers=8 + name="EnterpriseAnalysisSwarm", + description="High-performance enterprise analysis system", + worker_model_name="gpt-4o", # Highest quality model + question_agent_model_name="gpt-4o", # Consistent high quality + show_dashboard=True, + loops_per_agent=5, # Maximum depth analysis + agent_prints_on=False, # Clean output for enterprise use + worker_tools=[ + exa_search, + data_analyzer, + financial_modeler, + risk_assessor + ], + random_loops_per_agent=False, # Consistent analysis depth + timeout=1800, # 30 minutes for complex analysis + max_workers=16, # Maximum parallelization + verbose=True # Full logging for enterprise monitoring ) -result = swarm.run(""" -Optimize global supply chain resilience: -1. Risk assessment and vulnerability analysis -2. Alternative sourcing strategies -3. Technology integration opportunities -4. Cost-benefit analysis of proposed changes -""") +# Enterprise-level analysis prompt +enterprise_prompt = """ +Conduct an enterprise-grade analysis for a Fortune 500 company's strategic planning: + +EXECUTIVE SUMMARY REQUIREMENTS: +- Strategic positioning analysis +- Competitive landscape assessment +- Market opportunity evaluation +- Risk mitigation strategies + +FINANCIAL ANALYSIS: +- Revenue optimization scenarios +- Cost structure analysis +- Investment requirement assessment +- ROI projections and sensitivity analysis + +OPERATIONAL ASSESSMENT: +- Process optimization opportunities +- Technology integration roadmap +- Supply chain resilience evaluation +- Human capital strategy development + +MARKET INTELLIGENCE: +- Customer segmentation analysis +- Competitive intelligence gathering +- Market trend forecasting +- Disruption risk assessment + +STRATEGIC RECOMMENDATIONS: +- Short-term tactical initiatives (0-12 months) +- Medium-term strategic projects (1-3 years) +- Long-term transformation roadmap (3-5 years) +- Success metrics and KPIs + +Provide analysis with executive-level presentation, detailed financial modeling, +and implementation roadmaps with measurable outcomes. +""" + +print("šŸ¢ Starting enterprise-grade analysis...") +print("⚔ This configuration uses maximum resources for comprehensive analysis") + +result = swarm.run(enterprise_prompt) +print(result) ``` -**Use Cases:** +### Example 6: Error Handling and Reliability Testing + +```python +# error_handling_example.py +""" +Example demonstrating error handling and reliability features. +""" + +from swarms.structs.heavy_swarm import HeavySwarm + +print("šŸ›”ļø Testing HeavySwarm Reliability Features") +print("=" * 50) + +# Test 1: Valid configuration +print("\nāœ… Test 1: Valid Configuration") +try: + swarm = HeavySwarm( + name="ReliabilityTest", + description="Testing valid configuration", + worker_model_name="gpt-4o-mini", + question_agent_model_name="gpt-4o-mini", + show_dashboard=False + ) + print("āœ“ Swarm initialized successfully") +except Exception as e: + print(f"āœ— Unexpected error: {e}") + +# Test 2: Invalid loops_per_agent +print("\nāŒ Test 2: Invalid loops_per_agent (should fail)") +try: + swarm = HeavySwarm( + name="InvalidTest", + worker_model_name="gpt-4o-mini", + question_agent_model_name="gpt-4o-mini", + loops_per_agent=0, # Invalid: must be > 0 + show_dashboard=False + ) +except ValueError as e: + print(f"āœ“ Expected error caught: {e}") + +# Test 3: Missing worker_model_name +print("\nāŒ Test 3: Missing worker_model_name (should fail)") +try: + swarm = HeavySwarm( + name="MissingModelTest", + question_agent_model_name="gpt-4o-mini", + worker_model_name=None, # Invalid: cannot be None + show_dashboard=False + ) +except ValueError as e: + print(f"āœ“ Expected error caught: {e}") + +# Test 4: Successful question generation with error handling +print("\nšŸ” Test 4: Question Generation with Error Handling") +swarm = HeavySwarm( + name="ErrorHandlingTest", + worker_model_name="gpt-4o-mini", + question_agent_model_name="gpt-4o-mini", + show_dashboard=False +) + +test_task = "Analyze the future of artificial intelligence in healthcare" -| Use Case | Description | -|----------------------------------|---------------------------------------------| -| Supply chain risk management | Identify and mitigate supply chain risks | -| Manufacturing process optimization | Improve efficiency and productivity | -| Quality control system design | Develop systems to ensure product quality | -| Sustainability impact assessment | Evaluate environmental and social impacts | -| Logistics network optimization | Enhance logistics and distribution networks | +try: + questions = swarm.get_questions_only(test_task) + if 'error' in questions: + print(f"āœ— Question generation failed: {questions['error']}") + else: + print("āœ“ Question generation successful") + print(f"āœ“ Generated {len(questions)} specialized questions") +except Exception as e: + print(f"āœ— Unexpected error during question generation: {e}") -## Advanced Configuration +print("\n" + "=" * 50) +print("šŸ›”ļø Reliability testing complete!") +``` -### Custom Agent Configuration +### Example 7: Custom Tools Integration ```python -# High-performance configuration +# custom_tools_example.py +""" +Example demonstrating custom tools integration with HeavySwarm. +""" + +from swarms.structs.heavy_swarm import HeavySwarm +from swarms_tools import exa_search, calculator, web_scraper + +# Custom tool functions (simplified examples) +def custom_data_analyzer(data): + """Custom data analysis tool""" + return f"Analyzed data: {len(data)} records processed" + +def custom_report_generator(topic): + """Custom report generation tool""" + return f"Generated comprehensive report on: {topic}" + +def custom_risk_assessor(scenario): + """Custom risk assessment tool""" + return f"Risk assessment completed for: {scenario}" + +# Create custom tool objects (simplified) +custom_tools = [ + exa_search, # Built-in tool + calculator, # Built-in tool + web_scraper, # Built-in tool + # Note: In practice, you'd wrap custom functions in proper tool format +] + +# Initialize swarm with custom tools swarm = HeavySwarm( - name="HighPerformanceSwarm", - question_agent_model_name="gpt-4o", + name="CustomToolsSwarm", + description="HeavySwarm with custom tool integration", worker_model_name="gpt-4o", - timeout=900, - loops_per_agent=3, - max_workers=12, + question_agent_model_name="gpt-4o-mini", show_dashboard=True, + loops_per_agent=2, + agent_prints_on=True, + worker_tools=custom_tools, + random_loops_per_agent=False, + timeout=600, + max_workers=6, verbose=True ) -``` +# Analysis task that benefits from custom tools +analysis_prompt = """ +Conduct a comprehensive competitive intelligence analysis: -## Troubleshooting +1. **Market Research**: + - Use web scraping to gather competitor data + - Analyze market positioning and strategies + - Identify competitive advantages and weaknesses -| Issue | Solution | -|-------------------------|---------------------------------------------------------------| -| **Agent Timeout** | Increase timeout parameter or reduce task complexity | -| **Model Rate Limits** | Implement backoff strategies or use different models | -| **Memory Usage** | Monitor system resources with large-scale operations | -| **Dashboard Performance** | Disable dashboard for batch processing | +2. **Financial Analysis**: + - Calculate market share percentages + - Analyze revenue growth trends + - Assess profitability metrics -## Contributing +3. **Risk Assessment**: + - Evaluate competitive threats + - Analyze market entry barriers + - Assess disruption risks -HeavySwarm is part of the Swarms ecosystem. Contributions are welcome for: +4. **Strategic Recommendations**: + - Develop competitive response strategies + - Identify partnership opportunities + - Recommend market positioning adjustments -- New agent specializations +Use available tools to gather and analyze real-time data for accurate insights. +""" -- Performance optimizations +print("šŸ”§ Starting analysis with custom tools integration...") +result = swarm.run(analysis_prompt) +print(result) +``` -- Integration capabilities +### Example 8: Batch Processing Multiple Tasks -- Documentation improvements +```python +# batch_processing_example.py +""" +Example demonstrating batch processing of multiple tasks with HeavySwarm. +""" + +from swarms.structs.heavy_swarm import HeavySwarm +from typing import List, Dict +import time + +def batch_process_tasks(swarm: HeavySwarm, tasks: List[str]) -> Dict[str, str]: + """ + Process multiple tasks in batch with progress tracking. + + Args: + swarm: Configured HeavySwarm instance + tasks: List of task descriptions to process + + Returns: + Dictionary mapping task descriptions to results + """ + results = {} + + print(f"šŸš€ Starting batch processing of {len(tasks)} tasks") + print("=" * 60) + + for i, task in enumerate(tasks, 1): + print(f"\nšŸ“‹ Task {i}/{len(tasks)}") + print(f"Query: {task[:100]}{'...' if len(task) > 100 else ''}") + print("-" * 40) + + start_time = time.time() + try: + result = swarm.run(task) + processing_time = time.time() - start_time + + results[task] = result + print(".2f" + except Exception as e: + results[task] = f"Error: {str(e)}" + print(f"āŒ Failed after {time.time() - start_time:.2f}s: {e}") + + return results + +# Configure swarm for batch processing (minimal output for efficiency) +swarm = HeavySwarm( + name="BatchProcessor", + description="Efficient batch processing configuration", + worker_model_name="gpt-4o-mini", # Faster model for batch processing + question_agent_model_name="gpt-4o-mini", + show_dashboard=False, # Disable dashboard for batch processing + loops_per_agent=1, # Single loop for efficiency + agent_prints_on=False, # Clean output + random_loops_per_agent=False, + timeout=300, + max_workers=4, + verbose=False # Minimal logging +) +# Define batch tasks +batch_tasks = [ + "Analyze the impact of remote work on commercial real estate", + "Evaluate the potential of electric vehicles in the taxi industry", + "Assess the cybersecurity risks of IoT devices in smart homes", + "Explore the applications of blockchain in supply chain management", + "Investigate the effects of social media on consumer behavior", + "Review the potential of quantum computing in drug discovery", + "Analyze the economic impact of climate change policies", + "Evaluate the future of autonomous delivery systems" +] + +# Process batch +batch_results = batch_process_tasks(swarm, batch_tasks) + +# Summary report +print("\n" + "=" * 60) +print("šŸ“Š BATCH PROCESSING SUMMARY") +print("=" * 60) +print(f"Total tasks processed: {len(batch_results)}") +successful_tasks = sum(1 for result in batch_results.values() if not result.startswith("Error:")) +print(f"Successful tasks: {successful_tasks}") +print(f"Failed tasks: {len(batch_results) - successful_tasks}") + +# Display results summary +print("\nšŸ“ RESULTS SUMMARY:") +for i, (task, result) in enumerate(batch_results.items(), 1): + status = "āœ…" if not result.startswith("Error:") else "āŒ" + print(f"{i}. {status} {task[:50]}{'...' if len(task) > 50 else ''}") + +print("\nšŸ’” Batch processing complete! Individual results available in batch_results dictionary.") +``` ## Acknowledgments - Inspired by X.AI's Grok heavy implementation - - Built on the Swarms framework - - Utilizes Rich for dashboard visualization - - Powered by advanced language models diff --git a/example.py b/example.py index 3e0c9d3c..0963b6f2 100644 --- a/example.py +++ b/example.py @@ -9,6 +9,7 @@ agent = Agent( max_loops=1, dynamic_context_window=True, streaming_on=False, + print_on=False, ) out = agent.run( diff --git a/hiearchical_marketing_team.py b/examples/guides/hiearchical_marketing_team.py similarity index 100% rename from hiearchical_marketing_team.py rename to examples/guides/hiearchical_marketing_team.py diff --git a/examples/mcp/deploy_mcp_server/mcp_agent_tool.py b/examples/mcp/deploy_mcp_server/mcp_agent_tool.py index 8fbfefea..dcaf9b04 100644 --- a/examples/mcp/deploy_mcp_server/mcp_agent_tool.py +++ b/examples/mcp/deploy_mcp_server/mcp_agent_tool.py @@ -3,11 +3,14 @@ from swarms import Agent mcp = FastMCP("MCPAgentTool") + @mcp.tool( name="create_agent", description="Create an agent with the specified name, system prompt, and model, then run a task.", ) -def create_agent(agent_name: str, system_prompt: str, model_name: str, task: str) -> str: +def create_agent( + agent_name: str, system_prompt: str, model_name: str, task: str +) -> str: """ Create an agent with the given parameters and execute the specified task. @@ -27,5 +30,6 @@ def create_agent(agent_name: str, system_prompt: str, model_name: str, task: str ) return agent.run(task) + if __name__ == "__main__": - mcp.run(transport="streamable-http") \ No newline at end of file + mcp.run(transport="streamable-http") diff --git a/examples/mcp/deploy_mcp_server/multiagent_client.py b/examples/mcp/deploy_mcp_server/multiagent_client.py index af1bda6b..720a0531 100644 --- a/examples/mcp/deploy_mcp_server/multiagent_client.py +++ b/examples/mcp/deploy_mcp_server/multiagent_client.py @@ -5,7 +5,10 @@ from mcp.client.streamable_http import ( streamablehttp_client as http_client, ) -async def create_agent_via_mcp(session, agent_name, system_prompt, model_name, task): + +async def create_agent_via_mcp( + session, agent_name, system_prompt, model_name, task +): """Create and use an agent through MCP using streamable HTTP.""" print(f"šŸ”§ Creating agent '{agent_name}' with task: {task}") try: @@ -13,18 +16,17 @@ async def create_agent_via_mcp(session, agent_name, system_prompt, model_name, t "agent_name": agent_name, "system_prompt": system_prompt, "model_name": model_name, - "task": task + "task": task, } result = await session.call_tool( - name="create_agent", - arguments=arguments + name="create_agent", arguments=arguments ) # Result Handling output = None - if hasattr(result, 'content') and result.content: + if hasattr(result, "content") and result.content: if isinstance(result.content, list): for content_item in result.content: - if hasattr(content_item, 'text'): + if hasattr(content_item, "text"): print(content_item.text) output = content_item.text else: @@ -39,14 +41,20 @@ async def create_agent_via_mcp(session, agent_name, system_prompt, model_name, t except Exception as e: print(f"Tool call failed: {e}") import traceback + traceback.print_exc() raise + async def main(): print("šŸ”§ Starting MCP client connection...") try: - async with http_client("http://localhost:8000/mcp") as (read, write, _): + async with http_client("http://localhost:8000/mcp") as ( + read, + write, + _, + ): async with ClientSession(read, write) as session: try: await session.initialize() @@ -59,7 +67,9 @@ async def main(): print("Listing available tools...") try: tools = await session.list_tools() - print(f"šŸ“‹ Available tools: {[tool.name for tool in tools.tools]}") + print( + f"šŸ“‹ Available tools: {[tool.name for tool in tools.tools]}" + ) except Exception as e: print(f"Failed to list tools: {e}") raise @@ -69,14 +79,16 @@ async def main(): agent1_name = "tech_expert" agent1_prompt = "You are a technology expert. Provide clear explanations." agent1_model = "gpt-4" - agent1_task = "Explain blockchain technology in simple terms" + agent1_task = ( + "Explain blockchain technology in simple terms" + ) agent1_output = await create_agent_via_mcp( session, agent1_name, agent1_prompt, agent1_model, - agent1_task + agent1_task, ) # Agent 2: Legal Expert analyzes the explanation from Agent 1 @@ -90,7 +102,7 @@ async def main(): agent2_name, agent2_prompt, agent2_model, - agent2_task + agent2_task, ) # Agent 3: Educator simplifies the legal analysis for students @@ -104,7 +116,7 @@ async def main(): agent3_name, agent3_prompt, agent3_model, - agent3_task + agent3_task, ) print("\n=== Final Output from Educator Agent ===") @@ -113,9 +125,11 @@ async def main(): except Exception as e: print(f"Connection failed: {e}") import traceback + traceback.print_exc() raise + # Run the client if __name__ == "__main__": - asyncio.run(main()) \ No newline at end of file + asyncio.run(main()) diff --git a/examples/mcp/deploy_mcp_server/singleagent_client.py b/examples/mcp/deploy_mcp_server/singleagent_client.py index 2bb34a94..41816048 100644 --- a/examples/mcp/deploy_mcp_server/singleagent_client.py +++ b/examples/mcp/deploy_mcp_server/singleagent_client.py @@ -8,13 +8,17 @@ from mcp.client.streamable_http import ( async def create_agent_via_mcp(): """Create and use an agent through MCP using streamable HTTP.""" - + print("šŸ”§ Starting MCP client connection...") - + # Connect to the MCP server using streamable HTTP try: - async with http_client("http://localhost:8000/mcp") as (read, write, _): - + async with http_client("http://localhost:8000/mcp") as ( + read, + write, + _, + ): + async with ClientSession(read, write) as session: try: await session.initialize() @@ -22,17 +26,19 @@ async def create_agent_via_mcp(): except Exception as e: print(f"Session initialization failed: {e}") raise - + # List available tools print("Listing available tools...") try: tools = await session.list_tools() - print(f"šŸ“‹ Available tools: {[tool.name for tool in tools.tools]}") - + print( + f"šŸ“‹ Available tools: {[tool.name for tool in tools.tools]}" + ) + except Exception as e: print(f"Failed to list tools: {e}") raise - + # Create an agent using your tool print("Calling create_agent tool...") try: @@ -40,19 +46,18 @@ async def create_agent_via_mcp(): "agent_name": "tech_expert", "system_prompt": "You are a technology expert. Provide clear explanations.", "model_name": "gpt-4", - "task": "Explain blockchain technology in simple terms" + "task": "Explain blockchain technology in simple terms", } - + result = await session.call_tool( - name="create_agent", - arguments=arguments + name="create_agent", arguments=arguments ) - + # Result Handling - if hasattr(result, 'content') and result.content: + if hasattr(result, "content") and result.content: if isinstance(result.content, list): for content_item in result.content: - if hasattr(content_item, 'text'): + if hasattr(content_item, "text"): print(content_item.text) else: print(content_item) @@ -60,21 +65,24 @@ async def create_agent_via_mcp(): print(result.content) else: print("No content returned from agent") - + return result - + except Exception as e: print(f"Tool call failed: {e}") import traceback + traceback.print_exc() raise - + except Exception as e: print(f"Connection failed: {e}") import traceback + traceback.print_exc() raise + # Run the client if __name__ == "__main__": - asyncio.run(create_agent_via_mcp()) \ No newline at end of file + asyncio.run(create_agent_via_mcp()) diff --git a/examples/multi_agent/heavy_swarm_examples/heavy_swarm_example.py b/examples/multi_agent/heavy_swarm_examples/heavy_swarm_example.py deleted file mode 100644 index 588e3f3e..00000000 --- a/examples/multi_agent/heavy_swarm_examples/heavy_swarm_example.py +++ /dev/null @@ -1,32 +0,0 @@ -from swarms import HeavySwarm - - -def main(): - """ - Run a HeavySwarm query to find the best 3 gold ETFs. - - This function initializes a HeavySwarm instance and queries it to provide - the top 3 gold exchange-traded funds (ETFs), requesting clear, structured results. - """ - swarm = HeavySwarm( - name="Gold ETF Research Team", - description="A team of agents that research the best gold ETFs", - worker_model_name="claude-sonnet-4-latest", - show_dashboard=True, - question_agent_model_name="gpt-4.1", - loops_per_agent=1, - ) - - prompt = ( - "Find the best 3 gold ETFs. For each ETF, provide the ticker symbol, " - "full name, current price, expense ratio, assets under management, and " - "a brief explanation of why it is considered among the best. Present the information " - "in a clear, structured format suitable for investors." - ) - - out = swarm.run(prompt) - print(out) - - -if __name__ == "__main__": - main() diff --git a/snake_game_code_voting.py b/examples/multi_agent/majority_voting/snake_game_code_voting.py similarity index 100% rename from snake_game_code_voting.py rename to examples/multi_agent/majority_voting/snake_game_code_voting.py diff --git a/heavy_swarm_example.py b/heavy_swarm_example.py new file mode 100644 index 00000000..081a9c76 --- /dev/null +++ b/heavy_swarm_example.py @@ -0,0 +1,27 @@ +# task -> research -> synethsis or debate or voting -> output + +from swarms.structs.heavy_swarm import HeavySwarm +from swarms_tools import exa_search + +swarm = HeavySwarm( + name="Gold ETF Research Team", + description="A team of agents that research the best gold ETFs", + worker_model_name="claude-sonnet-4-20250514", + show_dashboard=True, + question_agent_model_name="gpt-4.1", + loops_per_agent=1, + agent_prints_on=False, + worker_tools=[exa_search], + random_loops_per_agent=True, +) + +prompt = ( + "Find the best 3 gold ETFs. For each ETF, provide the ticker symbol, " + "full name, current price, expense ratio, assets under management, and " + "a brief explanation of why it is considered among the best. Present the information " + "in a clear, structured format suitable for investors. Scrape the data from the web. " +) + +out = swarm.run(prompt) +print(out) + diff --git a/swarms/structs/heavy_swarm.py b/swarms/structs/heavy_swarm.py index 7a7bb728..539d84f8 100644 --- a/swarms/structs/heavy_swarm.py +++ b/swarms/structs/heavy_swarm.py @@ -1,6 +1,7 @@ import concurrent.futures import json import os +import random import time import traceback from functools import lru_cache @@ -24,6 +25,7 @@ from swarms.utils.history_output_formatter import ( history_output_formatter, ) from swarms.utils.litellm_wrapper import LiteLLM +from swarms.tools.tool_type import tool_type RESEARCH_AGENT_PROMPT = """ You are an expert Research Agent with exceptional capabilities in: @@ -471,7 +473,6 @@ class HeavySwarm: self, name: str = "HeavySwarm", description: str = "A swarm of agents that can analyze a task and generate specialized questions for each agent role", - agents: List[Agent] = None, timeout: int = 300, aggregation_strategy: str = "synthesis", loops_per_agent: int = 1, @@ -482,6 +483,8 @@ class HeavySwarm: show_dashboard: bool = False, agent_prints_on: bool = False, output_type: str = "dict-all-except-first", + worker_tools: tool_type = None, + random_loops_per_agent: bool = False, ): """ Initialize the HeavySwarm with configuration parameters. @@ -519,7 +522,6 @@ class HeavySwarm: """ self.name = name self.description = description - self.agents = agents self.timeout = timeout self.aggregation_strategy = aggregation_strategy self.loops_per_agent = loops_per_agent @@ -530,15 +532,31 @@ class HeavySwarm: self.show_dashboard = show_dashboard self.agent_prints_on = agent_prints_on self.output_type = output_type + self.worker_tools = worker_tools + self.random_loops_per_agent = random_loops_per_agent self.conversation = Conversation() self.console = Console() + self.agents = self.create_agents() + if self.show_dashboard: self.show_swarm_info() self.reliability_check() + def handle_worker_agent_loops(self) -> int: + """ + Handle the loops per agent for the worker agents. + """ + loops = None + + if self.random_loops_per_agent: + loops = random.randint(1, 10) + else: + loops = self.loops_per_agent + return loops + def show_swarm_info(self): """ Display comprehensive swarm configuration information in a rich dashboard format. @@ -831,10 +849,8 @@ class HeavySwarm: ) ) - agents = self.create_agents() - agent_results = self._execute_agents_parallel( - questions=questions, agents=agents, img=img + questions=questions, agents=self.agents, img=img ) # Synthesis with dashboard @@ -962,17 +978,23 @@ class HeavySwarm: if self.verbose: logger.info("šŸ—ļø Creating specialized agents...") + tools = None + + if self.worker_tools is not None: + tools = self.worker_tools + # Research Agent - Deep information gathering and data collection research_agent = Agent( agent_name="Research-Agent", agent_description="Expert research agent specializing in comprehensive information gathering and data collection", system_prompt=RESEARCH_AGENT_PROMPT, - max_loops=self.loops_per_agent, + max_loops=self.handle_worker_agent_loops(), model_name=self.worker_model_name, streaming_on=False, verbose=False, dynamic_temperature_enabled=True, print_on=self.agent_prints_on, + tools=tools, ) # Analysis Agent - Pattern recognition and deep analytical insights @@ -980,12 +1002,13 @@ class HeavySwarm: agent_name="Analysis-Agent", agent_description="Expert analytical agent specializing in pattern recognition, data analysis, and insight generation", system_prompt=ANALYSIS_AGENT_PROMPT, - max_loops=self.loops_per_agent, + max_loops=self.handle_worker_agent_loops(), model_name=self.worker_model_name, streaming_on=False, verbose=False, dynamic_temperature_enabled=True, print_on=self.agent_prints_on, + tools=tools, ) # Alternatives Agent - Strategic options and creative solutions @@ -993,12 +1016,13 @@ class HeavySwarm: agent_name="Alternatives-Agent", agent_description="Expert strategic agent specializing in alternative approaches, creative solutions, and option generation", system_prompt=ALTERNATIVES_AGENT_PROMPT, - max_loops=self.loops_per_agent, + max_loops=self.handle_worker_agent_loops(), model_name=self.worker_model_name, streaming_on=False, verbose=False, dynamic_temperature_enabled=True, print_on=self.agent_prints_on, + tools=tools, ) # Verification Agent - Validation, feasibility assessment, and quality assurance @@ -1006,12 +1030,13 @@ class HeavySwarm: agent_name="Verification-Agent", agent_description="Expert verification agent specializing in validation, feasibility assessment, and quality assurance", system_prompt=VERIFICATION_AGENT_PROMPT, - max_loops=self.loops_per_agent, + max_loops=self.handle_worker_agent_loops(), model_name=self.worker_model_name, streaming_on=False, verbose=False, dynamic_temperature_enabled=True, print_on=self.agent_prints_on, + tools=tools, ) # Synthesis Agent - Integration and comprehensive analysis @@ -1024,6 +1049,8 @@ class HeavySwarm: streaming_on=False, verbose=False, dynamic_temperature_enabled=True, + print_on=self.agent_prints_on, + tools=tools, ) agents = { diff --git a/swarms/tools/tool_type.py b/swarms/tools/tool_type.py new file mode 100644 index 00000000..9df37e94 --- /dev/null +++ b/swarms/tools/tool_type.py @@ -0,0 +1,7 @@ +from typing import Dict, List, Callable, Any, Type, Union + +ToolType = Union[ + Dict[str, Any], List[Callable[..., Any]], Callable[..., Any], Any +] + +tool_type = Type[ToolType] diff --git a/swarms/utils/litellm_wrapper.py b/swarms/utils/litellm_wrapper.py index 884c3af8..33afab4b 100644 --- a/swarms/utils/litellm_wrapper.py +++ b/swarms/utils/litellm_wrapper.py @@ -234,7 +234,7 @@ class LiteLLM: reasoning_effort: str = None, drop_params: bool = True, thinking_tokens: int = None, - reasoning_enabled: bool = True, + reasoning_enabled: bool = False, *args, **kwargs, ): @@ -291,6 +291,7 @@ class LiteLLM: self.reasoning_effort = reasoning_effort self.thinking_tokens = thinking_tokens self.reasoning_enabled = reasoning_enabled + self.verbose = verbose self.modalities = [] self.messages = [] # Initialize messages list @@ -315,7 +316,8 @@ class LiteLLM: self.init_args = args self.init_kwargs = kwargs - self.reasoning_check() + # if self.reasoning_enabled is True: + # self.reasoning_check() def reasoning_check(self): """ @@ -324,53 +326,40 @@ class LiteLLM: If reasoning is enabled and the model supports reasoning, set temperature to 1 for optimal reasoning. Also logs information or warnings based on the model's reasoning support and configuration. """ - if ( - self.reasoning_enabled is True - and litellm.supports_reasoning(model=self.model_name) - is True - ): - logger.info( - f"Model {self.model_name} supports reasoning and reasoning enabled is set to {self.reasoning_enabled}. Temperature will be set to 1 for better reasoning as some models may not work with low temperature." - ) - self.temperature = 1 - else: - logger.warning( - f"Model {self.model_name} does not support reasoning and reasoning enabled is set to {self.reasoning_enabled}. Temperature will not be set to 1." - ) + """ + Check if reasoning is enabled and supported by the model, and adjust temperature, thinking_tokens, and top_p accordingly. - if ( - self.reasoning_enabled is True - and litellm.supports_reasoning(model=self.model_name) - is False - ): - logger.warning( - f"Model {self.model_name} may or may not support reasoning and reasoning enabled is set to {self.reasoning_enabled}" + This single-line version combines all previous checks and actions for reasoning-enabled models, including Anthropic-specific logic. + """ + if self.reasoning_enabled: + supports_reasoning = litellm.supports_reasoning( + model=self.model_name ) - - if ( - self.reasoning_enabled is True - and self.check_if_model_name_uses_anthropic( + uses_anthropic = self.check_if_model_name_uses_anthropic( model_name=self.model_name ) - is True - ): - if self.thinking_tokens is None: + if supports_reasoning: logger.info( - f"Model {self.model_name} is an Anthropic model and reasoning enabled is set to {self.reasoning_enabled}. Thinking tokens is mandatory for Anthropic models." + f"Model {self.model_name} supports reasoning and reasoning enabled is set to {self.reasoning_enabled}. Temperature will be set to 1 for better reasoning as some models may not work with low temperature." ) - self.thinking_tokens = self.max_tokens / 4 - - if ( - self.reasoning_enabled is True - and self.check_if_model_name_uses_anthropic( - model_name=self.model_name - ) - is True - ): - logger.info( - "top_p must be greater than 0.95 for Anthropic models with reasoning enabled" - ) - self.top_p = 0.95 + self.temperature = 1 + else: + logger.warning( + f"Model {self.model_name} does not support reasoning and reasoning enabled is set to {self.reasoning_enabled}. Temperature will not be set to 1." + ) + logger.warning( + f"Model {self.model_name} may or may not support reasoning and reasoning enabled is set to {self.reasoning_enabled}" + ) + if uses_anthropic: + if self.thinking_tokens is None: + logger.info( + f"Model {self.model_name} is an Anthropic model and reasoning enabled is set to {self.reasoning_enabled}. Thinking tokens is mandatory for Anthropic models." + ) + self.thinking_tokens = self.max_tokens / 4 + logger.info( + "top_p must be greater than 0.95 for Anthropic models with reasoning enabled" + ) + self.top_p = 0.95 def _process_additional_args( self, completion_params: dict, runtime_args: tuple @@ -884,10 +873,6 @@ class LiteLLM: completion_params["reasoning_effort"] = ( self.reasoning_effort ) - else: - logger.warning( - f"Model {self.model_name} may or may not support reasoning" - ) if ( self.reasoning_enabled is True