ML skills
The AEA ML (machine learning) skills demonstrate an interaction between two AEAs, one purchasing data from the other and training a machine learning model with it.
There are two types of AEAs:
- The
ml_data_provider
which sells training data. - The
ml_model_trainer
which purchases data and trains a model
Discussion
This demo aims to demonstrate the integration of a simple AEA with machine learning using the AEA framework. The ml_data_provider
AEA provides some sample data and delivers to the client upon payment.
Once the client receives the data, it trains a model. This process can be found in tasks.py
.
This demo does not utilize a smart contract. As a result, the ledger interaction is only for completing a transaction.
Since the AEA framework enables using third-party libraries from PyPI, we can directly reference any external dependencies.
The aea install
command installs all dependencies an AEA needs that is listed in one of its skills' YAML file.
Communication
This diagram shows the communication between the two AEAs.
Option 1: AEA Manager approach
Follow this approach when using the AEA Manager Desktop app. Otherwise, skip and follow the CLI approach below.
Preparation instructions
Install the AEA Manager.
Demo instructions
The following steps assume you have launched the AEA Manager Desktop app.
-
Add a new AEA called
ml_data_provider
with public idfetchai/ml_data_provider:0.28.0
. -
Add another new AEA called
ml_model_trainer
with public idfetchai/ml_model_trainer:0.29.0
. -
Copy the address from the
ml_model_trainer
into your clip board. Then go to the Dorado block explorer and request some test tokens viaGet Funds
. -
Run the
ml_data_provider
AEA. Navigate to its logs and copy the multiaddress displayed. -
Navigate to the settings of the
ml_model_trainer
and undercomponents > connection >
fetchai/p2p_libp2p:0.22.0
update as follows (make sure to replace the placeholder with the multiaddress): -
Run the
ml_model_trainer
.
In the AEA's logs, you should see the agents trading successfully, and the training agent training its machine learning model using the data purchased.
The trainer keeps purchasing data and training its model until stopped.
Option 2: CLI approach
Follow this approach when using the aea
CLI.
Preparation instructions
Dependencies
Follow the Preliminaries and Installation sections from the AEA quick start.
Demo instructions
Create data provider AEA
First, fetch the data provider AEA:
Alternatively, create from scratch.
The following steps create the data provider from scratch:
aea create ml_data_provider
cd ml_data_provider
aea add connection fetchai/p2p_libp2p:0.26.0
aea add connection fetchai/soef:0.27.0
aea add connection fetchai/ledger:0.20.0
aea add skill fetchai/ml_data_provider:0.27.0
aea config set --type dict agent.dependencies \
'{
"aea-ledger-fetchai": {"version": "<2.0.0,>=1.0.0"}
}'
aea config set agent.default_connection fetchai/p2p_libp2p:0.26.0
aea config set --type dict agent.default_routing \
'{
"fetchai/ledger_api:1.1.0": "fetchai/ledger:0.20.0",
"fetchai/oef_search:1.1.0": "fetchai/soef:0.27.0"
}'
aea install
aea build
Create model trainer AEA
Then, fetch the model trainer AEA:
Alternatively, create from scratch.
The following steps create the model trainer from scratch:
aea create ml_model_trainer
cd ml_model_trainer
aea add connection fetchai/p2p_libp2p:0.26.0
aea add connection fetchai/soef:0.27.0
aea add connection fetchai/ledger:0.20.0
aea add skill fetchai/ml_train:0.29.0
aea config set --type dict agent.dependencies \
'{
"aea-ledger-fetchai": {"version": "<2.0.0,>=1.0.0"}
}'
aea config set agent.default_connection fetchai/p2p_libp2p:0.26.0
aea config set --type dict agent.default_routing \
'{
"fetchai/ledger_api:1.1.0": "fetchai/ledger:0.20.0",
"fetchai/oef_search:1.1.0": "fetchai/soef:0.27.0"
}'
aea install
aea build
Add keys for the data provider AEA
First, create the private key for the data provider AEA based on the network you want to transact. To generate and add a private-public key pair for Fetch.ai Dorado
use:
Next, create a private key used to secure the AEA's communications:
aea generate-key fetchai fetchai_connection_private_key.txt
aea add-key fetchai fetchai_connection_private_key.txt --connection
Finally, certify the key for use by the connections that request that:
Add keys and generate wealth for the model trainer AEA
The model trainer needs to have some wealth to purchase the data from the data provider.
First, create the private key for the model trainer AEA based on the network you want to transact. To generate and add a private-public key pair for Fetch.ai Dorado
use:
Then, create some wealth for your model trainer based on the network you want to transact with. On the Fetch.ai Dorado
network:
Next, create a private key used to secure the AEA's communications:
aea generate-key fetchai fetchai_connection_private_key.txt
aea add-key fetchai fetchai_connection_private_key.txt --connection
Finally, certify the key for use by the connections that request that:
Run both AEAs
Run both AEAs from their respective terminals.
First, run the data provider AEA:
Once you see a message of the form To join its network use multiaddr 'SOME_ADDRESS'
take note of the address. (Alternatively, use aea get-multiaddress fetchai -c -i fetchai/p2p_libp2p:0.26.0 -u public_uri
to retrieve the address.)
This is the entry peer address for the local agent communication network created by the ML data provider.
Then, in the ML model trainer, run this command (replace SOME_ADDRESS
with the correct value as described above):
aea config set --type dict vendor.fetchai.connections.p2p_libp2p.config \
'{
"delegate_uri": "127.0.0.1:11001",
"entry_peers": ["SOME_ADDRESS"],
"local_uri": "127.0.0.1:9001",
"log_file": "libp2p_node.log",
"public_uri": "127.0.0.1:9001"
}'
Then run the model trainer AEA:
You can see that the AEAs find each other, negotiate and eventually trade. After the trade, the model trainer AEA trains its ML model using the data it has purchased. This AEA keeps purchasing data and training its model until stopped.
Cleaning up
When you're finished, delete your AEAs: