> ## Documentation Index
> Fetch the complete documentation index at: https://docs.swarms.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Reasoning Agent Types

> Explore different reasoning agent architectures and their applications

Discover the different types of reasoning agents available in the Swarms API. The `/v1/reasoning-agent/types` endpoint provides information about specialized reasoning architectures designed for different problem-solving approaches.

> [!WARNING]
>
> **Premium Tier Required**: The `/v1/reasoning-agent/completions` endpoint is restricted to Pro, Ultra, and Premium plan subscribers. Free tier users will receive a 403 error. [Upgrade your account](https://swarms.world/platform/account) to access advanced reasoning capabilities.

> [!NOTE]
>
> Reasoning agents use advanced techniques like self-consistency, majority voting, and iterative refinement to improve answer quality and reliability.

## Quick Start

> [tab] Python
>
> ```python theme={null}
> import requests
> import json
> import os
> from dotenv import load_dotenv
>
> load_dotenv()
>
> API_KEY = os.getenv("SWARMS_API_KEY")
> BASE_URL = "https://api.swarms.world"
>
> headers = {
>     "x-api-key": API_KEY,
>     "Content-Type": "application/json"
> }
>
> def get_reasoning_agent_types():
>     """Get all available reasoning agent types"""
>     response = requests.get(
>         f"{BASE_URL}/v1/reasoning-agent/types",
>         headers=headers
>     )
>
>     if response.status_code == 200:
>         return response.json()
>     else:
>         print(f"Error: {response.status_code} - {response.text}")
>         return None
>
> # Get reasoning agent types
> reasoning_data = get_reasoning_agent_types()
> if reasoning_data:
>     print("✅ Reasoning agent types retrieved successfully!")
>     print(json.dumps(reasoning_data, indent=2))
> ```

> [tab] JavaScript
>
> ```javascript theme={null}
> const API_KEY = process.env.SWARMS_API_KEY;
> const BASE_URL = "https://api.swarms.world";
>
> const headers = {
>     "x-api-key": API_KEY,
>     "Content-Type": "application/json"
> };
>
> async function getReasoningAgentTypes() {
>     try {
>         const response = await fetch(`${BASE_URL}/v1/reasoning-agent/types`, {
>             method: 'GET',
>             headers: headers
>         });
>
>         if (!response.ok) {
>             throw new Error(`HTTP error! status: ${response.status}`);
>         }
>
>         const data = await response.json();
>         console.log("✅ Reasoning agent types retrieved successfully!");
>         console.log(JSON.stringify(data, null, 2));
>         return data;
>     } catch (error) {
>         console.error('Error:', error);
>         return null;
>     }
> }
>
> // Get reasoning agent types
> getReasoningAgentTypes();
> ```

> [tab] cURL
>
> ```bash theme={null}
> # Get reasoning agent types
> curl -X GET "https://api.swarms.world/v1/reasoning-agent/types" \
>   -H "x-api-key: your-api-key" \
>   -H "Content-Type: application/json"
>
> # Example response:
> # {
> #   "status": "success",
> #   "agent_types": [
> #     "AgentJudge",
> #     "ReflexionAgent",
> #     "self-consistency",
> #     "consistency-agent"
> #   ]
> # }
> ```

## Reasoning Agent Type Comparison

The `/v1/reasoning-agent/types` endpoint currently returns 4 reasoning agent types:

| Type | Description | Best For | Samples | Quality Focus |
| - | - | - | - | - |
| **self-consistency** | Samples `num_samples` independent answers, then an aggregation agent reconciles them | High-stakes decisions | 3-5 | Consistency |
| **consistency-agent** | Alias for `self-consistency` | Same as `self-consistency` | 3-5 | Consistency |
| **ReflexionAgent** | Self-critiques and revises its own output across iterations (`max_loops`) | Tasks that benefit from self-correction | Ignored | Self-improvement |
| **AgentJudge** | Evaluates and scores candidate outputs over `max_loops` rounds | Output evaluation / grading | Ignored | Evaluation |

Any other `swarm_type`, including the removed `reasoning-duo`, `reasoning-agent`, `ire`, `ire-agent` and `GKPAgent`, returns `422` before any model call or charge.

## Request Parameters

Send these fields in the JSON body of `POST /v1/reasoning-agent/completions` (the `ReasoningAgentSpec` schema):

| Parameter | Type | Default | Description |
| - | - | - | - |
| `agent_name` | `string` | `"reasoning-agent"` | The unique name assigned to the reasoning agent |
| `description` | `string` | `"A reasoning agent that can answer questions and help with tasks."` | A detailed explanation of the reasoning agent's purpose and capabilities |
| `model_name` | `string` | `"claude-sonnet-5"` | The name of the AI model that the reasoning agent will utilize |
| `system_prompt` | `string` | `None` | The initial instruction or context provided to the reasoning agent |
| `max_loops` | `integer` | `1` | Maximum number of times the agent repeats its task. Between 1 and 50 |
| `swarm_type` | `string` | `"self-consistency"` | The reasoning agent type — pass one of the 4 values listed above |
| `num_samples` | `integer` | `1` | How many independent answers `self-consistency` and `consistency-agent` generate before aggregating. Between 1 and 2000; `0`, a negative value, `null` or anything above 2000 returns `422`. Ignored by `AgentJudge` and `ReflexionAgent` |
| `output_type` | `string` | `"dict-all-except-first"` | Accepted for schema compatibility but **ignored by the server** — responses are always returned in `dict-all-except-first` format |
| `memory_capacity` | `integer` | `None` | The memory capacity for a `ReflexionAgent` |
| `task` | `string` | `None` | The task to be completed by the reasoning agent |

> [!NOTE]
>
> `self-consistency` and `consistency-agent` bill the prompt once per sample: input tokens are the counted prompt tokens × `num_samples`, so `num_samples: 5` costs about five times the prompt. `AgentJudge` and `ReflexionAgent` ignore `num_samples` and bill the tokens their internal agents used on every call. See [Billing](https://docs.swarms.ai/docs/documentation/capabilities/reasoning_agent.md#billing).

## Response Format

`POST /v1/reasoning-agent/completions` returns a `ReasoningAgentCompletionOutput` object:

| Field | Type | Description |
| - | - | - |
| `job_id` | `string` | Unique identifier for the reasoning agent run |
| `status` | `string` | Status of the run, `"success"` on completion |
| `outputs` | `any` | The output generated by the reasoning agent — shape varies by reasoning type |
| `timestamp` | `string` | ISO-formatted timestamp of when the run was executed |
| `agent_name` | `string` | Name of the agent |
| `agent_type` | `string` | Type of the agent (the `swarm_type` used) |
| `agent_id` | `string` | Unique identifier for the agent instance |
| `usage` | `object` | Token usage: `input_tokens`, `output_tokens`, `total_tokens`, plus `total_cost` (the credits charged) and `flash_sale_applied` |

## Usage Examples

> [tab] Self-Consistency Agent
>
> ```python theme={null}
> payload = {
>     "agent_name": "Consistent Reasoner",
>     "model_name": "gpt-4.1",
>     "system_prompt": "You are a reasoning agent that values consistency.",
>     "max_loops": 1,
>     "swarm_type": "self-consistency",
>     "num_samples": 3,
>     "task": "Determine the most logical conclusion from these premises: All humans are mortal. Socrates is human. Therefore..."
> }
> ```

> [tab] Reflexion Agent
>
> ```python theme={null}
> payload = {
>     "agent_name": "Refinement Agent",
>     "model_name": "gpt-4.1",
>     "system_prompt": "You are an agent that improves through iteration.",
>     "max_loops": 3,  # reflection iterations
>     "swarm_type": "ReflexionAgent",
>     "task": "Design a more efficient algorithm for sorting a list of numbers."
> }
> ```

> [tab] Agent Judge
>
> ```python theme={null}
> payload = {
>     "agent_name": "Answer Judge",
>     "model_name": "gpt-4.1",
>     "max_loops": 1,
>     "swarm_type": "AgentJudge",
>     "task": "Evaluate this answer for accuracy and completeness: 'Renewable energy is always cheaper than fossil fuels.'"
> }
> ```

## Advanced Configuration

> [tab] Custom Sample Count
>
> ```python theme={null}
> payload = {
>     "agent_name": "High Consistency Agent",
>     "model_name": "gpt-4.1",
>     "max_loops": 1,
>     "swarm_type": "self-consistency",
>     "num_samples": 5,  # Higher sample count for better consistency
>     "task": "Analyze the potential risks of artificial general intelligence."
> }
> ```

> [tab] Multi-Iteration Reasoning
>
> ```python theme={null}
> payload = {
>     "agent_name": "Deep Analysis Agent",
>     "model_name": "gpt-4.1",
>     "max_loops": 5,  # Multiple refinement iterations
>     "swarm_type": "ReflexionAgent",
>     "task": "Develop a comprehensive business strategy for a tech startup."
> }
> ```

> [tab] Reflexion Memory
>
> ```python theme={null}
> payload = {
>     "agent_name": "Knowledge Agent",
>     "model_name": "gpt-4.1",
>     "max_loops": 3,
>     "swarm_type": "ReflexionAgent",
>     "memory_capacity": 10,  # prior attempts kept in memory
>     "task": "Integrate these research findings into a coherent theory."
> }
> ```

## Output Format

> [!NOTE]
>
> The `output_type` request field is accepted by the schema but **ignored by the server** — the reasoning agent always runs with `dict-all-except-first`. For `self-consistency` and `consistency-agent`, `outputs` is a list of role/content entries: one holding the list of sample answers, then a `Majority Voting Agent` entry with the reconciled answer. `ReflexionAgent` and `AgentJudge` return a plain string. Passing `"dict"`, `"list"`, or `"final"` validates but has no effect on the response.

```python theme={null}
result = response.json()

# outputs is a list of role/content entries for most reasoning types
outputs = result["outputs"]
if isinstance(outputs, list):
    for entry in outputs:
        print(f"{entry.get('role', '')}: {entry.get('content', '')}")
else:
    # ReflexionAgent and AgentJudge return a plain string
    print(outputs)
```

## Performance Optimization

> [tab] Quality vs Speed
>
> ```python theme={null}
> def optimize_reasoning_config(task_complexity, time_constraint):
>     """Optimize reasoning configuration based on requirements"""
>
>     if time_constraint == "fast":
>         return {
>             "swarm_type": "self-consistency",
>             "num_samples": 1,
>             "max_loops": 1,
>             "model_name": "gpt-4.1-mini"
>         }
>     elif task_complexity == "high":
>         return {
>             "swarm_type": "ReflexionAgent",
>             "max_loops": 3,
>             "model_name": "gpt-4.1"
>         }
>     else:  # balanced
>         return {
>             "swarm_type": "self-consistency",
>             "num_samples": 3,
>             "max_loops": 1,
>             "model_name": "gpt-4.1"
>         }
> ```

> [tab] Cost Optimization
>
> ```python theme={null}
> def optimize_reasoning_cost(budget, quality_requirement):
>     """Optimize for cost while maintaining quality"""
>
>     if budget < 0.1:
>         return {
>             "swarm_type": "self-consistency",
>             "model_name": "gpt-4.1-mini",
>             "num_samples": 1
>         }
>     elif quality_requirement == "high":
>         return {
>             "swarm_type": "self-consistency",
>             "model_name": "gpt-4.1",
>             "num_samples": 3
>         }
>     else:
>         return {
>             "swarm_type": "self-consistency",
>             "model_name": "gpt-4.1-mini",
>             "num_samples": 2
>         }
> ```

## Use Cases by Domain

> [tab] Scientific Research
>
> ```python theme={null}
> payload = {
>     "agent_name": "Scientific Reasoner",
>     "swarm_type": "ReflexionAgent",
>     "max_loops": 3,
>     "task": "Design an experiment to test the hypothesis that X causes Y."
> }
> ```

> [tab] Business Strategy
>
> ```python theme={null}
> payload = {
>     "agent_name": "Strategy Consultant",
>     "swarm_type": "self-consistency",
>     "num_samples": 3,
>     "task": "Evaluate three potential market entry strategies for our product."
> }
> ```

> [tab] Legal Analysis
>
> ```python theme={null}
> payload = {
>     "agent_name": "Legal Analyst",
>     "swarm_type": "self-consistency",
>     "num_samples": 5,
>     "task": "Analyze the legal implications of this contract clause."
> }
> ```

> [tab] Technical Problem Solving
>
> ```python theme={null}
> payload = {
>     "agent_name": "Technical Expert",
>     "swarm_type": "consistency-agent",
>     "num_samples": 3,
>     "task": "Debug this software issue and propose a solution."
> }
> ```

## Best Practices

### Configuration Guidelines

1. **Task Complexity**: Match reasoning type to task complexity
2. **Sample Count**: Use more samples for high-stakes decisions
3. **Iteration Count**: Increase iterations for complex refinement
4. **Model Selection**: Choose appropriate model based on requirements

### Quality Assurance

1. **Consistency Checking**: Use self-consistency for critical decisions
2. **Self-Correction**: Use ReflexionAgent for drafts that improve with revision
3. **Evaluation**: Use AgentJudge to grade another agent's answer
4. **Validation**: Always validate reasoning outputs

### Performance Considerations

1. **Resource Usage**: Monitor token usage and costs
2. **Response Time**: Balance quality with response speed
3. **Scalability**: Consider parallel processing for multiple tasks
4. **Caching**: Cache reasoning results when appropriate

### Error Handling

1. **Fallback Logic**: Implement fallback to simpler reasoning types
2. **Timeout Handling**: Set appropriate timeouts for long-running tasks
3. **Result Validation**: Validate reasoning outputs for correctness
4. **Logging**: Log reasoning processes for debugging


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.