Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Rust WASM Agent

Build an agent in Rust using the akshi-sdk crate. This is the most direct path with full type safety and the smallest binary size.

Prerequisites

  • Rust toolchain with the wasm32-wasip1 target
  • Akshi CLI installed
rustup target add wasm32-wasip1

Create the project

akshi create agent my-agent --lang rust
cd my-agent

This scaffolds a Cargo project with the SDK dependency and WIT bindings pre-configured.

Project structure

my-agent/
  Cargo.toml
  src/
    main.rs
  wit/
    deps/         # akshi WIT interfaces (auto-managed)
    world.wit     # agent world definition

Write agent logic

Edit src/main.rs:

#![allow(unused)]
fn main() {
use akshi_sdk::prelude::*;

struct MyAgent;

impl Agent for MyAgent {
    fn tick(&mut self, ctx: &Context) -> Result<()> {
        let prompt = "Summarize recent activity.";
        let response = ctx.infer(prompt)?;
        ctx.journal_insert("summary", &response)?;
        Ok(())
    }
}

export_agent!(MyAgent);
}

The tick method runs each time the runtime schedules the agent. Use ctx to access host capabilities: inference, journal, HTTP fetch, and more.

Build

cargo build --target wasm32-wasip1 --release

The output is at target/wasm32-wasip1/release/my_agent.wasm.

Configure

Add the agent to runtime.toml:

[[agents]]
name = "my-agent"
wasm_path = "target/wasm32-wasip1/release/my_agent.wasm"
tick_interval_secs = 60
fuel_limit = 1_000_000

[agents.capabilities]
inference = true
journal = true

Run

akshi run

Check status with akshi status or open the dashboard at http://127.0.0.1:3210.

Next steps