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

# Reasoning Duo

> Dual-agent collaborative system that separates reasoning and execution phases for more robust and reliable outputs

The `ReasoningDuo` class implements a dual-agent reasoning system that combines a reasoning agent and a main agent to provide well-thought-out responses to complex tasks. This architecture separates the reasoning process from the final response generation.

## Architecture

```
Task Input → Reasoning Agent → Structured Analysis → Main Agent → Final Output
```

## Parameters

| Parameter              | Type            | Default                     | Description                                                                         |
| ---------------------- | --------------- | --------------------------- | ----------------------------------------------------------------------------------- |
| `id`                   | `str`           | random `uuid4()`            | Unique identifier for the duo                                                       |
| `agent_name`           | `str`           | `"reasoning-agent-01"`      | Name identifier shared by both internal agents                                      |
| `agent_description`    | `str`           | `"A highly intelligent..."` | Description passed to both internal agents                                          |
| `model_name`           | `str`           | `"gpt-5.4"`                 | Stored on the instance; not currently used to configure either internal agent       |
| `description`          | `str`           | `"A highly intelligent..."` | Description of the reasoning duo's capabilities                                     |
| `model_names`          | `list[str]`     | `["gpt-5.4", "gpt-5.4"]`    | Model names for `[reasoning_agent, main_agent]` (index 1 configures the main agent) |
| `system_prompt`        | `str`           | `"You are a helpful..."`    | System prompt for the main agent                                                    |
| `output_type`          | `OutputType`    | `"dict-all-except-first"`   | Format of the value returned by `run()`                                             |
| `reasoning_model_name` | `Optional[str]` | `"gpt-4o"`                  | Model used by the reasoning agent; if `None`, falls back to `model_names[0]`        |
| `max_loops`            | `int`           | `1`                         | Number of reasoning/main-agent loop iterations in `run()`                           |

### Methods

| Method        | Parameters                                           | Returns                                              | Description                                                                 |
| ------------- | ---------------------------------------------------- | ---------------------------------------------------- | --------------------------------------------------------------------------- |
| `step`        | `task: str, img: Optional[str] = None`               | `None`                                               | Runs one reasoning-agent → main-agent cycle and appends to the conversation |
| `run`         | `task: str, img: Optional[str] = None`               | Formatted per `output_type` (e.g. `dict` by default) | Processes a task through both agents for `max_loops` iterations             |
| `batched_run` | `tasks: List[str], imgs: Optional[List[str]] = None` | `list`                                               | Processes multiple tasks sequentially                                       |

## Quick Start

```python theme={null}
from swarms import ReasoningDuo

duo = ReasoningDuo(
    agent_name="reasoning-agent-01",
    model_names=["claude-sonnet-4-6", "gpt-5.4"]
)

result = duo.run("Explain the concept of gravitational waves")
```

## Examples

### Mathematical Analysis

```python theme={null}
duo = ReasoningDuo()

math_task = """
Solve the following differential equation:
dy/dx + 2y = x^2, y(0) = 1
"""

solution = duo.run(math_task)
```

### Financial Analysis

```python theme={null}
finance_task = """
Calculate the Net Present Value (NPV) of a project with:
- Initial investment: $100,000
- Annual cash flows: $25,000 for 5 years
- Discount rate: 8%
"""

analysis = duo.run(finance_task)
```

### Customizing Agent Behavior

```python theme={null}
duo = ReasoningDuo(
    agent_name="custom-reasoning-agent",
    description="Specialized financial analysis agent",
    model_names=["claude-sonnet-4-6", "gpt-5.4"],
    system_prompt="You are a financial expert AI assistant..."
)
```

### Batch Processing

```python theme={null}
tasks = [
    "Analyze market trends for tech stocks",
    "Calculate risk metrics for a portfolio",
    "Forecast revenue growth"
]

results = duo.batched_run(tasks)
```

## Best Practices

1. **Task Formulation**: Be specific and clear in task descriptions. Include relevant context and constraints.
2. **Performance Optimization**: Use `batched_run` for multiple related tasks. Monitor agent outputs for consistency.
3. **Model Selection**: Adjust model parameters based on task complexity.
