If you want to create Autonomous Economic Agents (AEAs) that can act independently of constant user input and autonomously execute actions to achieve their objective, you can use the Fetch.ai AEA framework.

This example will take you through the simplest AEA in order to make you familiar with the framework.

Preliminaries

Create and enter into a new working directory.

mkdir my_aea_projects/
cd my_aea_projects/

We highly recommend using a virtual environment to ensure consistency across dependencies.

Check that you have pipenv.

which pipenv

If you don't have it, install it. Instructions are here.

Once installed, create a new environment and open it (here we use Python 3.7 but the AEA framework supports any Python >= 3.6).

touch Pipfile && pipenv --python 3.7 && pipenv shell

Installing docker

At some point, you will need Docker installed on your machine (e.g. to run an OEF Node).

Note

For the purpose of the quickstart only, you can skip installation of docker.

Download the scripts and packages directories

Download folders containing examples, scripts and packages:

svn export https://github.com/fetchai/agents-aea.git/trunk/examples
svn export https://github.com/fetchai/agents-aea.git/trunk/scripts
svn export https://github.com/fetchai/agents-aea.git/trunk/packages
You can install the svn command with (brew install subversion or sudo apt-get install subversion).

Note

We will soon make packages available on our agent registry. For now you still have to download them manually.

Installation

The following installs the entire AEA package which also includes a command-line interface (CLI).

pip install aea[all]

If you are using zsh rather than bash type

pip install 'aea[all]'

Known issues

If the installation steps fail, it might be a dependency issue.

The following hints can help:

  • Ubuntu/Debian systems only: install Python 3.7 headers.

    sudo apt-get install python3.7-dev
    

  • Windows users: install tools for Visual Studio.

Setup Author name

You can now setup your author name:

aea init

You should see a similar output:

Please enter the author handle you would like to use: fetchai
    _     _____     _    
   / \   | ____|   / \   
  / _ \  |  _|    / _ \  
 / ___ \ | |___  / ___ \ 
/_/   \_\|_____|/_/   \_\

v0.2.3

AEA configurations successfully initialized: {'author': 'fetchai'}

Note

Once our agent registry becomes available you will have a unique author name in the Fetch.ai ecosystem.

Echo skill demo

The echo skill is a simple demo that introduces you to the main business logic components of an AEA. The fastest way to create your first AEA is to fetch it!

If you want to follow a step by step guide we show you how to do it at the end of the file.

aea fetch fetchai/my_first_aea:0.1.0
cd my_first_aea

Usage of the stub connection

AEAs use envelopes containing messages for communication. We use a stub connection to send envelopes to and receive envelopes from the AEA.

The stub connection is already added to the AEA by default.

A stub connection provides an I/O reader and writer. It uses two files for communication: one for incoming envelopes and the other for outgoing envelopes.

The AEA waits for a new envelope posted to the file my_first_aea/input_file, and adds a response to the file my_first_aea/output_file.

The format of each envelope is the following:

TO,SENDER,PROTOCOL_ID,ENCODED_MESSAGE,

For example:

recipient_aea,sender_aea,fetchai/default:0.1.0,\x08\x01*\x07\n\x05hello,

Run the AEA

Run the AEA with the default stub connection.

aea run

or

aea run --connections fetchai/stub:0.1.0

You will see the echo skill running in the terminal window.

    _     _____     _    
   / \   | ____|   / \   
  / _ \  |  _|    / _ \  
 / ___ \ | |___  / ___ \ 
/_/   \_\|_____|/_/   \_\

v0.2.3

my_first_aea starting ...
info: EchoHandler.__init__: arguments: {'foo': 'bar', 'skill_context': ..., 'name': 'echo'}
info: EchoBehaviour.__init__: arguments: {'tick_interval': 1.0, 'skill_context': ..., 'name': 'echo'}
info: Echo Handler: setup method called.
info: Echo Behaviour: setup method called.
info: Echo Behaviour: act method called.
info: Echo Behaviour: act method called.
info: Echo Behaviour: act method called.
...

The framework first calls the setup method on the Handler, and Behaviour code in that order; after which it repeatedly calls the Behaviour method act. This is the main agent loop in action.

Let's look at the Handler in more depth.

Add a message to the input file

From a different terminal and same directory, we send the AEA a message wrapped in an envelope via the input file.

echo 'my_first_aea,sender_aea,fetchai/default:0.1.0,\x08\x01*\x07\n\x05hello,' >> input_file

You will see the Echo Handler dealing with the envelope and responding with the same message to the output_file, and also decoding the Base64 encrypted message in this case.

info: Echo Behaviour: act method called.
info: Echo Handler: message=Message(dialogue_reference=('', '') message_id=1 target=0 performative=bytes content=b'hello'), sender=sender_aea
info: Echo Behaviour: act method called.
info: Echo Behaviour: act method called.

Stop the AEA

Stop the AEA by pressing CTRL C

Delete the AEA

Delete the AEA from the parent directory (cd .. to go to the parent directory).

aea delete my_first_aea

For more detailed analysis of the core components of the framework, please check the following:

For more demos, use cases or step by step guides, please check the following:


Step by step install Create a new AEA
First, create a new AEA project and enter it.
aea create my_first_aea     
cd my_first_aea     

Add the echo skill
Second, add the echo skill to the project.
aea add skill fetchai/echo:0.1.0        
This copies the `echo` skill code containing the "behaviours", and "handlers" into the skill, ready to run. The identifier of the skill `fetchai/echo:0.1.0` consists of the name of the author of the skill, followed by the skill name and its version.