ReasoningAgentRouter enables dynamic selection and execution of different reasoning strategies based on task requirements. It provides a flexible interface to work with multiple reasoning approaches.
The router builds a fresh agent of the selected type on every run() call, so no state carries over from one call to the next.
Tree of Thoughts is not a router type. Use
TreeOfThoughts directly.Architecture
Parameters
The constructor raises
ReasoningAgentInitializationError when max_loops is 0, or when model_name or swarm_type is empty. An unknown swarm_type is not caught until run(), which then raises ReasoningAgentExecutorError. Both exceptions live in swarms.agents.reasoning_agent_router.
Available Agent Types
swarm_type accepts the values in the agent_types literal, which you can import with from swarms import agent_types. Each type receives only some of the router’s parameters:
output_type has no effect on "ReflexionAgent", "GKPAgent" or "AgentJudge".
With
"ire", the router passes num_samples, not max_loops, as the number of IRE iterations. With "AgentJudge", the router’s system_prompt replaces the judge’s built-in evaluation prompt, so pass a judging prompt.Methods
Examples
Basic Usage
Self-Consistency with Evaluation
ReasoningDuo with Image Support
reasoning_model_name and the main agent on "gpt-5.4". Both must accept images.
GKP Agent
Reflexion Agent
IRE Agent
num_samples=2 runs two IRE iterations.
Choosing the Right Type
Best Practices
- Swarm Type Selection: Match the reasoning strategy to your task requirements
- Performance: Adjust
max_loopsandnum_samplesbased on task complexity - Self-Consistency: Use 3-5 samples for most tasks, 7+ for critical decisions
- Multi-modal: Use vision-capable models when processing images
- ReasoningDuo: Set the reasoning agent’s model with
reasoning_model_name. To choose the main agent’s model too, useReasoningDuodirectly