Skip to main content

Overview

This tutorial shows how to build autonomous prediction market agents using Swarms with the Polymarket API. You will build agents that discover markets, estimate probabilities, find edges against market odds, and execute trades programmatically. We cover a single-agent pattern for simple market analysis and a multi-agent swarm pattern with specialized research, analysis, risk, and execution agents.
Trading involves real financial risk. Always start with paper trading / dry-run mode before using real funds. The examples below include guardrails and dry-run mode — use them.

Prerequisites

Dependencies

API Keys & Accounts

  1. Create a wallet on Polymarket and fund it with USDC on Polygon
  2. Export your private key from your wallet
  3. Derive API credentials using the py-clob-client SDK
  4. Set environment variables:
Set your OpenAI key (or any provider supported by Swarms):

Part 1: Market Discovery Tools

Polymarket uses three APIs: Gamma (market discovery), CLOB (pricing/trading), and Data (positions). Market discovery endpoints are public — no authentication needed.

Part 2: Single-Agent Pattern

A single agent that discovers Polymarket markets, reasons about probability, and identifies edges.

Part 3: Multi-Agent Swarm Pattern

For serious trading, use a multi-agent swarm with specialized roles. Each agent has a focused responsibility, and they work together in a sequential pipeline.

Execution Tool

First, build the tool for actually placing trades (with dry-run support):

Agent Definitions

Running the Swarm

The sequential pipeline works as follows:
  1. Research Agent discovers markets and gathers context
  2. Analyst Agent estimates probabilities and identifies edges
  3. Risk Agent filters, sizes positions, and enforces limits
  4. Execution Agent places the approved orders (dry-run by default)

Part 4: Guardrails & Best Practices

Dry-Run Mode

The DRY_RUN = True flag at the top of the execution tool prevents any real orders from being placed. Set it to False only when you are confident in the system.

Position Limits

The risk agent enforces these limits, but you should also add hard-coded checks:

Logging

Log every agent decision and trade for audit purposes:

Paper Trading

Polymarket has no official testnet. Use DRY_RUN = True for simulation, or trade with very small sizes ($1-5) on mainnet to validate end-to-end flow.

Next Steps

Kalshi Prediction Markets

Build the same agent pattern against Kalshi’s regulated event markets.

Financial Analysis System

Multi-agent market analysis with MixtureOfAgents.