Golem add config moonbit

From golemcloud/golem · View interactive version

Golem add config moonbit is an AI agent skill from the GitHub repository golemcloud/golem. Adding typed configuration to a MoonBit Golem agent. Use when the user asks to add configuration, settings, or typed config parameters to a MoonBit agent.

How to use this skill

Skill file

Adding Typed Configuration to an Agent (MoonBit)

The MoonBit SDK has full support for code-first typed configuration via #derive.config, @config.Config[T], and @config.Secret[T], equivalent to the Rust SDK's ConfigSchema / #[agent_config].

1. Define Config Types with `#derive.config`

Annotate record structs with #derive.config. This auto-generates ConfigField trait implementations (via golem_sdk_tools) for schema collection and typed loading. Config types can be nested but must not be generic.

#derive.config
pub(all) struct DatabaseConfig {
  host : String
  port : UInt
  timeout : UInt64
}

#derive.config
pub(all) struct AppConfig {
  app_name : String
  debug : Bool
  database : DatabaseConfig  // nested config type
}

Supported field types

All primitive types that implement ConfigField: String, Bool, Int, UInt, Int64, UInt64, Float, Double, Byte, Char, Bytes, plus T? (optional), Array[T], Result[T, E], and nested #derive.config structs.

2. Inject Config into the Agent Constructor

Add a @config.Config[T] parameter to the agent's new function. The platform loads and validates all config values at agent construction time:

#derive.agent
pub(all) struct MyAgent {
  config : @config.Config[AppConfig]
}

fn MyAgent::new(config : @config.Config[AppConfig]) -> MyAgent {
  { config }
}

Access config values through self.config.value:

pub fn MyAgent::do_work(self : Self) -> Unit {
  let cfg = self.config.value
  if cfg.debug {
    @log.debug("Connected to \{cfg.database.host}:\{cfg.database.port}")
  }
}

3. Add Secrets with `@config.Secret[T]`

Wrap sensitive fields in @config.Secret[T]. Secrets are stored per-environment and fetched dynamically (not snapshot-cached like regular config):

#derive.config
pub(all) struct DatabaseConfig {
  host : String
  port : UInt
  password : @config.Secret[String]  // secret field
}

Access the current secret value with get!():

pub fn MyAgent::connect(self : Self) -> Unit {
  let db = self.config.value.database
  let password = db.password.get!()
  // use password...
}

4. Provide Config Values

In `golem.yaml` (application manifest)

Config values are typed — they match the schema defined in code:

agents:
  MyAgent:
    config:
      app_name: "my-app"
      debug: true
      database:
        host: "localhost"
        port: 5432
        timeout: 30000

Secrets via `secretDefaults` in the manifest

secretDefaults:
  local:
    database:
      password: "{{ DB_PASSWORD }}"

Secrets via CLI

golem secret create database.password --type String --value "pwd"
golem secret update database.password --value "new-pwd"

5. How It Works Under the Hood

  1. #derive.config is processed by golem_sdk_tools (see config_types.mbt and config_emit.mbt).
  2. For each annotated struct, the tool generates ConfigField trait implementations with:
  1. @config.load_config() is called during agent construction, which recursively loads all fields.
  2. Secret[T] fields store only the key path and expected type; the actual value is fetched on each get!() call via @host.get_config_value.
  3. The platform validates that all required config and secrets are provided at deploy time.

Key Constraints

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.