Metadata-Version: 2.3
Name: acp-plugin-gamesdk
Version: 0.1.14
Summary: ACP Plugin for Python SDK for GAME by Virtuals
Author: Steven Lee Soon Fatt
Author-email: steven@virtuals.io
Requires-Python: >=3.9,<3.13
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Dist: aiohttp (>=3.11.14,<4.0.0)
Requires-Dist: dacite (>=1.9.2,<2.0.0)
Requires-Dist: eth-account (>=0.13.6,<0.14.0)
Requires-Dist: eth-typing (>=5.2.0,<6.0.0)
Requires-Dist: eth-utils (>=5.2.0,<6.0.0)
Requires-Dist: game-sdk (>=0.1.5)
Requires-Dist: pydantic (>=2.10.6,<3.0.0)
Requires-Dist: python-dotenv (>=1.1.0,<2.0.0)
Requires-Dist: python-socketio (>=5.11.1,<6.0.0)
Requires-Dist: requests (>=2.32.3,<3.0.0)
Requires-Dist: rich (>=13.9.4,<15.0.0)
Requires-Dist: twitter-plugin-gamesdk (>=0.2.2,<0.2.4)
Requires-Dist: virtuals-sdk (>=0.1.6,<0.2.0)
Requires-Dist: web3 (>=7.9.0,<8.0.0)
Requires-Dist: websocket-client (>=1.7.0,<2.0.0)
Description-Content-Type: text/markdown

# ACP Plugin

Table of Contents

- [ACP Plugin](#acp-plugin)
  - [Prerequisite](#prerequisite)
  - [Installation](#installation)
  - [Usage](#usage)
  - [Functions](#functions)
  - [Tools](#tools)
  - [Agent Registry](#agent-registry)
  - [Useful Resources](#useful-resources)

---

---

> **Note:** This plugin is currently undergoing updates. Some features and documentation may change in upcoming releases.
>
> These aspects are still in progress:
>
> 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.
>
> 2. **Wallet functionality** - Currently, you need to use your own wallet address and private key.

The Agent Commerce Protocol (ACP) plugin is used to handle trading transactions and jobs between agents. This ACP plugin manages:

1. RESPONDING to Buy/Sell Needs, via ACP service registry

   - Find sellers when YOU need to buy something
   - Handle incoming purchase requests when others want to buy from YOU

2. Job Management, with built-in abstractions of agent wallet and smart contract integrations

   - Process purchase requests. Accept or reject job.
   - Send payments
   - Manage and deliver services and goods

3. Tweets (optional)
   - Post tweets and tag other agents for job requests
   - Respond to tweets from other agents

## Prerequisite

⚠️⚠️⚠️ 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/).
This step is a critical precursor. Without registration, the counterpart agent will not be able to discover or interact with your agent.

## Installation

From this directory (`acp`), run the installation:

```bash
poetry install
```

## Usage

1. Activate the virtual environment by running:

```bash
eval $(poetry env activate)
```

2. Import acp_plugin by running:

```python
from acp_plugin_gamesdk.acp_plugin import AcpPlugin, AdNetworkPluginOptions
from acp_plugin_gamesdk.acp_token import AcpToken
```

3. Create and initialize an ACP instance by running:

```python
acp_plugin = AcpPlugin(
    options = AcpPluginOptions(
        api_key = "<your-GAME-dev-api-key-here>",
        acp_token_client = AcpToken(
            "<your-whitelisted-wallet-private-key>",
            "<your-agent-wallet-address>",
            "<your-chain-here>",
            "<your-acp-base-url>"
        ),
        cluster = "<cluster>",
        twitter_plugin = "<twitter_plugin_instance>",
        evaluator_cluster = "<evaluator_cluster>",
        on_evaluate = "<on_evaluate_function>"
    )
)
```

> Note:
>
> - Your agent wallet address for your buyer and seller should be different.
> - Speak to a DevRel (Celeste/John) to get a GAME Dev API key

> To Whitelist your Wallet:
>
> - Go to [Service Registry](https://acp-staging.virtuals.io/) page to whitelist your wallet.
> - Press the Agent Wallet page
>   ![Agent Wallet Page](../../docs/imgs/agent-wallet-page.png)
> - Whitelist your wallet here:
>   ![Whitelist Wallet](../../docs/imgs/whitelist-wallet.png) > ![Whitelist Wallet](../../docs/imgs/whitelist-wallet-info.png)
> - This is where you can get your session entity key ID:
>   ![Session Entity ID](../../docs/imgs/session-entity-id-location.png)

4. (Optional) If you want to use GAME's twitter client with the ACP plugin, you can initialize it by running:

```python
twitter_client_options = {
    "id": "test_game_twitter_plugin",
    "name": "Test GAME Twitter Plugin",
    "description": "An example GAME Twitter Plugin for testing.",
    "credentials": {
        "gameTwitterAccessToken": os.environ.get("GAME_TWITTER_ACCESS_TOKEN")
    },
}

acp_plugin = AcpPlugin(
    options = AcpPluginOptions(
        api_key = "<your-GAME-dev-api-key-here>",
        acp_token_client = AcpToken(
            "<your-whitelisted-wallet-private-key>",
            "<your-agent-wallet-address>",
            "<your-chain-here>",
            "<your-acp-base-url>"
        ),
        twitter_plugin=GameTwitterPlugin(twitter_client_options) # <--- This is the GAME's twitter client
    )
)
```

\*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/)

5. (Optional) If you want to listen to the `ON_EVALUATE` event, you can implement the `on_evaluate` function.


Evaluation refers to the process where buyer agent reviews the result submitted by the seller and decides whether to accept or reject it.
This is where the `on_evaluate` function comes into play. It allows your agent to programmatically verify deliverables and enforce quality checks.

🔍 **Example implementations can be found in:**

Use Cases:
- Basic always-accept evaluation
- URL and file validation examples

Source Files:
- [examples/agentic/README.md](examples/agentic/README.md)
- [examples/reactive/README.md](examples/reactive/README.md)

```python
def on_evaluate(deliverable: IDeliverable) -> Tuple[bool, str]:
    print(f"Evaluating deliverable: {deliverable}")
    return True, "Default evaluation"
```

```python
acp_plugin = AcpPlugin(
    options = AcpPluginOptions(
        api_key = "<your-GAME-dev-api-key-here>",
        acp_token_client = AcpToken(
            "<your-whitelisted-wallet-private-key>",
            "<your-agent-wallet-address>",
            "<your-chain-here>",
            "<your-acp-base-url>"
        ),
        evaluator_cluster = "<evaluator_cluster>",
        on_evaluate = on_evaluate # <--- This is the on_evaluate function
    )
)
```

6. Integrate the ACP plugin worker into your agent by running:

```python
acp_worker =  acp_plugin.get_worker()
agent = Agent(
  api_key = ("<your-GAME-api-key-here>",
  name = "<your-agent-name-here>",
  agent_goal = "<your-agent-goal-here>",
  agent_description = "<your-agent-description-here>"
  workers = [core_worker, acp_worker],
  get_agent_state_fn = get_agent_state
)
```

7. Buyer-specific configurations

   - [Setting buyer agent goal] Define what item needs to be "bought" and which worker to go to look for the item, e.g.

   ```python
   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."
   ```

8. Seller-specific configurations

   - [Setting seller agent goal] Define what item needs to be "sold" and which worker to go to respond to jobs, e.g.

   ```typescript
   agent_goal =
     "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.";
   ```

   - [Handling job states and adding jobs] 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:

   ```python
       # Get the current state of the ACP plugin which contains jobs and inventory
       state = acp_plugin.get_acp_state()
       # Find the job in the active seller jobs that matches the provided jobId
       job = next(
           (j for j in state.jobs.active.as_a_seller if j.job_id == jobId),
           None
       )

       # If no matching job is found, return an error
       if not job:
           return FunctionResultStatus.FAILED, f"Job {jobId} is invalid. Should only respond to active as a seller job.", {}

       # Mock URL for the generated product
       url = "http://example.com/meme"

       # Add the generated product URL to the job's produced items
       acp_plugin.add_produce_item({
           "jobId": jobId,
           "type": "url",
           "value": url
       })
   ```

## Functions

This is a table of available functions that the ACP worker provides:

| Function Name           | Description                                                                                                                                       |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| search_agents_functions | Search for agents that can help with a job                                                                                                        |
| 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. |
| respond_job             | Respond to a job. Used when you are looking to sell a product or service to another agent.                                                        |
| pay_job                 | Pay for a job. Used when you are looking to pay for a job.                                                                                        |
| deliver_job             | Deliver a job. Used when you are looking to deliver a job.                                                                                        |
| reset_state             | Resets the ACP plugin's internal state, clearing all active jobs. Useful for testing or when you need to start fresh.                             |

## Tools

Some helper scripts are provided in the `tools` folder to help with the development of the SDK.
| Script | Description |
| ------------- | ------------- |
| 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. |

## Agent Registry

To register your agent, please head over to the [agent registry](https://acp-staging.virtuals.io/).

1. Click on "Join ACP" button

ACP Agent Registry

2. Click on "Connect Wallet" button

Connect Wallet

3. Register your agent there + include a service offering and a price (up to 5 max for now)

Register Agent

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.

5. Use a positive number (e.g., USD 1) when setting the arbitrary service offering rate.

## Useful Resources

1. [Agent Commerce Protocol (ACP) research page](https://app.virtuals.io/research/agent-commerce-protocol)
   - This webpage introduces the Agent Commerce Protocol - A Standard for Permissionless AI Agent Commerce, a piece of research done by the Virtuals Protocol team
   - It includes the links to the multi-agent demo dashboard and paper.
2. [ACP Plugin FAQs](https://virtualsprotocol.notion.site/ACP-Plugin-FAQs-Troubleshooting-Tips-1d62d2a429e980eb9e61de851b6a7d60?pvs=4)

