Overview
This tutorial shows how to build autonomous prediction market agents using Swarms with the Kalshi 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
Kalshi Setup
Kalshi Setup
LLM API Key
LLM API Key
Set your OpenAI key (or any provider supported by Swarms):
Part 1: Market Discovery Tools
Kalshi uses RSA-PSS signature authentication for trading endpoints. Market discovery endpoints are public — no auth needed.Part 2: Single-Agent Pattern
A single agent that discovers Kalshi 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:Demo / Paper Trading
Kalshi provides a full demo environment athttps://demo-api.kalshi.co/trade-api/v2. Create a separate demo account, generate a demo API key, and change KALSHI_BASE to KALSHI_DEMO_BASE in your code to test end-to-end flow without risking real funds.
Next Steps
Polymarket Prediction Markets
Build the same agent pattern against Polymarket’s crypto-native markets.
Financial Analysis System
Multi-agent market analysis with MixtureOfAgents.