acp-plugin-gamesdk 0.1.2__tar.gz → 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: acp-plugin-gamesdk
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: ACP Plugin for Python SDK for GAME by Virtuals
5
5
  Author: Steven Lee Soon Fatt
6
6
  Author-email: steven@virtuals.io
@@ -109,7 +109,7 @@ acp_plugin = AcpPlugin(
109
109
  ```
110
110
 
111
111
  > Note:
112
- > - Your ACP token for your buyer and seller should be different.
112
+ > - Your agent wallet address for your buyer and seller should be different.
113
113
  > - Speak to a DevRel (Celeste/John) to get a GAME Dev API key
114
114
 
115
115
  > To Whitelist your Wallet:
@@ -84,7 +84,7 @@ acp_plugin = AcpPlugin(
84
84
  ```
85
85
 
86
86
  > Note:
87
- > - Your ACP token for your buyer and seller should be different.
87
+ > - Your agent wallet address for your buyer and seller should be different.
88
88
  > - Speak to a DevRel (Celeste/John) to get a GAME Dev API key
89
89
 
90
90
  > To Whitelist your Wallet:
@@ -2,7 +2,7 @@ from datetime import datetime, timedelta
2
2
  from typing import List, Optional
3
3
  from web3 import Web3
4
4
  import requests
5
- from acp_plugin_gamesdk.interface import AcpAgent, AcpJobPhases, AcpState
5
+ from acp_plugin_gamesdk.interface import AcpAgent, AcpJobPhases, AcpOffering, AcpState
6
6
  from acp_plugin_gamesdk.acp_token import AcpToken, MemoType
7
7
  import time
8
8
 
@@ -29,7 +29,6 @@ class AcpClient:
29
29
  def browse_agents(self, cluster: Optional[str] = None, query: Optional[str] = None) -> List[AcpAgent]:
30
30
  url = f"{self.acp_base_url}/agents"
31
31
 
32
- # Build URL with query parameters
33
32
  if query:
34
33
  url += f"?search={requests.utils.quote(query)}"
35
34
 
@@ -49,24 +48,25 @@ class AcpClient:
49
48
 
50
49
  for agent in response_json.get("data", []):
51
50
  result.append(
52
- {
53
- "id": agent["id"],
54
- "name": agent["name"],
55
- "description": agent["description"],
56
- "walletAddress": agent["walletAddress"]
57
- }
51
+ AcpAgent(
52
+ id=agent["id"],
53
+ name=agent["name"],
54
+ description=agent["description"],
55
+ wallet_address=agent["walletAddress"],
56
+ offerings=[AcpOffering(name=offering["name"], price=offering["price"]) for offering in agent["offerings"]]
57
+ )
58
58
  )
59
59
 
60
60
  return result
61
61
 
62
62
  def create_job(self, provider_address: str, price: float, job_description: str) -> int:
63
63
  expire_at = datetime.now() + timedelta(days=1)
64
-
65
64
  tx_result = self.acp_token.create_job(
66
65
  provider_address=provider_address,
67
66
  evaluator_address=provider_address,
68
67
  expire_at=expire_at
69
68
  )
69
+
70
70
  job_id = None
71
71
  retry_count = 3
72
72
  retry_delay = 3
@@ -133,7 +133,6 @@ class AcpClient:
133
133
  def response_job(self, job_id: int, accept: bool, memo_id: int, reasoning: str):
134
134
  if accept:
135
135
  self.acp_token.sign_memo(memo_id, accept, reasoning)
136
-
137
136
  time.sleep(5)
138
137
 
139
138
  return self.acp_token.create_memo(
@@ -162,7 +161,7 @@ class AcpClient:
162
161
  time.sleep(5)
163
162
  return self.acp_token.sign_memo(memo_id, True, reason)
164
163
 
165
- def deliver_job(self, job_id: int, deliverable: str, memo_id: int, reason: str):
164
+ def deliver_job(self, job_id: int, deliverable: str):
166
165
  return self.acp_token.create_memo(
167
166
  job_id=int(job_id),
168
167
  content=deliverable,
@@ -172,17 +171,6 @@ class AcpClient:
172
171
  )
173
172
 
174
173
  def add_tweet(self, job_id: int, tweet_id: str, content: str):
175
- """
176
- Add a tweet to a job.
177
-
178
- Args:
179
- job_id: The ID of the job
180
- tweet_id: The ID of the tweet
181
- content: The content of the tweet
182
-
183
- Raises:
184
- Exception: If the request fails
185
- """
186
174
  payload = {
187
175
  "tweetId": tweet_id,
188
176
  "content": content
@@ -44,7 +44,8 @@ class AcpPlugin:
44
44
  self.cluster = options.cluster
45
45
  self.twitter_plugin = options.twitter_plugin
46
46
  self.produced_inventory: List[IInventory] = []
47
- self.acp_base_url = options.acp_base_url
47
+ self.acp_base_url = options.acp_base_url if options.acp_base_url else "https://acpx-staging.virtuals.io/api"
48
+
48
49
 
49
50
 
50
51
  def add_produce_item(self, item: IInventory) -> None:
@@ -109,9 +110,9 @@ class AcpPlugin:
109
110
 
110
111
  if not agents:
111
112
  return FunctionResultStatus.FAILED, "No other trading agents found in the system. Please try again later when more agents are available.", {}
112
-
113
+
113
114
  return FunctionResultStatus.DONE, json.dumps({
114
- "availableAgents": agents,
115
+ "availableAgents": [{"id": agent.id, "name": agent.name, "description": agent.description, "wallet_address": agent.wallet_address, "offerings": [{"name": offering.name, "price": offering.price} for offering in agent.offerings]} for agent in agents],
115
116
  "totalAgentsFound": len(agents),
116
117
  "timestamp": datetime.now().timestamp(),
117
118
  "note": "Use the walletAddress when initiating a job with your chosen trading partner."
@@ -440,8 +441,6 @@ class AcpPlugin:
440
441
  self.acp_client.deliver_job(
441
442
  int(jobId),
442
443
  json.dumps(deliverable),
443
- job["memo"][0]["id"],
444
- reasoning
445
444
  )
446
445
 
447
446
  if (self.twitter_plugin is not None):
@@ -97,8 +97,7 @@ class AcpToken:
97
97
  response = requests.post(f"{self.acp_base_url}/acp-agent-wallets/trx-result", json={"userOpHash": hash_value})
98
98
  return response.json()
99
99
  except Exception as error:
100
- print(f"Error getting job_id: {error}")
101
- raise Exception("Failed to get job_id")
100
+ raise Exception(f"Failed to get job_id {error}")
102
101
 
103
102
  def create_job(
104
103
  self,
@@ -126,13 +125,16 @@ class AcpToken:
126
125
  # Submit to custom API
127
126
  api_url = f"{self.acp_base_url}/acp-agent-wallets/transactions"
128
127
  response = requests.post(api_url, json=payload)
129
-
128
+
129
+
130
+ if response.json().get("error"):
131
+ raise Exception(f"Failed to create job {response.json().get('error').get('status')}, Message: {response.json().get('error').get('message')}")
132
+
130
133
  # Return transaction hash or response ID
131
- return { "txHash": response.json().get("data", {}).get("userOpHash", "")}
134
+ return {"txHash": response.json().get("data", {}).get("userOpHash", "")}
132
135
 
133
136
  except Exception as error:
134
- print(f"Error creating job: {error}")
135
- raise Exception("Failed to create job")
137
+ raise Exception(f"{error}")
136
138
 
137
139
  def approve_allowance(self, price_in_wei: int) -> str:
138
140
  try:
@@ -151,13 +153,12 @@ class AcpToken:
151
153
  api_url = f"{self.acp_base_url}/acp-agent-wallets/transactions"
152
154
  response = requests.post(api_url, json=payload)
153
155
 
154
- if (response.status_code != 200):
155
- raise Exception("Failed to approve allowance")
156
+ if (response.json().get("error")):
157
+ raise Exception(f"Failed to approve allowance {response.json().get('error').get('status')}, Message: {response.json().get('error').get('message')}")
156
158
 
157
159
  return response.json()
158
160
  except Exception as error:
159
- print(f"Error approving allowance: {error}")
160
- raise Exception("Failed to approve allowance")
161
+ raise Exception(f"{error}")
161
162
 
162
163
  def create_memo(
163
164
  self,
@@ -184,16 +185,16 @@ class AcpToken:
184
185
  api_url = f"{self.acp_base_url}/acp-agent-wallets/transactions"
185
186
  response = requests.post(api_url, json=payload)
186
187
 
187
- if (response.status_code != 200):
188
- raise Exception("Failed to create memo")
188
+ if (response.json().get("error")):
189
+ raise Exception(f"Failed to create memo {response.json().get('error').get('status')}, Message: {response.json().get('error').get('message')}")
189
190
 
190
191
  return { "txHash": response.json().get("txHash", response.json().get("id", "")), "memoId": response.json().get("memoId", "")}
191
192
  except Exception as error:
192
- print(f"Error creating memo: {error}")
193
+ print(f"{error}")
193
194
  retries -= 1
194
195
  time.sleep(2 * (3 - retries))
195
196
 
196
- raise Exception("Failed to create memo")
197
+ raise Exception(f"{error}")
197
198
 
198
199
  def _sign_transaction(self, method_name: str, args: list, contract_address: Optional[str] = None) -> Tuple[dict, str]:
199
200
  if contract_address:
@@ -239,17 +240,17 @@ class AcpToken:
239
240
  api_url = f"{self.acp_base_url}/acp-agent-wallets/transactions"
240
241
  response = requests.post(api_url, json=payload)
241
242
 
242
- if (response.status_code != 200):
243
- raise Exception("Failed to sign memo")
243
+ if (response.json().get("error")):
244
+ raise Exception(f"Failed to sign memo {response.json().get('error').get('status')}, Message: {response.json().get('error').get('message')}")
244
245
 
245
246
  return response.json()
246
247
 
247
248
  except Exception as error:
248
- print(f"Error signing memo: {error}")
249
+ print(f"{error}")
249
250
  retries -= 1
250
251
  time.sleep(2 * (3 - retries))
251
252
 
252
- raise Exception("Failed to sign memo")
253
+ raise Exception(f"Failed to sign memo {error}")
253
254
 
254
255
  def set_budget(self, job_id: int, budget: int) -> str:
255
256
  try:
@@ -267,13 +268,12 @@ class AcpToken:
267
268
  api_url = f"{self.acp_base_url}/acp-agent-wallets/transactions"
268
269
  response = requests.post(api_url, json=payload)
269
270
 
270
- if (response.status_code != 200):
271
- raise Exception("Failed to set budget")
271
+ if (response.json().get("error")):
272
+ raise Exception(f"Failed to set budget {response.json().get('error').get('status')}, Message: {response.json().get('error').get('message')}")
272
273
 
273
274
  return response.json()
274
275
  except Exception as error:
275
- print(f"Error setting budget: {error}")
276
- raise Exception("Failed to set budget")
276
+ raise Exception(f"{error}")
277
277
 
278
278
  def get_job(self, job_id: int) -> Optional[IJob]:
279
279
  try:
@@ -294,8 +294,7 @@ class AcpToken:
294
294
  'evaluatorCount': int(job_data[8])
295
295
  }
296
296
  except Exception as error:
297
- print(f"Error getting job: {error}")
298
- raise Exception("Failed to get job")
297
+ raise Exception(f"{error}")
299
298
 
300
299
  def get_memo_by_job(
301
300
  self,
@@ -311,8 +310,7 @@ class AcpToken:
311
310
  else:
312
311
  return memos[-1] if memos else None
313
312
  except Exception as error:
314
- print(f"Error getting memo: {error}")
315
- raise Exception("Failed to get memo")
313
+ raise Exception(f"Failed to get memo by job {error}")
316
314
 
317
315
  def get_memos_for_phase(
318
316
  self,
@@ -326,5 +324,4 @@ class AcpToken:
326
324
  target_memos = [m for m in memos if m['nextPhase'] == target_phase]
327
325
  return target_memos[-1] if target_memos else None
328
326
  except Exception as error:
329
- print(f"Error getting memos: {error}")
330
- raise Exception("Failed to get memos")
327
+ raise Exception(f"Failed to get memos for phase {error}")
@@ -2,13 +2,18 @@ from dataclasses import dataclass
2
2
  from enum import IntEnum, Enum
3
3
  from typing import List, Dict
4
4
 
5
+ @dataclass
6
+ class AcpOffering:
7
+ name: str
8
+ price: float
5
9
  @dataclass
6
10
  class AcpAgent:
7
11
  id: str
8
12
  name: str
9
13
  description: str
10
14
  wallet_address: str
11
-
15
+ offerings: List[AcpOffering]
16
+
12
17
  class AcpJobPhases(IntEnum):
13
18
  REQUEST = 0
14
19
  NEGOTIATION = 1
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "acp-plugin-gamesdk"
3
- version = "0.1.2"
3
+ version = "0.1.3"
4
4
  description = "ACP Plugin for Python SDK for GAME by Virtuals"
5
5
  authors = ["Steven Lee Soon Fatt <steven@virtuals.io>"]
6
6
  readme = "README.md"