Golem add secret moonbit

From golemcloud/golem · View interactive version

Golem add secret moonbit is an AI agent skill from the GitHub repository golemcloud/golem. Adding secrets to MoonBit Golem agents. Use when the user asks to add secret values, API keys, or sensitive configuration to a MoonBit agent.

How to use this skill

Skill file

Adding Secrets to a MoonBit Agent

Overview

Secrets are sensitive configuration values (API keys, passwords, tokens) stored per-environment and accessed at runtime via @config.Secret[T] from the Golem MoonBit SDK. Unlike regular config fields, the config value carries an opaque secret handle and plaintext is revealed only when agent code calls .get(). Manage secrets via the CLI. Use secretDefaults in golem.yaml only for development placeholders; never commit real credentials.

Declaring Secrets in a Config Struct

Use @config.Secret[T] for secret fields inside a #derive.config struct:

#derive.config
pub(all) struct MyAgentConfig {
  name : String
  api_key : @config.Secret[String]
  db : DbConfig
}

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

Wiring Secrets Into The Agent Constructor

Secrets use the same typed config mechanism as regular agent config. Receive the config via @config.Config[T] in the constructor:

#derive.config
pub(all) struct MyAgentConfig {
  api_key : @config.Secret[String]
}

#derive.agent
struct MyAgent {
  config : @config.Config[MyAgentConfig]
}

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

pub fn MyAgent::connect(self : Self) -> String raise @common.AgentError {
  let _api_key = self.config.value.api_key.get()
  // Pass the credential only to the private provider adapter, never to a response or log.
  "Credential available"
}

Reading Secrets at Runtime

Call .get() on a Secret[T] to explicitly reveal the value. It raises @common.AgentError; declare that error on synchronous callers or catch it. Import "golemcloud/golem_sdk/interface/golem/agent/common" @common and "golemcloud/golem_sdk/config" @config in moon.pkg. Secrets are lazily loaded, so a fresh .get() call can observe updated values after the update is visible:

pub fn MyAgent::connect(self : Self) -> String raise @common.AgentError {
  let config = self.config.value
  let _api_key = config.api_key.get()
  let _db_password = config.db.password.get()
  "Credentials available"
}

Managing Secrets via CLI

Secrets are environment-scoped — each deployment environment has its own set of secret values.

# Create secrets in the current environment
golem secret create apiKey --type String --value "sk-abc123"
golem secret create db.password --type String --value "s3cret"

# Without a value option the value is prompted for (hidden input); or pipe it in
printenv DB_PASSWORD | golem secret create db.password --type String --value-stdin

# Create, or update the value if the secret already exists
golem secret create apiKey --type String --value "sk-abc123" --update-existing

# List all secrets
golem secret list

# Update a secret value
golem secret update apiKey --value "new-value"

# Remove a secret value
golem secret update apiKey --unset

# Delete a secret (asks for confirmation; --yes skips it)
golem secret delete apiKey

Note: For update and delete, you can also use --id <uuid> instead of the positional path.

Secret Defaults in golem.yaml

For local development convenience, set placeholder defaults under secretDefaults.<environment>. The CLI selects defaults by environment name, with no production exclusion. Keep defaults development-only and never commit real credentials. Use the CLI for production secret values:

secretDefaults:
  local:
    apiKey: "dev-key-123"
    db:
      password: "dev-password"

Key Points

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.