Skip to content

[BUGF] Fix reasoning agent model compatibility and HierarchicalSwarm error propagation - #1213

Closed
Steve-Dusty wants to merge 4 commits into
kyegomez:masterfrom
Steve-Dusty:reasoning_hierarchical
Closed

[BUGF] Fix reasoning agent model compatibility and HierarchicalSwarm error propagation#1213
Steve-Dusty wants to merge 4 commits into
kyegomez:masterfrom
Steve-Dusty:reasoning_hierarchical

Conversation

@Steve-Dusty

@Steve-Dusty Steve-Dusty commented Nov 19, 2025

Copy link
Copy Markdown
Contributor

This PR addresses two unrelated issues:

  1. Reasoning agents failing with unavailable Claude model - switches default from claude-3-5-sonnet-20240620 to
    gpt-4o
  2. HierarchicalSwarm silently swallowing validation errors - ensures ValueError exceptions properly propagate

Problem 1: Reasoning Agent Model Not Found

Error

litellm.exceptions.NotFoundError: AnthropicException - {
"type": "error",
"error": {
"type": "not_found_error",
"message": "model: claude-3-5-sonnet-20240620"
}
}

Root Cause: The default reasoning_model_name parameter used claude-3-5-sonnet-20240620, which is not available or has
been deprecated by Anthropic.

Location:

  • swarms/agents/reasoning_agents.py:93
  • swarms/agents/reasoning_duo.py:40

Solution

Changed default reasoning model to gpt-4o, which is stable and widely available:

Before

reasoning_model_name: Optional[str] = "claude-3-5-sonnet-20240620"

After

reasoning_model_name: Optional[str] = "gpt-4o"

Rationale:

  • gpt-4o is reliable and consistently available
  • Other reasoning agents in the codebase already use GPT models as defaults
  • Users can still override with their preferred model if needed

Problem 2: HierarchicalSwarm Exception Swallowing

Error

def test_hierarchical_swarm_error_handling():
try:
HierarchicalSwarm(agents=[])
assert False, "Should have raised ValueError for empty agents list"
except ValueError:
pass # Expected

Test FAILED - ValueError was never raised

Root Cause: The reliability_checks() method caught exceptions for logging but failed to re-raise them:

def reliability_checks(self):
try:
if not self.agents or len(self.agents) == 0:
raise ValueError("No agents found...")
except Exception as e:
logger.error(f"[ERROR] Reliability checks failed: {str(e)}")
# Missing: raise ← Exception swallowed here!

Location: swarms/structs/hiearchical_swarm.py:917

Solution

Added raise statement to propagate the exception after logging:

except Exception as e:
logger.error(f"[ERROR] Reliability checks failed: {str(e)}")
raise # ← Added this line

Impact:

  • Validation errors now properly fail initialization (as designed)
  • Error messages are still logged for debugging
  • Tests correctly catch validation errors

Changes Made

Files Modified

File Lines Changed Purpose
swarms/agents/reasoning_agents.py 1 Change default model to gpt-4o
swarms/agents/reasoning_duo.py 1 Change default model to gpt-4o
test_reasoning_agent_router.py 2 Update test configs to use gpt-4o
swarms/structs/hiearchical_swarm.py 1 Add missing raise statement

Testing

Reasoning Agent Fix:

Before: NotFoundError from Anthropic

After: Successfully uses gpt-4o model

HierarchicalSwarm Fix:
$ pytest test_hierarchical_swarm.py::test_hierarchical_swarm_error_handling -v
test_hierarchical_swarm_error_handling PASSED ✅

Breaking Changes

None. Both fixes are backwards compatible:

  • Users can still specify Claude models explicitly if they have access
  • HierarchicalSwarm validation behavior remains unchanged (still validates at init)

Benefits

  1. ✅ Reasoning agents work out-of-the-box without model access issues
  2. ✅ HierarchicalSwarm validation errors are properly surfaced
  3. ✅ Better error visibility for debugging
  4. ✅ Tests accurately validate error handling

Checklist

  • Code changes implemented
  • Tests pass
  • No breaking changes
  • Error handling improved
  • Default models use reliable options

📚 Documentation preview 📚: https://swarms--1213.org.readthedocs.build/en/1213/

@github-actions github-actions Bot added documentation Improvements or additions to documentation tests structs agents labels Nov 19, 2025
ReasoningAgentRouter,
)

from dotenv import load_dotenv

Check failure

Code scanning / Pyre

Undefined import Error test

Undefined import [21]: Could not find a module corresponding to import dotenv.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents documentation Improvements or additions to documentation structs tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants