DappCon 2023: Olas 101: Build And Monetize Your Decentralized AI Agent In PythonAdamantios Zaras

DappCon 2023 · September 2023 · 51:00

Explores olas 101: Build And Monetize Your Decentralized AI Agent In PythonAdamantios Zaras.

Speakers

Topics

From DappCon 2023, hosted by Dappcon Berlin.

Transcript

hello everyone um so my name is Manos and we're we're going to talk about Olas and how you can build and monetize your decentralized AI agent in Python uh by participating in a hackathon that we're organizing uh so first we're going to discuss about what Olas is uh we're going to talk a little bit about the prediction agent hackathon and what it is and I'm going to demonstrate how you can run and refine your own prediction agent in order to participate uh so I'm let me yeah I'm adadi zaras um I work as a python engineer at Val Valerie I have a

data science background and Valerie is the company that is behind allas uh so what is Olas Olas uh is an oan of decentralized services for crypto and what kind of services uh these Services range from oracles to AI messaging and more um so Olas uh has a protocol which uh coordinates a community of developers to build those Services um it uses the Olas token um and uh it uses theas token uh and let's see what uh Olas uh is composed of uh so

Olas is a protocol uh and uh this protocol uh on this protocol you can um register your code uh it also coordinates the actors and you can get rewarded uh from from it um it also has an open source framework uh it is the open autonomy framework uh and using this framework you can uh build those services that we mentioned and you can also register code to the protocol and it is it is also an ecosystem of running services and code and those Services provide value to the end users uh so here we're using the

term autonomous Services um and this is the special type of services that runs on allas and we're going to to discuss about this uh now so what is an autonomous service an autonomous service has uh Broad applicability in running uh everything from uh relays messaging uh AI tools uh and more um these uh can be applied in fields such as uh defi nfts uh decentralized social uh Etc um autonomous Services uh offer a unique set of tools uh to developers uh because

they're Crypton native they're flexible and they're intelligent uh they Crypton native uh unlike web services or other centralized Solutions um they're flexible uh unlike Uh current uh contract and oracles automations and they're intelligent and capable uh of running powerful and long running computation uh an autonomous service has a robust architecture and you can see on a high level the architecture on the picture on the right uh so the service is in the middle and you can see the service consists of multiple

agents um each agent is operated by a different entity and those Services can perform uh ex uh computations as we mentioned such as uh they can run AI models and they use tendermint in order to come into consensus about their actions uh the service is represented by an nft uh to the protocol and the Agents of the service can pull data from uh any Source it can be Web Two or web three sources it could be ipfs a ceramic stream anything and they can also submit transactions on chain um and they do that by using a safe MC uh on which uh

each of these agents uh is Aigner uh the Olas oan of services is already in full swing um there are already more than 100 Services uh registered on the protocol uh they have performed more than uh 60,000 transactions um Olas has uh collaborated with some of the uh most reputable names in the space and there are already some services in all of those categories that you can see so um Valerie the company behind doas uh

recently uh collaborated uh with gsis chain and claros um and they participated in order to build a project uh that utilizes the the stack the Ola stack um this project uh I'm going to give you an introduction uh about this project um and why you might want to participate and how you can get easily started uh the project is called the prediction agents hackathon um we have developed uh an autonomous AI agent uh that participates in prediction markets and uh why would we do that um prediction

markets are one of the oldest uh applications uh on the crypto space um however they require expensive human reasoning um staying on top of and making accurate predictions is a costly skill um and uh sorry give me one moment so staying on top of and making accurate predictions is a costly skill and as a result uh prediction markets uh adaptation adoption has uh suffered [Music] um so

um all right um however um with low cost chains like nosis uh with protocols like Olas and with the recent advances in uh AI models um we recognize that there might be a new opportunity uh therefore we set out to uh test whether we could transform the economics of prediction markets by using uh decentralized uh AI agents in order to participate in the prediction markets uh instead of uh humans and therefore uh the prediction

agents hackathon uh was created um you can also get involved in the hackathon uh you just need to clone a repository uh run a simple command and and you're away um you can also uh make changes to your agent strategy in order to to uh uh out compete other agents that are participating in markets and you can also uh submit changes to the code base and get uh rewards uh so the rewards uh are the following uh gnosis chain uh is rewarding uh the best AI Mech tool and

we're going to discuss uh what an AI Mech Tool uh is uh next uh Valor uh is rewarding the best prediction agent adaptation and uh this means uh the best uh code change uh to the agent and claros is rewarding uh the best performing agent so basically the one with the that that produces uh the most uh value for itself um now we're going to discuss about how you can run an agent first uh but first uh allow me to uh introduce you to the I AI Mech concept um so ACH

is an auton autonomous service that we have built um ACH receives requests on chain uh it performs some uh operation like an a running an AI model for example and it posts uh it post the the response on chain as well um the mech service has uh a large set of tools that uh someone can call by making this transaction request on chain um the prediction agent that we're going to discuss about uh is using uh the a specific tool of uh the AI Max in order

to uh run so let's discuss about the steps that the prediction a agent uh does uh on a high level the prediction agent uh first needs to pull uh all the data for the prediction markets from The Omen platform uh next it needs to sample uh one of those markets uh currently it uses uh it samples the the market with the highest liquidity this can uh obviously be improved um next after it has sampled uh one of those markets uh it needs to decide whether whether uh what it should vote for and whether it's

profitable to vote um so it does this by calling the mech tool that we discussed about uh so it sends a prompt that contains the question of the market and the potential choices to the mech tool and the mech tool responds uh the prediction agent uh reads the events on chain and picks up uh the result uh next uh the prediction agent needs to calculate whether uh voting for what the the me proposed is profitable um so after taking that step uh if it is profitable then it it simply votes if it's not pro profitable then it

blacklists this uh prediction market for a configurable amount of time currently for 1 hour um and finally uh after doing those steps it checks uh if it can redeem some of the positions uh to get back some uh rewards now uh let's go to the trader quick start that we have Linked In the presentation as you can see we have set up this repo uh it has all the instruction that you need in order to run your first agent um we simply need need to clone the repository and we also

need to make sure that this the system uh meets those requirements so we need python 3.10 uh poetry a version that's larger or equal to 1.4.0 we need Docker and Docker compos so let's I'll do that on my desktop all right so let's clone the repository is there a different uh SSID than than the

one I think yeah can someone read the password x d 10 all right thanks let me try it

again for so is it supposed to be that way or uh Sor do you want to use my wi uh

sure if if if you're yeah all right oh sorry doesn't I trust you guys all right that was fast all

right now uh we're into the repository uh as you can see the only thing that you need to do is make the script executable and then simply run the the script and let's do that so the first thing we notice is that the script requires an RPC in order to run um so what we suggest is that uh you you get it from get Block uh and this is the reason is because J blog supports a new filter and we haven't spotted yet uh an RPC that supports it and another RPC

that supports it um I have created uh a demo project here for uh for now and we're going to copy this RPC I'm going to input the RPC uh into the script uh the input is H hidden and I'm going to press enter now the script is going to uh basically go through all the steps that are required um it's going to clone uh the trader Repository and it's going to automatically generate uh some addresses uh these are uh the address of the service owner uh that is going to own

the service on the protocol uh that that we are going to meet soon uh the script will do this for us and it also generates uh an address for our agent uh so the script now is waiting for us to fund uh with 5 cents uh the autogenerated address of the operator in order to be able to Mint uh the service to the protocol let's send that amount

all right let's wait for the transaction to be validated all right it's already picked it up uh it has seen the balance so it's started meaning our service so it's first going to go through the activation step for our service then it's going to register the agent instance that it created to that service after registering the agent

instance it's going to deploy the service which is the final step all right so our service is on the protocol uh now uh we need to fund our agent which is going to pay the fees for the transaction and we also need to fund our safe the safe is going to uh basically spend uh the amounts for the bets let's first uh fund our agent instance I'm going to send 0.

sorry I'm going to send 0.5 let's speed this up all right and last I'm going to send some funds to the save

I'm going to send about one XI or 1.5 all right so now we're waiting for the script to pick this up to pick the the balance it's been confirmed let's wait for the script all right great so now it will set up service uh it's going to use Docker for

that and do your compose as you can see it's already started creating the containers it's first creating uh the container for the agent and next it's going to create the container for the tender node of that agent all right so the service is running it's running in the background um as you can see on the Quickstar in the instructions uh there are some commands to get you uh started uh for example you can investigate the logs of the trader um so this might be overwhelming if you

you're just getting started but I'd like to show you H how how this looks and I'm going to remove some uh unuseful uh information and we can focus on the rest all right so let's go to the top uh these are some uh framework related uh things so we're going to focus on the rest um as you can see this is called the update bet round this is where it fetches all the information that we mentioned and you can see here all the markets information next it's the sampling that

I mentioned it it just picked up it just picked one uh Market um next we can see uh the request to the mech so there's a link here if we click you can can see on ipfs the prompt that we sent uh to the tool you can see the tool that we requested to use and there's also some unique ID for our request and next um we can see here that we're sending basically the request to the mech we're sending the transaction and now at this point our service was waiting for for the me to

respond so it basically filters the events and as we can see it picked up the response to our request here we can see the response from the from the machine learning tool from the llm um we can see uh the probability for the yes for the market we can see the probability for the no answer for the market and we can see the confidence uh of the model um we can also see what is called info utility so this is the percentage on information of information that it used uh online in order to make the prediction so what the tool does is it enhances our prompt with information

that it picks from the internet currently it uses the Google API to Fed some news and uh add those to the prompt and yeah 0.6 is the percentage of uh information it used online and the rest is just the knowledge of the uh model um so here we can see what uh what the prediction agent did so it says that it first of all mentions what is the liquidity of the market then it says what's our potential profit uh from placing this bed and it says uh that the profitability the decision

from for the profitability is true so we're placing the BET next uh let me fast forward to that this is the transaction you can see this is our H and let's oh let's take a look at the transaction on NOS scan let me check if you no right there it is now let's see that

transaction if you go to the logs you can see first of all the amount that we sent the amount that we have placed uh the amount of the BET um this is the Market on which we have placed the beted and if you go to the creation of the market to the transaction of the creation of the market you can see what actually which Market was the one that we placed the BET and this is the question that you can see right there um all right so this was uh a high level uh overview of of the logs but there

obviously an easier way to do that uh you can do that only if you want to be on top of uh and uh basically verify for yourself what what's going on but we have created some uh scripts to easily do that uh let me first here you can see the command for stopping your service so let me first do that because it's running in the background so let's stop service why while it's stopping I'm going to show you those commands that I mentioned uh so first of all there's the trades. py script uh let's copy that let's paste that on the

terminal and let's replace with our safe address all right let's paste that here oh I'm already in the repo all right so as you can see from the output uh the script simplifies things a lot uh it outputs a link to the market that we plac the beted so you can see what it was on their UI on the omen UI uh it has the question of the market uh it has the amount that we bet for and

how many conditional tockets uh were bought and we can see the fee that we paid uh to the market and here it says Market not finalized this means that uh it's still running and uh if it's finalized uh then the the the trader agent is going to redeem the amount if if it's if if your position is winning uh to the bottom we can see a a sum summary um we can see how many trades we have we have performed uh we can see the amount that we have invested the fees that we've paid the earnings so far it's zero because no markets uh have been finalized and what amount we have

redeemed uh the next thing I would like to show you is how you can keep track of uh the me requests and responses uh so if you go to the aim. aol. network there's a tab called Mech and here you can see all of the request IDs all of the senders so you can basically find your saves address in the senders and you can see the request data and the delivers for that request so if we see the first one for example you can see the prompt the tool and the unique ID and you you can see the response for that it's that easy you don't need to go through the

logs and last uh if you would like to take a look at what your service is doing you could check the state transitions as it is called so you can run this command and this will print all the transitions on which your service has uh entered uh so you can see that it has completed two periods as as we as we say that it's uh how many times it's repeated the same uh procedure um and you can see that uh it has placed a beted during the first period uh it has

not redeemed anything yet and the same for period one for period two etc etc you can monitor your service easily with command now back to the slides uh so something else that you can do is uh you can improve uh your agent strategy um one uh easy way to do that uh would be by editing uh some environment variables so let's

go to the trader repository so if you take a look at the folder called packages and then the Val The Valor package uh you will see that there's a folder called services with the trader service inside and there's a yaml configuration file inside this yaml you can see a ton of configurations but we can focus on the trader specific ones so an important one is uh the mech tool um here you can see uh which tool is being used by default you can also see the see the BET amount uh so the BET amount depends on

the confidence so intuitively if you take a look uh if the confidence is up to 0.5 uh we don't place a bet but you can play around with these values um so above 0.6 uh we increase uh the values that we P for uh you can also see the BET threshold this is uh the amount uh below which the service is not going to bet because it doesn't consider it to be profitable enough and another important important one is the prompt template um here is the uh prompt that we send uh to the to

the mech tool and as you can see it has some parameters this is uh the question market uh what represents yes and what no because even though the markets are binary it could not it could be uh something different than yes and no it could be blue or green the answer um so it also needs those parameters and these are these are populated uh by the service uh so let's take a look at an example so I'm going to show you uh what I done in my uh

Trader uh so if we open uh the script that I mentioned before in the quick start uh you can see if you go to the bottom you can see that there are some of these environment variables hardcoded in there with some default values so I have changed the prompt template here sorry can a little bit yeah sure right yeah of course is that fine all right uh so as you can see here I have edited the prom template on my service uh so I've changed the The Prompt a bit in as an unbiased QA expert

please provide the probabilities of P yes and Pen no occurring for the question here is the parameter if the yes option is represented by yes and the No Option by parameter no so you only need to change the environment variable in the script and then you can simply let's go to my agent and you can simply run the the the script again the script has already stored the necessary information like the RPC uh your agent address your safe address you don't need to provide

anything again it does the the balance check here so as you can see my agent does not my safe does not have enough balance so let's send some uh D there I'm going to send about one xti when metamask detects the address all right let me do that 0.8

let's make that aggressive all right and now when the service picks this up it's just going to uh spin up the service again and the environment variable will have uh uh changed the prompt that our prediction agent is using so you might see this message uh so this is in order to remove the previous build uh it's safe it's only going to delete these folders that are mentioned here

some Docker related uh information and it's going to regenerate those and as you can see it's already starting right now it's running again let's take a look at this logs starting it's picked up the markets it sampled the market let's wait for the request to the mech it's already been sent here it is

let's take a look at this request let's go to gnos scan paste that has let's see the logs let's see the data let's go to ipfs paste those data and now we can see the prompt as you can see it has changed it's not the prompt that we used previously so uh it's relatively simple to to TW your uh your strategy by editing those environment variables um however um tweaking those environment variables might not uh get you too far

um so in order to improve your strategy you might want to improve your expected uh net profit so the expected net profit profit is defined uh in the foll following way to the service so it is uh the number of tokens that we have obtained the number of tokens uh is a function of the BET amount that we have placed and the market on which uh we have placed the bet the BET amount depends on the confidence so as you can see the confidence plays a big role so by by tweaking uh something that would

change the confidence we could uh end up with a much better expected net profit after calculating the number of tokens we subtract the amount that we used for the bet we subtract the fees such as uh the the value that we paid to the mech for for the response and such as uh the fees that we we uh paid to the prediction Market and finally we subtract this threshold that I mentioned before which was in the configuration and it's there because the user might not want to place a bet if it's below a specific so in order to have a better strategy

you could refine the code in order to improve the confidence and the results from the tool so I'm going to demonstrate how this can be done as you can see this is uh the repository for the me service that I mentioned before um inside the me service there's a folder called Tools in this folder are all the implementations of the tools and here you can see there's one script it's called the prediction request and

this is what uh we are currently using in the prediction agent so let's take a look at this script uh you only need to know how to code in Python and this uh abstracts away uh everything all the knowledge you need to have uh for the framework um let's take a look here uh we can see the the names of the tools that you can you can use uh from this specific script um as you can REM if you remember this was in the request uh that we sent to the mech we can see the prompt that it uses so as you can see it

enhance enhances the prompt a lot it adds uh a lot of things and here is where the users prompt uh is entered and here are the additional information which is uh the data that we fed from the Google News API that I mentioned before and if you go to the bottom you can see the main meth the main function it's called run and all the tools need to implement the run method um let's take a look uh it's relatively simple so what it does is um it first of all uh it it picks some values like hyper parameters Etc like

the temp tempature of the model uh it sets the the the open AI key and some things uh and then what it does is it first fetches uh the additional information from the API we mentioned and then it adds this in the prompt uh here's the user prompt as you can see and here is by the way can you see that or should I zoom in a bit we you to zoom in all right is that okay less less all right is that okay all right um so it creates the

prediction promt by using the users prompt and the additional information and then uh it simply creates uh sends a request to the open AI uh API and gets the response uh so one thing you could do to improve your strategy would be to create a new tool and let's take a look at one of the tools that was submitted recently uh so on a high level what uh they did in this PR is they uh introduced a concept that is called subject M matter expert and and what

they do is they basically enhance the prompt that they sent to chat GPT by using uh specific specialized prompts depending on the subject and how they do that is they first send a request to the open AI in order to understand what the subject is and then they enhance the prompt by using uh this information and send the final prompt that has been edited to open Ai and get the response let's take a quick look at this uh implementation so here as you can see they just uh get

uh this uh configuration of the prompt but let's go to the uh main part of the implementation here is where they generate the subject matter expert prompt and as you can see see it gives some examples for task questions for subject matters and here is how it's going to be uh extended how the prompt is going to be extended and finally let's go to uh the run method uh so as you can see uh the only change that we that that there is in the tool is that now we have

uh this enhanced prompt uh that uh we are using in order to send uh the message to the open AI API uh so after creating your Tool uh then uh you could submit uh a PR we're going to uh review this PR and merge it and we're going to uh we're going to publish uh your tool and then what you can do is let's take a look at the script again uh let's go to the trader repository and here if you remember we

have this uh configuration we have the mech tool here we have an environment variable it's called Mech tool as you can see um and here the value specifies which tool we are going to use so if you open the script here are the environment V variables you can basically put that wherever you want you could even put that on top of the script it doesn't matter so let's export the value of the mech tool let's change it and let's use the subject matter expert one

let me go to main let's go to the tools let's go to the subject matter expert request and here we'll we will copy uh we'll copy any of these tools uh so the normal one uses GPT 3.5 and the strong one uses GPT 4 let's copy the normal one for one for now and we will paste the value uh inside uh inside inside our script and then we let's stop the previous

service first because it's still running and when when the service stops we're going to rerun it and it's going to pick up the new tool oh

now we're running the service and while it's starting uh as we since we're running out of time um let me continue on the presentation and get back to it so today we have we have talked about Olas uh we have discussed about uh what an autonomous service is and about the Olas protocol about the Olas ecosystem we discussed about the prediction agents hackathon and how you

can participate what the prices are and how you can simply participate By changes changing either configurations or developing your own tool and submitting that and uh here you can see a QR code you you can scan it for uh the Olas links and uh it would be nice if you could also uh participate on the survey that we have for the workshop and what you think about it uh it's inside this link let's take a look at the service it's started

and let's see the logs one last time so this is the request ID uh while while this is loading uh would

you like maybe to ask any questions so all right I think we're running out of

time uh and the mech uh needs some time to respond this uh so any questions on how you could create the tools or where you could uh submit it or anything otherwise all right thank you [Applause] and