Find help to trigger your Obyte powered Autonomous Agents when you need it

Hey_Monkey
Autonomous Agents powered by Obyte
4 min readSep 25, 2019

Autonomous Agents (AA) powered by Obyte are pieces of code that run when triggered by an incoming transaction (payment) on the Obyte network.

In most of the cases an AA reacts to a solicitation from a user. The user needs something from the AA so he sends a minimum payment (see my ‘bounce fee’ tutorial) therefore the AA code executes. However, sometime you may want to delay the response of your Agent or to reproduce it every given time.

Use cases

The use cases could be:

  • Pay interest;
  • Execute the draw of a lottery;
  • Remind a user that is time to act;
  • Any other cases that you can come across;

One possibility is to rely on the popularity of your Agent. If it receives a lot of triggers, you can compare the trigger timestamp to different state variables of your AA during its initialization (see my ‘AA structure’ tutorial) and try to mix your delayed operation with the operation requested by the user that just triggered the AA. In general it is not easy to do.

THAANKS

The other possibility is to use a ‘THAANKS like’ secondary agent. THAANKS is an AA that you can call from your main AA to request help for later. See its code here.

By providing some funds to THAANKS, he will take care of finding some real users or bots that are ready to trigger you at a requested time in the future in exchange of a reward.

How to use it

First let’s create a variable containing its address:

$THAANKS = "UHNH72MK4SENTB6OIC3GETMEPATCAP4P";

This address is the valid one for on September 18th, 2019 on the Obyte test net. You can also use the last version available or the most popular by employing LOPAVAA which is an Agent that keep track of AA versions.

$LOPAVAA = "ZZVAKHT4PHCHGM5HAKVTJIQQ5GJJGGSQ";
$THAANKS = var[$LOPAVAA][“THAANKS_last_version”];

To request some help, you have to trigger the secondary AA with a payment and attached data. The minimum data is ‘ask_help=true’ to specify that you need help and a ‘requested_time=<timestamp>’ to define when you want to receive the future trigger:

messages: [
{
app: “data”, payload: {
ask_help: “{ “true” }”,
requested_time: “{ timestamp + 60*60*24 }”
}
},
{
app: “payment”,payload: { asset: “{ "base" }”,outputs: [
{ address: “{ $THAANKS }”,amount: “{ 100000 }” },
] }
}
]

The ‘payment amount’ minus (-) the ‘functional fees’ will be used as reward to motivate the helper. Here we have used bytes as reward, but you could use other assets too. In this case you must as well add some functional bytes (1000) that THAANKS will need to send a message to the randomly picked helper:

messages: [
{
app: “data”, payload: {
ask_help: “{ “true” }”,
requested_time: “{ timestamp + 60*60*24 }”
}
},
{
app: “payment”,payload: { asset: “{ "base" }”,outputs: [
{ address: “{ $THAANKS }”,amount: “{ 1000 }” },
] }
},
{
app: “payment”,payload: { asset: “{ <asset id> }”,outputs: [
{ address: “{ $THAANKS }”,amount: “{ 9999 }” },
] }
}
]

If no more data is given, THAANKS will pick randomly one user from its ‘good guys’ pool and will send him a symbolic payment with a message explaining that a reward is available if he is the first to trigger THAANKS after the requested time. Good guy pool is composed of user that subscribe them self to THAANKS.

Only one user will receive a message, but other good guys can monitor the THAANKS public state variables and try to overtake the picked user.

Bots could also be coded to automatically detect new available rewards and compete to be first to trigger the AA.

When the helper trigger THAANKS, THAANKS is sending the reward to the user and trigger the AA that requested help in the first place with a small payment and the original token if existing (token = primary AA value that help it to deal with several processes in parallel).

Additional options

You can decide to force the user address that will receive the SOS message by setting ‘helper=<address>’, in this case only this address will be allowed to trigger THAANKS:

messages: [
{
app: “data”, payload: {
ask_help: “{ “true” }”,
helper: "{ "MYESSCFGDERS3YIEGNZDOG2BI5HKQHLU" }",
requested_time: “{ timestamp + 60*60*24 }”,
acceptable_delay: "{ 60*15 }"
}
},

And define and ‘acceptable_delay=<delay in seconds>’. After which the reward will be reduced and the rest will be sent back to the primary AA.

Last option is ‘private=true’, that allows the reward to be reserved for the selected helper only (defined with ‘helper’ or picked from the ‘good guys’ pool).

Subscribe to the ‘THAANKS good guys pool’

Open your wallet and prepare a payment to UHNH72MK4SENTB6OIC3GETMEPATCAP4P to receive introductions:

Instructions to subscribe and subscribe as a good guy

Just add a field ‘subscribe’ = true and directly see the result preview showing that your address will be subscribed:

Wallet preview of the transaction result

Send the payment and after confirmation you can check in the Obyte explorer, in the state variables of the AA that you are present.

state variable of THAANKS as seen in the test-net DAG explorer

You are now ready to compete with other good guys to be the one to receive the available rewards ^^.

--

--