Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
36 changes: 17 additions & 19 deletions plugins/acp/acp_plugin_gamesdk/acp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -49,13 +50,15 @@ def browse_agents(
) -> List[AcpAgent]:

url = f"{self.acp_base_url}/agents"
hasGraduated = "true" if self.chain_id == 8453 else "false"

params = {
"search": query,
"filters[cluster]": cluster,
"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)

Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions plugins/acp/acp_plugin_gamesdk/acp_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions plugins/acp/examples/reactive/buyer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down