Overview
Reasoning Agents are specialized AI agents designed to perform complex reasoning tasks with enhanced logical thinking, consistency checking, and iterative refinement capabilities.
Reasoning Agents are specialized AI agents designed to perform complex reasoning tasks with enhanced logical thinking, consistency checking, and iterative refinement capabilities. They leverage advanced reasoning techniques to solve problems that require deep analysis, multiple perspectives, and systematic thinking.
When to Use Reasoning Agents
Reasoning Agents are ideal for tasks that require:
Complex Problem Solving: Mathematical proofs, logical puzzles, and analytical challenges
Multi-Step Reasoning: Tasks that require breaking down problems into sequential steps
Consistency Validation: Ensuring logical coherence across multiple arguments or solutions
Iterative Refinement: Problems that benefit from multiple passes and refinement
Cross-Domain Thinking: Integrating knowledge from different fields
Self-Reflection: Tasks requiring meta-cognitive analysis and bias awareness
Knowledge Synthesis: Combining information from multiple sources into coherent conclusions
Available Reasoning Agent Types
reasoning-duo
Dual-agent system that approaches problems from two different perspectives and synthesizes the results
Mathematical problems, logical proofs, tasks requiring multiple viewpoints
Two-agent collaboration, perspective synthesis, comprehensive analysis
max_loops: 1
, num_samples: 1
self-consistency
Generates multiple reasoning paths and validates their consistency to ensure robust conclusions
Complex logical problems, consistency checking, validation tasks
Multiple reasoning paths, consistency validation, robust conclusions
max_loops: 1
, num_samples: 3-5
ire (Iterative Refinement)
Uses iterative refinement to progressively improve reasoning and address gaps in analysis
Complex analysis tasks, research problems, iterative improvement scenarios
Progressive refinement, gap identification, systematic improvement
max_loops: 2-3
, num_samples: 1
reasoning-agent
General-purpose reasoning agent for systematic problem-solving
General reasoning tasks, step-by-step problem solving, logical analysis
Systematic approach, step-by-step reasoning, logical structure
max_loops: 1
, num_samples: 1
consistency-agent
Specialized in checking logical consistency and identifying contradictions
Argument validation, logical consistency checking, contradiction detection
Logical validation, contradiction identification, argument analysis
max_loops: 1
, num_samples: 1
ReflexionAgent
Reflects on its own thinking process and validates assumptions
Meta-cognitive tasks, bias detection, self-aware reasoning
Self-reflection, assumption validation, bias detection
max_loops: 2-3
, num_samples: 1
GKPAgent (General Knowledge Processing)
Synthesizes information from various domains to solve complex problems
Cross-disciplinary problems, knowledge integration, multi-domain analysis
Cross-domain synthesis, knowledge integration, interdisciplinary thinking
max_loops: 1-2
, num_samples: 1
API Endpoints
Get Available Reasoning Agent Types
GET /v1/reasoning-agent/types
Headers:
x-api-key
: Your API key
Response:
{
"status": "success",
"agent_types": [
"reasoning-duo",
"self-consistency",
"ire",
"reasoning-agent",
"consistency-agent",
"ReflexionAgent",
"GKPAgent"
]
}
Run Reasoning Agent
POST /v1/reasoning-agent/completions
Headers:
x-api-key
: Your API keyContent-Type
: application/json
Request Parameters
ReasoningAgentSpec Schema
agent_name
string
No
"reasoning-agent"
Unique name for the reasoning agent
description
string
No
"A reasoning agent that can answer questions and help with tasks."
Detailed explanation of the agent's purpose
model_name
string
No
"claude-3-5-sonnet-20240620"
AI model to use (e.g., gpt-4o, claude-3-5-sonnet-20240620)
system_prompt
string
No
null
Initial instruction or context for the agent
max_loops
integer
No
1
Maximum number of reasoning iterations
swarm_type
string
No
"reasoning_duo"
Type of reasoning agent to use
num_samples
integer
No
1
Number of samples for self-consistency agents
output_type
string
No
"dict-all-except-first"
Output format type
num_knowledge_items
integer
No
null
Number of knowledge items to use
memory_capacity
integer
No
null
Memory capacity for the agent
task
string
Yes
null
The task to be completed
Response Format
{
"run_id": "swarms-abc123def456",
"status": "success",
"outputs": [
{
"role": "agent",
"content": "Step-by-step reasoning process..."
}
],
"timestamp": "2024-01-15T10:30:00Z",
"agent_name": "math-reasoner",
"agent_type": "reasoning-duo",
"agent_id": "uuid-1234-5678",
"usage": {
"input_tokens": 150,
"output_tokens": 300,
"total_tokens": 450
}
}
Examples
1. Mathematical Problem Solving (reasoning-duo)
import requests
payload = {
"agent_name": "math-reasoner",
"description": "A reasoning agent specialized in mathematical problem solving",
"model_name": "claude-3-5-sonnet-20240620",
"system_prompt": """You are an expert mathematical reasoning agent.
When solving problems, always show your step-by-step reasoning process.
Break down complex problems into smaller, manageable steps.
Verify your solutions and explain your logic clearly.""",
"max_loops": 1,
"swarm_type": "reasoning-duo",
"num_samples": 1,
"task": "If a train travels 120 miles in 2 hours, and then travels 180 miles in 3 hours, what is the average speed for the entire journey? Show your reasoning step by step."
}
response = requests.post(
"https://api.swarms.world/v1/reasoning-agent/completions",
headers={"x-api-key": "your-api-key"},
json=payload
)
2. Logical Consistency Checking (self-consistency)
payload = {
"agent_name": "logic-validator",
"description": "A reasoning agent that validates logical consistency",
"model_name": "claude-3-5-sonnet-20240620",
"system_prompt": """You are a logical consistency validator.
When presented with problems, generate multiple reasoning paths and verify their consistency.
Ensure all conclusions are logically sound and internally consistent.""",
"max_loops": 1,
"swarm_type": "self-consistency",
"num_samples": 3,
"task": "Prove that the sum of any three consecutive integers is divisible by 3. Use multiple reasoning approaches."
}
3. Iterative Refinement (ire)
payload = {
"agent_name": "iterative-reasoner",
"description": "A reasoning agent that uses iterative refinement",
"model_name": "claude-3-5-sonnet-20240620",
"system_prompt": """You are an iterative reasoning agent.
Start with initial reasoning and iteratively refine your approach.
Identify gaps in your reasoning and address them systematically.""",
"max_loops": 2,
"swarm_type": "ire",
"num_samples": 1,
"task": "Analyze the economic impact of renewable energy adoption. Start with basic analysis and iteratively refine your reasoning."
}
4. Cross-Domain Knowledge Synthesis (GKPAgent)
payload = {
"agent_name": "knowledge-processor",
"description": "A reasoning agent that processes general knowledge",
"model_name": "claude-3-5-sonnet-20240620",
"system_prompt": """You are a general knowledge processing agent.
Synthesize information from various domains to solve complex problems.
Apply cross-disciplinary thinking and knowledge integration.""",
"max_loops": 1,
"swarm_type": "GKPAgent",
"num_samples": 1,
"task": "How can principles from biology, physics, and engineering be combined to design more efficient solar panels?"
}
5. Self-Reflection and Bias Detection (ReflexionAgent)
payload = {
"agent_name": "reflexive-thinker",
"description": "A reasoning agent that reflects on its own thinking",
"model_name": "claude-3-5-sonnet-20240620",
"system_prompt": """You are a reflexive reasoning agent.
Reflect on your own thinking process and reasoning.
Question your assumptions and validate your conclusions.""",
"max_loops": 2,
"swarm_type": "ReflexionAgent",
"num_samples": 1,
"task": "Analyze the ethical implications of artificial intelligence. Reflect on your own biases and assumptions."
}
Advanced Configuration
Memory and Knowledge Management
For complex reasoning tasks, you can configure memory capacity and knowledge items:
payload = {
"agent_name": "advanced-reasoner",
"description": "Advanced reasoning with memory management",
"model_name": "claude-3-5-sonnet-20240620",
"swarm_type": "ire",
"max_loops": 3,
"num_knowledge_items": 10,
"memory_capacity": 1000,
"task": "Complex multi-step reasoning task..."
}
Multiple Samples for Robustness
For self-consistency agents, increase the number of samples for more robust results:
payload = {
"agent_name": "robust-validator",
"description": "Robust consistency checking with multiple samples",
"model_name": "claude-3-5-sonnet-20240620",
"swarm_type": "self-consistency",
"num_samples": 5, # Generate 5 different reasoning paths
"task": "Validate the consistency of complex logical argument..."
}
Best Practices
1. Choose the Right Agent Type
Use
reasoning-duo
for mathematical and logical problemsUse
self-consistency
for validation and consistency checkingUse
ire
for complex analysis requiring iterative improvementUse
ReflexionAgent
for tasks requiring self-awareness and bias detectionUse
GKPAgent
for cross-disciplinary problems
2. Optimize System Prompts
Be specific about the reasoning approach you want
Include examples of expected output format
Specify any constraints or requirements
Guide the agent's thinking process
3. Configure Loops Appropriately
Start with
max_loops: 1
for simple tasksIncrease to 2-3 for complex problems requiring refinement
Monitor token usage as loops increase costs
4. Use Appropriate Models
claude-3-5-sonnet-20240620
is recommended for reasoning tasksgpt-4o
for tasks requiring creative reasoningConsider model-specific strengths for your use case
Error Handling
Common error scenarios and solutions:
Invalid Agent Type
{
"detail": "Invalid swarm_type. Available types: reasoning-duo, self-consistency, ire, reasoning-agent, consistency-agent, ReflexionAgent, GKPAgent"
}
Missing Required Fields
{
"detail": "The 'task' field is mandatory for reasoning agent creation. Please provide a valid task description to proceed."
}
Rate Limiting
{
"detail": "Rate limit exceeded. Upgrade to Premium for increased limits at https://swarms.world/platform/account"
}
Cost Considerations
Reasoning agents consume tokens based on:
Input prompt length
Number of reasoning iterations (max_loops)
Number of samples generated (num_samples)
Output length
Monitor usage through the response's usage
field and consider the service_tier
parameter for cost optimization.
Integration Examples
Python Client
import requests
import json
class ReasoningAgentClient:
def __init__(self, api_key, base_url="https://api.swarms.world"):
self.api_key = api_key
self.base_url = base_url
self.headers = {"x-api-key": api_key, "Content-Type": "application/json"}
def get_agent_types(self):
response = requests.get(f"{self.base_url}/v1/reasoning-agent/types", headers=self.headers)
return response.json()
def run_reasoning_agent(self, spec):
response = requests.post(
f"{self.base_url}/v1/reasoning-agent/completions",
headers=self.headers,
json=spec
)
return response.json()
# Usage
client = ReasoningAgentClient("your-api-key")
agent_types = client.get_agent_types()
result = client.run_reasoning_agent(payload)
JavaScript/Node.js Client
class ReasoningAgentClient {
constructor(apiKey, baseUrl = 'https://api.swarms.world') {
this.apiKey = apiKey;
this.baseUrl = baseUrl;
this.headers = {
'x-api-key': apiKey,
'Content-Type': 'application/json'
};
}
async getAgentTypes() {
const response = await fetch(`${this.baseUrl}/v1/reasoning-agent/types`, {
headers: this.headers
});
return response.json();
}
async runReasoningAgent(spec) {
const response = await fetch(`${this.baseUrl}/v1/reasoning-agent/completions`, {
method: 'POST',
headers: this.headers,
body: JSON.stringify(spec)
});
return response.json();
}
}
// Usage
const client = new ReasoningAgentClient('your-api-key');
const agentTypes = await client.getAgentTypes();
const result = await client.runReasoningAgent(payload);
Support and Resources
API Documentation: https://docs.swarms.world
API Keys: https://swarms.world/platform/api-keys
Support: https://cal.com/swarms/swarms-technical-support
Community: Join our Discord for discussions and examples
For additional help with reasoning agents or to report issues, please contact our support team or visit our documentation portal.
Last updated
Was this helpful?