vigoo's software development blog

Golem 1.5 features - Part 15: MoonBit

Posted on April 23, 2026

Introduction

I am writing a series of short posts showcasing the new features of Golem 1.5, to be released at the end of April, 2026. The episodes of this series will be short and assume the reader knows what Golem is. Check my other Golem-related posts for more information!

Parts released so far:

MoonBit support

The new Golem 1.5 release compes with two new supported languages: Scala and MoonBit. An experimental Golem MoonBit SDK has already been released as a separate project for the previous Golem version, but now it becomes a first-class supported language, integrated with our CLI and build flows.

MoonBit is an interesting new language with many nice features. One property that distinguishes it from the other languages we support is that it can compile to very small WASM binaries (and very quickly). This makes a difference in Golem, as the smallest the actual compiled component is, the faster we can instantiate an agent.

As with Scala, we don't have bridge generators and a MoonBit REPL yet, but the TypeScript REPL is fully usable with MoonBit agents as well.

How does it look like?

Let's see how the simplest counter agent example looks like in MooBit:

///|
/// Counter agent in MoonBit
#derive.agent
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 and returns the new value
pub fn Counter::increment(self : Self) -> UInt64 {
  self.value += 1
  self.value
}

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

Agents are structs annotated with #derive.agent, and all public methods are becoming agent methods. The type needs a new constructor that is going to the agent's identity.

Custom data types are supported by annotating them with #derive.golem_schema:

#derive.golem_schema
struct MyData {
  field1: String
  field2: UInt
}

#derive.golem_schema
enum Status {
  Active
  Inactive(String)

Every type used in the constructor or agent methods (either as a parameter or return type) must have a derived Golem schema.

RPC

Agent to agent communication works just like with the other languages - for each agent we have a client type generated:

CounterClient::scoped("my-counter", fn(counter) raise @common.AgentError {
  counter.increment()
  counter.increment()
  let value = counter.get_value()
  value
})

The scoped function is equivalent to calling the get constructor (that in Golem means "get or create if not existing" an agent), and dropping the remote connection in the end.

Exposing HTTP endpoints

As we've seen, Golem 1.5 comes with code-first routes and MoonBit also fully supports this. For example we could expose our counter via a POST endpoint by just adding a few more annotations:

#derive.agent
#derive.mount("/moonbit-counters/{name}")
struct Counter {
 // ...
}

#derive.endpoint(post="/increment")
pub fn Counter::increment(self : Self) -> UInt64 {
  // ..
}

Other features

Every other feature we mentioned in this series is available for MoonBit. The new version of our documentation will have every code snippet presented in all supported languages including MoonBit, and we our skill catalog also have a large number of MoonBit specific agent skills. Until the new documentation site is published, they can be checked in the repo.

Implementation details

The MoonBit SDK consists of two major parts: a code-level transformation tool implemented in MoonBit using the moonbitlang/parser and moonbitlang/formatter packages, and a MoonBit library every Golem application must depend on.

The tool parses the user's source code and finds all the Golem-specific derive attributes, and generates code (typeclass implementations for annotated custom types, agent registration code, RPC clients etc). The SDK encapsulates the generated WASM bindings (using wit-bindgen-moonbit) and presents them as a higher level MoonBit library for the Golem developers.

The whole multi-step build flow is hidden in a golem-managed build template.