Phala Network Docs
  • Home
    • 👾Phala Network Docs
  • Overview
    • ⚖️Phala Network
      • 💎Phala Cloud
      • 🥷Dstack
      • 🔐GPU TEE
    • 💎PHA Token
      • 🪙Introduction
      • 👐Delegation
        • Delegate to StakePool
        • What is Vault
        • What is Share
        • WrappedBalances & W-PHA
        • Examples of Delegation
        • Use Phala App to Delegate
        • Estimate Your Reward
      • 🗳️Governance
        • Governance Mechanism
        • Join the Council
        • Voting for Councillors
        • Apply for Project Funding
        • Phala Treasury
        • Phala Governance
        • Setting Up an Account Identity
  • Phala Cloud
    • 🚀Getting Started
      • Create Your Phala Cloud Account
      • Your First CVM Deployment
      • Explore Templates
        • Launch an Eliza Agent
        • Start from Template
    • 🪨TEEs, Attestation & Zero Trust Security
      • Attestation
      • Security Architecture
    • 🥷Phala Cloud User Guides
      • Deploy and Manage CVMs
        • Deploy CVM with Docker Compose
        • Set Secure Environment Variables
        • Deploy Private Docker Image to CVM
        • Debugging and Analyzing Logs
          • Check Logs
          • Private Log Viewer
          • Debug Your Application
        • Application Scaling & Resource Management
        • Upgrade Application
        • Deployment Cheat Sheet
      • Building with TEE
        • Access Your Applications
        • Expose Service Port
        • Setting Up Custom Domain
        • Secure Access Database
        • Create Crypto Wallet
        • Generate Remote Attestation
      • Advanced Deployment Options
        • Deploy CVM with Phala Cloud CLI
        • Deploy CVM with Phala Cloud API
        • Setup a CI/CD Pipeline
    • 🚢Be Production Ready
      • CI/CD Automation
        • Setup a CI/CD Pipeline
      • Production Checklist
      • Troubleshooting Guide
      • Glossary
    • 🔒Use Cases
      • TEE with AI
      • TEE with FHE and MPC
      • TEE with ZK and ZKrollup
    • 📋References
      • Phala Cloud CLI Reference
        • phala
          • auth
          • cvms
          • docker
          • simulator
      • Phala Cloud API & SDKs
        • API Endpoints & Examples
        • SDKs and Integrations
      • Phala Cloud Pricing
    • ❓FAQs
  • Dstack
    • Overview
    • Getting Started
    • Hardware Requirements
    • Design Documents
      • Decentralized Root-of-Trust
      • Key Management Service
      • Zero Trust HTTPs (TLS)
    • Acknowledgement
    • ❓FAQs
  • LLM in GPU TEE
    • 👩‍💻Host LLM in GPU TEE
    • 🔐GPU TEE Inference API
    • 🏎️GPU TEE Benchmark
    • ❓FAQs
  • Tech Specs
    • ⛓️Blockchain
      • Blockchain Entities
      • Cluster of Workers
      • Secret Key Hierarchy
  • References
    • 🔐Setting Up a Wallet on Phala
      • Acquiring PHA
    • 🌉SubBridge
      • Cross-chain Transfer
      • Supported Assets
      • Asset Integration Guide
      • Technical Details
    • 👷Community Builders
    • 🤹Hackathon Guides
      • ETHGlobal Singapore
      • ETHGlobal San Francisco
      • ETHGlobal Bangkok
    • 🤯Advanced Topics
      • Cross Chain Solutions
      • System Contract and Drivers
      • Run Local Testnet
      • SideVM
    • 🆘Support
      • Available Phala Chains
      • Resource Limits
      • Transaction Costs
      • Compatibility Matrix
      • Block Explorers
      • Faucet
    • ⁉️FAQ
  • Compute Providers
    • 🙃Basic Info
      • Introduction
      • Gemini Tokenomics (Worker Rewards)
      • Budget balancer
      • Staking Mechanism
      • Requirements in Phala
      • Confidence Level & SGX Function
      • Rent Hardware
      • Error Summary
    • 🦿Run Workers on Phala
      • Solo Worker Deployment
      • PRBv3 Deployment
      • Using PRBv3 UI
      • PRB Worker Deployment
      • Switch Workers from Solo to PRB Mode
      • Headers-cache deployment
      • Archive node deployment
    • 🛡️Gatekeeper
      • Collator
      • Gatekeeper
  • Web Directory
    • Discord
    • GitHub
    • Twitter
    • YouTube
    • Forum
    • Medium
    • Telegram
Powered by GitBook
LogoLogo

Participate

  • Compute Providers
  • Node
  • Community
  • About Us

Resources

  • Technical Whitepaper
  • Token Economics
  • Docs
  • GitHub

More

  • Testnet
  • Explorer
  • Careers
  • Responsible Disclosure

COPYRIGHT © 2024 PHALA.LTD ALL RIGHTS RESERVED. May Phala be with you!

On this page
  • Phala's WASM Runtime (Wapo)
  • Why Wapo?
  • WapoJS

Was this helpful?

Edit on GitHub
  1. Legacy

AI Agent Contract

Last updated 1 month ago

Was this helpful?

WARNING

This section is no longer recommended for deploying on Phala. To build and deploy securely and efficiently, please use the fully managed platform instead. Check out the doc on how to .

This section will dive into the technical specifications of the AI Agent Contract's execution. All content will focus on the off-chain components that allow for developers to host their Agent scripts or general purpose JS programs on Phala Network as a serverless backend.

Phala's WASM Runtime (Wapo)

The AI Agent Contract is served through Phala's gateway (https://wapo-testnet.phala.network/ipfs/<cid>) and executes in a TEE compute node on Phala Network. Phala enables the execution of JS programs through a custom built WASM runtime called Wapo.

Wapo is a poll-based async WebAssembly runtime that provides extended networking support for guest WASM applications. It originated as a module called SideVM in Phala PRuntime, now independent, and the execution engine has been switched from wasmer to wasmtime.

Why Wapo?

Wapo is mainly designed as the next version of the AI Agent Contract execution engine. However, it can be used as a general-purpose WebAssembly runtime with networking support. The AI Agent Contract execution engine today is based on Substrate's pallet-contracts, which is not flexible enough and also has many limitations. Here is the table of comparison between 2.x and 3.0:

AI Agent Contract 2.0

AI Agent Contract 3.0

Program Type

WebAssembly

WebAssembly

VM Engine

wasmi

wasmtime (faster)

Incoming Networking

Query RPC

Query RPC or Listening on TCP port

Outgoing Networking

HTTP requests (with time and size limit)

Arbitrary TCP connections

Execution mode

Transaction/query-based, 10s limit

Long-running or query-based, no tx

App Memory

4MB for ink / 16 MB for JS

Up to 4GB due to wasm32 limit

With the enhancements with Wapo, Phala has taken the next steps to port the QuickJS implementation to execute in Wapo runtime called WapoJS.

WapoJS

WapoJS is an upgrade from the previous JS runtime called SideVM QuickJS. With this upgrade, developers can push the boundaries with their general-purpose JS programs with a faster response time vs the previous implementation.

Feature
SideVM QuickJS
WapoJS

VM Memory

16MB

100MB (default) Up to 4GB

Maximum Execution Time

60 seconds (default) to unlimited

60 seconds (default) to unlimited

HTTP Request API

Websockets

Not Supported

Supported (not enabled, yet)

Concurrent Requests

Fully supported

Fully supported

Execution Speed

Fast

Faster

SCALE codec API

Sidevm.SCALE

Wapo.SCALE

Max Code Size

500KB

Unlimited (Could be limited by streaming receiving from fetch + AbortController)

Limited CPU Burst

CPU time between async calls is limited. e.g. Too complex for-loop may hit the burst limit.

CPU time between async calls is limited. e.g. Too complex for-loop may hit the burst limit.

Asynchronous API

Asynchronous API

For more information or inquries about increasing some resource limits, reach out the Phala Network team on .

🥷
discord
fetch
fetch
Phala Cloud
get started