Skip to content

Commit

Permalink
Job completion from general agent (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
kongzii authored Nov 6, 2024
1 parent 612db6b commit ec52359
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
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.

30 changes: 27 additions & 3 deletions prediction_market_agent/agents/microchain_agent/jobs_functions.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -24,21 +23,46 @@ 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,
default=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,
]

0 comments on commit ec52359

Please sign in to comment.