Skip to content

Commit

Permalink
Merge pull request #32 from valory-xyz/feat/support_different_networks
Browse files Browse the repository at this point in the history
Support different networks
  • Loading branch information
DavidMinarsch authored Mar 29, 2024
2 parents 4e76e95 + 0f1bb3f commit 88fb917
Show file tree
Hide file tree
Showing 5 changed files with 334 additions and 66 deletions.
36 changes: 28 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,10 @@ Basic client to interact with a mech
pip install mech-client
```

Then, set a websocket endpoint for Gnosis RPC like so:

```bash
export WEBSOCKET_ENDPOINT=<YOUR ENDPOINT>
```

Note: If you encounter an "Out of gas" error when executing the tool, you will need to increase the gas limit by setting, e.g.,

```bash
export MANUAL_GAS_LIMIT=200000
export MECHX_GAS_LIMIT=200000
```

## CLI:
Expand Down Expand Up @@ -88,24 +82,50 @@ mechx interact <prompt> <agent_id> --key <key_file>
Example output:
```bash
mechx interact "write a short poem" 3 --key ~/gnosis_key --tool openai-text-davinci-003
Chain configuration: gnosis
Prompt uploaded: https://gateway.autonolas.tech/ipfs/f01701220ad773628911d12e28f005e3f249e990d684e5dba07542259195602f9afed30bf
Transaction sent: https://gnosisscan.io/tx/0x0d9209e32e965a820b9e80accfcd71ea3b1174b9758dd251c2e627a60ec426a5
Created on-chain request with ID 111240237160304797537720810617416341148235899500021985333360197012735240803849
Data arrived: https://gateway.autonolas.tech/ipfs/bafybeifk2h35ncszlze7t64rpblfo45rezc33xzbya3cjiyumtaioyat3e
Data from agent: {'requestId': 111240237160304797537720810617416341148235899500021985333360197012735240803849, 'result': "\n\nI am brave and I'm strong\nI don't hide away my song\nI am here and I'm proud\nMy voice will be heard loud!"}
```

By default the client will wait for data to arrive from on-chain using the websocket subscription and off-chain using the ACN and show you the result which arrives first. You can specify the type of confirmation you want using `--confirm` flag like this
By default the client will wait for data to arrive from on-chain using the websocket subscription and subgraph, and off-chain using the ACN and show you the result which arrives first. You can specify the type of confirmation you want using `--confirm` flag like this

```bash
mechx interact "write a short poem" 3 --key ~/gnosis_key --tool openai-text-davinci-003 --confirm on-chain
Chain configuration: gnosis
Prompt uploaded: https://gateway.autonolas.tech/ipfs/f017012205e37f761221a8ba4005e91c36b94153e9432b8888ff2acae6b101dd5a5de6768
Transaction sent: https://gnosisscan.io/tx/0xf1ef63f617717bbb8deb09699af99aa39f10155d33796de2fd7eb61c9c1458b6
Created on-chain request with ID 81653153529124597849081567361606842861262371002932574194580478443414142139857
Data arrived: https://gateway.autonolas.tech/ipfs/f0170122069b55e077430a00f3cbc3b069347e901396f978ff160eb2b0a947872be1848b7
Data from agent: {'requestId': 81653153529124597849081567361606842861262371002932574194580478443414142139857, 'result': "\n\nA summer breeze, so sweet,\nA gentle reminder of summer's heat.\nThe sky so blue, no cloud in sight,\nA perfect day, a wondrous sight."}
```

### Chain configuration

Configurations for different chains are stored in the file `configs/mechs.json`. By default, `mech interact` will choose the first configuration on the JSON. You can specify which config you want to use using the `--chain-config` flag, for example,

```bash
mechx interact <prompt> <agent_id> --chain-config gnosis
```

Additionally, you can override any configuration parameter by exporting any of the following environment variables:

```bash
MECHX_CHAIN_RPC
MECHX_WSS_ENDPOINT
MECHX_GAS_LIMIT
MECHX_CONTRACT_ABI_URL
MECHX_SUBGRAPH_URL

MECHX_LEDGER_ADDRESS
MECHX_LEDGER_CHAIN_ID
MECHX_LEDGER_POA_CHAIN
MECHX_LEDGER_DEFAULT_GAS_PRICE_STRATEGY
MECHX_LEDGER_IS_GAS_ESTIMATION_ENABLED
```

## Programmatic Usage:

```python
Expand Down
17 changes: 12 additions & 5 deletions mech_client/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ def cli() -> None:
@click.command()
@click.argument("prompt")
@click.argument("agent_id", type=int)
@click.option(
"--key",
type=click.Path(exists=True, file_okay=True, dir_okay=False),
help="Path to private key to use for request minting",
)
@click.option(
"--tool",
type=str,
Expand All @@ -52,11 +57,6 @@ def cli() -> None:
help="Extra attribute (key=value) to be included in the request metadata",
metavar="KEY=VALUE",
)
@click.option(
"--key",
type=click.Path(exists=True, file_okay=True, dir_okay=False),
help="Path to private key to use for request minting",
)
@click.option(
"--confirm",
type=click.Choice(
Expand All @@ -79,6 +79,11 @@ def cli() -> None:
type=float,
help="Amount of sleep before retrying the transaction",
)
@click.option(
"--chain-config",
type=str,
help="Id of the mech's chain configuration (stored configs/mechs.json)",
)
def interact( # pylint: disable=too-many-arguments
prompt: str,
agent_id: int,
Expand All @@ -89,6 +94,7 @@ def interact( # pylint: disable=too-many-arguments
retries: Optional[int] = None,
timeout: Optional[float] = None,
sleep: Optional[float] = None,
chain_config: Optional[str] = None,
) -> None:
"""Interact with a mech specifying a prompt and tool."""
try:
Expand All @@ -112,6 +118,7 @@ def interact( # pylint: disable=too-many-arguments
retries=retries,
timeout=timeout,
sleep=sleep,
chain_config=chain_config,
)
except (ValueError, FileNotFoundError) as e:
raise click.ClickException(str(e)) from e
Expand Down
92 changes: 92 additions & 0 deletions mech_client/configs/mechs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"gnosis": {
"agent_registry_contract": "0xE49CB081e8d96920C38aA7AB90cb0294ab4Bc8EA",
"rpc_url": "https://rpc.eu-central-2.gateway.fm/v4/gnosis/non-archival/mainnet",
"wss_endpoint": "wss://rpc.eu-central-2.gateway.fm/ws/v4/gnosis/non-archival/mainnet",
"ledger_config": {
"address": "https://rpc.eu-central-2.gateway.fm/v4/gnosis/non-archival/mainnet",
"chain_id": 100,
"poa_chain": false,
"default_gas_price_strategy": "eip1559",
"is_gas_estimation_enabled": false
},
"gas_limit": 100000,
"contract_abi_url": "https://gnosis.blockscout.com/api/v2/smart-contracts/{contract_address}",
"subgraph_url": "https://api.studio.thegraph.com/query/57238/mech/version/latest"
},
"arbitrum": {
"agent_registry_contract": "0xa4799B083E0068732456EF45ff9fe5c683658327",
"rpc_url": "https://arbitrum.llamarpc.com",
"wss_endpoint": "wss://arbitrum.gateway.tenderly.co",
"ledger_config": {
"address": "https://arbitrum.llamarpc.com",
"chain_id": 42161,
"poa_chain": false,
"default_gas_price_strategy": "eip1559",
"is_gas_estimation_enabled": false
},
"gas_limit": 100000,
"contract_abi_url": "https://api.arbiscan.io/api?module=contract&action=getabi&address={contract_address}",
"subgraph_url": ""
},
"polygon": {
"agent_registry_contract": "0x984cf72FDe8B5aA910e9e508aC5e007ae5BDcC9C",
"rpc_url": "https://polygon-bor-rpc.publicnode.com",
"wss_endpoint": "wss://polygon.gateway.tenderly.co",
"ledger_config": {
"address": "https://polygon-bor-rpc.publicnode.com",
"chain_id": 137,
"poa_chain": true,
"default_gas_price_strategy": "eip1559",
"is_gas_estimation_enabled": false
},
"gas_limit": 100000,
"contract_abi_url": "https://api.polygonscan.com/api?module=contract&action=getabi&address={contract_address}",
"subgraph_url": ""
},
"base": {
"agent_registry_contract": "0x88DE734655184a09B70700aE4F72364d1ad23728",
"rpc_url": "https://base.llamarpc.com",
"wss_endpoint": "wss://base.gateway.tenderly.co",
"ledger_config": {
"address": "https://base.llamarpc.com",
"chain_id": 8453,
"poa_chain": false,
"default_gas_price_strategy": "eip1559",
"is_gas_estimation_enabled": false
},
"gas_limit": 100000,
"contract_abi_url": "https://api.basescan.org/api?module=contract&action=getabi&address={contract_address}",
"subgraph_url": ""
},
"celo": {
"agent_registry_contract": "0xE49CB081e8d96920C38aA7AB90cb0294ab4Bc8EA",
"rpc_url": "https://forno.celo.org",
"wss_endpoint": "wss://forno.celo.org/ws",
"ledger_config": {
"address": "https://forno.celo.org",
"chain_id": 42220,
"poa_chain": false,
"default_gas_price_strategy": "eip1559",
"is_gas_estimation_enabled": false
},
"gas_limit": 100000,
"contract_abi_url": "https://api.celoscan.io/api?module=contract&action=getabi&address={contract_address}",
"subgraph_url": ""
},
"optimism": {
"agent_registry_contract": "0x75D529FAe220bC8db714F0202193726b46881B76",
"rpc_url": "https://mainnet.optimism.io",
"wss_endpoint": "wss://optimism.gateway.tenderly.co",
"ledger_config": {
"address": "https://mainnet.optimism.io",
"chain_id": 10,
"poa_chain": false,
"default_gas_price_strategy": "eip1559",
"is_gas_estimation_enabled": false
},
"gas_limit": 100000,
"contract_abi_url": "https://api-optimistic.etherscan.io/api?module=contract&action=getabi&address={contract_address}",
"subgraph_url": ""
}
}
Loading

0 comments on commit 88fb917

Please sign in to comment.