Skip to content

Commit d63f9dc

Browse files
authored
Merge pull request #1560 from oasisprotocol/matevz/feat/trustless-agent-doc
docs: add Trustless AI guide
2 parents 4eedf19 + eb67647 commit d63f9dc

File tree

5 files changed

+249
-14
lines changed

5 files changed

+249
-14
lines changed

docs/build/README.mdx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ right into it, check out our use cases that combine TEE and blockchain to
1313
build trustless distributed apps.
1414

1515
<DocCardList items={[
16-
findSidebarItem('/build/use-cases/price-oracle'),
17-
findSidebarItem('/build/use-cases/tgbot'),
1816
findSidebarItem('/build/use-cases/key-generation'),
17+
findSidebarItem('/build/use-cases/trustless-agent'),
18+
findSidebarItem('/build/use-cases/tgbot'),
19+
findSidebarItem('/build/use-cases/price-oracle'),
1920
]} />
2021

2122
## The Oasis SDK

docs/build/use-cases/price-oracle.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ confidential smart contract on [Oasis Sapphire].
1818

1919
This guide requires:
2020
- a working Docker (or Podman),
21-
- [Oasis CLI] and
22-
- at least 120 TEST tokens in your wallet.
21+
- **Oasis CLI** and at least **120 TEST** tokens in your wallet
22+
(use [Oasis Testnet faucet]).
2323

2424
Check out the [Quickstart Prerequisites] section for details.
2525

2626
[Quickstart Prerequisites]: ../rofl/quickstart.mdx#prerequisites
27-
[Oasis CLI]: https://github.com/oasisprotocol/cli/blob/master/docs/README.md
27+
[Oasis Testnet faucet]: https://faucet.testnet.oasis.io
2828

2929
## Init App
3030

31-
First we init the basic directory structure for the app using the [Oasis CLI]:
31+
First we init the basic directory structure for the app using the Oasis CLI:
3232

3333
```shell
3434
oasis rofl init rofl-price-oracle

docs/build/use-cases/tgbot.mdx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
description: Build a private Telegram bot running in ROFL containing a simple python script and an Ollama LLM.
3-
tags: [ROFL, secrets]
3+
tags: [ROFL, AI, secrets]
44
---
55

66
import Tabs from '@theme/Tabs';
@@ -18,18 +18,17 @@ protected by the Trusted Execution Environment and the Oasis blockchain!
1818
This guide requires:
1919
- a working python (>3.9)
2020
- a working Docker (or Podman),
21-
- [Oasis CLI] and
22-
- at least 120 TEST tokens in your wallet.
21+
- **Oasis CLI** and at least **120 TEST** tokens in your wallet
22+
(use [Oasis Testnet faucet]).
2323

2424
Check out the [Quickstart Prerequisites] section for details.
2525

2626
[Quickstart Prerequisites]: ../rofl/quickstart#prerequisites
27-
[Oasis CLI]: https://github.com/oasisprotocol/cli/blob/master/docs/README.md
27+
[Oasis Testnet faucet]: https://faucet.testnet.oasis.io
2828

2929
## Init App
3030

31-
First we init the basic directory structure for the app using the [Oasis
32-
CLI]:
31+
First we init the basic directory structure for the app using the Oasis CLI:
3332

3433
```shell
3534
oasis rofl init rofl-tgbot
@@ -202,6 +201,5 @@ You can fetch a finished project of this tutorial from GitHub
202201

203202
:::
204203

205-
[oasis-cli-dl]: https://github.com/oasisprotocol/cli/releases
206204
[demo-rofl-tgbot]: https://github.com/oasisprotocol/demo-rofl-tgbot
207205
[Oasis Explorer]: https://explorer.oasis.io/testnet/sapphire/rofl/app/rofl1qpjsc3qplf2szw7w3rpzrpq5rqvzv4q5x5j23msu
Lines changed: 235 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
---
2+
description: Deploy a trustless Eliza AI agent on Oasis using ROFL enclaves,
3+
with enclave-managed keys and on-chain verification on Sapphire.
4+
tags: [ROFL, AI, appd, secrets]
5+
---
6+
7+
import Tabs from '@theme/Tabs';
8+
import TabItem from '@theme/TabItem';
9+
10+
# Trustless AI Agent
11+
12+
Learn how to deploy a trustless Eliza agent on Oasis using ROFL enclaves.
13+
14+
## What You’ll Build
15+
16+
By the end you will have a working Eliza agent running inside a ROFL Trusted
17+
Execution Environment (TEE), registered and validated as a trustless agent in
18+
the [ERC-8004] registry. The agent's code can be fully audited and proved that
19+
the deployed instance really originates from it and cannot be silently altered.
20+
21+
[ERC-8004]: https://eips.ethereum.org/EIPS/eip-8004
22+
23+
## Prerequisites
24+
25+
You will need:
26+
- **Docker** (or Podman) with credentials on docker.io, ghcr.io or other
27+
public OCI registry
28+
- **Oasis CLI** and at least **120 TEST** tokens in your wallet
29+
(use [Oasis Testnet faucet]).
30+
- **Node.js 22+** (for Eliza and helper scripts)
31+
- **OpenAI** API key
32+
- **RPC URL** for accessing the ERC-8004 registry (e.g. Infura)
33+
- **Pinata JWT** for storing agent information to IPFS
34+
35+
Check [Quickstart Prerequisites] for setup details.
36+
37+
[Quickstart Prerequisites]: ../rofl/quickstart#prerequisites
38+
[Oasis Testnet faucet]: https://faucet.testnet.oasis.io
39+
40+
## Create an Eliza Agent
41+
42+
Initialize a project using the ElizaOS CLI and prepare it for ROFL.
43+
44+
```shell
45+
# Install bun and ElizaOS CLI
46+
bun --version || curl -fsSL https://bun.sh/install | bash
47+
bun install -g @elizaos/cli
48+
49+
# Create and configure the agent
50+
elizaos create -t project rofl-eliza
51+
# 1) Select Pqlite database
52+
# 2) Select the OpenAI model and enter your OpenAI key
53+
54+
# Test the agent locally
55+
cd rofl-eliza
56+
elizaos start
57+
# Visiting http://localhost:3000 with your browser should open Eliza UI
58+
```
59+
60+
## Containerize the App and the ERC-8004 wrapper
61+
62+
The Eliza agent startup wizard already generated the `Dockerfile` that packs
63+
your agent into a container.
64+
65+
Next, we'll make sure that the Eliza agent is registered as a trustless agent in
66+
the ERC-8004 registry. A helper image called [`rofl-8004`] will do the
67+
registration for us. Create the following `compose.yaml` file:
68+
69+
```yaml title="compose.yaml"
70+
services:
71+
rofl-eliza:
72+
build: .
73+
image: docker.io/YOUR_USERNAME/rofl-eliza:latest
74+
platform: linux/amd64
75+
environment:
76+
- OPENAI_API_KEY=${OPENAI_API_KEY}
77+
ports:
78+
- "3000:3000"
79+
volumes:
80+
- eliza-storage:/root/.eliza
81+
82+
rofl-8004:
83+
image: ghcr.io/oasisprotocol/rofl-8004@sha256:2226a17a56420c271362ca7874d243efb63ddafb608b661f488c10e54bc24f63
84+
platform: linux/amd64
85+
environment:
86+
- RPC_URL=${RPC_URL}
87+
- PINATA_JWT=${PINATA_JWT}
88+
volumes:
89+
- /run/rofl-appd.sock:/run/rofl-appd.sock
90+
91+
volumes:
92+
eliza-storage:
93+
```
94+
95+
Build and push:
96+
97+
```shell
98+
docker compose build
99+
docker compose push
100+
```
101+
102+
For extra security and verifiability pin the digest and use
103+
`image: ...@sha256:...` in `compose.yaml`.
104+
105+
[`rofl-8004`]: https://github.com/oasisprotocol/erc-8004
106+
107+
## Init ROFL and Create App
108+
109+
The agent will run in a container inside a TEE. ROFL will handle the startup
110+
attestation of the container and the secrets in form of environment variables.
111+
This way TEE will be completely transparent to the agent app.
112+
113+
```shell
114+
oasis rofl init
115+
oasis rofl create --network testnet
116+
```
117+
118+
Inspect on-chain activity and app details in the [Oasis Explorer].
119+
120+
## Build ROFL bundle
121+
122+
Eliza requires at least 2 GiB of memory and 5 GB of storage. Update the
123+
`resources` section in `rofl.yaml` accordingly:
124+
125+
```yaml title="rofl.yaml"
126+
resources:
127+
memory: 2048
128+
cpus: 1
129+
storage:
130+
kind: disk-persistent
131+
size: 5000
132+
```
133+
134+
Then, build the ROFL bundle by invoking:
135+
136+
<Tabs>
137+
<TabItem value="Native Linux">
138+
```shell
139+
oasis rofl build
140+
```
141+
</TabItem>
142+
<TabItem value="Docker (Mac/Windows/Linux)">
143+
```shell
144+
docker run --platform linux/amd64 --volume .:/src \
145+
-it ghcr.io/oasisprotocol/rofl-dev:main oasis rofl build
146+
```
147+
</TabItem>
148+
</Tabs>
149+
150+
## Secrets
151+
152+
Let's end-to-end encrypt `OPENAI_API_KEY` and store it on-chain. Also, provide
153+
the `RPC_URL` and `PINATA_JWT` values for ERC-8004 registration.
154+
155+
```shell
156+
echo -n "<your-openai-key-here>" | oasis rofl secret set OPENAI_API_KEY -
157+
echo -n "https://sepolia.infura.io/v3/<YOUR_KEY>" | oasis rofl secret set RPC_URL -
158+
echo -n "<your-pinata-key-here>" | oasis rofl secret set PINATA_JWT -
159+
```
160+
161+
Then store enclave identities and secrets on-chain:
162+
163+
```shell
164+
oasis rofl update
165+
```
166+
167+
## Deploy
168+
169+
Deploy your Eliza agent to a ROLF provider by invoking:
170+
171+
```shell
172+
oasis rofl deploy
173+
```
174+
175+
By default, the Oasis-maintained provider is selected on Testnet that lends
176+
you a node for 1 hour. You can extend the rental, for example by 4 hours by
177+
invoking `oasis rofl machine top-up --term hour --term-count 4`
178+
[command][deploy].
179+
180+
[deploy]: https://github.com/oasisprotocol/cli/blob/master/docs/rofl.md#deploy
181+
182+
## Trying it out
183+
184+
After deploying the agent, use the CLI to check, if the agent is running:
185+
186+
```shell
187+
# Show machine details (state, proxy URLs, expiration).
188+
oasis rofl machine show
189+
```
190+
191+
If the agent successfully booted up, the `Proxy:` section contains the
192+
URL where your agent is accessible on, for example:
193+
194+
```
195+
Proxy:
196+
Domain: m1058.opf-testnet-rofl-25.rofl.app
197+
Ports from compose file:
198+
3000 (rofl-eliza): https://p3000.m1058.opf-testnet-rofl-25.rofl.app
199+
```
200+
201+
In the example above, our app is accessible at
202+
https://p3000.m1058.opf-testnet-rofl-25.rofl.app.
203+
204+
## ERC-8004 Registration and Validation
205+
206+
When spinning up the agent for the first time, the `rofl-8004` service will
207+
derive the ethereum address for registering the agent. You will need to
208+
fund that account with a small amount of ether to pay for the fees.
209+
210+
Fetch your app logs:
211+
212+
```shell
213+
oasis rofl machine logs
214+
```
215+
216+
Then look for `Please top it up` line which contains the derived address.
217+
After funding it, your agent will automatically be registered and validated.
218+
219+
:::warning
220+
221+
Logs are accessible to the app admin and are stored **unencrypted on the ROFL
222+
node**. Avoid printing secrets!
223+
224+
:::
225+
226+
:::example Trustless Agent Demo
227+
228+
You can fetch a complete example shown in this chapter from
229+
https://github.com/oasisprotocol/demo-trustless-agent.
230+
231+
:::
232+
233+
[machine-logs]: https://github.com/oasisprotocol/cli/blob/master/docs/rofl.md#machine-logs
234+
[sdk-deploy-logs]: https://github.com/oasisprotocol/oasis-sdk/blob/main/docs/rofl/workflow/deploy.md#check-that-the-app-is-running
235+
[Oasis Explorer]: https://explorer.oasis.io/testnet/sapphire

sidebarBuild.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ export const sidebarBuild: SidebarsConfig = {
1717
slug: '/build/use-cases',
1818
},
1919
items: [
20+
'build/use-cases/key-generation',
21+
'build/use-cases/trustless-agent',
2022
'build/use-cases/price-oracle',
2123
'build/use-cases/tgbot',
22-
'build/use-cases/key-generation',
2324
]
2425
},
2526
{

0 commit comments

Comments
 (0)