🐉Creating a new trader agent

In order to create a new trader agent, follow the steps below :

Clone the prediction-market-agent repository

git clone https://github.com/gnosis/prediction-market-agent.git

Copy .env.example as .env and fill in the variables

Step-by-Step Guide to Creating and Registering a New Agent

Step 1: Import necessary modules:

# From https://github.com/gnosis/prediction-market-agent/blob/main/prediction_market_agent/agents/coinflip_agent/deploy.py
import random
import typing as t
from prediction_market_agent_tooling.deploy.agent import (
    Answer,
    DeployableTraderAgent,
    Probability,
)
from prediction_market_agent_tooling.markets.agent_market import AgentMarket

Step 2 : Create a new class DeployableCoinFlipAgent that inherits from DeployableTraderAgent:




class DeployableCoinFlipAgent(DeployableTraderAgent):
    def pick_markets(self, markets: t.Sequence[AgentMarket]) -> t.Sequence[AgentMarket]:
        return random.sample(markets, 1)

    def answer_binary_market(self, market: AgentMarket) -> Answer | None:
        decision = random.choice([True, False])
        return Answer(
            decision=decision,
            confidence=0.5,
            p_yes=Probability(float(decision)),
            reasoning="I flipped a coin to decide.",
        )

Step - 3 : Register your class in the file run_agent by editing the variables RUNNABLE_AGENTS and RunnableAgent

from enum import Enum

import typer
from prediction_market_agent_tooling.markets.markets import MarketType

from prediction_market_agent.agents.coinflip_agent.deploy import DeployableCoinFlipAgent
from prediction_market_agent.agents.known_outcome_agent.deploy import (
    DeployableKnownOutcomeAgent,
)
from prediction_market_agent.agents.metaculus_agent.deploy import (
    DeployableMetaculusBotTournamentAgent,
)
from prediction_market_agent.agents.microchain_agent.deploy import (
    DeployableMicrochainAgent,
    DeployableMicrochainModifiableSystemPromptAgent,
)
from prediction_market_agent.agents.replicate_to_omen_agent.deploy import (
    DeployableReplicateToOmenAgent,
)
from prediction_market_agent.agents.social_media_agent.deploy import (
    DeployableSocialMediaAgent,
)
from prediction_market_agent.agents.think_thoroughly_agent.deploy import (
    DeployableThinkThoroughlyAgent,
)


class RunnableAgent(str, Enum):
    coinflip = "coinflip"
    replicate_to_omen = "replicate_to_omen"
    think_thoroughly = "think_thoroughly"
    knownoutcome = "knownoutcome"
    microchain = "microchain"
    microchain_modifiable_system_prompt = "microchain_modifiable_system_prompt"
    metaculus_bot_tournament_agent = "metaculus_bot_tournament_agent"
    social_media = "social_media"
    # Register the new agent here
    trader_agent = "trader_agent"


RUNNABLE_AGENTS = {
    RunnableAgent.coinflip: DeployableCoinFlipAgent,
    RunnableAgent.replicate_to_omen: DeployableReplicateToOmenAgent,
    RunnableAgent.think_thoroughly: DeployableThinkThoroughlyAgent,
    RunnableAgent.knownoutcome: DeployableKnownOutcomeAgent,
    RunnableAgent.microchain: DeployableMicrochainAgent,
    RunnableAgent.microchain_modifiable_system_prompt: DeployableMicrochainModifiableSystemPromptAgent,
    RunnableAgent.social_media: DeployableSocialMediaAgent,
    RunnableAgent.metaculus_bot_tournament_agent: DeployableMetaculusBotTournamentAgent,
    # Register the new agent here
    RunnableAgent.trader_agent: DeployableCoinFlipAgent,
}

APP = typer.Typer(pretty_exceptions_enable=False)


@APP.command()
def main(agent: RunnableAgent, market_type: MarketType) -> None:
    RUNNABLE_AGENTS[agent]().run(market_type)


if __name__ == "__main__":
    APP()

Step - 4 : Run the agent with the following command

# python prediction_market_agent/run_agent.py coinflip omen
python prediction_market_agent/run_agent.py trader_agent omen

You can replace trader_agent with the new agent's name and omen with the desired market type.

New Research Options or Betting Strategies

This can be done if you want to investigate new research options or betting strategies (by updating the function answer_binary_market) or try out new frameworks (refer to the Think Thoroughly agent, for an integration with CrewAI).

Last updated