Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coinflip agent deployment #64

Merged
merged 13 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a CMD/ENTRYPOINT here or is that done in the Kubernetes config? I guess if we're building this in CI then we want to test running it too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, command is easily changeable and I put it into Terraform https://github.com/gnosis/gnosisai-infrastructure/pull/3/files#diff-fa25fb4ef6fa67ec2382f07d26b9039099ce7a314a7e98517370a8439a0d0365R42

But if I put it here, it's easier to change it without the need for updating Terraform 🤔 I'll give it a try!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also support @evangriffiths suggestion, the Entrypoint seems to me something that should be part of the image definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep works fine, updated 🙏


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.
kongzii marked this conversation as resolved.
Show resolved Hide resolved
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)

evangriffiths marked this conversation as resolved.
Show resolved Hide resolved
def answer_binary_market(self, market: AgentMarket) -> bool | None:
return random.choice([True, False])
evangriffiths marked this conversation as resolved.
Show resolved Hide resolved
33 changes: 33 additions & 0 deletions prediction_market_agent/run_agent.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
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)
Loading