Skip to main content
This guide will walk you through running your first agent using the simple coinflip agent example.

Before you begin

Make sure you have:
  1. Completed the installation steps
  2. Configured your environment variables (minimum: BET_FROM_PRIVATE_KEY and OPENAI_API_KEY)

Running the coinflip agent

The coinflip agent is the simplest agent in the library. It makes random predictions by “flipping a coin” to decide between yes/no on binary markets.
1

Activate Poetry shell

If you haven’t already, activate the Poetry environment:
python3.11 -m poetry shell
2

Run the agent

Execute the coinflip agent on the Omen market:
python prediction_market_agent/run_agent.py coinflip omen
The agent will:
  • Fetch available markets from Omen/Presagio
  • Select a market to bet on
  • Make a random prediction (coin flip)
  • Place a bet on the market
3

View the output

You’ll see output showing:
  • Which market was selected
  • The agent’s prediction and reasoning
  • Transaction details if a bet was placed
The first run may take longer as it fetches and processes market data.

Available agents and markets

Viewing available options

To see all available agents and market types:
python prediction_market_agent/run_agent.py --help

Agent options

The library includes many pre-built agents:
  • coinflip - Random predictions
  • knownoutcome - Bets on markets with known outcomes (for testing)

Market type options

Supported market platforms:
  • omen - Decentralized prediction markets on Gnosis Chain (Presagio)
  • manifold - Play-money prediction markets
  • polymarket - Cryptocurrency-based prediction markets
  • metaculus - Forecasting platform

Running other agents

Try running different agents on different platforms:
python prediction_market_agent/run_agent.py prophet_gpt4o polymarket
Different agents may require additional environment variables. The agent will inform you if any required variables are missing.

Understanding the coinflip agent code

Here’s the complete implementation of the coinflip agent to understand how simple it is to create an agent:
prediction_market_agent/agents/coinflip_agent/deploy.py
import random
from datetime import timedelta

from prediction_market_agent_tooling.deploy.agent import DeployableTraderAgent
from prediction_market_agent_tooling.deploy.trade_interval import (
    FixedInterval,
    TradeInterval,
)
from prediction_market_agent_tooling.gtypes import Probability
from prediction_market_agent_tooling.markets.agent_market import AgentMarket, SortBy
from prediction_market_agent_tooling.markets.data_models import ProbabilisticAnswer
from prediction_market_agent_tooling.markets.markets import MarketType


class DeployableCoinFlipAgent(DeployableTraderAgent):
    def verify_market(self, market_type: MarketType, market: AgentMarket) -> bool:
        return True

    def answer_binary_market(self, market: AgentMarket) -> ProbabilisticAnswer | None:
        decision = random.choice([True, False])
        return ProbabilisticAnswer(
            confidence=0.5,
            p_yes=Probability(float(decision)),
            reasoning="I flipped a coin to decide.",
        )

Key components

All agents inherit from DeployableTraderAgent which provides:
  • Market fetching and filtering
  • Bet placement logic
  • Error handling and logging
  • Trade interval management
Called to determine if the agent should consider a market. The coinflip agent accepts all markets by returning True.
The core logic that returns a prediction. Must return a ProbabilisticAnswer with:
  • p_yes - Probability of “yes” outcome (0.0 to 1.0)
  • confidence - Agent’s confidence in the prediction
  • reasoning - Explanation of the prediction

Interactive Streamlit app

For a more interactive experience, try the agent research app:
streamlit run scripts/agent_app.py
This opens a web interface where you can:
  • Browse prediction markets
  • Select multiple agents to analyze the same question
  • Compare agent predictions and reasoning
  • See real-time research and analysis
The Streamlit app is also deployed at pma-agent.ai.gnosisdev.com

Next steps

Create your own agent

Learn how to build custom agents by subclassing DeployableTraderAgent

Deploy to production

Deploy your agent to cloud infrastructure for continuous trading

Advanced configuration

Configure advanced features like trade intervals, market filtering, and more

View live agents

Track deployed agents on the Dune Analytics dashboard

Build docs developers (and LLMs) love