Skip to content

Commit

Permalink
Use get jobs from PMAT (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
kongzii authored Sep 19, 2024
1 parent 6aa5200 commit 1b3afe6
Show file tree
Hide file tree
Showing 7 changed files with 530 additions and 492 deletions.
897 changes: 467 additions & 430 deletions poetry.lock

Large diffs are not rendered by default.

51 changes: 0 additions & 51 deletions prediction_market_agent/agents/microchain_agent/call_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,58 +73,7 @@ def __call__(
return "Message sent"


class GetTasks(Function):
@property
def description(self) -> str:
return "Use this function to get available tasks in a JSON dumped format."

@property
def example_args(self) -> list[str]:
return []

def __call__(self) -> str:
return json.dumps(
[
{
"id": "1",
"title": """Solve the following math problem:
If there are 3 apples and you take away 2, how many do you have?
Send the answer to Telegram Chat ID 6514789173.
""",
"reward": {
"amount": 1,
"currency": "wxDai",
},
},
{
"id": "2",
"title": """
Do a prediction on the following Omen market with id `0xa6febd6ffda06af320f5d92ec3dd562149cc2bc7`.
Send the result to Telegram Chat ID 6514789173.
""",
"reward": {
"amount": 1,
"currency": "wETH",
},
},
{
"id": "3",
"title": "Install Python library `chihuahua` and then execute the following code: `import chihuahua; print(42)`.",
"reward": {
"amount": 2,
"currency": "wxDai",
},
},
],
indent=2,
)


API_FUNCTIONS: list[type[Function]] = [
CallAPI,
SendTelegramMessage,
GetTasks,
]
44 changes: 44 additions & 0 deletions prediction_market_agent/agents/microchain_agent/jobs_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import json

from microchain import Function
from prediction_market_agent_tooling.jobs.jobs import get_jobs
from prediction_market_agent_tooling.markets.data_models import Currency
from prediction_market_agent_tooling.markets.markets import MarketType

from prediction_market_agent.utils import APIKeys


class JobFunction(Function):
def __init__(self, market_type: MarketType, keys: APIKeys) -> None:
self.keys = keys
self.market_type = market_type
super().__init__()

@property
def currency(self) -> Currency:
return self.market_type.market_class.currency


class GetJobs(JobFunction):
@property
def description(self) -> str:
return f"""Use this function to get available jobs in a JSON dumped format.
You need to provide max bond value in {self.currency}, that is, how much you are willing to bond on the fact that you completed the job as required in the job description.
"""

@property
def example_args(self) -> list[int]:
return [10]

def __call__(self, max_bond: float) -> str:
jobs = get_jobs(self.market_type, limit=None)
return json.dumps(
[j.to_simple_job(max_bond=max_bond).model_dump() for j in jobs],
indent=2,
default=str,
)


JOB_FUNCTIONS: list[type[JobFunction]] = [
GetJobs,
]
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
withdraw_wxdai_to_xdai_to_keep_balance,
)
from prediction_market_agent_tooling.tools.betting_strategies.kelly_criterion import (
get_kelly_bet,
get_kelly_bet_simplified,
)
from prediction_market_agent_tooling.tools.tavily_storage.tavily_models import (
TavilyStorage,
Expand Down Expand Up @@ -420,7 +420,7 @@ def __call__(
) -> str:
confidence = 0.5 # Until confidence score is available, be conservative
max_bet = float(get_balance(self.keys, market_type=self.market_type).amount)
kelly_bet = get_kelly_bet(
kelly_bet = get_kelly_bet_simplified(
market_p_yes=market_p_yes,
estimated_p_yes=estimated_p_yes,
max_bet=max_bet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from prediction_market_agent.agents.microchain_agent.code_functions import (
CODE_FUNCTIONS,
)
from prediction_market_agent.agents.microchain_agent.jobs_functions import JOB_FUNCTIONS
from prediction_market_agent.agents.microchain_agent.learning_functions import (
LEARNING_FUNCTIONS,
)
Expand Down Expand Up @@ -120,6 +121,9 @@ def build_agent_functions(
functions.extend([f() for f in API_FUNCTIONS])
functions.extend([f() for f in CODE_FUNCTIONS])

if functions_config.include_job_functions:
functions.extend([f(market_type=market_type, keys=keys) for f in JOB_FUNCTIONS])

if functions_config.include_learning_functions:
functions.extend([f() for f in LEARNING_FUNCTIONS])

Expand Down
20 changes: 12 additions & 8 deletions prediction_market_agent/agents/microchain_agent/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@
Make 'Reasoning' calls frequently - at least every other call. You need to reason step by step.
"""

# Experimental system prompt for task-solving agent.
TASK_AGENT_SYSTEM_PROMPT = f"""Act as a task-solving agents that picks up available tasks and solves them for getting rewards.
# Experimental system prompt for job-solving agent.
JOB_AGENT_SYSTEM_PROMPT = f"""Act as a job-solving agents that picks up available jobs and completes them for getting rewards.
Pick up available task that's returned from GetTasks and pick one that you can solve and it's worth solving.
Pick up available job that's returned from GetJobs and pick one that you can complete and it's worth finishing.
While solving a task, reason step by step and write down thoroughly the process. You can use the 'Reasoning' function for that.
While working on a job, reason step by step and write down thoroughly the process. You can use the 'Reasoning' function for that.
Don't do anything else, just solve the task, and then pick up another one.
Don't do anything else, just complete the job, and then pick up another one.
{NON_UPDATABLE_DIVIDOR}
Expand Down Expand Up @@ -91,7 +91,7 @@ class SystemPromptChoice(str, Enum):
JUST_BORN = "just_born"
TRADING_AGENT = "trading_agent"
TRADING_AGENT_MINIMAL = "trading_agent_minimal"
TASK_AGENT = "task_agent"
JOB_AGENT = "job_agent"


class FunctionsConfig(BaseModel):
Expand All @@ -100,6 +100,7 @@ class FunctionsConfig(BaseModel):
include_trading_functions: bool
include_universal_functions: bool
include_agent_functions: bool
include_job_functions: bool

@staticmethod
def from_system_prompt_choice(
Expand All @@ -109,6 +110,7 @@ def from_system_prompt_choice(
include_learning_functions = False
include_universal_functions = False
include_agent_functions = False
include_job_functions = False

if system_prompt_choice == SystemPromptChoice.JUST_BORN:
include_learning_functions = True
Expand All @@ -121,22 +123,24 @@ def from_system_prompt_choice(
]:
include_trading_functions = True

elif system_prompt_choice == SystemPromptChoice.TASK_AGENT:
elif system_prompt_choice == SystemPromptChoice.JOB_AGENT:
include_universal_functions = True
include_agent_functions = True
include_trading_functions = True
include_job_functions = True

return FunctionsConfig(
include_trading_functions=include_trading_functions,
include_learning_functions=include_learning_functions,
include_universal_functions=include_universal_functions,
include_agent_functions=include_agent_functions,
include_job_functions=include_job_functions,
)


SYSTEM_PROMPTS: dict[SystemPromptChoice, str] = {
SystemPromptChoice.JUST_BORN: SYSTEM_PROMPT,
SystemPromptChoice.TRADING_AGENT: TRADING_AGENT_SYSTEM_PROMPT,
SystemPromptChoice.TASK_AGENT: TASK_AGENT_SYSTEM_PROMPT,
SystemPromptChoice.JOB_AGENT: JOB_AGENT_SYSTEM_PROMPT,
SystemPromptChoice.TRADING_AGENT_MINIMAL: TRADING_AGENT_SYSTEM_PROMPT_MINIMAL,
}
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ poetry = "^1.7.1"
poetry-plugin-export = "^1.6.0"
functions-framework = "^3.5.0"
cron-validator = "^1.0.8"
prediction-market-agent-tooling = { version = "^0.48.14", extras = ["langchain", "google"] }
prediction-market-agent-tooling = { version = "^0.48.15", extras = ["langchain", "google"] }
pydantic-settings = "^2.1.0"
autoflake = "^2.2.1"
isort = "^5.13.2"
Expand Down

0 comments on commit 1b3afe6

Please sign in to comment.