golem_sdk

    Golem SDK for MoonBit — build durable, fault-tolerant agents on the Golem platform

    golem
    wasm
    agent
    sdk
    webassembly
    durable
    component-model
    Download zip
    Version
    0.5.2
    License
    Apache-2.0
    Last updated
    3 months ago
    Downloads
    41

    #Golem SDK for MoonBit

    Build durable, fault-tolerant agents on the Golem platform using MoonBit.

    #Overview

    This SDK lets you write Golem agents in MoonBit with minimal boilerplate. Agents are compiled to WebAssembly components and run on Golem, which provides automatic durable execution, persistent state, and agent-to-agent communication.

    #Quick Start

    Currently (Golem 1.4.2) the MoonBit SDK is not part of the official Golem release, so there is no built-in MoonBit template to be used with the golem new command. Use the golem_sdk_example1 package in this repository as a template.

    #0. Set up your project from the template

    Copy the golem_sdk_example1 directory and make the following changes:

    #moon.mod.json

    • Change "name" from "golemcloud/golem_sdk_example1" to your module name (e.g. "myorg/my_app")
    • Update "description", "repository", and other metadata fields

    #golem.yaml

    • Change app: from golem-sdk-example1 to your application name (e.g. my-app)
    • Under components:, rename the component key from golem:moonbit-examples: to your component name (e.g. myorg:my-agent:)

    #Component package directory

    • Rename the golem_moonbit_examples/ directory to your component name in snake_case (e.g. my_agent/)
    • The directory name must match the {{ component_name | to_snake_case }} value used in golem.yaml's build commands

    #Agent source files

    • Delete or modify the example agent files (counter.mbt, task_manager.mbt, multimodal_agent.mbt, rpc_example.mbt)
    • The generated files (golem_reexports.mbt, golem_agents.mbt, golem_derive.mbt, golem_clients.mbt) will be regenerated by golem build
    • Add your own agents with #derive.agent structs
    • Make sure you have an empty fn main {} somewhere in the package

    #golem_moonbit_examples/moon.pkg (now your renamed directory)

    • The import and link sections are auto-managed by the reexports codegen tool — no manual changes needed; they will be regenerated on first golem build

    After these changes, run moon install to download dependencies, then golem build to build.

    The MoonBit Golem SDK 0.4.x is ONLY compatible with Golem 1.4.x

    #1. Define an agent

    Annotate a struct with #derive.agent, provide a ::new constructor, and add public methods:

    ///|
    #deriveagent
    struct Counter {
    name : String
    mut value : UInt64
    }

    ///|
    /// Creates a new counter with the given name
    fn Counter::new(name : String) -> Counter {
    { name, value: 0 }
    }

    ///|
    /// Increments the counter
    pub fn Counter::increment(self : Self) -> Unit {
    self.value 1
    }

    ///|
    /// Returns the current value
    pub fn Counter::get_value(self : Self) -> UInt64 {
    self.value
    }

    #2. Use custom data types

    Annotate structs and enums with #derive.golem_schema to make them usable as method parameters and return types:

    ///|
    #derivegolem_schema
    pub(all) enum Priority {
    Low
    Medium
    High
    } derive(Eq)

    ///|
    #derivegolem_schema
    pub(all) struct TaskInfo {
    title : String
    priority : Priority
    description : String?
    }

    #3. Build and deploy

    Use golem build and golem deploy with a golem.yaml application manifest. See the example project for a complete setup.

    #Features

    • Agent registry — register multiple agent types in a single component via #derive.agent
    • Custom data types#derive.golem_schema implements every nexessary trait to use custom data types on the public interface of your agents
    • Agent-to-agent RPC — auto-generated client stubs (CounterClient) with awaited, fire-and-forget, and scheduled invocations
    • Multimodal input — accept mixed text, binary, and custom modality data via #derive.multimodal and Multimodal[T]
    • Unstructured dataUnstructuredText and UnstructuredBinary types with optional language/MIME restrictions
    • Logging — structured logging via @logging.with_name("my-agent") with level filtering
    • Tracing — span-based tracing via @context.with_span(...) with attributes
    • Host API - exports Golem's host API

    #Packages

    PackageDescription
    agentsAgent registry, RawAgent trait, register_agent
    agents/typesUnstructuredText, UnstructuredBinary, Multimodal[T] types
    schemaSerialization traits and impls for primitives, Option, Array, Result
    builderFluent API for constructing WitValue and WitType trees
    extractorTrait-based API for reading values from WitValue trees
    loggingStructured logging with named loggers and level filtering
    contextSpan-based tracing and invocation context
    rpcAgent-to-agent RPC helpers
    interface/WIT-generated bindings (Golem host APIs, WASI interfaces)
    gen/WIT-generated WASM export glue code

    #Code Generation

    This SDK is designed to be used with golemcloud/golem_sdk_tools, which generates the boilerplate code that connects your agent definitions to the Golem runtime:

    • golem_reexports.mbt — re-exports WASM entry points from the SDK
    • golem_agents.mbt — agent registration, constructor deserialization, method dispatch
    • golem_derive.mbt — serialization impls for #derive.golem_schema types
    • golem_clients.mbt — RPC client stubs for agent-to-agent calls

    #Requirements

    • MoonBit toolchain (moon)
    • Golem CLI (golem) version 1.4.x+
    • wasm-tools for component model linking
    • golemcloud/golem_sdk_tools for code generation

    #Documentation

    #License

    Apache-2.0