Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Prediction Market Agent Tooling

Tooling for benchmarking, deploying and monitoring agents for prediction market applications.

Setup

Install the project dependencies with poetry, using Python >=3.10:

python3.10 -m pip install poetry
python3.10 -m poetry install
python3.10 -m poetry shell

Create a .env file in the root of the repo with the following variables:

Deploying and monitoring agents using GCP requires that you set up the gcloud CLI (see here for installation instructions, and use gcloud auth login to authorize.)

MANIFOLD_API_KEY=...
BET_FROM_PRIVATE_KEY=...
OPENAI_API_KEY=...

Benchmarking

Create a benchmarkable agent by subclassing the AbstractBenchmarkedAgent base class, and plug in your agent's research and prediction functions into the predict method.

Use the Benchmarker class to compare your agent's predictions vs. the 'wisdom of the crowd' on a set of markets from your chosen prediction market platform.

For example:

import prediction_market_agent_tooling.benchmark.benchmark as bm
from prediction_market_agent_tooling.benchmark.agents import RandomAgent
from prediction_market_agent_tooling.markets.markets import MarketType, get_binary_markets

benchmarker = bm.Benchmarker(
    markets=get_binary_markets(limit=10, market_type=MarketType.MANIFOLD),
    agents=[RandomAgent(agent_name="a_random_agent")],
)
benchmarker.run_agents()
md = benchmarker.generate_markdown_report()

This produces a markdown report that you can use for comparing agents side-by-side, like:

Benchmark results

Deploying

Deprecated: We suggest using your own infrastructure to deploy, but you may still find this useful.

Create a deployable agent by subclassing the DeployableTraderAgent base class, and implementing the answer_binary_market method.

For example, deploy an agent that randomly picks an outcome:

import random
from prediction_market_agent_tooling.deploy.agent import DeployableTraderAgent
from prediction_market_agent_tooling.markets.agent_market import AgentMarket

class DeployableCoinFlipAgent(DeployableTraderAgent):
    def answer_binary_market(self, market: AgentMarket) -> bool | None:
        return random.choice([True, False])

DeployableCoinFlipAgent().deploy_gcp(...)

Safe

Agents can control funds via a wallet primary key only, or optionally via a Safe as well. For deploying a Safe manually for a given agent, run the script below:

poetry run python scripts/create_safe_for_agent.py  --from-private-key <YOUR_AGENT_PRIVATE_KEY> --salt-nonce 42

This will output the newly created Safe in the terminal, and it can then be copied over to the deployment part (e.g. Terraform). Note that salt_nonce can be passed so that the created safe is deterministically created for each agent, so that, if the same salt_nonce is used, the script will not create a new Safe for the agent, instead it will output the previously existent Safe.

You can then specify this agent's Safe address with the SAFE_ADDRESS environment variable.

Monitoring

Monitor the performance of the agents deployed to GCP, as well as meta-metrics of the prediction market platforms they are deployed to.

This runs as a streamlit app on a localhost server, executed with:

PYTHONPATH=. streamlit run examples/monitor/monitor.py

Which launches in the browser:

Monitoring

The Market Platforms

The following prediction market platforms are supported:

Platform Benchmarking Deployment Monitoring
Manifold ✅ ✅ ✅
AIOmen ✅ ✅ ✅
Polymarket ✅ ❌ ❌

Prediction Markets Python API

We have built clean abstractions for taking actions on the different prediction market platforms (retrieving markets, buying and selling tokens, etc.). This is currently undocumented, but for now, inspecting the AgentMarket class and its methods is your best bet.

For example:

from prediction_market_agent_tooling.config import APIKeys
from prediction_market_agent_tooling.markets.agent_market import SortBy
from prediction_market_agent_tooling.markets.omen.omen import OmenAgentMarket

# Place a bet on the market closing soonest
market = OmenAgentMarket.get_binary_markets(limit=1, sort_by=SortBy.CLOSING_SOONEST)[0]
market.place_bet(outcome=True, amount=market.get_bet_amount(0.1))

# View your positions
my_positions = OmenAgentMarket.get_positions(user_id=APIKeys().bet_from_address)
print(my_positions)

# Sell position (accounting for fees)
market.sell_tokens(outcome=True, amount=market.get_bet_amount(0.095))

This API can be built on top of to create your application. See here for an example.

Contributing

See the Issues for ideas of things that need fixing or implementing. The team is also receptive to new issues and PRs.

We use mypy for static type checking, and isort, black and autoflake for linting, and pre-commit to minimise unwanted pushes to the public repositories. These all run as steps in CI, but pre-commit also needs to be installed locally using the provided install_hooks.sh script.

Metadata

Release files for prediction-market-agent-tooling 0.64.11.dev653

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prediction-market-agent-tooling 0.64.11.dev653
File Size Uploaded
prediction_market_agent_tooling-0.64.11.dev653.tar.gz 156.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for prediction-market-agent-tooling 0.64.11.dev653
File Interpreter ABI Platform
prediction_market_agent_tooling-0.64.11.dev653-py3-none-any.whl Python 3 none any Details

Total release size: 370.2 kB

Release files / prediction_market_agent_tooling-0.64.11.dev653.tar.gz

Download URL prediction_market_agent_tooling-0.64.11.dev653.tar.gz
Size 156.9 kB
Tags Source
SHA-256 checksum
How to use checksums
027ac9430781ab39d34ff0f5c5eb3235bbedfbdd25dbfb275fa82bf9ef1a881e
BLAKE2b-256 checksum
How to use checksums
fbbe30c43de682886ad10ecea05c484f01999be8d3e4043abf9db2af84559548
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-1012-azure

Release files / prediction_market_agent_tooling-0.64.11.dev653-py3-none-any.whl

Download URL prediction_market_agent_tooling-0.64.11.dev653-py3-none-any.whl
Size 213.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
35b330341ae2fed68cc2dc7116fcc8b6d41bbd423cce1afd154351b3ad35c43f
BLAKE2b-256 checksum
How to use checksums
8db026eb781b50b5b90a443f8cee8bd23102c7a7ee3201c34515e37f070607d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-1012-azure

Release history Release notifications | RSS feed

0.69.9

2 release files

0.69.8

2 release files

0.69.7

2 release files

0.69.5

2 release files

0.69.4

2 release files

0.69.3

2 release files

0.69.2

2 release files

0.69.1

2 release files

0.69.0

2 release files

0.68.1

2 release files

0.68.0

2 release files

0.67.3

2 release files

0.67.2

2 release files

0.67.1

2 release files

0.66.6

2 release files

0.66.2

2 release files

0.66.1

2 release files

0.66.0

2 release files

0.65.7

2 release files

0.65.6

2 release files

0.65.5

2 release files

0.65.4

2 release files

0.65.3

2 release files

0.65.2

2 release files

0.65.1

2 release files

0.65.0

2 release files

This release

0.64.11.dev653 This release

2 release files

0.64.9

2 release files

0.64.8

2 release files

0.64.7

2 release files

0.64.1

2 release files

0.64.0

2 release files

0.63.9

2 release files

0.63.8

2 release files

0.63.7

2 release files

0.63.6

2 release files

0.62.1

2 release files

0.62.0

2 release files

0.61.1

2 release files

0.61.0

2 release files

0.60.2

2 release files

0.60.1

2 release files

0.60.0

2 release files

0.59.2

2 release files

0.59.1

2 release files

0.59.0

2 release files

0.58.5

2 release files

0.58.4

2 release files

0.58.3

2 release files

0.58.2

2 release files

0.58.1

2 release files

0.58.0

2 release files

0.57.9

2 release files

0.57.8

2 release files

0.57.3

2 release files

0.57.2

2 release files

0.57.1

2 release files

0.57.0

2 release files

0.56.3

2 release files

0.56.2

2 release files

0.55.2

2 release files

0.55.1

2 release files

0.55.0

2 release files

0.54.0

2 release files

0.53.0

2 release files

0.52.2

2 release files

0.52.1

2 release files

0.52.0

2 release files

0.51.1

2 release files

0.49.0

2 release files

0.48.6

2 release files

0.48.5

2 release files

0.48.4

2 release files

0.48.3

2 release files

0.48.2

2 release files

0.48.1

2 release files

0.48.0

2 release files

0.47.1

2 release files

0.45.0

2 release files

0.44.0

2 release files

0.43.4

2 release files

0.43.2

2 release files

0.43.1

2 release files

0.43.0

2 release files

0.42.1

2 release files

0.42.0

2 release files

0.39.4

1 release file

0.39.3

2 release files

0.39.2

2 release files

0.39.1

2 release files

0.39.0

2 release files

0.38.0

2 release files

0.37.0

2 release files

0.33.0

2 release files

0.32.0

2 release files

0.31.0

1 release file

0.30.0

2 release files

0.29.0

2 release files

0.28.0

2 release files

0.27.0

2 release files

0.21.0

2 release files

0.20.0

2 release files

0.19.0

2 release files

0.18.0

2 release files

0.17.0

2 release files

0.16.0

2 release files

0.15.1

2 release files

0.15.0

2 release files

0.14.1

2 release files

0.14.0

2 release files

0.13.2

2 release files

0.13.1

2 release files

0.13.0

2 release files

0.11.0

2 release files

0.9.3

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.8

2 release files

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page