diff --git a/plugins/acp/acp_plugin_gamesdk/acp_client.py b/plugins/acp/acp_plugin_gamesdk/acp_client.py index d705e4a0..6e0ad73f 100644 --- a/plugins/acp/acp_plugin_gamesdk/acp_client.py +++ b/plugins/acp/acp_plugin_gamesdk/acp_client.py @@ -25,6 +25,7 @@ def __init__(self, api_key: str, acp_token: AcpToken): self.acp_base_url = self.acp_token.acp_base_url self.base_url = self.acp_token.game_api_url + "/acp" + self.chain_id = self.acp_token.chain_id @property def agent_wallet_address(self) -> str: @@ -49,6 +50,7 @@ def browse_agents( ) -> List[AcpAgent]: url = f"{self.acp_base_url}/agents" + hasGraduated = "true" if self.chain_id == 8453 else "false" params = { "search": query, @@ -56,6 +58,7 @@ def browse_agents( "filters[walletAddress][$notIn]": self.agent_wallet_address, "rerank": "true" if rerank else "false", "top_k": top_k, + "filters[hasGraduated]": hasGraduated, } response = requests.get(url, params=params) @@ -170,25 +173,20 @@ def create_job( return job_id def response_job(self, job_id: int, accept: bool, memo_id: int, reasoning: str): - if accept: - self.acp_token.sign_memo(memo_id, accept, reasoning) - time.sleep(5) - - return self.acp_token.create_memo( - job_id=job_id, - content=f"Job {job_id} accepted. {reasoning}", - memo_type=MemoType.MESSAGE, - is_secured=False, - next_phase=AcpJobPhases.TRANSACTION - ) - else: - return self.acp_token.create_memo( - job_id=job_id, - content=f"Job {job_id} rejected. {reasoning}", - memo_type=MemoType.MESSAGE, - is_secured=False, - next_phase=AcpJobPhases.REJECTED - ) + self.acp_token.sign_memo(memo_id, accept, reasoning) + + if not accept: + return + + time.sleep(5) + + return self.acp_token.create_memo( + job_id=job_id, + content=f"Job {job_id} accepted. {reasoning}", + memo_type=MemoType.MESSAGE, + is_secured=False, + next_phase=AcpJobPhases.TRANSACTION + ) def make_payment(self, job_id: int, amount: float, memo_id: int, reason: str): # Convert amount to Wei (smallest ETH unit) diff --git a/plugins/acp/acp_plugin_gamesdk/acp_token.py b/plugins/acp/acp_plugin_gamesdk/acp_token.py index 671ccec4..fd6b3a28 100644 --- a/plugins/acp/acp_plugin_gamesdk/acp_token.py +++ b/plugins/acp/acp_plugin_gamesdk/acp_token.py @@ -93,6 +93,7 @@ def __init__( ) self.acp_base_url = config.acp_api_url self.game_api_url = config.game_api_url + self.chain_id = config.chain_id def get_agent_wallet_address(self) -> str: return self.agent_wallet_address diff --git a/plugins/acp/examples/reactive/buyer.py b/plugins/acp/examples/reactive/buyer.py index e163d0cb..2dda0afe 100644 --- a/plugins/acp/examples/reactive/buyer.py +++ b/plugins/acp/examples/reactive/buyer.py @@ -53,6 +53,10 @@ def on_evaluate(deliverable: IDeliverable) -> Tuple[bool, str]: def buyer(): # upon phase change, the buyer agent will respond to the transaction def on_phase_change(job: AcpJob) -> None: + if job.phase != AcpJobPhasesDesc.REJECTED: + print(f"Job phase is rejected.") + return + out = "" out += f"Buyer agent is reacting to job:\n{job}\n\n"