Golem add config rust

From golemcloud/golem · View interactive version

Golem add config rust is an AI agent skill from the GitHub repository golemcloud/golem. Adding typed configuration to a Rust Golem agent. Use when the user asks about agent config, Config<T>, ConfigSchema, #[agent_config], or passing configuration values to agents.

How to use this skill

Skill file

Adding Typed Configuration to an Agent (Rust)

Golem agents can receive typed configuration via Config<T> from golem_rust::agentic::Config. Configuration values are validated against a schema derived from your Rust struct.

1. Define a Config Struct

Derive ConfigSchema on a struct whose fields become config keys:

use golem_rust::ConfigSchema;

#[derive(ConfigSchema)]
pub struct MyAgentConfig {
    pub foo: i32,
    pub bar: String,
    #[config_schema(nested)]
    pub nested: NestedConfig,
}

#[derive(ConfigSchema)]
pub struct NestedConfig {
    pub a: bool,
    pub b: Vec<i32>,
}

2. Add `Config<T>` to the Agent Constructor

Annotate the config parameter with #[agent_config]:

use golem_rust::{agent_definition, agent_implementation};
use golem_rust::agentic::Config;

#[agent_definition]
pub trait MyAgent {
    fn new(name: String, #[agent_config] config: Config<MyAgentConfig>) -> Self;
    fn get_foo(&self) -> i32;
}

struct MyAgentImpl {
    config: Config<MyAgentConfig>,
}

#[agent_implementation]
impl MyAgent for MyAgentImpl {
    fn new(_name: String, #[agent_config] config: Config<MyAgentConfig>) -> Self {
        Self { config }
    }

    fn get_foo(&self) -> i32 {
        self.config.get().expect("config").foo
    }
}

3. Set Config in `golem.yaml`

Provide default values under agents.<Name>.config (or components.<Name>.config):

agents:
  MyAgent:
    config:
      foo: 42
      bar: "hello"
      nested:
        a: true
        b: [1, 2, 3]

Regular config keys in golem.yaml retain Rust field names, including snake_case. Secret paths have separate canonicalization rules.

4. Pass Config via CLI

Override or supply config when creating an agent instance:

golem agent create --keyed 'MyAgent("agent-1")' \
  --config foo=42 \
  --config 'bar="hello"' \
  --config nested.a=true \
  --config nested.b="[1, 2, 3]"

Dot-separated keys address nested struct fields. With --keyed, the command creates the keyed agent of the constructor parameters, so later golem agent invoke 'MyAgent("agent-1")' ... calls reach it; it fails when that agent already exists. Without --keyed, each call creates a new agent without a key, reachable only by the agent ID that the command prints.

5. RPC Config Overrides

When creating an agent via RPC, pass the generated *ConfigRpc type as the config of the async create. upsert takes no overrides:

let agent = MyAgentClient::create(
    name,
    golem_rust::CreateOptions {
        keyed: true,
        config: MyAgentConfigRpc {
            foo: Some(42),
            ..Default::default()
        },
        env: Vec::new(),
    },
)
.await?;

Config Cascade

Config values follow the same cascade as environment variables:

componentTemplates → components → agents, with presets resolved within each template,

component, and agent layer, not as one final global layer.

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.