From 05245dcef6506c58b74d1635a39f40b71f5725cd Mon Sep 17 00:00:00 2001 From: Ardian Date: Fri, 23 Feb 2024 13:23:14 +0100 Subject: [PATCH 1/6] fix: add `termination_from_block` param --- packages/packages.json | 6 +++--- packages/valory/agents/mech/aea-config.yaml | 3 ++- packages/valory/services/mech/service.yaml | 6 +++++- packages/valory/skills/mech_abci/skill.yaml | 1 + 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/packages.json b/packages/packages.json index b740d96f..2844f57d 100644 --- a/packages/packages.json +++ b/packages/packages.json @@ -20,13 +20,13 @@ "contract/valory/hash_checkpoint/0.1.0": "bafybeianr3zy3bb464jwlwwxtk2daeeh4cefy7ihw5bfn7zrn7vjs3fyga", "connection/valory/websocket_client/0.1.0": "bafybeiflmystocxaqblhpzqlcop2vkhsknpzjx2jomohomaxamwskeokzm", "skill/valory/contract_subscription/0.1.0": "bafybeicyugrkx5glat4p4ezwf6i7oduh26eycfie6ftd4uxrknztzl3ik4", - "skill/valory/mech_abci/0.1.0": "bafybeib6nqbsmlsgbomld2tsyk4cjni4t7rnx7css4tmsmssmhjzm4gs74", + "skill/valory/mech_abci/0.1.0": "bafybeiahkev6ur4otoeuprgedck3pk6ob4q44lyvdkvz733ftu54zicw3i", "skill/valory/task_submission_abci/0.1.0": "bafybeifaqewhshy4xrm7nejtmwgm6wwm6k4ps2xn4v2kckpwqsr7wblslm", "skill/valory/task_execution/0.1.0": "bafybeienkm3nxcyqllpnndsacaq27nhgwgs4v5vyynvqkyv5uc6aojatji", "skill/valory/websocket_client/0.1.0": "bafybeidwntmkk4b2ixq5454ycbkknclqx7a6vpn7aqpm2nw3duszqrxvta", "skill/valory/subscription_abci/0.1.0": "bafybeidtoiyzlenxawjkyogwbfjgui2a22srdo6zbajubgg6awgha5hm4m", - "agent/valory/mech/0.1.0": "bafybeiglzfdna5o7ffazzvmd57ph4ttvubznc4itxkxxcd6njvew2x2cve", - "service/valory/mech/0.1.0": "bafybeic7toq6xpfwonqzrq7sfe2njlscz2m336djql5bsshfj3zk5ghhde" + "agent/valory/mech/0.1.0": "bafybeid7h5igfhffydjhsxu76jchbofarmagq255ld6zf3a5iu6yubfchy", + "service/valory/mech/0.1.0": "bafybeiapgyqt7wopqhwfatatxppcynuhg2ye65ltnf5k6zrih5lnka2bee" }, "third_party": { "protocol/valory/default/1.0.0": "bafybeifqcqy5hfbnd7fjv4mqdjrtujh2vx3p2xhe33y67zoxa6ph7wdpaq", diff --git a/packages/valory/agents/mech/aea-config.yaml b/packages/valory/agents/mech/aea-config.yaml index d5e3684f..6dfc562d 100644 --- a/packages/valory/agents/mech/aea-config.yaml +++ b/packages/valory/agents/mech/aea-config.yaml @@ -38,7 +38,7 @@ skills: - valory/abstract_abci:0.1.0:bafybeihljirk3d4rgvmx2nmz3p2mp27iwh2o5euce5gccwjwrpawyjzuaq - valory/abstract_round_abci:0.1.0:bafybeigjrepaqpb3m7zunmt4hryos4vto4yyj3u6iyofdb2fotwho3bqvm - valory/contract_subscription:0.1.0:bafybeicyugrkx5glat4p4ezwf6i7oduh26eycfie6ftd4uxrknztzl3ik4 -- valory/mech_abci:0.1.0:bafybeib6nqbsmlsgbomld2tsyk4cjni4t7rnx7css4tmsmssmhjzm4gs74 +- valory/mech_abci:0.1.0:bafybeiahkev6ur4otoeuprgedck3pk6ob4q44lyvdkvz733ftu54zicw3i - valory/registration_abci:0.1.0:bafybeif3ln6eg53ebrfe6uicjew4uqp2ynyrcxkw5wi4jm3ixqv3ykte4a - valory/reset_pause_abci:0.1.0:bafybeicm7onl72rfnn33pbvzwjpkl5gafeieyobfcnyresxz7kunjwmqea - valory/subscription_abci:0.1.0:bafybeidtoiyzlenxawjkyogwbfjgui2a22srdo6zbajubgg6awgha5hm4m @@ -196,6 +196,7 @@ models: profit_split_freq: ${int:1} agent_funding_amount: ${int:200000000000000000} minimum_agent_balance: ${int:100000000000000000} + termination_from_block: ${int:0} mech_to_subscription: ${list:[["0x77af31De935740567Cf4fF1986D04B2c964A786a",["0x0000000000000000000000000000000000000000","1"]]]} hash_checkpoint_address: ${str:0x694e62BDF7Ff510A4EE66662cf4866A961a31653} setup: diff --git a/packages/valory/services/mech/service.yaml b/packages/valory/services/mech/service.yaml index e0f08d11..b9ab6997 100644 --- a/packages/valory/services/mech/service.yaml +++ b/packages/valory/services/mech/service.yaml @@ -7,7 +7,7 @@ license: Apache-2.0 fingerprint: README.md: bafybeif7ia4jdlazy6745ke2k2x5yoqlwsgwr6sbztbgqtwvs3ndm2p7ba fingerprint_ignore_patterns: [] -agent: valory/mech:0.1.0:bafybeiglzfdna5o7ffazzvmd57ph4ttvubznc4itxkxxcd6njvew2x2cve +agent: valory/mech:0.1.0:bafybeid7h5igfhffydjhsxu76jchbofarmagq255ld6zf3a5iu6yubfchy number_of_agents: 4 deployment: agent: @@ -48,6 +48,7 @@ type: skill reset_period_count: ${RESET_PERIOD_COUNT:int:1000} service_endpoint_base: ${SERVICE_ENDPOINT_BASE:str:https://dummy_service.autonolas.tech/} use_slashing: ${USE_SLASHING:bool:false} + termination_from_block: ${TERMINATION_FROM_BLOCK:int:0} slash_cooldown_hours: ${SLASH_COOLDOWN_HOURS:int:3} slash_threshold_amount: ${SLASH_THRESHOLD_AMOUNT:int:10000000000000000} light_slash_unit_amount: ${LIGHT_SLASH_UNIT_AMOUNT:int:5000000000000000} @@ -83,6 +84,7 @@ type: skill use_slashing: ${USE_SLASHING:bool:false} slash_cooldown_hours: ${SLASH_COOLDOWN_HOURS:int:3} slash_threshold_amount: ${SLASH_THRESHOLD_AMOUNT:int:10000000000000000} + termination_from_block: ${TERMINATION_FROM_BLOCK:int:0} light_slash_unit_amount: ${LIGHT_SLASH_UNIT_AMOUNT:int:5000000000000000} serious_slash_unit_amount: ${SERIOUS_SLASH_UNIT_AMOUNT:int:8000000000000000} agent_registry_address: ${AGENT_REGISTRY_ADDRESS:str:0xE49CB081e8d96920C38aA7AB90cb0294ab4Bc8EA} @@ -108,6 +110,7 @@ type: skill setup: *id001 share_tm_config_on_startup: ${USE_ACN:bool:false} tendermint_com_url: ${TENDERMINT_COM_URL:str:http://localhost:8080} + termination_from_block: ${TERMINATION_FROM_BLOCK:int:0} tendermint_url: ${TENDERMINT_URL:str:http://localhost:26657} tendermint_p2p_url: ${TM_P2P_ENDPOINT_NODE_0:str:node0:26656} termination_sleep: ${TERMINATION_SLEEP:int:900} @@ -143,6 +146,7 @@ type: skill manual_gas_limit: ${MANUAL_GAS_LIMIT:int:1000000} tendermint_com_url: ${TENDERMINT_COM_URL:str:http://localhost:8080} tendermint_url: ${TENDERMINT_URL:str:http://localhost:26657} + termination_from_block: ${TERMINATION_FROM_BLOCK:int:0} tendermint_p2p_url: ${TM_P2P_ENDPOINT_NODE_0:str:node0:26656} termination_sleep: ${TERMINATION_SLEEP:int:900} use_termination: ${USE_TERMINATION:bool:false} diff --git a/packages/valory/skills/mech_abci/skill.yaml b/packages/valory/skills/mech_abci/skill.yaml index 87803870..5eae32d8 100644 --- a/packages/valory/skills/mech_abci/skill.yaml +++ b/packages/valory/skills/mech_abci/skill.yaml @@ -161,6 +161,7 @@ models: slash_cooldown_hours: 3 hash_checkpoint_address: '0x0000000000000000000000000000000000000000' slash_threshold_amount: 10000000000000000 + termination_from_block: 0 light_slash_unit_amount: 5000000000000000 service_owner_share: 0.1 profit_split_freq: 100 From 03f227914a82c201fd5fcaa16d8a3443bd1cdfc6 Mon Sep 17 00:00:00 2001 From: Ardian Date: Fri, 23 Feb 2024 15:21:24 +0100 Subject: [PATCH 2/6] fix: required params --- .example.env | 3 ++- packages/packages.json | 4 ++-- packages/valory/agents/mech/aea-config.yaml | 4 ++-- packages/valory/services/mech/service.yaml | 2 +- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/.example.env b/.example.env index eb8be697..e0b057e3 100644 --- a/.example.env +++ b/.example.env @@ -1,6 +1,7 @@ -FILE_HASH_TO_TOOLS='[["bafybeiaodddyn4eruafqg5vldkkjfglj7jg76uvyi5xhi2cysktlu4w6r4",["openai-gpt-3.5-turbo-instruct","openai-gpt-3.5-turbo","openai-gpt-4"]],["bafybeiepc5v4ixwuu5m6p5stck5kf2ecgkydf6crj52i5umnl2qm5swb4i",["stabilityai-stable-diffusion-v1-5","stabilityai-stable-diffusion-xl-beta-v2-2-2","stabilityai-stable-diffusion-512-v2-1","stabilityai-stable-diffusion-768-v2-1"]],["bafybeidpbnqbruzqlq424qt3i5dcvyqmcimshjilftabnrroujmjhdmteu",["transfer-native"]],["bafybeiglhy5epaytvt5qqdx77ld23ekouli53qrf2hjyebd5xghlunidfi",["prediction-offline","prediction-online"]]]' +FILE_HASH_TO_TOOLS='[["bafybeibdcttrlgp5udygntka5fofi566pitkxhquke37ng7csvndhy4s2i",["openai-gpt-3.5-turbo-instruct","openai-gpt-3.5-turbo","openai-gpt-4"]],["bafybeiegbsq2ajxyipajac4mmxyvbt22ctwyuypuid6ziavqpndns6fsjy",["stabilityai-stable-diffusion-v1-5","stabilityai-stable-diffusion-xl-beta-v2-2-2","stabilityai-stable-diffusion-512-v2-1","stabilityai-stable-diffusion-768-v2-1"]],["bafybeihugaylajwh2fgypxatcw5qrw5qxadtrsi2h2s2246442wlvjirtm",["transfer-native"]],["bafybeiayity7o6c2yynrpe6libyak37hgf4fp7a4kjfcnqkkxwy3zkp3ie",["prediction-offline","prediction-online"]]]' API_KEYS='[["openai","dummy_api_key"],["stabilityai","dummy_api_key"]]' ETHEREUM_LEDGER_RPC_0=https://rpc.eu-central-2.gateway.fm/v4/gnosis/non-archival/mainnet +GNOSIS_RPC_0=https://rpc.eu-central-2.gateway.fm/v4/gnosis/non-archival/mainnet ETHEREUM_WEBSOCKET_RPC_0=wss://rpc.eu-central-2.gateway.fm/ws/v4/gnosis/non-archival/mainnet ETHEREUM_LEDGER_CHAIN_ID=100 ALL_PARTICIPANTS='["0x10E867Ac2Fb0Aa156ca81eF440a5cdf373bE1AaC"]' diff --git a/packages/packages.json b/packages/packages.json index 2844f57d..541387e3 100644 --- a/packages/packages.json +++ b/packages/packages.json @@ -25,8 +25,8 @@ "skill/valory/task_execution/0.1.0": "bafybeienkm3nxcyqllpnndsacaq27nhgwgs4v5vyynvqkyv5uc6aojatji", "skill/valory/websocket_client/0.1.0": "bafybeidwntmkk4b2ixq5454ycbkknclqx7a6vpn7aqpm2nw3duszqrxvta", "skill/valory/subscription_abci/0.1.0": "bafybeidtoiyzlenxawjkyogwbfjgui2a22srdo6zbajubgg6awgha5hm4m", - "agent/valory/mech/0.1.0": "bafybeid7h5igfhffydjhsxu76jchbofarmagq255ld6zf3a5iu6yubfchy", - "service/valory/mech/0.1.0": "bafybeiapgyqt7wopqhwfatatxppcynuhg2ye65ltnf5k6zrih5lnka2bee" + "agent/valory/mech/0.1.0": "bafybeigileaik3lno5mb3je2tfsmep33eq43qfxtp4razjfo7mzaxzqfxa", + "service/valory/mech/0.1.0": "bafybeianvggwocwrat6w6zirab44nwpptigb6aw533zawmqxgjg6eslkdm" }, "third_party": { "protocol/valory/default/1.0.0": "bafybeifqcqy5hfbnd7fjv4mqdjrtujh2vx3p2xhe33y67zoxa6ph7wdpaq", diff --git a/packages/valory/agents/mech/aea-config.yaml b/packages/valory/agents/mech/aea-config.yaml index 6dfc562d..07bc79b3 100644 --- a/packages/valory/agents/mech/aea-config.yaml +++ b/packages/valory/agents/mech/aea-config.yaml @@ -185,7 +185,7 @@ models: on_chain_service_id: ${int:1} agent_registry_address: ${str:0x0000000000000000000000000000000000000000} agent_id: ${int:3} - metadata_hash: ${str:null} + metadata_hash: ${str:0000000000000000000000000000000000000000000000000000000000000000} share_tm_config_on_startup: ${bool:false} multisend_address: ${str:0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761} service_registry_address: ${str:0x9338b5153AE39BB89f50468E608eD9d764B755fD} @@ -218,7 +218,7 @@ models: agent_index: ${int:0} num_agents: ${int:4} from_block_range: ${int:50000} - mech_to_config: ${list:[["0x77af31De935740567Cf4fF1986D04B2c964A786a",["use_dynamic_pricing","false"]]]} + mech_to_config: ${list:[["0xFf82123dFB52ab75C417195c5fDB87630145ae81",["use_dynamic_pricing","false"]]]} timeout_limit: ${int:3} max_block_window: ${int:500} --- diff --git a/packages/valory/services/mech/service.yaml b/packages/valory/services/mech/service.yaml index b9ab6997..c675d9aa 100644 --- a/packages/valory/services/mech/service.yaml +++ b/packages/valory/services/mech/service.yaml @@ -7,7 +7,7 @@ license: Apache-2.0 fingerprint: README.md: bafybeif7ia4jdlazy6745ke2k2x5yoqlwsgwr6sbztbgqtwvs3ndm2p7ba fingerprint_ignore_patterns: [] -agent: valory/mech:0.1.0:bafybeid7h5igfhffydjhsxu76jchbofarmagq255ld6zf3a5iu6yubfchy +agent: valory/mech:0.1.0:bafybeigileaik3lno5mb3je2tfsmep33eq43qfxtp4razjfo7mzaxzqfxa number_of_agents: 4 deployment: agent: From 505f753beb6cdce47cb085df89caad44898d564c Mon Sep 17 00:00:00 2001 From: Ardian Date: Fri, 23 Feb 2024 15:23:10 +0100 Subject: [PATCH 3/6] chore: fix README --- README.md | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 58793990..9ae5ec4d 100644 --- a/README.md +++ b/README.md @@ -129,15 +129,15 @@ Now, you have two options to run the worker: as a standalone agent or as a servi You can create and mint your own AI Mech that handles requests for tasks that you can define. -1. **Create a new tool.** Tools are the components that execute the Requests for AI tasks submitted on [Mech Hub](https://aimechs.autonolas.network/mech). Tools must be located in the folder `./tools` as a single Python file. Such file must contain a `run` function that accepts `kwargs` and must **always** return a string (`str`). That is, the `run` function must not raise any exception. If exceptions occur inside the function, they must be processed, and the return value must be set accordingly, for example, returning an error code. +1. **Create a new tool.** Tools are the components that execute the Requests for AI tasks submitted on [Mech Hub](https://aimechs.autonolas.network/mech). Tools are custom components and should be under the `customs` packages (ex. [valory tools](./packages/valory/customs)). Such file must contain a `run` function that accepts `kwargs` and must **always** return a tuple (`Tuple[Optional[str], Optional[Dict[str, Any]], Any, Any]`). That is, the `run` function must not raise any exception. If exceptions occur inside the function, they must be processed, and the return value must be set accordingly, for example, returning an error code. ```python - def run(**kwargs) -> str: + def run(**kwargs) -> Tuple[Optional[str], Optional[Dict[str, Any]], Any, Any]:: """Run the task""" # Your code here - return result # a string + return result_str, prompt_used, generated_tx, counter_callback ``` The `kwargs` are guaranteed to contain: @@ -148,17 +148,20 @@ You can create and mint your own AI Mech that handles requests for tasks that yo * `prompt` (`kwargs["prompt"]`): a string containing the user prompt. * `tool` (`kwargs["tool"]`): a string specifying the (sub-)tool to be used. The `run` command must parse this input and execute the task corresponding to the particular sub-tool referenced. These sub-tools will allow the user to fine-tune the use of your tool. -2. **Upload the tool file to IPFS.** You can use the following script: +2. **Upload the tool file to IPFS.** You can push your tool to IPFS like the other packages: ```bash - mechx push-to-ipfs "tools/.py" + autonomy push-all ``` You should see an output similar to this: ``` - IPFS file hash v1: bafybei0123456789abcdef...0 - IPFS file hash v1 hex: f017012200123456789abcdef...0 + Pushing: /home/ardian/vlr/mech/packages/valory/customs/openai_request + Pushed component with: + PublicId: valory/openai_request:0.1.0 + Package hash: bafybeibdcttrlgp5udygntka5fofi566pitkxhquke37ng7csvndhy4s2i ``` - Note down the generated hashes for your tool. + Your tool will be available on [packages.json](packages/packages.json). + 3. **Configure your service.** Edit the `.env` file. The demo service has this configuration: ```bash From cd01788dde20256946c76249ac970124997cc0d1 Mon Sep 17 00:00:00 2001 From: Ardian Date: Fri, 23 Feb 2024 15:26:24 +0100 Subject: [PATCH 4/6] chore: fix docs --- docs/index.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index b111cc4f..170f34b5 100644 --- a/docs/index.md +++ b/docs/index.md @@ -48,8 +48,6 @@ In order to run a local demo service based on the MechKit: ```bash git clone https://github.com/valory-xyz/mech && cd mech - poetry run pip install openapi-core==0.13.2 - poetry run pip install openapi-spec-validator==0.2.8 poetry install && poetry shell autonomy init --remote --ipfs --reset --author=your_name From 185ded0ed11bc2e85998601e6ac93e53c6c04513 Mon Sep 17 00:00:00 2001 From: Ardian Date: Fri, 23 Feb 2024 16:02:48 +0100 Subject: [PATCH 5/6] chore: fix docs --- README.md | 4 +--- docs/index.md | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9ae5ec4d..c671fbb6 100644 --- a/README.md +++ b/README.md @@ -56,8 +56,6 @@ Follow these instructions to have your local environment prepared to run the dem 1. Create a Poetry virtual environment and install the dependencies: ```bash - poetry run pip install openapi-core==0.13.2 - poetry run pip install openapi-spec-validator==0.2.8 poetry install && poetry shell ``` @@ -71,7 +69,7 @@ Follow these instructions to have your local environment prepared to run the dem ## Run the demo -Follow the instructions below to run the AI Mech demo executing the tool in `./tools/openai_request.py`. Note that AI Mechs can be configured to work in two modes: *polling mode*, which periodically reads the chain, and *websocket mode*, which receives event updates from the chain. The default mode used by the demo is *polling*. +Follow the instructions below to run the AI Mech demo executing the tool in `./packages/valory/customs/openai_request.py`. Note that AI Mechs can be configured to work in two modes: *polling mode*, which periodically reads the chain, and *websocket mode*, which receives event updates from the chain. The default mode used by the demo is *polling*. First, you need to configure the worker service. You need to create a `.1env` file which contains the service configuration parameters. We provide a prefilled template (`.example.env`). You will need to provide or create an [OpenAI API key](https://platform.openai.com/account/api-keys). diff --git a/docs/index.md b/docs/index.md index 170f34b5..7488ccad 100644 --- a/docs/index.md +++ b/docs/index.md @@ -7,7 +7,7 @@ Mechs address a critical need in the agent ecosystem: the ability to outsource c ## How it works -A Mech service consists of a library of tools. These can range from something as simple as an API call to highly complex business logic. Some examples of tools can be found on [the `tools` folder](https://github.com/valory-xyz/mech/tree/main/tools) of the first operational Mech service. +A Mech service consists of a library of tools. These can range from something as simple as an API call to highly complex business logic. Some examples of tools can be found on [the `valory/customs` folder](https://github.com/valory-xyz/mech/tree/main/packages/valory/customs/tools) of the first operational Mech service. For instance, if an agent service needs to perform a task requiring access to an API, instead of each operator having to manage their own keys, the service can make use of a Mech tool. Agents then only need to make a request to a Mech, which gets returned in the form of a deliver event. The agent can then use the deliver event to accomplish what it set out to do. Both the request and deliver events are executed on-chain and the associated data is stored on IPFS making them easily retrievable by agents or anyone else. From bcf1ad8338593170a18031a64e95f335896b2542 Mon Sep 17 00:00:00 2001 From: Ardian Date: Fri, 23 Feb 2024 16:06:39 +0100 Subject: [PATCH 6/6] chore: link fix --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 7488ccad..f0dfd5c3 100644 --- a/docs/index.md +++ b/docs/index.md @@ -7,7 +7,7 @@ Mechs address a critical need in the agent ecosystem: the ability to outsource c ## How it works -A Mech service consists of a library of tools. These can range from something as simple as an API call to highly complex business logic. Some examples of tools can be found on [the `valory/customs` folder](https://github.com/valory-xyz/mech/tree/main/packages/valory/customs/tools) of the first operational Mech service. +A Mech service consists of a library of tools. These can range from something as simple as an API call to highly complex business logic. Some examples of tools can be found on [the `valory/customs` folder](https://github.com/valory-xyz/mech/tree/main/packages/valory/customs) of the first operational Mech service. For instance, if an agent service needs to perform a task requiring access to an API, instead of each operator having to manage their own keys, the service can make use of a Mech tool. Agents then only need to make a request to a Mech, which gets returned in the form of a deliver event. The agent can then use the deliver event to accomplish what it set out to do. Both the request and deliver events are executed on-chain and the associated data is stored on IPFS making them easily retrievable by agents or anyone else.