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.Prerequisites
Dependencies
API Keys & Accounts
Polymarket Setup
Polymarket Setup
- Create a wallet on Polymarket and fund it with USDC on Polygon
- Export your private key from your wallet
- Derive API credentials using the py-clob-client SDK
- Set environment variables:
LLM API Key
LLM API Key
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
- Research Agent discovers markets and gathers context
- Analyst Agent estimates probabilities and identifies edges
- Risk Agent filters, sizes positions, and enforces limits
- Execution Agent places the approved orders (dry-run by default)
Part 4: Guardrails & Best Practices
Dry-Run Mode
TheDRY_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. UseDRY_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.