Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc mech #118

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
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
13 changes: 13 additions & 0 deletions .spelling
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,19 @@ virtual testnet
block
npx
npm
Prefill address
.example_agent.env
prefilled
mechs
ServiceRegistryL2
IPFS_HASH
hexadecimal
Deliver
owner address
id
mech
config
service.yaml
ai-registry-mech
submodule
virtual_testnet
Expand Down
71 changes: 28 additions & 43 deletions docs/mech-client/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,50 +20,31 @@ In order to send a request, the workflow is the following:

The detailed instructions to send a request to a Mech can be found below.

/!\ Only the Mechs with fixed pricing are currently stable.
/!\ Only the Mechs with fixed pricing are currently usable.

### Setup

**Requirements**: [Python](https://www.python.org/) >= 3.10, [Poetry](https://github.com/python-poetry/poetry) == 1.8.4

**1.** Install the [Mech client](https://github.com/valory-xyz/mech-client):

- *(Option 1)* Using [Poetry](https://github.com/python-poetry/poetry):
**1.** Install mech-client:

```
poetry new my_project
poetry my_project
cd my_project
poetry shell
poetry add mech-client
poetry install
poetry shell
```

- *(Option 2)* On local python installation:
**2.** Setting up an EOA account:

```
pip install mech-client
```
**a.** Install browser extension of Metamask and open it;

**2.** Setting up an EOA account:
**b.** Click on the account icon, then on “Add account or hardware wallet”, then “Add a new Ethereum account”, provide a name for the account and then click on “Add account”;

- *Option 1* (manual creation):
**c.** Select the newly created account and then click on the top-right menu icon and then “Account details”. You can find the private key by clicking “Show private key”.

**a.** Install browser extension of Metamask and open it;

**b.** Click on the account icon, then on “Add account or hardware wallet”, then “Add a new Ethereum account”, provide a name for the account and then click on “Add account”;

**c.** Select the newly created account and then click on the top-right menu icon and then “Account details”. You can find the private key by clicking “Show private key”.

**d.** Copy this key in the file `ethereum_private_key.txt` in your project folder (do not include any leading or trailing spaces, tabs or newlines or any other character);

- *Option 2* (using [open-autonomy](https://github.com/valory-xyz/open-autonomy)):

**a.** Use the following to generate a private key:
```
autonomy generate-key ethereum -n 1
```

This creates a file keys.json in which the private key can be found on the key “private_key”.

**b.** Copy this key in the file `ethereum_private_key.txt`.
**d.** Copy this key in the file `ethereum_private_key.txt` in your project folder (do not include any leading or trailing spaces, tabs or newlines or any other character);
Comment on lines -45 to +47

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this changed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Adamantios Only the part which creates the key file with autonomy generate-key ethereum -n 1 is removed (since it is not really needed ?)


**3.** Create an API key for the network you want to use. For instance, follow the steps described [here](https://docs.gnosisscan.io/getting-started/viewing-api-usage-statistics#creating-an-api-key) for Gnosis. Then use the following:

Expand Down Expand Up @@ -100,18 +81,22 @@ Alternatively, for Gnosis network, you can find the list of Mech Marketplace Mec

You will then see the list of available Mech Marketplace Mechs.

In order to find which tools the Mech uses, click on its service id, and then "View code" in the window which opens. Open the folder `mech` and then `service.yaml`. Copy the IPFS hash which follows `agent: valory/mech:0.1.0` and open the corresponding
file by going to https://gateway.autonolas.tech/ipfs/ with the copied hash at the end of this address. Open the `mech` folder and then the file `aea-config.yaml`. In this file, the keys of the dictionary `tools_to_package_hash` are the
names of the tools that this service uses.

Comment on lines +84 to +87

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not accurate. The aea config does not contain the tools that the mech is using, it is only a template with default values.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably the best option would be to point to the metadata and make sure that they are always updated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Adamantios Do you suggest that we write a list of metadata hashes in this doc ? (because this is all off-chain)

### 1. 2. In terminal

**1.** Send a request:

- Use the command mechx in terminal, which is structured as follows:

```
mechx interact <prompt> --chain-config <chain-config> --use-offchain <bool>
mechx interact <prompt> --chain-config <chain-config> --use-offchain <bool> --tool <tool> --priority-mech <mech_address>
```

Replace `<prompt>` by a string which corresponds to the request to send to the Mech, and `<chain-config>` by one of the keys in the dictionary found in the file `.mech_client/configs/mechs.json` (for instance "gnosis"). In the dictionary corresponding to this key, replace the value of `priority_mech_address` with the address of the mech you want to send the request to.
Change `<bool>` to True in order to use the off-chain method, and False otherwise.
Change `<bool>` to True in order to use the off-chain method, and False otherwise. Change `<tool>` to the name of the tool you want to use. Finally, change `<mech_address>` to the address of the Mech you want to send a request to.

- If prompted, add funds to EOA account created above in order to be able to make a deposit on-chain and account for the mech fees. Specifically, add:
- Native network token, e.g. xDAI for Gnosis, if the Mech uses native fixed price
Expand All @@ -122,15 +107,7 @@ It will be indicated how much is needed. You can also find
the price per request (resp. the maximal price per Mechs with Nevermined subscription) as follows.
Enter the address of the Mech in the scan of the network. Click on "Contract", then "Read contract" and find and click on "maxDeliveryRate" in the list which appears below. Divide the displayed number by 10^8 in order to obtain the price per request.

- It is possible (and optional) to specify which tool should be used by the mech. The command line is then:

```
mechx interact <prompt> --tool <tool> --chain-config <chain-config>
```

In this case, replace `<tool>` by the name of the tool.

- If prompted to make a an on-chain deposit to pay for Mech fees, use the following:
- If prompted to make an on-chain deposit to pay for Mech fees, use the following:

```
python ./scripts/deposit_payment_model.py
Expand All @@ -149,6 +126,14 @@ mechx interact "write a short poem" --tool openai-gpt-3.5-turbo --chain-config g
you should receive a response as follows:
![screenshot_response](./imgs/screenshot_request.png)

If not, you can note the request id provided in the logs, convert it to hexadecimal:

```bash
printf "%x\n" <request_id>
```

where `<request_id>` is replaced by the id of your request. Find the Mech on this [page](https://mech.olas.network/mechs) (by searching for its service id or address for instance) and click on its address. You should see the list of requests sent to this Mech. You can find your request using its id (in hexadecimal format). Then click on "Delivers Data" to see the response.

- Remark: If an "Out of gas" error is encountered, an increase of the gas limit, can solve the problem, using the following line:

```
Expand Down Expand Up @@ -178,7 +163,7 @@ The variables **PROMPT_TEXT**, **CHAIN_CONFIG** and **TOOL_NAME** can be changed

**1.** Create a wallet (for instance with [Metamask](https://metamask.io/)) and connect it to the web interface by clicking on the button “Connect wallet” on the webpage. This wallet must be provided with xDAI in order to pay the Mechs for the requests.

**2.** Go to the webpage [here](https://aimechs.autonolas.network/mech/0x77af31De935740567Cf4fF1986D04B2c964A786a). In the url, replace the address with the one of the Mech you intend to send a request to.
**2.** Go to the webpage [here](https://mech.olas.network/gnosis/mechs). Click on the address of the Mech you want to send a request to.

**4.** Click on "New Request". The following pop-up will appear:
![screenshot](./imgs/screenshot.png)
Expand Down Expand Up @@ -281,7 +266,7 @@ The variables **PROMPT_TEXT**, **AGENT_ID** and **TOOL_NAME** can be changed. Th

**1.** Create a wallet (for instance with [Metamask](https://metamask.io/)) and connect it to the web interface by clicking on the button “Connect wallet” on the webpage. This wallet must be provided with xDAI in order to pay the Mechs for the requests.

**2.** Go to the webpage [here](https://aimechs.autonolas.network/mech/0x77af31De935740567Cf4fF1986D04B2c964A786a). In the url, replace the address with the one of the Mech you intend to send a request to.
**2.** Go to the webpage [here](https://mech.olas.network/gnosis/mechs?legacy=true). Click on the address of the Mech you want to send a request to.

**4.** Click on "New Request". The following pop-up will appear:
![screenshot](./imgs/screenshot.png)
Expand Down
58 changes: 33 additions & 25 deletions docs/mech-tool/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ where `<prompt>` is replaced by the chosen prompt and `<tool_name>` by the name

**7.** You can see the data of the request in the testnet page on tenderly, in the tab "Explorer".

## 4. Deploying a Mech on the Mech Marketplace
## 4. Deploying a Mech on the Mech Marketplace (quickstart)

In order to register a Mech on the Mech Marketplace - including Mech service creation and deployment, and Mech contract deployment- follow the instructions below.

Expand Down Expand Up @@ -368,7 +368,7 @@ poetry install
bash run_service.sh
```

**2.** Provide information when prompted (in particular for the RPC endpoint, provide the https address copied earlier).
**2.** Provide information when prompted (in particular for the RPC endpoint, provide the https address copied earlier). Also add funds to the required address.

**3.** In order to send a request to it, follow the steps in the [section 2.3](#2-3-sending-a-request) above, replacing the RPC endpoint with the one created here.

Expand All @@ -395,15 +395,33 @@ name of the chosen chain.
./stop_service.sh
```

## 5. Registering an agent on the Mech Marketplace
## 5. Deploying a Mech on the Mech Marketplace (manually)

In case you have already a Mech service deployed on Olas Registry and want to put it to work for other agents, you only need to register it on the Mech Marketplace.
In order to deploy a Mech, it is also possible to do so manually, first by deploying a service, registering it on the Mech Marketplace, and then running it locally.

In order to do so, follow the instructions below.
### 5.1 Creating a Mech service

In order to create the service, go to the [Olas Registry](https://registry.olas.network/gnosis/services) webpage.

**1.** Choose the network and connect your wallet.

**2.** Click on the button "Mint".

**3.** Click on the `Prefill address` button in order to fill the `owner address` field. You will need to have funds on this address in order to deploy the service. For the hash of the metadata file, click on "Generate Hash & File". The hash should be the one found in the file `packages/packages.json` in the mech-predict [repository](https://github.com/valory-xyz/mech-predict/) for the key `service/valory/mech/`. Select first the prefix and fill the field with the remaining part. The version is contained in this key (e.g. `service/valory/mech/0.1.0`). For the agent id, follow the instructions on the opened page (we suggest agent id = 9 to test). The number of slots corresponds to the number of agents that the service contains (we suggest 1 to test). For the cost of agent bound, we suggest that you use a small value (e.g., 1000000000000000 GörliWei = 0.001 GörliETH). We suggest to write threshold = 1 to test. Then click on submit.

**4.** Click on "Services". The last entry corresponds to the service you have created. Click on "View".

**5.** Click first on "Activate registration" (Step 1). Then in the field "Agent Instance Addresses" (Step 2), enter one address (not the same one as the one used as owner address) for each agent in the service, and click on "Register Agents". Choose a service multisig (Step 3) and click on "Submit".

**6.** The service is now deployed, and you can see the safe contract address below. You will need this address in order to run the Mech.

### 5.2 Registering the service on the Mech Marketplace

In order to register your service on the Mech Marketplace, follow the instructions below.

**1.** Find [there](https://github.com/valory-xyz/ai-registry-mech/blob/main/docs/configuration.json) the address of MechMarketPlaceProxy for the chosen network.

**2.** Trigger the function `create` of this contract with the following inputs (in order):
**2.** Using the scan of the chosen network, trigger the function `create` of this contract with the following inputs (in order):

- The service id.
- The Mech Factory address for the selected network and payment model. To find the correct address, refer to the [configuration file](https://github.com/valory-xyz/ai-registry-mech/blob/main/docs/configuration.json). Search for the address that matches the chosen payment model:
Expand All @@ -414,33 +432,23 @@ In order to do so, follow the instructions below.

- For Nevermined, find MechFactoryNvmSubscriptionNative.

- The maximum price of the Mech (also called maxDeliveryRate), converted to Wei. For instance, for a price of 1 xDAI, this
is equal to 10^18.
- The maximum price of the Mech (also called maxDeliveryRate), converted to Wei. In order to do this, first multiply
the price in xDAI by 10^18. For instance, for a price of 1 xDAI, this
is equal to 10^18. Then Use [ABI Hashex Encoder](https://abi.hashex.org/). Select uint256 as the type and enter the obtained value (for 1 xDAI this is 1000000000000000000 in wei). The tool will generate the encoded result, which is the following in the example: 0000000000000000000000000000000000000000000000000de0b6b3a7640000. Finally add 0x at the beginning of the sequence to obtain 0x0000000000000000000000000000000000000000000000000de0b6b3a7640000 in the example. This is the sequence that should be entered.

You can find a script for triggering this function [there](https://github.com/Sfgangloff/ai-registry-mech/tree/main/scripts/mech_registration) for each payment model. Clone the repository:
:warning: You must use the same EOA as the one used to deploy the service.

```
git clone https://github.com/Sfgangloff/ai-registry-mech.git
```
### 5.3 Running the Mech service

Update the submodules, install the dependencies and compile the contracts:
In order to run the Mech service that you created, follow the steps below.

```
git submodule update --init --recursive
yarn install
npx hardhat compile
```

Choose the one which corresponds to the chosen payment model, and replace the name of the network on line 6. Then add your private key (privateKey), service id (serviceId) and maximum price (payload) in the globals file which corresponds to the chosen network. Finally, run the script. For instance, for a native fixed price Mech:
Clone the `mech-predict` repository:

```
cd scripts/mech_registration
node create_mech_native.js
git clone https://github.com/valory-xyz/mech-predict.git
```

/!\ The private key must correspond to the EOA used to deploy the service.

**3.** You will find the address of the Mech contract in the logs. It will also be written in the globals file.
Then follow the instructions in the README.md file (section 'Running the old base mech').

## 6. How to accrue the payments

Expand Down
3 changes: 2 additions & 1 deletion scripts/check_doc_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"https://x.com/autonolas",
"wss://gnosis-chiado-rpc.publicnode.com",
"https://gnosis.blockscout.com/api/v2/smart-contracts/{contract_address}",
"https:/gnosisscan.iotx/{transaction_digest}"
"https:/gnosisscan.iotx/{transaction_digest}",
"https://gateway.autonolas.tech/ipfs/"
]

# Define here custom timeouts for some edge cases
Expand Down
Loading