Skip to main content

Tools to benchmark, deploy and monitor prediction market agents.

Project description

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.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prediction_market_agent_tooling-0.62.0.dev490.tar.gz (149.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file prediction_market_agent_tooling-0.62.0.dev490.tar.gz.

File metadata

File hashes

Hashes for prediction_market_agent_tooling-0.62.0.dev490.tar.gz
Algorithm Hash digest
SHA256 784d90b759e2d0af8b067ef99beb976d81ec7e80859937b1cf9fa626d453552b
MD5 0041d12b439456e5301657c068defb29
BLAKE2b-256 ba832012dc9cdfa83121c744ecad3277021c9477f9005d826d8af82b2b66d50c

See more details on using hashes here.

File details

Details for the file prediction_market_agent_tooling-0.62.0.dev490-py3-none-any.whl.

File metadata

File hashes

Hashes for prediction_market_agent_tooling-0.62.0.dev490-py3-none-any.whl
Algorithm Hash digest
SHA256 b4fb8e40ed441640caf66b60efd8fe4ffbc21a4abc3b66d332dd6d7a79b969ee
MD5 93428f7811788d691c60376497e75295
BLAKE2b-256 15473f198e19d9de309cab0deb5c0e8fa3bf0be8e8418174d7b77d83c7328573

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page