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

# PredictionMarket

> A multi-agent prediction market that bets on answers instead of voting or debating, so correct minority answers pay more than the majority

## Overview

`PredictionMarket` lets agents bet on candidate answers instead of voting on them or debating them. Each agent first solves independently. Equal answers are grouped, and those reached by at least `min_attempts` attempts become tradable assets whose opening prices follow how many attempts reached them. Each agent then reads one solution per answer, bets chips without seeing the others, and may trade once more after seeing the updated prices. The answer with the highest closing price wins.

An answer few attempts reached is cheap, so a correct minority answer pays more than a popular one and following the majority pays little. That is the whole incentive: the market rewards being right when the others are wrong.

Based on [Betting Against the Majority: Multi-Agent Prediction Market Reduces Conformity](https://dinobby.github.io/blogs/multi-agent-prediction-market) by Justin Chih-Yao Chen, Zaid Khan, Joykirat Singh, Runchu Tian, Hyunji Lee, Elias Stengel-Eskin and Mohit Bansal (2026).

## Installation

```bash theme={null}
pip install -U swarms
```

## Architecture

```mermaid theme={null}
graph TD
    A[Task] --> B[Solve: each agent writes attempts_per_agent solutions]
    B --> C[Group equal answers]
    C --> D[Listed answers: at least min_attempts, or your possible_answers]
    D --> E[Open market: opening prices follow attempt counts]
    E --> F[Round 1 sealed: each trader checks one solution per answer and bets]
    F --> G{First choices differ?}
    G -->|Yes| H[Round 2: prices only, trade once more]
    G -->|No| I[Close]
    H --> I
    I --> J[Highest closing price wins]
```

### Key Concepts

* **Attempts**: Independent solutions from `agents` worth `attempts_per_agent` each. Every attempt ends with a `final_answer`.
* **Listed answers**: Answers reached at least `min_attempts` times. When only one is listed, it is returned directly without opening a market. When none reaches `min_attempts`, every answer is listed.
* **LMSR market maker**: Prices follow `price / total` where each price is `exp(q / b)`. `liquidity` (`b`, default `10`) controls how much a chip moves the price.
* **Chips**: Every agent may spend `chips_per_agent` per round. Chips reset every run.
* **Structured outputs**: Solving returns `SolverOutput` and trading returns `TraderOutput` through `response_format`. Set `use_structured_outputs=False` to read formatted lines instead.

## Attributes

**id** `Optional[str]` (default: None)

Unique identifier for the market. When omitted, one is generated as `prediction-market-<32 hex characters>`.

**name** `str` (default: PredictionMarket)

Name of the market.

**description** `str` (default: A multi-agent prediction market that bets on candidate answers)

Description of the market.

**agents** `List[Agent]` *required*

The agents that solve and trade. Each needs a unique `agent_name`.

**attempts\_per\_agent** `int` (default: 3)

Independent solutions each agent writes before trading.

**min\_attempts** `int` (default: 2)

Fewest attempts an answer needs to be listed. When no answer reaches it, every answer is listed.

**chips\_per\_agent** `float` (default: 10.0)

Chips each agent may spend in one trading round.

**liquidity** `float` (default: 10.0)

The market maker liquidity parameter `b`. A larger value makes prices move less per chip.

**trading\_rounds** `int` (default: 2)

`1` for a sealed round only, or `2` to let agents trade again after seeing the prices. The second round runs only when first choices differ.

**max\_solution\_chars** `int` (default: 2000)

Longest solution shown to a trader. Longer solutions are truncated.

**answer\_normalizer** `Callable[[str], str]` (default: normalize\_answer)

Maps an answer to the grouping key. The default unwraps boxed answers, drops markup and a trailing period, collapses whitespace, and lowercases.

**seed** `Optional[int]` (default: None)

Seed for shuffling, for repeatable runs.

**autosave** `bool` (default: False)

When `True`, each run writes the conversation to the workspace directory.

**verbose** `bool` (default: False)

Whether to enable verbose logging.

**output\_type** `OutputType` (default: dict)

How `run` formats the conversation, for example `"dict"`, `"list"`, `"str"`, or `"final"`.

**use\_structured\_outputs** `bool` (default: True)

Ask for `SolverOutput` while solving and `TraderOutput` while trading through `response_format`. When `False`, the market reads `FINAL ANSWER`, `BELIEF` and `BUY` lines instead.

> [!NOTE]
>
> The constructor raises `ValueError` for empty agents, out-of-range settings, or repeated agent names. When `use_structured_outputs` is `True`, it also rejects agents with `max_loops="auto"`, which structured outputs do not support. Give agents a number or set `use_structured_outputs=False`. The market also restores each agent's original `output_schema` when a run ends.

## Methods

### run()

Open a market on the task and return the winning answer.

```python theme={null}
def run(self, task: str, img: Optional[str] = None, possible_answers: Optional[List[str]] = None, solve_attempts: bool = True, *args: Any, **kwargs: Any) -> Any
```

**Parameters:**

* `task` (str): The question to answer.
* `img` (Optional\[str]): Image sent to every agent with the task.
* `possible_answers` (Optional\[List\[str]]): Known options to trade on. Without them the market lists only answers reached by several attempts. With them the market lists these strings, using attempt counts for opening prices.
* `solve_attempts` (bool): Solve before trading when `True`. When `False` with `possible_answers` set, trade on the list directly without solving.

**Returns:** The conversation formatted according to `output_type`. Its last message holds the winning answer and the closing prices.

**Raises:**

* `RuntimeError`: If no attempt produced a final answer and no `possible_answers` were given.
* `ValueError`: If `possible_answers` is empty or duplicated, or if solving is off without `possible_answers`.

Every agent is reset before each call, so it must carry the system prompt and settings it should always use. When `possible_answers` is given but solving produces no matching attempts, the market still opens on the list instead of raising.

The structured outcome is kept on `market.result` as a `MarketResult` with `winner`, `market_opened`, `attempt_counts`, `opening_prices`, `closing_prices`, `trades`, and `beliefs`.

### batch\_run()

Run one market per task, one after another. `possible_answers` and `solve_attempts` are shared by every market.

```python theme={null}
def batch_run(self, tasks: List[str], possible_answers: Optional[List[str]] = None, solve_attempts: bool = True, *args: Any, **kwargs: Any) -> List[Any]
```

### usage

Provider token usage summed over every agent in the market, with `input_tokens`, `output_tokens`, `cached_tokens`, `reasoning_tokens`, and `total_tokens`.

```python theme={null}
market.usage
```

## Examples

### Market on an open-ended question

```python theme={null}
from swarms import Agent, PredictionMarket

agents = [
    Agent(agent_name=f"Trader-{i}", model_name="gpt-5.4", max_loops=1)
    for i in range(3)
]

market = PredictionMarket(
    agents=agents,
    attempts_per_agent=3,
    output_type="final",
    seed=0,
)

print(
    market.run(
        "In how many ways can the six corners of a regular hexagon "
        "be coloured with three colours so that neighbouring corners "
        "differ, counting rotations of each other once?"
    )
)

print(market.result.winner)
print(market.result.closing_prices)
```

### Market on a known list with search tools

```python theme={null}
from dotenv import load_dotenv

from swarms import Agent, PredictionMarket
from swarms_tools import exa_search

load_dotenv()

agents = [
    Agent(
        agent_name=f"Trader-{i}",
        system_prompt="You are a market analyst. Use exa_search to check recent market cap data before answering.",
        model_name="gpt-5.4",
        max_loops=3,
        tools=[exa_search],
    )
    for i in range(1, 7)
]

market = PredictionMarket(
    agents=agents,
    attempts_per_agent=2,
    use_structured_outputs=True,
    output_type="final",
    seed=0,
)

print(
    market.run(
        "Which of Apple, Microsoft or Nvidia will have the highest "
        "market capitalization on 31 December 2026?",
        possible_answers=["Apple", "Microsoft", "Nvidia"],
    )
)
```

## Source Code

View the [source code on GitHub](https://github.com/kyegomez/swarms/blob/master/swarms/structs/prediction_market.py)


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