From ec52359c9d38fcde80f51c4d5bb69d1e77734a7b Mon Sep 17 00:00:00 2001 From: Peter Jung Date: Wed, 6 Nov 2024 13:05:35 +0100 Subject: [PATCH] Job completion from general agent (#541) --- poetry.lock | 2 +- .../agents/microchain_agent/jobs_functions.py | 30 +++++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/poetry.lock b/poetry.lock index 23eaab67..b437eb85 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.8.4 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand. [[package]] name = "aiohappyeyeballs" diff --git a/prediction_market_agent/agents/microchain_agent/jobs_functions.py b/prediction_market_agent/agents/microchain_agent/jobs_functions.py index d098cfd4..1eb01a78 100644 --- a/prediction_market_agent/agents/microchain_agent/jobs_functions.py +++ b/prediction_market_agent/agents/microchain_agent/jobs_functions.py @@ -1,7 +1,6 @@ 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 @@ -24,14 +23,15 @@ class GetJobs(JobFunction): 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. +After completion, use SubmitJobResult. """ @property def example_args(self) -> list[int]: - return [10] + return [1] def __call__(self, max_bond: float) -> str: - jobs = get_jobs(self.market_type, limit=None) + jobs = self.market_type.job_class.get_jobs(limit=None) return json.dumps( [j.to_simple_job(max_bond=max_bond).model_dump() for j in jobs], indent=2, @@ -39,6 +39,30 @@ def __call__(self, max_bond: float) -> str: ) +class SubmitJobResult(JobFunction): + @property + def description(self) -> str: + return f"""Use this function to submit result of a job that you completed. +You need to submit this even if the job itself didn't ask for it explicitly, to prove that you completed the job. +""" + + @property + def example_args(self) -> list[int | str]: + return ["0x1", "GeneralAgent", 1, "I completed this job as described."] + + def __call__( + self, job_id: str, agent_name: str, max_bond: float, result: str + ) -> str: + job = self.market_type.job_class.get_job(id=job_id) + processed = job.submit_job_result(agent_name, max_bond, result) + return json.dumps( + processed.model_dump(), + indent=2, + default=str, + ) + + JOB_FUNCTIONS: list[type[JobFunction]] = [ GetJobs, + SubmitJobResult, ]