mech-client 0.10.0__py3-none-any.whl → 0.11.0__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.
mech_client/__init__.py CHANGED
@@ -1,3 +1,3 @@
1
1
  """Mech client."""
2
2
 
3
- __version__ = "0.10.0"
3
+ __version__ = "0.11.0"
mech_client/cli.py CHANGED
@@ -29,9 +29,11 @@ from tabulate import tabulate # type: ignore
29
29
  from mech_client import __version__
30
30
  from mech_client.interact import ConfirmationType
31
31
  from mech_client.interact import interact as interact_
32
+ from mech_client.marketplace_interact import IPFS_URL_TEMPLATE
32
33
  from mech_client.marketplace_interact import (
33
34
  marketplace_interact as marketplace_interact_,
34
35
  )
36
+ from mech_client.mech_marketplace_subgraph import query_mm_mechs_info
35
37
  from mech_client.mech_marketplace_tool_management import (
36
38
  extract_input_schema,
37
39
  extract_output_schema,
@@ -515,6 +517,54 @@ def nvm_subscribe(
515
517
  nvm_subscribe_main(private_key_path=key, chain_config=chain_config)
516
518
 
517
519
 
520
+ @click.command(name="fetch-mm-mechs-info")
521
+ @click.option(
522
+ "--chain-config",
523
+ type=str,
524
+ help="Id of the mech's chain configuration (stored configs/mechs.json)",
525
+ )
526
+ def query_mm_mechs_info_cli(
527
+ chain_config: str,
528
+ ) -> None:
529
+ """Fetches info of mm mechs"""
530
+ try:
531
+ mech_list = query_mm_mechs_info(chain_config=chain_config)
532
+ if mech_list is None:
533
+ print("No mechs found")
534
+ return None
535
+
536
+ headers = [
537
+ "Service Id",
538
+ "Mech Type",
539
+ "Mech Address",
540
+ "Total Deliveries",
541
+ "Metadata Link",
542
+ ]
543
+
544
+ data = [
545
+ (
546
+ items["service"]["id"],
547
+ items["mech_type"],
548
+ items["address"],
549
+ items["service"]["totalDeliveries"],
550
+ (
551
+ IPFS_URL_TEMPLATE.format(
552
+ items["service"]["metadata"]["metadata"][2:]
553
+ )
554
+ if items["service"].get("metadata") is not None
555
+ else None
556
+ ),
557
+ )
558
+ for items in mech_list
559
+ ]
560
+
561
+ click.echo(tabulate(data, headers=headers, tablefmt="grid"))
562
+ return None
563
+ except Exception as e: # pylint: disable=broad-except
564
+ click.echo(f"Error: {str(e)}")
565
+ return None
566
+
567
+
518
568
  cli.add_command(interact)
519
569
  cli.add_command(prompt_to_ipfs)
520
570
  cli.add_command(push_to_ipfs)
@@ -528,6 +578,7 @@ cli.add_command(tool_description_for_marketplace_mech)
528
578
  cli.add_command(deposit_native)
529
579
  cli.add_command(deposit_token)
530
580
  cli.add_command(nvm_subscribe)
581
+ cli.add_command(query_mm_mechs_info_cli)
531
582
 
532
583
 
533
584
  if __name__ == "__main__":
@@ -16,7 +16,7 @@
16
16
  "gas_limit": 500000,
17
17
  "price": 10000000000000000,
18
18
  "transaction_url": "https://gnosisscan.io/tx/{transaction_digest}",
19
- "subgraph_url": ""
19
+ "subgraph_url": "https://api.studio.thegraph.com/query/89372/olas-gnosis-mech-marketplace/v0.0.2"
20
20
  },
21
21
  "arbitrum": {
22
22
  "agent_registry_contract": "0xa4799B083E0068732456EF45ff9fe5c683658327",
@@ -73,7 +73,7 @@
73
73
  "gas_limit": 500000,
74
74
  "price": 3000000000000,
75
75
  "transaction_url": "https://basescan.org/tx/{transaction_digest}",
76
- "subgraph_url": ""
76
+ "subgraph_url": "https://api.studio.thegraph.com/query/89372/olas-base-mech-marketplace/v0.0.2"
77
77
  },
78
78
  "celo": {
79
79
  "agent_registry_contract": "0xE49CB081e8d96920C38aA7AB90cb0294ab4Bc8EA",
@@ -0,0 +1,94 @@
1
+ # -*- coding: utf-8 -*-
2
+ # ------------------------------------------------------------------------------
3
+ #
4
+ # Copyright 2025 Valory AG
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ # ------------------------------------------------------------------------------
19
+
20
+ """Subgraph client for mech."""
21
+
22
+ from typing import List, Optional
23
+
24
+ from gql import Client, gql
25
+ from gql.transport.aiohttp import AIOHTTPTransport
26
+
27
+ from mech_client.interact import get_mech_config
28
+
29
+
30
+ RESULTS_LIMIT = 20
31
+ CHAIN_TO_MECH_FACTORY_TO_MECH_TYPE = {
32
+ "gnosis": {
33
+ "0x8b299c20F87e3fcBfF0e1B86dC0acC06AB6993EF": "Fixed Price Native",
34
+ "0x31ffDC795FDF36696B8eDF7583A3D115995a45FA": "Fixed Price Token",
35
+ "0x65fd74C29463afe08c879a3020323DD7DF02DA57": "NvmSubscription Native",
36
+ },
37
+ "base": {
38
+ "0x2E008211f34b25A7d7c102403c6C2C3B665a1abe": "Fixed Price Native",
39
+ "0x97371B1C0cDA1D04dFc43DFb50a04645b7Bc9BEe": "Fixed Price Token",
40
+ "0x847bBE8b474e0820215f818858e23F5f5591855A": "NvmSubscription Native",
41
+ "0x7beD01f8482fF686F025628e7780ca6C1f0559fc": "NvmSubscription Token USDC",
42
+ },
43
+ }
44
+
45
+
46
+ MM_MECHS_INFO_QUERY = """
47
+ query MechsOrderedByServiceDeliveries {
48
+ meches(orderBy: service__totalDeliveries, orderDirection: desc) {
49
+ address
50
+ mechFactory
51
+ service {
52
+ id
53
+ totalDeliveries
54
+ metadata {
55
+ metadata
56
+ }
57
+ }
58
+ }
59
+ }
60
+ """
61
+
62
+ DEFAULT_TIMEOUT = 600.0
63
+
64
+
65
+ def query_mm_mechs_info(chain_config: str) -> Optional[List]:
66
+ """
67
+ Query MM mechs and related info from subgraph.
68
+
69
+ :param chain_config: Id of the mech's chain configuration (stored configs/mechs.json)
70
+ :type chain_config: str
71
+ :return: The return list of data if found, None otherwise.
72
+ :rtype: Optional[List]
73
+ """
74
+ mech_config = get_mech_config(chain_config)
75
+ if not mech_config.subgraph_url:
76
+ raise Exception(f"Subgraph URL not set for chain config: {chain_config}")
77
+
78
+ client = Client(
79
+ transport=AIOHTTPTransport(url=mech_config.subgraph_url),
80
+ execute_timeout=DEFAULT_TIMEOUT,
81
+ )
82
+ response = client.execute(document=gql(request_string=MM_MECHS_INFO_QUERY))
83
+
84
+ mech_factory_to_mech_type = {
85
+ k.lower(): v
86
+ for k, v in CHAIN_TO_MECH_FACTORY_TO_MECH_TYPE[chain_config].items()
87
+ }
88
+ filtered_mechs_data = []
89
+ for item in response["meches"]: # pylint: disable=unsubscriptable-object
90
+ if item.get("service") and int(item["service"]["totalDeliveries"]) > 0:
91
+ item["mech_type"] = mech_factory_to_mech_type[item["mechFactory"].lower()]
92
+ filtered_mechs_data.append(item)
93
+
94
+ return filtered_mechs_data[:RESULTS_LIMIT]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mech-client
3
- Version: 0.10.0
3
+ Version: 0.11.0
4
4
  Summary: Basic client to interact with a mech
5
5
  License: Apache-2.0
6
6
  Author: David Minarsch
@@ -32,6 +32,12 @@ A basic client to interact with an AI Mech. [AI Mechs](https://github.com/valory
32
32
 
33
33
  - Python >=3.10
34
34
 
35
+ ## Developing, running and deploying Mechs and Mech tools
36
+
37
+ The easiest way to create, run, deploy and test your own Mech and Mech tools is to follow the Mech and Mech tool docs [here](https://open-autonomy.docs.autonolas.tech/mech-tools-dev/). The [Mech tools dev repo](https://github.com/valory-xyz/mech-tools-dev) used in those docs greatly simplifies the development flow and dev experience.
38
+
39
+ Only continue reading this README if you know what you are doing and you are specifically interested in this repo.
40
+
35
41
  ## Installation
36
42
 
37
43
  Find the latest available release on [PyPi](https://pypi.org/project/mech-client/#description).
@@ -120,9 +126,9 @@ The EOA you use must have enough funds to pay for the Mech requests, or alternat
120
126
 
121
127
  In order to fetch on-chain data for Gnosis and Base, mech client requires an API key from a blockchain data provider. You can find them here for [GnosisScan](https://gnosisscan.io/) and [BaseScan](https://basescan.org/). Follow these steps to generate your API key if you are planning to use mech client for gnosis and base:
122
128
 
123
- 1. Sign up or log in
129
+ 1. Sign up or log in
124
130
  2. Go to API Dashboard on the left menu
125
- 3. Add a new API key
131
+ 3. Add a new API key
126
132
  4. Once generated copy your API key
127
133
 
128
134
  Once you have your API key, you'll need to configure it in your environment. Use the following command to set it for your environment.
@@ -135,7 +141,7 @@ export MECHX_API_KEY=<your api key>
135
141
 
136
142
  #### Select the mech you are going to send requests to
137
143
 
138
- Mechs can receive requests via the [Mech Marketplace](https://github.com/valory-xyz/ai-registry-mech/) or directly. We call the last ones _Legacy Mechs_.
144
+ Mechs can receive requests via the [Mech Marketplace](https://github.com/valory-xyz/ai-registry-mech/) or directly. We call the last ones _Legacy Mechs_.
139
145
  Mechs are deployed on several networks. Find the list of supported networks and corresponding mech addresses [here](https://github.com/valory-xyz/mech?tab=readme-ov-file#examples-of-deployed-mechs). Additionally, you can find more available Mechs [here](https://mech.olas.network/) (click on the tab "Legacy Mech" in order to see Legacy Mech (available only on Gnosis) and "Mech Marketplace" for the ones which receive requests via the Mech Marketplace).
140
146
 
141
147
  #### Legacy Mechs
@@ -201,22 +207,22 @@ Data from agent: {'requestId': 1004074058566339663950817114309409628095686850319
201
207
 
202
208
  #### With the Mech Marketplace
203
209
 
204
- With the Mech Marketplace, in order to pay for the Mech fees, you can make a deposit before sending requests. The deposit depends on the
205
- payment model of the Mech. For a fixed price Mech receiving payments in native token, use the following:
210
+ With the Mech Marketplace, in order to pay for the Mech fees, you can make a deposit before sending requests. The deposit depends on the
211
+ payment model of the Mech. For a fixed price Mech receiving payments in native token, use the following:
206
212
 
207
213
  ```bash
208
214
  mechx deposit-native --chain-config <chain_config> <amount>
209
215
  ```
210
216
 
211
- For a fixed price Mech receiving payments in OLAS, use the following (the amount is in ether):
217
+ For a fixed price Mech receiving payments in OLAS, use the following (the amount is in ether):
212
218
 
213
219
  ```bash
214
220
  mechx deposit-token --chain-config <chain_config> <amount>
215
221
  ```
216
222
 
217
- For a Mech using Nevermined subscriptions, to make requests, it is necessary to buy a subscription. To do that you can use the following command:
223
+ For a Mech using Nevermined subscriptions, to make requests, it is necessary to buy a subscription. To do that you can use the following command:
218
224
 
219
- ```bash
225
+ ```bash
220
226
  mechx purchase-nvm-subscription --chain-config <chain_config>
221
227
  ```
222
228
 
@@ -244,11 +250,11 @@ export MECHX_MECH_OFFCHAIN_URL="http://localhost:8000/"
244
250
  If you want to use a Valory mech for offchain requests, below is the list of mechs and their address and offchain urls.
245
251
 
246
252
  | Service ID | Priority Mech Address | Offchain URL |
247
- | :---: | :---: | :---: |
253
+ | :---: | :---: | :---: |
248
254
  | 2182 | 0xB3C6319962484602b00d5587e965946890b82101 | https://d19715222af5b940.agent.propel.autonolas.tech/ |
249
255
 
250
256
 
251
- The Mech Client can also be used to send batch requests. There are couple of different ways to achieve this:
257
+ The Mech Client can also be used to send batch requests. There are couple of different ways to achieve this:
252
258
 
253
259
  ```bash
254
260
  mechx interact --prompts={<prompt-1>,<prompt-2>} --priority-mech <priority mech address> --tools={<tool-1>,<tool-2>} --chain-config <chain_config>
@@ -260,6 +266,27 @@ or <br>
260
266
  mechx interact --prompts <prompt-1> --prompts <prompt-2> --priority-mech <priority mech address> --tools <tool-1> --tools <tool-2> --chain-config <chain_config>
261
267
  ```
262
268
 
269
+ ### List marketplace mechs
270
+ To list the top marketplace mechs based on deliveries, use the `fetch-mm-mechs-info` command. You can specify the chain you want to query. Please note that only the first 20 mechs sorted by number of deliveries will be shown.
271
+ Currently supported chains are gnosis and base
272
+ ```bash
273
+ mechx fetch-mm-mechs-info --chain-config gnosis
274
+ ```
275
+ ```bash
276
+ +--------------+--------------------+--------------------------------------------+--------------------+---------------------------------------------------------------------------------------------------------------+
277
+ | Service Id | Mech Type | Mech Address | Total Deliveries | Metadata Link |
278
+ +==============+====================+============================================+====================+===============================================================================================================+
279
+ | 2182 | Fixed Price Native | 0xc05e7412439bd7e91730a6880e18d5d5873f632c | 41246 | https://gateway.autonolas.tech/ipfs/f01701220157d3b106831e2713b86af1b52af76a3ef28c52ae0853e9638180902ebee41d4 |
280
+ +--------------+--------------------+--------------------------------------------+--------------------+---------------------------------------------------------------------------------------------------------------+
281
+ | 2235 | Fixed Price Native | 0xb3c6319962484602b00d5587e965946890b82101 | 10127 | https://gateway.autonolas.tech/ipfs/f01701220157d3b106831e2713b86af1b52af76a3ef28c52ae0853e9638180902ebee41d4 |
282
+ +--------------+--------------------+--------------------------------------------+--------------------+---------------------------------------------------------------------------------------------------------------+
283
+ | 2198 | Fixed Price Native | 0x601024e27f1c67b28209e24272ced8a31fc8151f | 5714 | https://gateway.autonolas.tech/ipfs/f01701220157d3b106831e2713b86af1b52af76a3ef28c52ae0853e9638180902ebee41d4 |
284
+ +--------------+--------------------+--------------------------------------------+--------------------+---------------------------------------------------------------------------------------------------------------+
285
+ | 1722 | Fixed Price Token | 0x13f36b1a516290b7563b1de574a02ebeb48926a1 | 399 | https://gateway.autonolas.tech/ipfs/f01701220157d3b106831e2713b86af1b52af76a3ef28c52ae0853e9638180902ebee41d4 |
286
+ +--------------+--------------------+--------------------------------------------+--------------------+---------------------------------------------------------------------------------------------------------------+
287
+ | 2135 | Fixed Price Native | 0xbead38e4c4777341bb3fd44e8cd4d1ba1a7ad9d7 | 353 | https://gateway.autonolas.tech/ipfs/f01701220157d3b106831e2713b86af1b52af76a3ef28c52ae0853e9638180902ebee41d4 |
288
+ +--------------+--------------------+--------------------------------------------+--------------------+---------------------------------------------------------------------------------------------------------------+
289
+ ```
263
290
 
264
291
  ### List tools available for legacy mechs and marketplace mechs
265
292
 
@@ -287,7 +314,7 @@ You will see an output like this:
287
314
  ```bash
288
315
  mechx tools-for-agents --agent-id "agent_id"
289
316
  ```
290
- Eaxmple usage
317
+ Eaxmple usage
291
318
  ```bash
292
319
  mechx tools-for-agents --agent-id 6
293
320
  ```
@@ -545,7 +572,7 @@ This script will:
545
572
 
546
573
  #### For Mechs receiving requests via the Mech Marketplace
547
574
 
548
- In this case, the script is the same, except for the function result. When this function has no argument agent_id,
575
+ In this case, the script is the same, except for the function result. When this function has no argument agent_id,
549
576
  the request is sent to the Mech Marketplace. The target Mech to which the request is relayed should be in the chain_config file (key `priority_mech_address`).
550
577
 
551
578
  ## Developer installation
@@ -1,4 +1,4 @@
1
- mech_client/__init__.py,sha256=zubatTm13iBIEOwOE74QFlqg6tpFL5v53x4lS6XYY0U,43
1
+ mech_client/__init__.py,sha256=3tdrspbKpX2LqQeSSU-GYhFWTPKj5iNGsLrd8NCJoXU,43
2
2
  mech_client/abis/AgentMech.json,sha256=IEbs_xBGunBu5h-uT5DvIty8Zw412QoPI46S_DUMYNw,18082
3
3
  mech_client/abis/AgentRegistry.json,sha256=2qmXeFINZWz9pyOma6Bq67kMDSUI1lD7WvgHLwuETD8,24723
4
4
  mech_client/abis/AgreementStoreManager.base.json,sha256=_ljdIZcfFGmFzBHUTfhA4X0382ZHHpkdr_CziTwUETo,34360
@@ -30,8 +30,8 @@ mech_client/abis/SubscriptionToken.base.json,sha256=5StPEyfRvDMTqtQPO-KakXXZqobX
30
30
  mech_client/abis/TransferNFTCondition.base.json,sha256=71O_3itHBz9qPtoTLev8_a7KxlcQfIZSfxK2562lkqw,42540
31
31
  mech_client/abis/TransferNFTCondition.gnosis.json,sha256=-huhxV54eoNY8mR9WtQdmSgQDgaKiUi0PULJ4HEshWw,42540
32
32
  mech_client/acn.py,sha256=Rj_jLPvJ5loDQfGbu3a_O24cJC4SwIErLceSz_zVYS8,5356
33
- mech_client/cli.py,sha256=CgpembCl3JTubCgUYw7-one6cuge8YlUTHfoIkhbZu4,17957
34
- mech_client/configs/mechs.json,sha256=Zv8JrY6yvNsSxTP7RchvR1yz2k3yjYUZkuSILnPbWzg,5445
33
+ mech_client/cli.py,sha256=MVytCoZQ5wlkxbOBUcUGfR3tdTVCIFLxld0Uf_qaLZU,19475
34
+ mech_client/configs/mechs.json,sha256=P27UibjGSlmRt199AEWi2xBHrjCnSk6p7KSbZ9nRSiY,5601
35
35
  mech_client/fetch_ipfs_hash.py,sha256=tg_hYVf4deXl89x3SOBrGFUthaSeN_Vg_OHDtfjdbp4,2752
36
36
  mech_client/helpers/__init__.py,sha256=nmQig1EqBQ9EMOpgdykP3a6_2NWcoVH3-lnyHP5n0ws,1196
37
37
  mech_client/helpers/acn/README.md,sha256=WMXR2Lk0IpWjr3vpZ8cxcTHk4gwsx4wC06UPkwj9dbQ,1641
@@ -63,6 +63,7 @@ mech_client/helpers/p2p_libp2p_client/connection.py,sha256=b5jfcUeSoNrUw8DOSTCbK
63
63
  mech_client/helpers/p2p_libp2p_client/connection.yaml,sha256=nMiHnU_dv9EFjVNqZ-0SAnoATfadJSad-JsbDvk97Mk,1790
64
64
  mech_client/interact.py,sha256=52UW5NysSTIC--APLpJde8VvrruWeYFCFzO02uRQpwc,21288
65
65
  mech_client/marketplace_interact.py,sha256=24louKzqpgDVYmuOIwZQzIVnZwPLXhkF2LPSQVrEuvE,35554
66
+ mech_client/mech_marketplace_subgraph.py,sha256=X_ypxfokN-YBtsUCVOHUecsinkbRDZ5fR5WCkid1ntM,3153
66
67
  mech_client/mech_marketplace_tool_management.py,sha256=G1O0ajbeltRM5FpqPfmn2C4QRrwqf5HfWKUH2VKn6UA,7365
67
68
  mech_client/mech_tool_management.py,sha256=NQFmVzzGZsIkeHokDPWXGHwa8u-pyQIMPR1Q5H81bKw,7806
68
69
  mech_client/prompt_to_ipfs.py,sha256=XqSIBko15MEkpWOQNT97fRI6jNxMF5EDBDEPOJFdhyk,2533
@@ -92,8 +93,8 @@ scripts/nvm_subscription/manager.py,sha256=y0Qh0aVAmOPB4Ytt93alIarSvhrQpC-lRYNAY
92
93
  scripts/nvm_subscription/resources/networks.json,sha256=xH0P3YkgkMTkQdahVKO0kI9m6ybJ67iwHApstUlfRmw,2359
93
94
  scripts/utils.py,sha256=lXjY3s1HvNHT2fXm2fBpZtVvlQaqW288Y2S-s3rpSDM,3248
94
95
  scripts/whitelist.py,sha256=-TF4fcojBmF6a7fXleBk96DvJ-xWkNGoN0s_8r8J20Q,289
95
- mech_client-0.10.0.dist-info/LICENSE,sha256=mdBDB-mWKV5Cz4ejBzBiKqan6Z8zVLAh9xwM64O2FW4,11339
96
- mech_client-0.10.0.dist-info/METADATA,sha256=wXMRgH_HN3Kg0yt4k9rsfySvc6XL-TmQkyqKQ-3rtto,25936
97
- mech_client-0.10.0.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
98
- mech_client-0.10.0.dist-info/entry_points.txt,sha256=SbRMRsayzD8XfNXhgwPuXEqQsdZ5Bw9XDPnUuaDExyY,45
99
- mech_client-0.10.0.dist-info/RECORD,,
96
+ mech_client-0.11.0.dist-info/LICENSE,sha256=mdBDB-mWKV5Cz4ejBzBiKqan6Z8zVLAh9xwM64O2FW4,11339
97
+ mech_client-0.11.0.dist-info/METADATA,sha256=SkSPlS_1QeANJhAZeZuO2hJzrkQcaJ6Qq5w1hJYCLsU,29615
98
+ mech_client-0.11.0.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
99
+ mech_client-0.11.0.dist-info/entry_points.txt,sha256=SbRMRsayzD8XfNXhgwPuXEqQsdZ5Bw9XDPnUuaDExyY,45
100
+ mech_client-0.11.0.dist-info/RECORD,,