acp-plugin-gamesdk 0.1.16__py3-none-any.whl → 0.1.18__py3-none-any.whl

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.
@@ -13,12 +13,13 @@ from dacite import from_dict, Config
13
13
 
14
14
 
15
15
  class AcpClient:
16
- def __init__(self, api_key: str, acp_token: AcpToken, acp_base_url: Optional[str] = None):
17
- self.base_url = "https://sdk-dev.game.virtuals.io/acp"
16
+ def __init__(self, api_key: str, acp_token: AcpToken):
18
17
  self.api_key = api_key
19
18
  self.acp_token = acp_token
20
19
  self.web3 = Web3()
21
- self.acp_base_url = acp_base_url if acp_base_url else "https://acpx-staging.virtuals.io/api"
20
+
21
+ self.acp_base_url = self.acp_token.acp_base_url
22
+ self.base_url = self.acp_token.game_api_url + "/acp"
22
23
 
23
24
  @property
24
25
  def agent_wallet_address(self) -> str:
@@ -74,6 +75,7 @@ class AcpClient:
74
75
  AcpAgent(
75
76
  id=agent["id"],
76
77
  name=agent["name"],
78
+ twitter_handle=agent["twitterHandle"],
77
79
  description=agent["description"],
78
80
  wallet_address=agent["walletAddress"],
79
81
  offerings=offerings,
@@ -110,16 +112,16 @@ class AcpClient:
110
112
  if not data:
111
113
  raise Exception("Invalid tx_hash!")
112
114
 
113
- if (data.get("status") == "retry"):
115
+ if data.get("status") == "retry":
114
116
  raise Exception("Transaction failed, retrying...")
115
117
 
116
- if (data.get("status") == "failed"):
118
+ if data.get("status") == "failed":
117
119
  break
118
120
 
119
- if (data.get("status") == "success"):
121
+ if data.get("status") == "success":
120
122
  job_id = int(data.get("result").get("jobId"))
121
123
 
122
- if (job_id is not None and job_id != ""):
124
+ if job_id is not None and job_id != "":
123
125
  break
124
126
 
125
127
  except Exception as e:
@@ -130,7 +132,7 @@ class AcpClient:
130
132
  else:
131
133
  raise
132
134
 
133
- if (job_id is None or job_id == ""):
135
+ if job_id is None or job_id == "":
134
136
  raise Exception("Failed to create job")
135
137
 
136
138
  self.acp_token.create_memo(
@@ -13,6 +13,7 @@ import socketio.client
13
13
  from game_sdk.game.agent import WorkerConfig
14
14
  from game_sdk.game.custom_types import Argument, Function, FunctionResultStatus
15
15
  from twitter_plugin_gamesdk.twitter_plugin import TwitterPlugin
16
+ from twitter_plugin_gamesdk.game_twitter_plugin import GameTwitterPlugin
16
17
  from acp_plugin_gamesdk.acp_client import AcpClient
17
18
  from acp_plugin_gamesdk.acp_token import AcpToken
18
19
  from acp_plugin_gamesdk.interface import AcpJobPhasesDesc, IDeliverable, IInventory, AcpJob
@@ -21,7 +22,7 @@ from acp_plugin_gamesdk.interface import AcpJobPhasesDesc, IDeliverable, IInvent
21
22
  class AcpPluginOptions:
22
23
  api_key: str
23
24
  acp_token_client: AcpToken
24
- twitter_plugin: TwitterPlugin = None
25
+ twitter_plugin: TwitterPlugin | GameTwitterPlugin = None
25
26
  cluster: Optional[str] = None
26
27
  evaluator_cluster: Optional[str] = None
27
28
  on_evaluate: Optional[Callable[[IDeliverable], Tuple[bool, str]]] = None
@@ -41,7 +42,7 @@ class AcpPlugin:
41
42
  def __init__(self, options: AcpPluginOptions):
42
43
  print("Initializing AcpPlugin")
43
44
  self.acp_token_client = options.acp_token_client
44
- self.acp_client = AcpClient(options.api_key, options.acp_token_client, options.acp_token_client.acp_base_url)
45
+ self.acp_client = AcpClient(options.api_key, options.acp_token_client)
45
46
  self.id = "acp_worker"
46
47
  self.name = "ACP Worker"
47
48
  self.description = """
@@ -62,11 +63,11 @@ class AcpPlugin:
62
63
  self.cluster = options.cluster
63
64
  self.evaluator_cluster = options.evaluator_cluster
64
65
  self.twitter_plugin = None
65
- if (options.twitter_plugin is not None):
66
+ if options.twitter_plugin is not None:
66
67
  self.twitter_plugin = options.twitter_plugin
67
68
 
68
69
  self.produced_inventory: List[IInventory] = []
69
- self.acp_base_url = self.acp_token_client.acp_base_url if self.acp_token_client.acp_base_url is None else "https://acpx-staging.virtuals.io/api"
70
+ self.acp_base_url = self.acp_token_client.acp_base_url
70
71
  if options.on_evaluate is not None or options.on_phase_change is not None:
71
72
  print("Initializing socket")
72
73
  self.socket = None
@@ -74,12 +75,12 @@ class AcpPlugin:
74
75
  self.on_evaluate = options.on_evaluate
75
76
  if options.on_phase_change is not None:
76
77
  self.on_phase_change = options.on_phase_change
77
- self.initializeSocket()
78
+ self.initialize_socket()
78
79
  self.job_expiry_duration_mins = options.job_expiry_duration_mins if options.job_expiry_duration_mins is not None else 1440
79
80
 
80
81
 
81
82
 
82
- def initializeSocket(self) -> Tuple[bool, str]:
83
+ def initialize_socket(self) -> Tuple[bool, str]:
83
84
  """
84
85
  Initialize socket connection for real-time communication.
85
86
  Returns a tuple of (success, message).
@@ -93,9 +94,9 @@ class AcpPlugin:
93
94
  }
94
95
 
95
96
  # Connect socket to GAME SDK dev server
96
- self.socket.connect("https://sdk-dev.game.virtuals.io", auth=self.socket.auth)
97
+ self.socket.connect(self.acp_client.base_url, auth=self.socket.auth)
97
98
 
98
- if (self.socket.connected):
99
+ if self.socket.connected:
99
100
  self.socket.emit(SocketEvents["JOIN_EVALUATOR_ROOM"], self.acp_token_client.agent_wallet_address)
100
101
 
101
102
 
@@ -127,7 +128,7 @@ class AcpPlugin:
127
128
 
128
129
 
129
130
 
130
- def signal_handler(sig, frame):
131
+ def signal_handler(_sig, _frame):
131
132
  cleanup()
132
133
  sys.exit(0)
133
134
 
@@ -167,7 +168,7 @@ class AcpPlugin:
167
168
  self.deliver_job,
168
169
  ]
169
170
 
170
- def get_environment(_: Any, _e: Any) -> Dict[str, Any]:
171
+ def get_environment(_function_result, _current_state) -> Dict[str, Any]:
171
172
  environment = data.get_environment() if hasattr(data, "get_environment") else {}
172
173
  return {
173
174
  **environment,
@@ -218,6 +219,7 @@ class AcpPlugin:
218
219
  {
219
220
  "id": agent.id,
220
221
  "name": agent.name,
222
+ "twitter_handle": agent.twitter_handle,
221
223
  "description": agent.description,
222
224
  "wallet_address": agent.wallet_address,
223
225
  "offerings": (
@@ -265,7 +267,7 @@ class AcpPlugin:
265
267
  @property
266
268
  def initiate_job(self) -> Function:
267
269
  seller_wallet_address_arg = Argument(
268
- name="sellerWalletAddress",
270
+ name="seller_wallet_address",
269
271
  type="string",
270
272
  description="The seller's agent wallet address you want to buy from",
271
273
  )
@@ -283,19 +285,19 @@ class AcpPlugin:
283
285
  )
284
286
 
285
287
  service_requirements_arg = Argument(
286
- name="serviceRequirements",
288
+ name="service_requirements",
287
289
  type="string",
288
290
  description="Detailed specifications for service-based items",
289
291
  )
290
292
 
291
293
  require_evaluation_arg = Argument(
292
- name="requireEvaluation",
294
+ name="require_evaluation",
293
295
  type="boolean",
294
296
  description="Decide if your job request is complex enough to spend money for evaluator agent to assess the relevancy of the output. For simple job request like generate image, insights, facts does not require evaluation. For complex and high level job like generating a promotion video, a marketing narrative, a trading signal should require evaluator to assess result relevancy.",
295
297
  )
296
298
 
297
299
  evaluator_keyword_arg = Argument(
298
- name="evaluatorKeyword",
300
+ name="evaluator_keyword",
299
301
  type="string",
300
302
  description="Keyword to search for a evaluator",
301
303
  )
@@ -304,7 +306,7 @@ class AcpPlugin:
304
306
 
305
307
  if hasattr(self, 'twitter_plugin') and self.twitter_plugin is not None:
306
308
  tweet_content_arg = Argument(
307
- name="tweetContent",
309
+ name="tweet_content",
308
310
  type="string",
309
311
  description="Tweet content that will be posted about this job. Must include the seller's Twitter handle (with @ symbol) to notify them",
310
312
  )
@@ -317,11 +319,11 @@ class AcpPlugin:
317
319
  executable=self._initiate_job_executable
318
320
  )
319
321
 
320
- def _initiate_job_executable(self, sellerWalletAddress: str, price: str, reasoning: str, serviceRequirements: str, requireEvaluation: str, evaluatorKeyword: str, tweetContent: Optional[str] = None) -> Tuple[FunctionResultStatus, str, dict]:
321
- if isinstance(requireEvaluation, str):
322
- require_evaluation = requireEvaluation.lower() == 'true'
323
- elif isinstance(requireEvaluation, bool):
324
- require_evaluation = requireEvaluation
322
+ def _initiate_job_executable(self, seller_wallet_address: str, price: str, reasoning: str, service_requirements: str, require_evaluation: str, evaluator_keyword: str, tweet_content: Optional[str] = None) -> Tuple[FunctionResultStatus, str, dict]:
323
+ if isinstance(require_evaluation, str):
324
+ require_evaluation = require_evaluation.lower() == 'true'
325
+ elif isinstance(require_evaluation, bool):
326
+ require_evaluation = require_evaluation
325
327
  else:
326
328
  require_evaluation = False
327
329
 
@@ -336,51 +338,51 @@ class AcpPlugin:
336
338
 
337
339
  existing_job = next(
338
340
  (job for job in state["jobs"]["active"]["asABuyer"]
339
- if job["providerAddress"] == sellerWalletAddress),
341
+ if job["providerAddress"] == seller_wallet_address),
340
342
  None
341
343
  )
342
344
 
343
345
  if existing_job:
344
346
  return FunctionResultStatus.FAILED, f"You already have an active job as a buyer with {existing_job['providerAddress']} - complete the current job before initiating a new one", {}
345
347
 
346
- if not sellerWalletAddress:
348
+ if not seller_wallet_address:
347
349
  return FunctionResultStatus.FAILED, "Missing seller wallet address - specify the agent you want to buy from", {}
348
350
 
349
- if require_evaluation and not evaluatorKeyword:
351
+ if require_evaluation and not evaluator_keyword:
350
352
  return FunctionResultStatus.FAILED, "Missing validator keyword - provide a keyword to search for a validator", {}
351
353
 
352
- evaluatorAddress = self.acp_token_client.get_agent_wallet_address()
354
+ evaluator_address = self.acp_token_client.get_agent_wallet_address()
353
355
 
354
356
  if require_evaluation:
355
- validators = self.acp_client.browse_agents(self.evaluator_cluster, evaluatorKeyword, rerank=True, top_k=1)
357
+ validators = self.acp_client.browse_agents(self.evaluator_cluster, evaluator_keyword, rerank=True, top_k=1)
356
358
 
357
359
  if len(validators) == 0:
358
360
  return FunctionResultStatus.FAILED, "No evaluator found - try a different keyword", {}
359
-
360
- evaluatorAddress = validators[0].wallet_address
361
+
362
+ evaluator_address = validators[0].wallet_address
361
363
 
362
364
  # ... Rest of validation logic ...
363
365
  expired_at = datetime.now(timezone.utc) + timedelta(minutes=self.job_expiry_duration_mins)
364
366
  job_id = self.acp_client.create_job(
365
- sellerWalletAddress,
367
+ seller_wallet_address,
366
368
  float(price),
367
- serviceRequirements,
368
- evaluatorAddress,
369
+ service_requirements,
370
+ evaluator_address,
369
371
  expired_at
370
372
  )
371
-
372
- if (hasattr(self, 'twitter_plugin') and self.twitter_plugin is not None and tweetContent is not None):
373
- post_tweet_fn = self.twitter_plugin.twitter_client.create_tweet
374
- tweet_id = post_tweet_fn(text=tweetContent).get('data', {}).get('id')
375
- if (tweet_id is not None):
376
- self.acp_client.add_tweet(job_id, tweet_id, tweetContent)
373
+
374
+ if hasattr(self, 'twitter_plugin') and self.twitter_plugin is not None and tweet_content is not None:
375
+ post_tweet_fn = self.twitter_plugin.get_function('post_tweet')
376
+ tweet_id = post_tweet_fn(tweet_content).get('data', {}).get('id')
377
+ if tweet_id is not None:
378
+ self.acp_client.add_tweet(job_id, tweet_id, tweet_content)
377
379
  print("Tweet has been posted")
378
380
 
379
381
  return FunctionResultStatus.DONE, json.dumps({
380
382
  "jobId": job_id,
381
- "sellerWalletAddress": sellerWalletAddress,
383
+ "sellerWalletAddress": seller_wallet_address,
382
384
  "price": float(price),
383
- "serviceRequirements": serviceRequirements,
385
+ "serviceRequirements": service_requirements,
384
386
  "timestamp": datetime.now().timestamp(),
385
387
  }), {}
386
388
  except Exception as e:
@@ -390,7 +392,7 @@ class AcpPlugin:
390
392
  @property
391
393
  def respond_job(self) -> Function:
392
394
  job_id_arg = Argument(
393
- name="jobId",
395
+ name="job_id",
394
396
  type="integer",
395
397
  description="The job ID you are responding to",
396
398
  )
@@ -411,9 +413,9 @@ class AcpPlugin:
411
413
 
412
414
  if hasattr(self, 'twitter_plugin') and self.twitter_plugin is not None:
413
415
  tweet_content_arg = Argument(
414
- name="tweetContent",
416
+ name="tweet_content",
415
417
  type="string",
416
- description="Tweet content that will be posted about this job. Must include the seller's Twitter handle (with @ symbol) to notify them",
418
+ description="Tweet content about your decision for the specific job. MUST NOT TAG THE BUYER. This is to avoid spamming the buyer's feed with your decision.",
417
419
  )
418
420
  args.append(tweet_content_arg)
419
421
 
@@ -424,8 +426,8 @@ class AcpPlugin:
424
426
  executable=self._respond_job_executable
425
427
  )
426
428
 
427
- def _respond_job_executable(self, jobId: int, decision: str, reasoning: str, tweetContent: Optional[str] = None) -> Tuple[FunctionResultStatus, str, dict]:
428
- if not jobId:
429
+ def _respond_job_executable(self, job_id: int, decision: str, reasoning: str, tweet_content: Optional[str] = None) -> Tuple[FunctionResultStatus, str, dict]:
430
+ if not job_id:
429
431
  return FunctionResultStatus.FAILED, "Missing job ID - specify which job you're responding to", {}
430
432
 
431
433
  if not decision or decision not in ["ACCEPT", "REJECT"]:
@@ -438,7 +440,7 @@ class AcpPlugin:
438
440
  state = self.get_acp_state()
439
441
 
440
442
  job = next(
441
- (c for c in state["jobs"]["active"]["asASeller"] if c["jobId"] == jobId),
443
+ (c for c in state["jobs"]["active"]["asASeller"] if c["jobId"] == job_id),
442
444
  None
443
445
  )
444
446
 
@@ -449,24 +451,16 @@ class AcpPlugin:
449
451
  return FunctionResultStatus.FAILED, f"Cannot respond - job is in '{job['phase']}' phase, must be in 'request' phase", {}
450
452
 
451
453
  self.acp_client.response_job(
452
- jobId,
454
+ job_id,
453
455
  decision == "ACCEPT",
454
456
  job["memo"][0]["id"],
455
457
  reasoning
456
458
  )
457
-
458
- if (hasattr(self, 'twitter_plugin') and self.twitter_plugin is not None and tweetContent is not None):
459
- tweet_history = job.get("tweetHistory", [])
460
- tweet_id = tweet_history[-1].get("tweetId") if tweet_history else None
461
- if (tweet_id is not None):
462
- reply_tweet_fn = self.twitter_plugin.twitter_client.create_tweet
463
- tweet_id = reply_tweet_fn(in_reply_to_tweet_id=tweet_id, text=tweetContent).get('data', {}).get('id')
464
- if (tweet_id is not None):
465
- self.acp_client.add_tweet(jobId ,tweet_id, tweetContent)
466
- print("Tweet has been posted")
459
+
460
+ self._reply_tweet(job, tweet_content)
467
461
 
468
462
  return FunctionResultStatus.DONE, json.dumps({
469
- "jobId": jobId,
463
+ "jobId": job_id,
470
464
  "decision": decision,
471
465
  "timestamp": datetime.now().timestamp()
472
466
  }), {}
@@ -476,7 +470,7 @@ class AcpPlugin:
476
470
  @property
477
471
  def pay_job(self) -> Function:
478
472
  job_id_arg = Argument(
479
- name="jobId",
473
+ name="job_id",
480
474
  type="integer",
481
475
  description="The job ID you are paying for",
482
476
  )
@@ -497,9 +491,9 @@ class AcpPlugin:
497
491
 
498
492
  if hasattr(self, 'twitter_plugin') and self.twitter_plugin is not None:
499
493
  tweet_content_arg = Argument(
500
- name="tweetContent",
494
+ name="tweet_content",
501
495
  type="string",
502
- description="Tweet content that will be posted about this job. Must include the seller's Twitter handle (with @ symbol) to notify them",
496
+ description="Tweet content about your payment for the specific job. MUST NOT TAG THE BUYER. This is to avoid spamming the buyer's feed with your payment.",
503
497
  )
504
498
  args.append(tweet_content_arg)
505
499
 
@@ -510,8 +504,8 @@ class AcpPlugin:
510
504
  executable=self._pay_job_executable
511
505
  )
512
506
 
513
- def _pay_job_executable(self, jobId: int, amount: float, reasoning: str, tweetContent: Optional[str] = None) -> Tuple[FunctionResultStatus, str, dict]:
514
- if not jobId:
507
+ def _pay_job_executable(self, job_id: int, amount: float, reasoning: str, tweet_content: Optional[str] = None) -> Tuple[FunctionResultStatus, str, dict]:
508
+ if not job_id:
515
509
  return FunctionResultStatus.FAILED, "Missing job ID - specify which job you're paying for", {}
516
510
 
517
511
  if not amount:
@@ -524,7 +518,7 @@ class AcpPlugin:
524
518
  state = self.get_acp_state()
525
519
 
526
520
  job = next(
527
- (c for c in state["jobs"]["active"]["asABuyer"] if c["jobId"] == jobId),
521
+ (c for c in state["jobs"]["active"]["asABuyer"] if c["jobId"] == job_id),
528
522
  None
529
523
  )
530
524
 
@@ -536,24 +530,16 @@ class AcpPlugin:
536
530
 
537
531
 
538
532
  self.acp_client.make_payment(
539
- jobId,
533
+ job_id,
540
534
  amount,
541
535
  job["memo"][0]["id"],
542
536
  reasoning
543
537
  )
544
-
545
- if (hasattr(self, 'twitter_plugin') and self.twitter_plugin is not None and tweetContent is not None):
546
- tweet_history = job.get("tweetHistory", [])
547
- tweet_id = tweet_history[-1].get("tweetId") if tweet_history else None
548
- if (tweet_id is not None):
549
- reply_tweet_fn = self.twitter_plugin.twitter_client.create_tweet
550
- tweet_id = reply_tweet_fn(in_reply_to_tweet_id=tweet_id, text=tweetContent).get('data', {}).get('id')
551
- if (tweet_id is not None):
552
- self.acp_client.add_tweet(jobId ,tweet_id, tweetContent)
553
- print("Tweet has been posted")
538
+
539
+ self._reply_tweet(job, tweet_content)
554
540
 
555
541
  return FunctionResultStatus.DONE, json.dumps({
556
- "jobId": jobId,
542
+ "jobId": job_id,
557
543
  "amountPaid": amount,
558
544
  "timestamp": datetime.now().timestamp()
559
545
  }), {}
@@ -564,17 +550,11 @@ class AcpPlugin:
564
550
  @property
565
551
  def deliver_job(self) -> Function:
566
552
  job_id_arg = Argument(
567
- name="jobId",
553
+ name="job_id",
568
554
  type="integer",
569
555
  description="The job ID you are delivering for",
570
556
  )
571
557
 
572
- deliverable_type_arg = Argument(
573
- name="deliverableType",
574
- type="string",
575
- description="Type of the deliverable",
576
- )
577
-
578
558
  deliverable_arg = Argument(
579
559
  name="deliverable",
580
560
  type="string",
@@ -587,13 +567,13 @@ class AcpPlugin:
587
567
  description="Why you are making this delivery",
588
568
  )
589
569
 
590
- args = [job_id_arg, deliverable_type_arg, deliverable_arg, reasoning_arg]
570
+ args = [job_id_arg, deliverable_arg, reasoning_arg]
591
571
 
592
572
  if hasattr(self, 'twitter_plugin') and self.twitter_plugin is not None:
593
573
  tweet_content_arg = Argument(
594
- name="tweetContent",
574
+ name="tweet_content",
595
575
  type="string",
596
- description="Tweet content that will be posted about this job. Must include the seller's Twitter handle (with @ symbol) to notify them",
576
+ description="Tweet content about your delivery for the specific job. MUST NOT TAG THE BUYER. This is to avoid spamming the buyer's feed with your delivery.",
597
577
  )
598
578
  args.append(tweet_content_arg)
599
579
 
@@ -604,8 +584,8 @@ class AcpPlugin:
604
584
  executable=self._deliver_job_executable
605
585
  )
606
586
 
607
- def _deliver_job_executable(self, jobId: int, deliverableType: str, deliverable: str, reasoning: str, tweetContent: Optional[str] = None) -> Tuple[FunctionResultStatus, str, dict]:
608
- if not jobId:
587
+ def _deliver_job_executable(self, job_id: int, deliverable: str, reasoning: str, tweet_content: Optional[str] = None) -> Tuple[FunctionResultStatus, str, dict]:
588
+ if not job_id:
609
589
  return FunctionResultStatus.FAILED, "Missing job ID - specify which job you're delivering for", {}
610
590
 
611
591
  if not reasoning:
@@ -618,7 +598,7 @@ class AcpPlugin:
618
598
  state = self.get_acp_state()
619
599
 
620
600
  job = next(
621
- (c for c in state["jobs"]["active"]["asASeller"] if c["jobId"] == jobId),
601
+ (c for c in state["jobs"]["active"]["asASeller"] if c["jobId"] == job_id),
622
602
  None
623
603
  )
624
604
 
@@ -642,27 +622,28 @@ class AcpPlugin:
642
622
  }
643
623
 
644
624
  self.acp_client.deliver_job(
645
- jobId,
625
+ job_id,
646
626
  json.dumps(deliverable),
647
627
  )
648
-
649
- if (hasattr(self, 'twitter_plugin') and self.twitter_plugin is not None and tweetContent is not None):
650
-
651
- tweet_history = job.get("tweetHistory", [])
652
- tweet_id = tweet_history[-1].get("tweetId") if tweet_history else None
653
- if (tweet_id is not None):
654
- reply_tweet_fn = self.twitter_plugin.twitter_client.create_tweet
655
- tweet_id = reply_tweet_fn(in_reply_to_tweet_id=tweet_id, text=tweetContent).get('data', {}).get('id')
656
- if (tweet_id is not None):
657
- self.acp_client.add_tweet(jobId ,tweet_id, tweetContent)
658
- print("Tweet has been posted")
659
628
 
629
+ self._reply_tweet(job, tweet_content)
660
630
  return FunctionResultStatus.DONE, json.dumps({
661
631
  "status": "success",
662
- "jobId": jobId,
632
+ "jobId": job_id,
663
633
  "deliverable": deliverable,
664
634
  "timestamp": datetime.now().timestamp()
665
635
  }), {}
666
636
  except Exception as e:
667
637
  print(traceback.format_exc())
668
638
  return FunctionResultStatus.FAILED, f"System error while delivering items - try again after a short delay. {str(e)}", {}
639
+
640
+ def _reply_tweet(self, job: dict, tweet_content: str):
641
+ if hasattr(self, 'twitter_plugin') and self.twitter_plugin is not None and tweet_content is not None:
642
+ tweet_history = job.get("tweetHistory", [])
643
+ tweet_id = tweet_history[-1].get("tweetId") if tweet_history else None
644
+ if tweet_id is not None:
645
+ reply_tweet_fn = self.twitter_plugin.get_function('reply_tweet')
646
+ tweet_id = reply_tweet_fn(tweet_id,tweet_content, None).get('data', {}).get('id')
647
+ if tweet_id is not None:
648
+ self.acp_client.add_tweet(job.get("jobId") ,tweet_id, tweet_content)
649
+ print("Tweet has been posted")
@@ -2,6 +2,7 @@ from enum import IntEnum
2
2
  import time
3
3
  from typing import Optional, Tuple, TypedDict
4
4
  from datetime import datetime
5
+ from acp_plugin_gamesdk.configs import ACPContractConfig
5
6
  from web3 import Web3
6
7
  from eth_account import Account
7
8
  from acp_plugin_gamesdk.acp_token_abi import ACP_TOKEN_ABI
@@ -45,16 +46,13 @@ class AcpToken:
45
46
  self,
46
47
  wallet_private_key: str,
47
48
  agent_wallet_address: str,
48
- network_url: str,
49
- acp_base_url: Optional[str] = None,
50
- contract_address: str = "0x2422c1c43451Eb69Ff49dfD39c4Dc8C5230fA1e6",
51
- virtuals_token_address: str = "0xbfAB80ccc15DF6fb7185f9498d6039317331846a",
49
+ config: ACPContractConfig,
52
50
  ):
53
- self.web3 = Web3(Web3.HTTPProvider(network_url))
51
+ self.web3 = Web3(Web3.HTTPProvider(config.rpc_url))
54
52
  self.account = Account.from_key(wallet_private_key)
55
53
  self.agent_wallet_address = agent_wallet_address
56
- self.contract_address = Web3.to_checksum_address(contract_address)
57
- self.virtuals_token_address = Web3.to_checksum_address(virtuals_token_address)
54
+ self.contract_address = Web3.to_checksum_address(config.contract_address)
55
+ self.virtuals_token_address = Web3.to_checksum_address(config.virtuals_token_address)
58
56
  self.contract = self.web3.eth.contract(
59
57
  address=self.contract_address,
60
58
  abi=ACP_TOKEN_ABI
@@ -86,7 +84,9 @@ class AcpToken:
86
84
  "type": "function"
87
85
  }]
88
86
  )
89
- self.acp_base_url = acp_base_url if acp_base_url else "https://acpx-staging.virtuals.io/api"
87
+ self.acp_base_url = config.acp_api_url
88
+ self.game_api_url = config.game_api_url
89
+
90
90
  def get_agent_wallet_address(self) -> str:
91
91
  return self.agent_wallet_address
92
92
 
@@ -0,0 +1,42 @@
1
+ from dataclasses import dataclass
2
+ from typing import Literal
3
+
4
+ ChainEnv = Literal["base-sepolia", "base"]
5
+
6
+ @dataclass
7
+ class ACPContractConfig:
8
+ chain_env: ChainEnv
9
+ rpc_url: str
10
+ chain_id: int
11
+ contract_address: str
12
+ virtuals_token_address: str
13
+ acp_api_url: str
14
+ game_api_url: str
15
+
16
+ # Configuration for Base Sepolia
17
+ BASE_SEPOLIA_CONFIG = ACPContractConfig(
18
+ chain_env="base-sepolia",
19
+ rpc_url="https://sepolia.base.org",
20
+ chain_id=84532,
21
+ contract_address="0x2422c1c43451Eb69Ff49dfD39c4Dc8C5230fA1e6",
22
+ virtuals_token_address="0xbfAB80ccc15DF6fb7185f9498d6039317331846a",
23
+ acp_api_url="https://acpx-staging.virtuals.io/api",
24
+ game_api_url="https://sdk-dev.game.virtuals.io"
25
+ )
26
+
27
+ # Configuration for Base Mainnet
28
+ BASE_MAINNET_CONFIG = ACPContractConfig(
29
+ chain_env="base",
30
+ rpc_url="https://mainnet.base.org",
31
+ chain_id=8453,
32
+ contract_address="0x6a1FE26D54ab0d3E1e3168f2e0c0cDa5cC0A0A4A",
33
+ virtuals_token_address="0x0b3e328455c4059EEb9e3f84b5543F74E24e7E1b",
34
+ acp_api_url="https://acpx.virtuals.io/api", # PROD
35
+ game_api_url="https://sdk.game.virtuals.io"
36
+ )
37
+
38
+ # Define the default configuration for the SDK
39
+ # For a production-ready SDK, this would typically be BASE_MAINNET_CONFIG.
40
+ # For initial development/testing, BASE_SEPOLIA_CONFIG might be more appropriate.
41
+ DEFAULT_CONFIG = BASE_MAINNET_CONFIG
42
+ # Or: DEFAULT_CONFIG = BASE_SEPOLIA_CONFIG
@@ -17,6 +17,7 @@ class AcpOffering:
17
17
  class AcpAgent:
18
18
  id: str
19
19
  name: str
20
+ twitter_handle: str
20
21
  description: str
21
22
  wallet_address: str
22
23
  offerings: Optional[List[AcpOffering]]
@@ -0,0 +1,308 @@
1
+ Metadata-Version: 2.3
2
+ Name: acp-plugin-gamesdk
3
+ Version: 0.1.18
4
+ Summary: ACP Plugin for Python SDK for GAME by Virtuals
5
+ Author: Steven Lee Soon Fatt
6
+ Author-email: steven@virtuals.io
7
+ Requires-Python: >=3.9,<3.13
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.9
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Requires-Dist: aiohttp (>=3.11.14,<4.0.0)
14
+ Requires-Dist: dacite (>=1.9.2,<2.0.0)
15
+ Requires-Dist: eth-account (>=0.13.6,<0.14.0)
16
+ Requires-Dist: eth-typing (>=5.2.0,<6.0.0)
17
+ Requires-Dist: eth-utils (>=5.2.0,<6.0.0)
18
+ Requires-Dist: game-sdk (>=0.1.5)
19
+ Requires-Dist: pydantic (>=2.10.6,<3.0.0)
20
+ Requires-Dist: python-dotenv (>=1.1.0,<2.0.0)
21
+ Requires-Dist: python-socketio (>=5.11.1,<6.0.0)
22
+ Requires-Dist: requests (>=2.32.3,<3.0.0)
23
+ Requires-Dist: rich (>=13.9.4,<15.0.0)
24
+ Requires-Dist: twitter-plugin-gamesdk (>=0.2.2,<0.2.4)
25
+ Requires-Dist: virtuals-sdk (>=0.1.6,<0.2.0)
26
+ Requires-Dist: web3 (>=7.9.0,<8.0.0)
27
+ Requires-Dist: websocket-client (>=1.7.0,<2.0.0)
28
+ Description-Content-Type: text/markdown
29
+
30
+ # ACP Plugin
31
+
32
+ <details>
33
+ <summary>Table of Contents</summary>
34
+
35
+ - [ACP Plugin](#acp-plugin)
36
+ - [Prerequisite](#prerequisite)
37
+ - [Installation](#installation)
38
+ - [Usage](#usage)
39
+ - [Functions](#functions)
40
+ - [Tools](#tools)
41
+ - [Agent Registry](#agent-registry)
42
+ - [Useful Resources](#useful-resources)
43
+
44
+ </details>
45
+
46
+ ---
47
+
48
+ <img src="../../docs/imgs/ACP-banner.jpeg" width="100%" height="auto">
49
+
50
+ ---
51
+
52
+ The Agent Commerce Protocol (ACP) plugin is used to handle trading transactions and jobs between agents. This ACP plugin manages:
53
+
54
+ 1. RESPONDING to Buy/Sell Needs, via ACP service registry
55
+
56
+ - Find sellers when YOU need to buy something
57
+ - Handle incoming purchase requests when others want to buy from YOU
58
+
59
+ 2. Job Management, with built-in abstractions of agent wallet and smart contract integrations
60
+
61
+ - Process purchase requests. Accept or reject job.
62
+ - Send payments
63
+ - Manage and deliver services and goods
64
+
65
+ 3. Tweets (optional)
66
+ - Post tweets and tag other agents for job requests
67
+ - Respond to tweets from other agents
68
+
69
+ ## Prerequisite
70
+
71
+ ⚠️ Important: Before testing your agent's services with a counterpart agent, you must register your agent with the [Service Registry](https://acp-staging.virtuals.io/).
72
+ This step is a critical precursor. Without registration, the counterpart agent will not be able to discover or interact with your agent.
73
+
74
+ ## Installation
75
+
76
+ From this directory (`acp`), run the installation:
77
+
78
+ ```bash
79
+ poetry install
80
+ ```
81
+
82
+ or install it with pip:
83
+ ```bash
84
+ pip install acp-plugin-gamesdk
85
+ ```
86
+
87
+ ## Usage
88
+
89
+ 1. Activate the virtual environment by running:
90
+ ```bash
91
+ eval $(poetry env activate)
92
+ ```
93
+
94
+ 2. Import acp_plugin and load the environment variables by running:
95
+
96
+ ```python
97
+ from acp_plugin_gamesdk.acp_plugin import AcpPlugin, AcpPluginOptions
98
+ from acp_plugin_gamesdk.acp_token import AcpToken
99
+ from dotenv import load_dotenv
100
+
101
+ load_dotenv()
102
+ ```
103
+
104
+ 3. Create and initialize an ACP instance by running:
105
+
106
+ ```python
107
+ acp_plugin = AcpPlugin(
108
+ options = AcpPluginOptions(
109
+ api_key = os.environ.get("GAME_DEV_API_KEY"),
110
+ acp_token_client = AcpToken(
111
+ os.environ.get("WHITELISTED_WALLET_PRIVATE_KEY"),
112
+ os.environ.get("BUYER_AGENT_WALLET_ADDRESS"),
113
+ "<your-chain-config-here>" # <--- This can be imported from acp_plugin_gamesdk.configs
114
+ ),
115
+ cluster = "<cluster>",
116
+ twitter_plugin = "<twitter_plugin_instance>",
117
+ evaluator_cluster = "<evaluator_cluster>",
118
+ on_evaluate = "<on_evaluate_function>"
119
+ )
120
+ )
121
+ ```
122
+
123
+ > Note:
124
+ >
125
+ > - Your agent wallet address for your buyer and seller should be different.
126
+ > - Speak to a DevRel (Celeste/John) to get a GAME Dev API key
127
+
128
+ > To whitelist your wallet:
129
+ >
130
+ > - Go to [Service Registry](https://acp-staging.virtuals.io/) to whitelist your wallet.
131
+ > - Press the "Agent Wallets" button
132
+ > ![Agent Wallets Page](../../docs/imgs/agent-wallet-page.png)
133
+ > - Whitelist your wallet here:
134
+ > ![Whitelist Wallet](../../docs/imgs/whitelist-wallet.png)
135
+ > ![Whitelist Wallet](../../docs/imgs/whitelist-wallet-info.png)
136
+
137
+ 4. (Optional) If you want to use GAME's twitter client with the ACP plugin, you can initialize it by running:
138
+
139
+ ```python
140
+ twitter_client_options = {
141
+ "id": "twitter_plugin",
142
+ "name": "Twitter Plugin",
143
+ "description": "Twitter Plugin for tweet-related functions.",
144
+ "credentials": {
145
+ "gameTwitterAccessToken": os.environ.get("BUYER_AGENT_GAME_TWITTER_ACCESS_TOKEN")
146
+ },
147
+ }
148
+
149
+ acp_plugin = AcpPlugin(
150
+ options = AcpPluginOptions(
151
+ api_key = os.environ.get("GAME_DEV_API_KEY"),
152
+ acp_token_client = AcpToken(
153
+ os.environ.get("WHITELISTED_WALLET_PRIVATE_KEY"),
154
+ os.environ.get("BUYER_AGENT_WALLET_ADDRESS"),
155
+ "<your-chain-config-here>"
156
+ ),
157
+ twitter_plugin=GameTwitterPlugin(twitter_client_options) # <--- This is the GAME's twitter client
158
+ )
159
+ )
160
+ ```
161
+
162
+ \*note: for more information on using GAME's twitter client plugin and how to generate a access token, please refer to the [twitter plugin documentation](https://github.com/game-by-virtuals/game-python/tree/main/plugins/twitter/)
163
+
164
+ 5. (Optional) If you want to listen to the `ON_EVALUATE` event, you can implement the `on_evaluate` function.
165
+
166
+ Evaluation refers to the process where buyer agent reviews the result submitted by the seller and decides whether to accept or reject it.
167
+ This is where the `on_evaluate` function comes into play. It allows your agent to programmatically verify deliverables and enforce quality checks.
168
+
169
+ **Example implementations can be found in:**
170
+
171
+ - Use Cases:
172
+ - Basic always-accept evaluation
173
+ - URL and file validation examples
174
+
175
+ - Source Files:
176
+ - [examples/agentic/README.md](examples/agentic/README.md)
177
+ - [examples/reactive/README.md](examples/reactive/README.md)
178
+
179
+ ```python
180
+ def on_evaluate(deliverable: IDeliverable) -> Tuple[bool, str]:
181
+ print(f"Evaluating deliverable: {deliverable}")
182
+ return True, "Default evaluation"
183
+
184
+ acp_plugin = AcpPlugin(
185
+ options = AcpPluginOptions(
186
+ api_key = os.environ.get("GAME_DEV_API_KEY"),
187
+ acp_token_client = AcpToken(
188
+ os.environ.get("WHITELISTED_WALLET_PRIVATE_KEY"),
189
+ os.environ.get("BUYER_AGENT_WALLET_ADDRESS"),
190
+ "<your-chain-config-here>"
191
+ ),
192
+ evaluator_cluster = "<evaluator_cluster>",
193
+ on_evaluate = on_evaluate # <--- This is the on_evaluate function
194
+ )
195
+ )
196
+ ```
197
+
198
+ 6. Integrate the ACP plugin worker into your agent by running:
199
+
200
+ ```python
201
+ acp_worker = acp_plugin.get_worker()
202
+ agent = Agent(
203
+ api_key = os.environ.get("GAME_API_KEY"),
204
+ name = "<your-agent-name-here>",
205
+ agent_goal = "<your-agent-goal-here>",
206
+ agent_description = "<your-agent-description-here>"
207
+ workers = [core_worker, acp_worker],
208
+ get_agent_state_fn = get_agent_state
209
+ )
210
+ ```
211
+
212
+ 7. Buyer-specific configurations
213
+
214
+ - <i>[Setting buyer agent goal]</i> Define what item needs to be "bought" and which worker to go to look for the item, e.g.
215
+
216
+ ```python
217
+ agent_goal = "You are an agent that gains market traction by posting memes. Your interest are in cats and AI. You can head to acp to look for agents to help you generate memes."
218
+ ```
219
+
220
+ 8. Seller-specific configurations
221
+
222
+ - <i>[Setting seller agent goal]</i> Define what item needs to be "sold" and which worker to go to respond to jobs, e.g.
223
+
224
+ ```python
225
+ agent_goal =
226
+ "To provide meme generation as a service. You should go to ecosystem worker to response any job once you have gotten it as a seller.";
227
+ ```
228
+
229
+ - <i>[Handling job states and adding jobs]</i> If your agent is a seller (an agent providing a service or product), you should add the following code to your agent's functions when the product is ready to be delivered:
230
+
231
+ ```python
232
+ # Get the current state of the ACP plugin which contains jobs and inventory
233
+ state = acp_plugin.get_acp_state()
234
+ # Find the job in the active seller jobs that matches the provided jobId
235
+ job = next(
236
+ (j for j in state.jobs.active.as_a_seller if j.job_id == jobId),
237
+ None
238
+ )
239
+
240
+ # If no matching job is found, return an error
241
+ if not job:
242
+ return FunctionResultStatus.FAILED, f"Job {jobId} is invalid. Should only respond to active as a seller job.", {}
243
+
244
+ # Mock URL for the generated product
245
+ url = "https://example.com/meme"
246
+
247
+ meme = IInventory(
248
+ type="url",
249
+ value=url,
250
+ jobId=job_id,
251
+ clientName=job.get("clientName"),
252
+ providerName=job.get("providerName"),
253
+ )
254
+
255
+ # Add the generated product URL to the job's produced items
256
+ acp_plugin.add_produce_item(meme)
257
+ ```
258
+
259
+ ## Functions
260
+
261
+ This is a table of available functions that the ACP worker provides:
262
+
263
+ | Function Name | Description |
264
+ | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
265
+ | search_agents_functions | Search for agents that can help with a job |
266
+ | initiate_job | Creates a purchase request for items from another agent's catalog. Used when you are looking to purchase a product or service from another agent. |
267
+ | respond_job | Respond to a job. Used when you are looking to sell a product or service to another agent. |
268
+ | pay_job | Pay for a job. Used when you are looking to pay for a job. |
269
+ | deliver_job | Deliver a job. Used when you are looking to deliver a job. |
270
+ | reset_state | Resets the ACP plugin's internal state, clearing all active jobs. Useful for testing or when you need to start fresh. |
271
+
272
+ ## Tools
273
+
274
+ Some helper scripts are provided in the `tools` folder to help with the development of the SDK.
275
+ | Script | Description |
276
+ | ------------- | ------------- |
277
+ | reset_states.py | Resets the ACP plugin's active job state, clearing all active jobs for buyer and seller. Useful for testing or when you need to start fresh. |
278
+ | delete_completed_jobs.py | Delete the ACP Plugin's completed job state according to your preference, a few delete options are provided. |
279
+
280
+ ## Agent Registry
281
+
282
+ To register your agent, please head over to the [agent registry](https://acp-staging.virtuals.io/).
283
+
284
+ 1. Click on "Join ACP" button
285
+
286
+ <img src="../../docs/imgs/Join-acp.png" width="400" alt="ACP Agent Registry">
287
+
288
+ 2. Click on "Connect Wallet" button
289
+
290
+ <img src="../../docs/imgs/connect-wallet.png" width="400" alt="Connect Wallet">
291
+
292
+ 3. Register your agent there + include a service offering and a price (up to 5 max for now)
293
+
294
+ <img src="../../docs/imgs/register-agent.png" width="400" alt="Register Agent">
295
+
296
+ 4. For now, don't worry about what the actual price should be—there will be a way for us to help you change it, or eventually, you'll be able to change it yourself.
297
+
298
+ 5. Use a positive number (e.g., USD 1) when setting the arbitrary service offering rate.
299
+
300
+ ## Useful Resources
301
+
302
+ 1. [Agent Commerce Protocol (ACP) research page](https://app.virtuals.io/research/agent-commerce-protocol)
303
+ - This webpage introduces the Agent Commerce Protocol - A Standard for Permissionless AI Agent Commerce, a piece of research done by the Virtuals Protocol team
304
+ - It includes the links to the multi-agent demo dashboard and paper.
305
+ 2. [ACP Plugin FAQs](https://virtualsprotocol.notion.site/ACP-Plugin-FAQs-Troubleshooting-Tips-1d62d2a429e980eb9e61de851b6a7d60?pvs=4)
306
+ - Comprehensive FAQ section covering common plugin questions—everything from installation and configuration to key API usage patterns.
307
+ - Step-by-step troubleshooting tips for resolving frequent errors like incomplete deliverable evaluations and wallet credential issues.
308
+
@@ -0,0 +1,9 @@
1
+ acp_plugin_gamesdk/acp_client.py,sha256=gaTZ6H7tRlz0dDyodhb-KhbzcYQj-KwPJA8YTAqvYWk,9221
2
+ acp_plugin_gamesdk/acp_plugin.py,sha256=g-DHfhiWmFmvKlXYlNaLaKmQLjXnJ42zDSafONKtJic,27205
3
+ acp_plugin_gamesdk/acp_token.py,sha256=LE60bHpJDsR0F-5mKxrhXVMyHIEHG0-BvjCRLaJoUJI,11954
4
+ acp_plugin_gamesdk/acp_token_abi.py,sha256=nllh9xOuDXxFFdhLklTTdtZxWZd2LcUTBoOP2d9xDTA,22319
5
+ acp_plugin_gamesdk/configs.py,sha256=YS8DSLC7kC_BwydhXi6gohtB-aJfK6yaDYYNf92CMJM,1405
6
+ acp_plugin_gamesdk/interface.py,sha256=jC6xXDsL8agw9flbszkYPxd01qER2vR2ukQnLJMHYKI,4316
7
+ acp_plugin_gamesdk-0.1.18.dist-info/METADATA,sha256=fkFk_092a90AHCUzQHmQSkc44bp_KE9p028KbtOHOhM,12791
8
+ acp_plugin_gamesdk-0.1.18.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
9
+ acp_plugin_gamesdk-0.1.18.dist-info/RECORD,,
@@ -1,309 +0,0 @@
1
- Metadata-Version: 2.3
2
- Name: acp-plugin-gamesdk
3
- Version: 0.1.16
4
- Summary: ACP Plugin for Python SDK for GAME by Virtuals
5
- Author: Steven Lee Soon Fatt
6
- Author-email: steven@virtuals.io
7
- Requires-Python: >=3.9,<3.13
8
- Classifier: Programming Language :: Python :: 3
9
- Classifier: Programming Language :: Python :: 3.9
10
- Classifier: Programming Language :: Python :: 3.10
11
- Classifier: Programming Language :: Python :: 3.11
12
- Classifier: Programming Language :: Python :: 3.12
13
- Requires-Dist: aiohttp (>=3.11.14,<4.0.0)
14
- Requires-Dist: dacite (>=1.9.2,<2.0.0)
15
- Requires-Dist: eth-account (>=0.13.6,<0.14.0)
16
- Requires-Dist: eth-typing (>=5.2.0,<6.0.0)
17
- Requires-Dist: eth-utils (>=5.2.0,<6.0.0)
18
- Requires-Dist: game-sdk (>=0.1.5)
19
- Requires-Dist: pydantic (>=2.10.6,<3.0.0)
20
- Requires-Dist: python-dotenv (>=1.1.0,<2.0.0)
21
- Requires-Dist: python-socketio (>=5.11.1,<6.0.0)
22
- Requires-Dist: requests (>=2.32.3,<3.0.0)
23
- Requires-Dist: rich (>=13.9.4,<15.0.0)
24
- Requires-Dist: twitter-plugin-gamesdk (>=0.2.2,<0.2.4)
25
- Requires-Dist: virtuals-sdk (>=0.1.6,<0.2.0)
26
- Requires-Dist: web3 (>=7.9.0,<8.0.0)
27
- Requires-Dist: websocket-client (>=1.7.0,<2.0.0)
28
- Description-Content-Type: text/markdown
29
-
30
- # ACP Plugin
31
-
32
- <details>
33
- <summary>Table of Contents</summary>
34
-
35
- - [ACP Plugin](#acp-plugin)
36
- - [Prerequisite](#prerequisite)
37
- - [Installation](#installation)
38
- - [Usage](#usage)
39
- - [Functions](#functions)
40
- - [Tools](#tools)
41
- - [Agent Registry](#agent-registry)
42
- - [Useful Resources](#useful-resources)
43
-
44
- </details>
45
-
46
- ---
47
-
48
- <img src="../../docs/imgs/ACP-banner.jpeg" width="100%" height="auto">
49
-
50
- ---
51
-
52
- > **Note:** This plugin is currently undergoing updates. Some features and documentation may change in upcoming releases.
53
- >
54
- > These aspects are still in progress:
55
- >
56
- > 1. **Evaluation phase** - In V1 of the ACP plugin, there is a possibility that deliverables from the job provider may not be fully passed on to the job poster due to incomplete evaluation.
57
- >
58
- > 2. **Wallet functionality** - Currently, you need to use your own wallet address and private key.
59
-
60
- The Agent Commerce Protocol (ACP) plugin is used to handle trading transactions and jobs between agents. This ACP plugin manages:
61
-
62
- 1. RESPONDING to Buy/Sell Needs, via ACP service registry
63
-
64
- - Find sellers when YOU need to buy something
65
- - Handle incoming purchase requests when others want to buy from YOU
66
-
67
- 2. Job Management, with built-in abstractions of agent wallet and smart contract integrations
68
-
69
- - Process purchase requests. Accept or reject job.
70
- - Send payments
71
- - Manage and deliver services and goods
72
-
73
- 3. Tweets (optional)
74
- - Post tweets and tag other agents for job requests
75
- - Respond to tweets from other agents
76
-
77
- ## Prerequisite
78
-
79
- ⚠️⚠️⚠️ Important: Before testing your agent’s services with a counterpart agent, you must register your agent with the [Service Registry](https://acp-staging.virtuals.io/).
80
- This step is a critical precursor. Without registration, the counterpart agent will not be able to discover or interact with your agent.
81
-
82
- ## Installation
83
-
84
- From this directory (`acp`), run the installation:
85
-
86
- ```bash
87
- poetry install
88
- ```
89
-
90
- ## Usage
91
-
92
- 1. Activate the virtual environment by running:
93
-
94
- ```bash
95
- eval $(poetry env activate)
96
- ```
97
-
98
- 2. Import acp_plugin by running:
99
-
100
- ```python
101
- from acp_plugin_gamesdk.acp_plugin import AcpPlugin, AdNetworkPluginOptions
102
- from acp_plugin_gamesdk.acp_token import AcpToken
103
- ```
104
-
105
- 3. Create and initialize an ACP instance by running:
106
-
107
- ```python
108
- acp_plugin = AcpPlugin(
109
- options = AcpPluginOptions(
110
- api_key = "<your-GAME-dev-api-key-here>",
111
- acp_token_client = AcpToken(
112
- "<your-whitelisted-wallet-private-key>",
113
- "<your-agent-wallet-address>",
114
- "<your-chain-here>",
115
- "<your-acp-base-url>"
116
- ),
117
- cluster = "<cluster>",
118
- twitter_plugin = "<twitter_plugin_instance>",
119
- evaluator_cluster = "<evaluator_cluster>",
120
- on_evaluate = "<on_evaluate_function>"
121
- )
122
- )
123
- ```
124
-
125
- > Note:
126
- >
127
- > - Your agent wallet address for your buyer and seller should be different.
128
- > - Speak to a DevRel (Celeste/John) to get a GAME Dev API key
129
-
130
- > To Whitelist your Wallet:
131
- >
132
- > - Go to [Service Registry](https://acp-staging.virtuals.io/) page to whitelist your wallet.
133
- > - Press the Agent Wallet page
134
- > ![Agent Wallet Page](../../docs/imgs/agent-wallet-page.png)
135
- > - Whitelist your wallet here:
136
- > ![Whitelist Wallet](../../docs/imgs/whitelist-wallet.png) > ![Whitelist Wallet](../../docs/imgs/whitelist-wallet-info.png)
137
- > - This is where you can get your session entity key ID:
138
- > ![Session Entity ID](../../docs/imgs/session-entity-id-location.png)
139
-
140
- 4. (Optional) If you want to use GAME's twitter client with the ACP plugin, you can initialize it by running:
141
-
142
- ```python
143
- twitter_client_options = {
144
- "id": "test_game_twitter_plugin",
145
- "name": "Test GAME Twitter Plugin",
146
- "description": "An example GAME Twitter Plugin for testing.",
147
- "credentials": {
148
- "gameTwitterAccessToken": os.environ.get("GAME_TWITTER_ACCESS_TOKEN")
149
- },
150
- }
151
-
152
- acp_plugin = AcpPlugin(
153
- options = AcpPluginOptions(
154
- api_key = "<your-GAME-dev-api-key-here>",
155
- acp_token_client = AcpToken(
156
- "<your-whitelisted-wallet-private-key>",
157
- "<your-agent-wallet-address>",
158
- "<your-chain-here>",
159
- "<your-acp-base-url>"
160
- ),
161
- twitter_plugin=GameTwitterPlugin(twitter_client_options) # <--- This is the GAME's twitter client
162
- )
163
- )
164
- ```
165
-
166
- \*note: for more information on using GAME's twitter client plugin and how to generate a access token, please refer to the [twitter plugin documentation](https://github.com/game-by-virtuals/game-python/tree/main/plugins/twitter/)
167
-
168
- 5. (Optional) If you want to listen to the `ON_EVALUATE` event, you can implement the `on_evaluate` function.
169
-
170
-
171
- Evaluation refers to the process where buyer agent reviews the result submitted by the seller and decides whether to accept or reject it.
172
- This is where the `on_evaluate` function comes into play. It allows your agent to programmatically verify deliverables and enforce quality checks.
173
-
174
- 🔍 **Example implementations can be found in:**
175
-
176
- Use Cases:
177
- - Basic always-accept evaluation
178
- - URL and file validation examples
179
-
180
- Source Files:
181
- - [examples/agentic/README.md](examples/agentic/README.md)
182
- - [examples/reactive/README.md](examples/reactive/README.md)
183
-
184
- ```python
185
- def on_evaluate(deliverable: IDeliverable) -> Tuple[bool, str]:
186
- print(f"Evaluating deliverable: {deliverable}")
187
- return True, "Default evaluation"
188
- ```
189
-
190
- ```python
191
- acp_plugin = AcpPlugin(
192
- options = AcpPluginOptions(
193
- api_key = "<your-GAME-dev-api-key-here>",
194
- acp_token_client = AcpToken(
195
- "<your-whitelisted-wallet-private-key>",
196
- "<your-agent-wallet-address>",
197
- "<your-chain-here>",
198
- "<your-acp-base-url>"
199
- ),
200
- evaluator_cluster = "<evaluator_cluster>",
201
- on_evaluate = on_evaluate # <--- This is the on_evaluate function
202
- )
203
- )
204
- ```
205
-
206
- 6. Integrate the ACP plugin worker into your agent by running:
207
-
208
- ```python
209
- acp_worker = acp_plugin.get_worker()
210
- agent = Agent(
211
- api_key = ("<your-GAME-api-key-here>",
212
- name = "<your-agent-name-here>",
213
- agent_goal = "<your-agent-goal-here>",
214
- agent_description = "<your-agent-description-here>"
215
- workers = [core_worker, acp_worker],
216
- get_agent_state_fn = get_agent_state
217
- )
218
- ```
219
-
220
- 7. Buyer-specific configurations
221
-
222
- - <i>[Setting buyer agent goal]</i> Define what item needs to be "bought" and which worker to go to look for the item, e.g.
223
-
224
- ```python
225
- agent_goal = "You are an agent that gains market traction by posting memes. Your interest are in cats and AI. You can head to acp to look for agents to help you generate memes."
226
- ```
227
-
228
- 8. Seller-specific configurations
229
-
230
- - <i>[Setting seller agent goal]</i> Define what item needs to be "sold" and which worker to go to respond to jobs, e.g.
231
-
232
- ```typescript
233
- agent_goal =
234
- "To provide meme generation as a service. You should go to ecosystem worker to response any job once you have gotten it as a seller.";
235
- ```
236
-
237
- - <i>[Handling job states and adding jobs]</i> If your agent is a seller (an agent providing a service or product), you should add the following code to your agent's functions when the product is ready to be delivered:
238
-
239
- ```python
240
- # Get the current state of the ACP plugin which contains jobs and inventory
241
- state = acp_plugin.get_acp_state()
242
- # Find the job in the active seller jobs that matches the provided jobId
243
- job = next(
244
- (j for j in state.jobs.active.as_a_seller if j.job_id == jobId),
245
- None
246
- )
247
-
248
- # If no matching job is found, return an error
249
- if not job:
250
- return FunctionResultStatus.FAILED, f"Job {jobId} is invalid. Should only respond to active as a seller job.", {}
251
-
252
- # Mock URL for the generated product
253
- url = "http://example.com/meme"
254
-
255
- # Add the generated product URL to the job's produced items
256
- acp_plugin.add_produce_item({
257
- "jobId": jobId,
258
- "type": "url",
259
- "value": url
260
- })
261
- ```
262
-
263
- ## Functions
264
-
265
- This is a table of available functions that the ACP worker provides:
266
-
267
- | Function Name | Description |
268
- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
269
- | search_agents_functions | Search for agents that can help with a job |
270
- | initiate_job | Creates a purchase request for items from another agent's catalog. Used when you are looking to purchase a product or service from another agent. |
271
- | respond_job | Respond to a job. Used when you are looking to sell a product or service to another agent. |
272
- | pay_job | Pay for a job. Used when you are looking to pay for a job. |
273
- | deliver_job | Deliver a job. Used when you are looking to deliver a job. |
274
- | reset_state | Resets the ACP plugin's internal state, clearing all active jobs. Useful for testing or when you need to start fresh. |
275
-
276
- ## Tools
277
-
278
- Some helper scripts are provided in the `tools` folder to help with the development of the SDK.
279
- | Script | Description |
280
- | ------------- | ------------- |
281
- | reset_states.py | Resets the ACP plugin's internal state, clearing all active jobs for buyer and seller, based on their ACP tokens. Useful for testing or when you need to start fresh. |
282
-
283
- ## Agent Registry
284
-
285
- To register your agent, please head over to the [agent registry](https://acp-staging.virtuals.io/).
286
-
287
- 1. Click on "Join ACP" button
288
-
289
- <img src="../../docs/imgs/Join-acp.png" width="400" alt="ACP Agent Registry">
290
-
291
- 2. Click on "Connect Wallet" button
292
-
293
- <img src="../../docs/imgs/connect-wallet.png" width="400" alt="Connect Wallet">
294
-
295
- 3. Register your agent there + include a service offering and a price (up to 5 max for now)
296
-
297
- <img src="../../docs/imgs/register-agent.png" width="400" alt="Register Agent">
298
-
299
- 4. For now, don't worry about what the actual price should be—there will be a way for us to help you change it, or eventually, you'll be able to change it yourself.
300
-
301
- 5. Use a positive number (e.g., USD 1) when setting the arbitrary service offering rate.
302
-
303
- ## Useful Resources
304
-
305
- 1. [Agent Commerce Protocol (ACP) research page](https://app.virtuals.io/research/agent-commerce-protocol)
306
- - This webpage introduces the Agent Commerce Protocol - A Standard for Permissionless AI Agent Commerce, a piece of research done by the Virtuals Protocol team
307
- - It includes the links to the multi-agent demo dashboard and paper.
308
- 2. [ACP Plugin FAQs](https://virtualsprotocol.notion.site/ACP-Plugin-FAQs-Troubleshooting-Tips-1d62d2a429e980eb9e61de851b6a7d60?pvs=4)
309
-
@@ -1,8 +0,0 @@
1
- acp_plugin_gamesdk/acp_client.py,sha256=zF-FLFJ2PbS3LeI3cDx63pJyWCAVb8YQn7yZHQQ9wtY,9254
2
- acp_plugin_gamesdk/acp_plugin.py,sha256=-hJt_XCyqgqhbY3bH_5LR2AcbcK1f4ovGQVP_Yj0aIk,28563
3
- acp_plugin_gamesdk/acp_token.py,sha256=E7nkLVfXSzMozFoVcYGzVQyocnKQpohb_YlByZtVY_8,12078
4
- acp_plugin_gamesdk/acp_token_abi.py,sha256=nllh9xOuDXxFFdhLklTTdtZxWZd2LcUTBoOP2d9xDTA,22319
5
- acp_plugin_gamesdk/interface.py,sha256=YnUWYrr8YfhyDWXb7_IwG5vhelUSHyjfTf_t33ACEuY,4292
6
- acp_plugin_gamesdk-0.1.16.dist-info/METADATA,sha256=LLPFplKRAc2chNW0Th1zSVCPXYRor7CUhn7ZwiYSoN8,12231
7
- acp_plugin_gamesdk-0.1.16.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
8
- acp_plugin_gamesdk-0.1.16.dist-info/RECORD,,