Skip to content

Commit

Permalink
Coinflip agent deployment (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
kongzii authored Apr 11, 2024
1 parent 284fe76 commit 0b1b213
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 3 deletions.
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Docker specific ignores:
.git

# .gitignore ignores:
.env
.agents_workspace
.cache
__pycache__
*.egg-info
logs
.mypy_cache
.pytest_cache
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
requirements.txt
.venv
.env
.agents_workspace
.cache
Expand Down
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Install Poetry and create venv in the builder step,
# then copy the venv to the runtime image, so that the runtime image is as small as possible.
FROM --platform=linux/amd64 python:3.10.14-slim-bookworm AS builder

RUN pip install poetry==1.8.2

ENV POETRY_NO_INTERACTION=1 \
POETRY_VIRTUALENVS_IN_PROJECT=1 \
POETRY_VIRTUALENVS_CREATE=1 \
POETRY_CACHE_DIR=/tmp/poetry_cache

WORKDIR /app

COPY pyproject.toml poetry.lock ./

RUN --mount=type=cache,target=$POETRY_CACHE_DIR poetry install --no-root --only main

FROM --platform=linux/amd64 python:3.10.14-slim-bookworm AS runtime

ENV VIRTUAL_ENV=/app/.venv \
PATH="/app/.venv/bin:$PATH"

WORKDIR /app

COPY --from=builder ${VIRTUAL_ENV} ${VIRTUAL_ENV}

COPY prediction_market_agent ./prediction_market_agent

ENV PYTHONPATH=/app

CMD ["bash", "-c", "python prediction_market_agent/run_agent.py ${runnable_agent_name} ${market_type}"]
3 changes: 3 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
# TODO: This should be automated as part of CI/CD pipeline, but for now, execute it locally on the main branch.
docker build . -t ghcr.io/gnosis/pma:latest && docker push ghcr.io/gnosis/pma:latest
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions prediction_market_agent/agents/coinflip_agent/deploy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import random
import typing as t

from prediction_market_agent_tooling.deploy.agent import DeployableAgent
from prediction_market_agent_tooling.markets.agent_market import AgentMarket


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

def answer_binary_market(self, market: AgentMarket) -> bool | None:
return random.choice([True, False])
31 changes: 31 additions & 0 deletions prediction_market_agent/run_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""
Entrypoint for running the agent in GKE.
If the agent adheres to PMAT standard (subclasses DeployableAgent),
simply add the agent to the `RunnableAgent` enum and then `RUNNABLE_AGENTS` dict.
Can also be executed locally, simply by running `python prediction_market_agent/run_agent.py <agent> <market_type>`.
"""

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


class RunnableAgent(str, Enum):
coinflip = "coinflip"


RUNNABLE_AGENTS = {
RunnableAgent.coinflip: DeployableCoinFlipAgent,
}


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


if __name__ == "__main__":
typer.run(main)

0 comments on commit 0b1b213

Please sign in to comment.