Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.swarms.world/llms.txt

Use this file to discover all available pages before exploring further.

The 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.

Architecture

Parameters

ParameterTypeDefaultDescription
agent_namestr"reasoning_agent"Name identifier for the agent
descriptionstr"A reasoning agent..."Description of the agent’s capabilities
model_namestr"claude-sonnet-4-6"The underlying language model to use
system_promptstr"You are a helpful..."System prompt for the agent
max_loopsint1Maximum number of reasoning loops
swarm_typeagent_types"reasoning_duo"Type of reasoning swarm to use
num_samplesint1Number of samples for self-consistency
output_typeOutputType"dict-all-except-first"Format of the output
num_knowledge_itemsint6Number of knowledge items for GKP agent
memory_capacityint6Memory capacity for agents that support it
evalboolFalseEnable evaluation mode for self-consistency
random_models_onboolFalseEnable random model selection for diversity
majority_voting_promptOptional[str]NoneCustom prompt for majority voting
reasoning_model_nameOptional[str]"claude-3-5-sonnet-20240620"Model for reasoning in ReasoningDuo

Available Agent Types

The following values are supported for the swarm_type parameter:
  • "reasoning-duo" or "reasoning-agent"
  • "self-consistency" or "consistency-agent"
  • "ire" or "ire-agent"
  • "ReflexionAgent"
  • "GKPAgent"
  • "AgentJudge"

Methods

MethodDescription
select_swarm()Selects and initializes the appropriate reasoning swarm
run(task, img?, **kwargs)Executes the selected swarm’s reasoning process
batched_run(tasks, imgs?, **kwargs)Executes the reasoning process on a batch of tasks

Examples

Basic Usage

from swarms.agents.reasoning_agent_router import ReasoningAgentRouter

router = ReasoningAgentRouter(
    agent_name="reasoning-agent",
    model_name="claude-sonnet-4-6",
    swarm_type="self-consistency",
    num_samples=3,
)

result = router.run("What is the best approach to solve this problem?")

Self-Consistency with Evaluation

router = ReasoningAgentRouter(
    swarm_type="self-consistency",
    num_samples=5,
    model_name="claude-sonnet-4-6",
    eval=True,
    random_models_on=True
)

result = router.run("What is 2 + 2?")

ReasoningDuo with Image Support

router = ReasoningAgentRouter(
    swarm_type="reasoning-duo",
    model_name="claude-sonnet-4-6",
    reasoning_model_name="claude-3-5-sonnet-20240620",
    max_loops=2
)

result = router.run(
    "Analyze this image and explain the patterns you see",
    img="data_visualization.png"
)

GKP Agent

router = ReasoningAgentRouter(
    swarm_type="GKPAgent",
    model_name="claude-sonnet-4-6",
    num_knowledge_items=6
)

result = router.run("What are the implications of quantum entanglement?")

Reflexion Agent

router = ReasoningAgentRouter(
    swarm_type="ReflexionAgent",
    max_loops=3,
    model_name="claude-sonnet-4-6"
)

result = router.run("Explain quantum computing to a beginner.")

Choosing the Right Type

ScenarioRecommended TypeWhy
Tasks requiring high reliabilityself-consistencyMultiple validation paths, consensus building
Complex tasks needing analysis + actionreasoning-duoSeparates reasoning from execution
Problems requiring iterative refinementireDesigned for progressive improvement
Tasks requiring introspectionReflexionAgentSelf-reflection and learning from experience
Knowledge-intensive tasksGKPAgentGenerates knowledge before reasoning
Quality controlAgentJudgeSpecialized evaluation capabilities

Best Practices

  1. Swarm Type Selection: Match the reasoning strategy to your task requirements
  2. Performance: Adjust max_loops and num_samples based on task complexity
  3. Self-Consistency: Use 3-5 samples for most tasks, 7+ for critical decisions
  4. Multi-modal: Use vision-capable models when processing images
  5. ReasoningDuo: Set different models for reasoning vs execution via reasoning_model_name