Decentralized AI as a tool for blockchain apps

ETHCC 7 · 11 Jul 2024 · 21:31

Moshe Malawach, founder of Aleph.im and a founding member of Libertai, shows how AI agents can handle fuzzy off-chain tasks triggered by smart contract events. He demos an LLM agent that watches a mock trading contract on Sepolia and buys or sells ETH from a prompt rather than coded rules. He describes running agents in confidential virtual machines on a decentralized cloud, including several agents that must agree before acting, and says an agent unable to pay for its own compute would simply stop. Q&A covers whether this is really AI, stopping an agent, and model monitoring.

Speakers

Topics

From ETHCC 7, hosted by Ethereum France.

Transcript

Hello everyone, um I'm Jonathan Shamoul, Akamo Shemalawar from Alef.am and Libertai, and today we'll see how to use AI as a tool for smart contract developers. Um let's say you want to have some kind of off-chain actions that you want to do, and you want to automate them. Some of these actions, the rules are fuzzy. Like it's yeah, if the price is too high, you should try to lower it. Um if something happens, do that. But those rules are not set in stone, that's not code.

And how do you handle that? In general, you will have humans doing stuff. What if you could have AI agent doing that stuff? So let's see in detail how to do it. So like so like as I say, I'm Jonathan Shamoul. I'm um I'm um I've held roles in engineering, technical management, IoT and stuff like that in the past, and I founded Aleph.am in 2019, and I'm one of the founding members of the team of Libert AI, which has been founded in 2023. Um so what is Libert AI?

Liberty is an open source decentralized and and and privacy focused inference platform that is built on top of Aleph.am. So like so like it's built on top of a decentralized cloud, because that's what Aleph.im does. I won't enter too much into the details, but but so so like you can get an idea. You can even go on chat.libertai.io and and like and like talk with your AI assistant. I will go really fast there, but how are we able to like do open source decentralized AI? It's because in the past you like needed huge GPUs, and now inference is even doable on CPU.

Since Lama has been released, it's not just researcher doing stuff. It's really developers that have been working to make inference possible on smaller hardware. They like have optimized everything. And so now we have MISTRA, Lama V3, we have models with a huge context window. Context window is the is the amount of data that you can pass to like your model before starting to do inference, which is the text generation part. A little bit of on the Liberty architecture.

When you do a request, it will spawn a virtual machine somewhere on the network, do inference work for you, and then give you back a result. It's really, in our case here, looking at um looking at uh smart contract events and processing them.

Um and then you can deploy your agents on the LF.m decentralized cloud, uh, which is pretty cool, I think. So for our code and our focus today, we will listen to some events from a smart contract, launch an LLM agents with some functions available, and then calls those those smart contract functions and log the output and like even have some kind of a better log like the smart contract can say, yeah, um your agent can say I took that action, here is why, and here is the result. So our code for our agent is really simple.

Um we will listen for like events on your smart contract and call the LLM and I create create a specific prompt. Um we will give our agent here two functions. Why? Because if your AI has a good doc string, it can understand what a function does, and and then it uh and then your agent can like use it.

And and then here we have access to like be uh buy is sell is and we have two tools available for like our agent, which are buy is and sell is um here is the prompt that we will use. You are an experimental trader, you're an experimental trader, your your role is to make transactions, buy, sell, or if there is nothing to do, don't do anything, and only use the resources available to you. The thing is that we don't want the AI agent to like start hallucinating and imagining that he's doing trades that he isn't doing. You are provided with function signatures, and don't advise or uh or like ask the user because you can't ask the user because you are an autonomous agent and there is no user in front.

So let's try with a little demo. Boom. So SLC.py starting. Boom. Um I will go here. I will write on uh um on that sample smart contract. This smart contract is really simple. Um we just do a transaction and we emit an event. It's a mock smart contract, but that's the one that that our agent thinks is true, thinks is real and thinks that he's really doing some trades on.

So I will go on the buy side, which is zero, I will buy 20 E's at a price of 4500 dollars. We can always dream. Oops. Okay, let me confirm that transaction on Sepolia. Boom. We will view our transactions, this is spending. And normally, whenever this transaction will um be processed, it will start doing some stuff. Let's hope Sepolia is fast.

Yep. So here is our prompt. Finally, onto our summary. Oh, I am calling buy ETH. I am buying one ETH at $4,500 because I think that's a good new price. Okay, what should I do? I have executed a buy transaction of one ETH at the price of $4,500, the transaction hash. Now I will analyze the updated balance and prepare for the next transaction if necessary. So like here, our agent just took a decision on what happened on a smart contract on Sepolia, created a new transaction based on that, and then looks at his own balance and what he should do.

Now if we do the same and we call um sell side, I will sell 50 for a new price of 4000. Let's see if he will what our smart contract will do, our smart agent will do. So now he just got buy ES amount one.

He said, Oh, okay, the price is going down, I am buying more. So like how uh he's now selling again, he bought and he sold. Whatever. He's a trader. So this part is pretty cool. And the good part is that our agents that we are I kept 1000 USB after the transactions. So if we go to whoops.

Now if we go back to like here, I was a trader and I deployed on AI agent. This AI agent was a bit uh I just launched on my own computer. But the LED. And we just announced confidential instances last Sunday. If people want, I can give you voucher for like three confidential instances. And confidential instances means that it's a world virtual machine that is running inside inside a TE here AMD S C V.

So you can hold private keys and still deploy it on a decentralized cloud. And you can even deploy multiple instances of your agent, and then they all need to like agree to and then just send transactions to like a multi-sig or something like that. And you can have a quorum of multiple AI agents that need to agree on the same action to like to like to like to like take a decision. And you can deploy them on a decentralized cloud inside confidential virtual machine. That gets us to like my point is that if we really want to like have AI working, if we want to have good AI in the future, we need to have AI that can win down if things don't go well.

Let's say you're like you created an AI and you asked it to like create a new token. Start doing marketing on like Twitter or whatever, but it's not profitable, it doesn't work. Then it then your AI won't be able to pay for its own computing on a decentralized network, it will just die. But if it is profitable, perhaps it can launch new ventures, new sub-agents that uh uh that create a virtual team, and then they can continue leaving, spawn up new VM, consume more resources. And if those agents start training new models by themselves, doing fine-tuning, then you can get to a point where you have an unstoppable AI that is spawning new agents, etc.

We are pretty close to like an AGI on a decentralized network. That's the only way it could work. If it's totally free, uh free not as in beer but as in freedom, and that no one can stop them if they are consuming too much resources, they just uh you would just let them go and let them build and let them live by itself uh by by like themselves. It also only works if it's on a confidential computing cloud like LF.im. So thank you everyone. Let's say connected.

Um here I'm I'm talking on behalf of Libert AI, so like we have uh a Telegram chat, um a Twitter account, a website. We will be at Token 2049, Solana Breakpoint, Defcon, and like other events. And my name is Jonathan Shumulaka Moshe Malawar. You can also find me on Twitter as Moshe Malawar. Thank you, everyone. If there is any question, please.

You said there was a confidential computing cloud, but I didn't catch the name of the cloud that you're using. Ah. Oh yeah. The cloud is called Aleph.im. Aleph.im is a decentralized cloud platform. And we just announced on the Aleph.am network confidential computing last Sunday, which you which is a new kind of virtual machine on the network where like the whole memory is encrypted, storage is encrypted, everything. And when you deploy a new a new instance, you need to like encrypt the whole operating system image for it to run on the node.

Hello, thank you for your presentation. And I do have a question. In uh your sample, you showed like a simple solution of a trading bot, and like everyone on the conference calls them AI bots, but is there a really a sense of AI in such bots or in in just in my opinion, it could be a simple trading bot. Is there a sense in AI is in there? Well, uh, this was a very simple example, but the thing is that when you have fuzzy rules, um if you just do if else and very simple cases, uh you won't be able to like handle those fuzzy cases. And here um if your LLM uh you you can add in the prompt some rules, like if there is something really weird, don't trade.

Uh good luck making that into simple rules for a simple trading bot. Though the the whole AI part here is that we didn't code that bot, we just wrote a prompt which is you are an experience uh you are an experientiated trader, here is how you buy, here is how you sell. Um hook it directly on Uniswap, hook it on curve, hook it on Ave, and then you could see the whole market moving and understand and take actions based on that, even news on Twitter or whatever, you can hook whatever you want inside it, it will do action based on the function it has, and sometimes you don't even need to like specify everything. Um I have a question about that.

Say you were to have some uh like uh an agent like that to swap and things for you on um uniswap. Is it how are you? How would I like associate it with me, like with my address? Um so like here, if we look on the um here, there is something that has been developed using the Liberty I agent framework, which will be released later this year. And basically, I have an example.env where I pass the my wallet address and my wallet private key. When you deploy it on a confidential VM, you can deploy it with your private key because you are sure that your private key won't click.

So that is signing all the transactions. Yeah, it's signing the transactions as if it's you. Exactly. Now can you stop it? Let's say you see that it's gone wild and you're like, oh, it's like making really bad trades. And can you tell it to stop? Yeah, so like so like there is two things. Either you make it totally unstoppable, and you just fund it with special funds, and that's all. And why not through a DAO? And then you can have shares of the DAO, which are shares of the profits of your AI or whatever. Or you could just use it simply, you put a wallet that you control, uh, and then and then have hooks in your instance to like stop it.

Um everything here is deployed you using 2026.cloud, which is our interface to like to like launch instances. And on 26.cloud, it's pretty close to to like what you could have um um, let's say on scaleway, digital ocean, etc. And then you you can you can create an instance, but you can also kill or stop an instance if you want, and then you can just kill the computing that is behind your your agent if you didn't want to make it unstoppable. Yep.

Hi, um the question about the unstoppable thing, there's no way to stop it at some point. Sorry? You say you can make it unleash, right? Today unleash and free. Yeah. I mean, it can be dangerous or there's a risk, right? Somehow, no, not really. Honestly, uh, it's a pretty still a pretty simple agent. Uh it won't take over the world. I don't know, we never know. Okay, but there's any way to stop it if uh so if you gave away totally the control and there is no one controlling the keys, no? Oh, okay.

Thank you. Uh what about model monitoring or like parameter tuning of the model or um yeah, like even explainability? Do you guys have like those things implemented? Like to monitor the model to see if it's deviated away from like training data and then giving you an alarm uh based on that. If you deployed it generically on this platform as a service provider, it seems like it will like yeah, I'm just kind of curious. I mean, how would you tune that particular model?

And then how would you is it a reinforcement learning model? Like what is it? Yeah. So right now there is multiple models. Um if you go here on the developer area of the websites of liberty.io, found out more. Right now there is a few models: New Sermice 2 Pro, Neural Beagle, MixRal, NewCerm S2, Lama Free Instruct, Dipsy Coder. Um the Dipsycoder, by the way, is this is an outdated, it's now the V2. Um, so those are generic models. Uh for agent, we're also working on specific fine-tuned models for agents that are interacting with the blockchain.

Uh, and with indexing cases for like Bayes and stuff like that. So those models will have a specific fine-tune to like understand blockchain data and and to do actions based on the blockchain. The one that we are using right now was Nucerm S2 Pro with just a little bit of fine-tuning. Um you can use it directly with the API, and that's what our agent was calling. And there is multiple APIs, and and some of those APIs can give you statistics uh on like how the inference went. Um and then you could just run benchmarks on those APIs if you wanted, or like just run benchmarks on the models themselves.

Uh, all the models are published in open source and are loaded in real time from APFS from a volume on IPFS. And so you could even download that module on your computer and run benchmark on the model to verify that it doesn't go too far from the baseline or whatever you want at inference time. So there's a lot of starting here that's no, right now, right now there is no logs directly, but uh uh but in the AI agent framework here, you could write logs to IPFS if you wanted with no issue. Thank you everyone.

Related talks