Skip to content

Rust quick start

Terminal window
act-build init rust my-component
cd my-component
just init

act-build init carries the templates inside the binary — there is no copier, uvx, or Python toolchain involved. Pass --http / --fs to have it declare those capabilities in act.toml for you.

The template sets up Cargo.toml with a current act-sdk, a wit/ directory tracking act:tools (and act:sessions for stateful components) over act:core, a rust-toolchain.toml pinning nightly + wasm32-wasip2, and a justfile with build / test / publish recipes.

src/lib.rs:

use act_sdk::prelude::*;
#[act_component]
mod component {
use super::*;
#[act_tool(description = "Reverse a string", read_only)]
fn reverse(
/// Text to reverse
text: String,
) -> ActResult<String> {
Ok(text.chars().rev().collect())
}
}

The #[act_component] macro generates the WIT tool-provider export. The #[act_tool] macro derives the JSON Schema from the function signature, collects std:* metadata (read_only, idempotent, destructive, timeout_ms), and registers the function with the component’s dispatcher.

Terminal window
just build

This runs:

  1. cargo build --release → target/wasm32-wasip2/release/<name>.wasm
  2. act-build pack <name>.wasm → embeds the act:component custom section (CBOR-encoded metadata) and the contents of skill/ as an Agent Skill tar.
Terminal window
act info target/wasm32-wasip2/release/component_my_component.wasm --tools

Should print your component name, version, and the reverse tool with its auto-derived schema.

Terminal window
just test # e2e suite: pytest driving the component over MCP
act call <wasm> reverse --args '{"text":"hello"}'
Macro / typePurpose
#[act_component]Wraps a module as the act:tools/tool-provider export
#[act_tool(…)]Registers a fn as a tool, emits JSON Schema from the signature + doc comments
ActError / ActResultReturn errors with a std:* kind and localized message
Json<T>Opt into JSON encoding (default is CBOR, per ACT-SPEC)
Content { mime, data }Return raw bytes with an explicit MIME type
#[session_open] / #[session_close]Mark the session lifecycle hooks of a stateful component
ActContext / SessionRegistryPer-call context and per-session state

Agent Skills need no macro: act-build pack embeds a skill/ directory automatically. See Agent Skills.