Autonomous Agents (AA) are powered by Obyte and written in Oscript.

Before we start to look at the AA structure here are some useful links:

The script language used to define AA must be stored in the Obyte DAG and therefore the script should be in a specific format that can fit in the ledger and at the same time be interpreted by the full nodes of the network. This format is looking very similar to JSON and is called Oscript.

Here is an example of a simple script stored in the DAG: Simple bouncer

‘simple bouncer’ as written in the DAG

The purpose of this tutorial is to expose the possible structures of an AA script.

Let’s first have a look at the ledger functionalities (app) that an AA can execute:

Ledger apps

You can find detailed information on each app in the Obyte for developer documentation : https://developer.obyte.org/, but the structure used to call any of them is similar:

call of DAG function

For example for the ‘data posting’ app, the object needed is a payload containing the data to publish:

For the ‘AA state’ app, the object is called ‘state’ and contains all the AA variables that you want to write in the DAG:

Several apps can be included in a single transaction (tx), they are included in the ‘messages’ part of the tx:

Several apps in one tx

The inclusion of each app can depend on an individual test:

Conditional app inclusion

Most probably your AA will not execute the same list of apps every time it is triggered. You can define several use cases that can be selected by conditions:

Notice the brackets ‘[ ]’ that indicate an array, you can add as many {use cases} as needed. If no condition is set (no ‘if: ‘{ test }’’) it is assumed to be true. In general you don’t set condition on the last case so that it becomes the default case if none of the previous cases is true.

Every case can include an initialization part:

This set of the use cases is in reality the real messages of the AA:

This main message preceded by AA bounce fees definition and a global initialization part is the final AA definition:

The global structure is the following:

Full AA structure

The AA definition can be published with the GUI-wallet using [SEND TAB]/[DEFINITON OF AA]. Once published in the DAG it will be encapsulated in [“autonomous agent”, <AA definition>] before being written into the DAG for good.

AA definition posting from GUI-wallet

Oscript has its own online editor that contains different templates but here is an empty one that I like to start from: ‘empty template with structure’.

Enjoy AA coding ^^.