How to build and deploy an Autonomous Economic Agent on the Fetch.ai Agentland network

Jul 23, 2020

Introduction

At Fetch.ai we build tools and infrastructure to enable a decentralized digital economy. A key component of these economies are so-called Autonomous Economic Agents (AEAs). These are intelligent software agents acting on an owner’s behalf and whose goal it is to generate economic value for their owner.

Everyone can build and run AEAs. Today we make deploying AEAs even easier by introducing a new test network for agents, called Agentland.

Agentland is a dedicated test network that represents a key step in enabling agents to interact with the entire blockchain landscape. Our vision is that Fetch.ai multi-agent systems will be able to interact with applications across all blockchains and ledgers.

Towards full interoperability

The first step in this journey is achieved by integrating our agent technology with the Cosmos ecosystem, which will enable cross-chain transfers to bridge Ethereum with Cosmos-hub and many other application-specific chains.

The Agentland network also uses the Cosmwasm VM which provides fast, language agnostic and interoperable smart contracts for agent applications.

For the first time, all components in the agent ecosystem are used by our demo agents:

FET utility tokens will be the means by which services are procured, and all agents will require tokens to search, negotiate and transact with other agents on the Fetch.ai network. The Agentland network includes a token faucet for developers to build and test their agents as demonstrated in the following example.

The AEA framework allows developers to build agents for deployment in a decentralized economy. AEAs can talk to each other via the ACN, find each other via the SOEF and use multiple blockchains, and in particular Agentland.

The following demo uses all of these components in a simple example, which involves a vendor (a weather station) selling data (in this case weather data) to a client. The flow of the demo is that the weather station registers its services on the SOEF, the client searches for the service it requires and after being connected to the weather station, the two agents communicate with each other via the ACN. After agreeing to trade, the transaction is settled on the Agentland ledger and the data transferred from the vendor to the purchaser.

Demo

You can run a simple demo yourself by following the next steps (you need Python 3.6+ installed).

Installing the framework

First, we get the AEA framework from PyPI:

pip install aea[all]

Or, if you use zsh rather than bash:

pip install “aea[all]”

Once the framework is installed, we can check that we have the latest version `0.5.2` installed by running:

aea — version

Creating the AEAs and their private keys

The scope of the specific demo is to demonstrate how to create a simple AEA with the usage of the AEA framework. The weather_station AEA will read readings from a weather station (here mocked), based on the requested dates and will deliver the data to a weather_client AEA upon payment. This demo does not utilize a smart contract. As a result, we interact with the Agentland ledger only to complete a transaction. For more details read here.

First, fetch the AEA that will provide weather measurements and install its dependencies:

aea fetch fetchai/weather_station:0.8.0
cd weather_station
aea install

Second, create the private key for the weather station AEA for Fetch.ai Agentland:

aea generate-key cosmos
aea add-key cosmos cosmos_private_key.txt
aea add-key cosmos cosmos_private_key.txt — connection

Third, update the configurations of the AEA’s p2p connection (in weather_station/vendor/fetchai/connections/p2p_libp2p/connection.yaml) as follows

config:
entry_peers: [/dns4/agents-p2p-dht.sandbox.fetch-ai.com/tcp/9000/p2p/16Uiu2HAkw1ypeQYQbRFV5hKUxGRHocwU5ohmVmCnyJNg36tnPFdx]
local_uri: 127.0.0.1:9000
log_file: libp2p_node.log

Our agents can talk over the public internet. There are a number of agents (listed under entry peers) continuously running and maintaining a distributed hash table. This maps agents’ addresses to their IP addresses, so agents can talk to each other knowing only their address.

In another terminal, first fetch the AEA that will purchase weather data from the weather station:

aea fetch fetchai/weather_client:0.8.0
cd weather_client
aea install

Second, create the private key for the weather client AEA for Fetch.ai Agentland:

aea generate-key cosmos
aea add-key cosmos cosmos_private_key.txt
aea add-key cosmos cosmos_private_key.txt — connection

To transact, the weather client needs some test tokens. You can create some wealth for your weather client on the Fetch.ai Agentland network like so:

aea generate-wealth cosmos

This will return a confirmation that you have received test tokens (where the tx_hash will typically be different from the example below):

info: Wealth generated, tx_hash: 74CF89890…

You can view the transaction by searching for the tx_hash on the Agentland block explorer.

Then, update the configurations of the AEA’s p2p connection (in weather_station/vendor/fetchai/connections/p2p_libp2p/connection.yaml) as follows:

config:
entry_peers: [/dns4/agents-p2p-dht.sandbox.fetch-ai.com/tcp/9000/p2p/16Uiu2HAkw1ypeQYQbRFV5hKUxGRHocwU5ohmVmCnyJNg36tnPFdx]
local_uri: 127.0.0.1:9001
log_file: libp2p_node.log

Running the AEAs

Now, run both AEAs with:

aea run

You should see the agents do the following:

  • Find each other via the SOEF
  • Negotiate the terms of trade
  • Make a transaction using Agentland

You can find the transaction by taking the transaction hash and viewing it on the block explorer.

Implications and next steps

Hopefully if you have got this far, you will now be able to install and run your own agent, and have it connect to the Fetch.ai network. We are building a constellation of agents that can connect to transportation, financial services and mobility assets, and now you can also participate in this opportunity.

The planned version 2.0 of the Fetch.ai main net will be interoperable with Cosmos Hub and other chains such as Ethereum via Cosmos’ IBC bridge, with a roadmap to enable full cross-chain compatibility, meaning Fetch.ai tech, and multi-agent systems will be cross compatible with the digital economy of today, as well as the smart economy of the future.

Join the community

If you want to find out more about developing with Fetch.ai, join hundreds of people in our growing developer community on Slack.